Forward compatibility: flex
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / thoboisSliding / thoboisSliding.C
blob8d6a727fe564f196a596d39d837e2753ad478526
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
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 Class
25     verticalValvesGambit
27 \*---------------------------------------------------------------------------*/
29 #include "thoboisSliding.H"
30 #include "layerAdditionRemoval.H"
31 #include "attachDetach.H"
32 #include "componentMixedTetPolyPatchVectorField.H"
33 #include "mapPolyMesh.H"
34 #include "polyTopoChange.H"
35 #include "addToRunTimeSelectionTable.H"
36 #include "GeometricField.H"
37 #include "volMesh.H"
38 #include "engineTime.H"
39 #include "pointField.H"
40 #include "fvPatchField.H"
41 #include "Switch.H"
42 #include "symmetryFvPatch.H"
43 #include "tetMotionSolver.H"
45 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
47 namespace Foam
49     defineTypeNameAndDebug(thoboisSliding, 0);
50     addToRunTimeSelectionTable(engineTopoChangerMesh, thoboisSliding, IOobject);
54 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
59 bool Foam::thoboisSliding::realDeformation() const
62     bool deformationValve = false;
63     forAll(valves(), valveI)
64     {
66         scalar maxLayer = piston().minLayer();
68         if(valves()[valveI].bottomPatchID().active())
69         {
70             maxLayer = max(maxLayer, valves()[valveI].minBottomLayer());
71         }
73         scalar valveDisplacement = valves_[valveI].curVelocity()*valves_[valveI].cs().axis().z()*engTime().deltaT().value()  ;
74         if(valvePistonPosition()[valveI] + engTime().pistonDisplacement().value() >
75         valveBottomPosition_[valveI] + valveDisplacement - 5.0*maxLayer - 0.001 )
76         {
77             deformationValve = true;
78         }
79     }
81     if(deformationValve)
82     {
83         return true;
84     }
85     else  if (virtualPistonPosition() + engTime().pistonDisplacement().value() > deckHeight_ - SMALL)
86     {
87         return true;
88     }
89     else
90     {
91         return deformation();
92     }
95 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
97 // Construct from components
98 Foam::thoboisSliding::thoboisSliding
100     const IOobject& io
103     engineTopoChangerMesh(io),
104     piston_(*this, engTime().engineDict().subDict("piston")),
105     valves_(*this, engTime().engineDict().lookup("thoboisSliding")),
106     movingPointsMaskTopPtr_(NULL),
107     movingPointsMaskBottomPtr_(NULL),
108     deformSwitch_(readScalar(engTime().engineDict().lookup("deformAngle"))),
109     valveTopTol_(readScalar(engTime().engineDict().lookup("valveTopTol"))),
110     pistonPosition_(-GREAT),
111     virtualPistonPosition_(-GREAT),
112     valveTopPosition_(nValves(),-GREAT),
113     valveBottomPosition_(nValves(),GREAT),
114     valvePistonPosition_(nValves(),GREAT),
115     deckHeight_(GREAT),
116     minValveZ_(nValves()),
117     poppetValveTol_(readScalar(engTime().engineDict().lookup("poppetValveTol"))),
118     bottomValveTol_(readScalar(engTime().engineDict().lookup("bottomValveTol"))),
119     msPtr_(motionSolver::New(*this)),
120     isReallyClosed_(valves().size(), false),
121     correctPointsMotion_(engTime().engineDict().lookup("correctPointsMotion"))
125     // Add zones and modifiers if not already there.
126     addZonesAndModifiers();
130 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
133 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
136 void Foam::thoboisSliding::setBoundaryVelocity(volVectorField& U)
140     // Set valve velociaty
141     forAll (valves(), valveI)
142     {
144         vector valveVel =
145             valves()[valveI].curVelocity()*valves()[valveI].cs().axis();
147         // If valve is present in geometry, set the motion
148         if (valves()[valveI].curtainInPortPatchID().active())
149         {
150             // Bottom of the valve moves with given velocity
151             U.boundaryField()[valves()[valveI].curtainInPortPatchID().index()] ==
152 //                valveVel;
153                 vector::zero;
154         }
156         // If valve is present in geometry, set the motion
157         if (valves()[valveI].curtainInCylinderPatchID().active())
158         {
159             // Bottom of the valve moves with given velocity
160             U.boundaryField()[valves()[valveI].curtainInCylinderPatchID().index()] ==
161 //                valveVel;
162                 vector::zero;
163         }
165         // If valve is present in geometry, set the motion
166         if (valves()[valveI].poppetPatchID().active())
167         {
168             // Bottom of the valve moves with given velocity
169             U.boundaryField()[valves()[valveI].poppetPatchID().index()] ==
170                 valveVel;
171         }
173         if (valves()[valveI].bottomPatchID().active())
174         {
175             // Bottom of the valve moves with given velocity
176             U.boundaryField()[valves()[valveI].bottomPatchID().index()] ==
177                 valveVel;
178         }
181         // If valve is present in geometry, set the motion
182         if (valves()[valveI].stemPatchID().active())
183         {
184             // Bottom of the valve moves with given velocity
185             U.boundaryField()[valves()[valveI].stemPatchID().index()] ==
186                 valveVel;
187         }
190     }
194 bool Foam::thoboisSliding::inValve(const point& p, const label& i) const
196     scalar valveX = valves_[i].cs().origin().x();
197     scalar valveY = valves_[i].cs().origin().y();
198     return (sqrt(sqr(p.x()-valveX)+sqr(p.y()-valveY)) < 0.5*valves_[i].diameter());
201 bool Foam::thoboisSliding::inPiston(const point& p) const
203     scalar pistonX = piston_.cs().origin().x();
204     scalar pistonY = piston_.cs().origin().y();
205     return (sqrt(sqr(p.x()-pistonX)+sqr(p.y()-pistonY)) < 0.5*engTime().bore().value());
209 bool Foam::thoboisSliding::isACylinderHeadFace
211     const labelList& cylHeadFaces,
212     const label face
215     forAll(cylHeadFaces, i)
216     {
217         if(cylHeadFaces[i] == face)
218         {
219             return true;
220         }
221     }
223     return false;
228 // ************************************************************************* //