Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / twoStrokeEngine / twoStrokeEngine.C
blob8eeb6e8016d2a815068bd14910555b6440f2163c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "twoStrokeEngine.H"
27 #include "layerAdditionRemoval.H"
28 #include "componentMixedTetPolyPatchVectorField.H"
29 #include "mapPolyMesh.H"
30 #include "polyTopoChange.H"
31 #include "addToRunTimeSelectionTable.H"
32 #include "GeometricField.H"
33 #include "volMesh.H"
34 #include "engineTime.H"
35 #include "pointField.H"
36 #include "fvPatchField.H"
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 namespace Foam
42     defineTypeNameAndDebug(twoStrokeEngine, 0);
43     addToRunTimeSelectionTable
44     (
45         engineTopoChangerMesh,
46         twoStrokeEngine,
47         IOobject
48     );
52 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
54 bool Foam::twoStrokeEngine::realDeformation() const
56     if
57     (
58         virtualPistonPosition() + engTime().pistonDisplacement().value()
59       > deckHeight() - engTime().clearance().value() - SMALL
60     )
61     {
62         return true;
63     }
64     else
65     {
66         return deformation();
67     }
71 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
73 // Construct from components
74 Foam::twoStrokeEngine::twoStrokeEngine
76     const IOobject& io
79     engineTopoChangerMesh(io),
80     piston_(*this, engTime().engineDict().subDict("piston")),
81     scavInPortPatches_(engTime().engineDict().lookup("scavInPortPatches")),
82     scavInCylPatches_(engTime().engineDict().lookup("scavInCylPatches")),
83     headPointsSetName_(engTime().engineDict().lookup("headPointsSetName")),
84     headCellsSetName_(engTime().engineDict().lookup("headCellsSetName")),
85     movingCellSetName_(engTime().engineDict().lookup("movingCellSetName")),
86     movingPointsMaskPtr_(NULL),
87     deformSwitch_(readScalar(engTime().engineDict().lookup("deformAngle"))),
88     pistonPosition_(-GREAT),
89     virtualPistonPosition_(-GREAT),
90     deckHeight_(GREAT),
91     csPtr_
92     (
93         coordinateSystem::New
94         (
95             "coordinateSystem",
96             engTime().engineDict().subDict("coordinateSystem")
97         )
98     )
101     if(scavInPortPatches_.size() != scavInCylPatches_.size())
102     {
103             FatalErrorIn
104             (
105                 "Foam::twoStrokeEngine::twoStrokeEngine(const IOobject& io)"
106             )   << "The size of the scavenging-cylinder patches is not"
107                 << "the same of the scavenging-port patches"
108                 << abort(FatalError);
109     }
111     forAll (scavInPortPatches_, patchi)
112     {
113         if(boundaryMesh().findPatchID(scavInPortPatches_[patchi]) == -1)
114         {
115             FatalErrorIn
116             (
117                 "Foam::twoStrokeEngine::twoStrokeEngine(const IOobject& io)"
118             )   << "patch called" << scavInPortPatches_[patchi]
119                 << "does not exist"
120                 << abort(FatalError);
121         }
122     }
124     forAll (scavInCylPatches_, patchi)
125     {
126         if(boundaryMesh().findPatchID(scavInCylPatches_[patchi]) == -1)
127         {
128             FatalErrorIn
129             (
130                 "Foam::twoStrokeEngine::twoStrokeEngine(const IOobject& io)"
131             )   << "patch called" << scavInCylPatches_[patchi]
132                 << "does not exist"
133                 << abort(FatalError);
134         }
135     }
137     // Add zones and modifiers if not already there.
138     addZonesAndModifiers();
142 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
144 void Foam::twoStrokeEngine::setBoundaryVelocity(volVectorField& U)
146     vector pistonVel = piston().cs().axis()*engTime().pistonSpeed().value();
148     //  On the piston movingWallVelocity is used.
149     // There is no need to update the piston velocity
151     forAll (scavInPortPatches_, patchi)
152     {
153         const label curPatchID =
154             boundaryMesh().findPatchID(scavInPortPatches_[patchi]);
156         U.boundaryField()[curPatchID] == pistonVel;
157     }
161 // ************************************************************************* //