Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / simpleTwoStroke / simpleTwoStroke.C
blob44017fc0269dde6f904e2fe3f57ec69be27c45fd
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 "simpleTwoStroke.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(simpleTwoStroke, 0);
43     addToRunTimeSelectionTable(engineTopoChangerMesh, simpleTwoStroke, IOobject);
47 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
52 bool Foam::simpleTwoStroke::realDeformation() const
56     if (virtualPistonPosition()+ engTime().pistonDisplacement().value() > deckHeight()-engTime().clearance().value()-SMALL)
57     {
58         return true;
59     }
60     else
61     {
62         return deformation();
63     }
67 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
69 // Construct from components
70 Foam::simpleTwoStroke::simpleTwoStroke
72     const IOobject& io
75     engineTopoChangerMesh(io),
76     piston_(*this, engTime().engineDict().subDict("piston")),
77     scavInCylPatchName_(engTime().engineDict().lookup("scavInCylPatch")),
78     scavInPortPatchName_(engTime().engineDict().lookup("scavInPortPatch")),
79     movingPointsMaskPtr_(NULL),
80     deformSwitch_(readScalar(engTime().engineDict().lookup("deformAngle"))),
81     delta_(readScalar(engTime().engineDict().lookup("delta"))),
82     offSet_(readScalar(engTime().engineDict().lookup("offSet"))),
83     pistonPosition_(-GREAT),
84     virtualPistonPosition_(-GREAT),
85     deckHeight_(GREAT),
86     csPtr_
87     (
88         coordinateSystem::New
89         (
90             "coordinateSystem",
91             engTime().engineDict().subDict("coordinateSystem")
92         )
93     ),
94     foundScavPorts_
95     (
96         boundaryMesh().findPatchID(scavInCylPatchName_) != -1
97         &&
98         boundaryMesh().findPatchID(scavInPortPatchName_) != -1
99     ),
100     scavPortsTol_(readScalar(engTime().engineDict().lookup("scavPortsTol")))
102     // Add zones and modifiers if not already there.
103     addZonesAndModifiers();
107 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
110 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
113 void Foam::simpleTwoStroke::setBoundaryVelocity(volVectorField& U)
115     vector pistonVel = piston().cs().axis()*engTime().pistonSpeed().value();
117     // On the piston movingWallVelocity is used. There is no need to update
118     // the piston velocity
120 //    U.boundaryField()[piston().patchID().index()] = pistonVel;
122     Info << "setting the boundary velocity" << endl;
123     U.boundaryField()[boundaryMesh().findPatchID(scavInPortPatchName_)] ==
124         pistonVel;
128 bool Foam::simpleTwoStroke::portsOpened() const
131     scalar maxScavPortsZ = max
132        (
133            boundary()
134            [
135                boundaryMesh().findPatchID(scavInPortPatchName_)
136            ].patch().localPoints()
137        ).z();
140     scalar minLinerZ = min
141        (
142            boundary()
143            [
144                boundaryMesh().findPatchID(scavInCylPatchName_)
145            ].patch().localPoints()
146        ).z();
149     if (maxScavPortsZ - scavPortsTol_ < minLinerZ)
150     {
151         return false;
152     }
153     else
154     {
155         return true;
156     }
160 // ************************************************************************* //