fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / thoboisSliding / thoboisSliding.C
blobe60055ef4690a441bcf6aa39b2747316a1dddb9e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2005-2010 Tommaso Lucchini
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM 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 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     verticalValvesGambit
28 \*---------------------------------------------------------------------------*/
30 #include "thoboisSliding.H"
31 #include "layerAdditionRemoval.H"
32 #include "attachDetach.H"
33 #include "componentMixedTetPolyPatchVectorField.H"
34 #include "mapPolyMesh.H"
35 #include "polyTopoChange.H"
36 #include "addToRunTimeSelectionTable.H"
37 #include "GeometricField.H"
38 #include "volMesh.H"
39 #include "engineTime.H"
40 #include "pointField.H"
41 #include "fvPatchField.H"
42 #include "Switch.H"
43 #include "symmetryFvPatch.H"
44 #include "tetDecompositionMotionSolver.H"
46 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
48 namespace Foam
50     defineTypeNameAndDebug(thoboisSliding, 0);
51     addToRunTimeSelectionTable(engineTopoChangerMesh, thoboisSliding, IOobject);
55 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
59     
60 bool Foam::thoboisSliding::realDeformation() const
63     bool deformationValve = false;
64     forAll(valves(), valveI)
65     {
66         
67         scalar maxLayer = piston().minLayer();
68             
69         if(valves()[valveI].bottomPatchID().active())
70         {
71             maxLayer = max(maxLayer, valves()[valveI].minBottomLayer());
72         }
73     
74         scalar valveDisplacement = valves_[valveI].curVelocity()*valves_[valveI].cs().axis().z()*engTime().deltaT().value()  ;
75         if(valvePistonPosition()[valveI] + engTime().pistonDisplacement().value() >
76         valveBottomPosition_[valveI] + valveDisplacement - 5.0*maxLayer - 0.001 )
77         {
78             deformationValve = true;
79         }
80     }    
82     if(deformationValve)
83     {
84         return true;
85     }
86     else  if (virtualPistonPosition() + engTime().pistonDisplacement().value() > deckHeight_ - SMALL)
87     {
88         return true;
89     }
90     else
91     {
92         return deformation();
93     }
96 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
98 // Construct from components
99 Foam::thoboisSliding::thoboisSliding
101     const IOobject& io
104     engineTopoChangerMesh(io),
105     piston_(*this, engTime().engineDict().subDict("piston")),
106     valves_(*this, engTime().engineDict().lookup("thoboisSliding")),
107     movingPointsMaskTopPtr_(NULL),
108     movingPointsMaskBottomPtr_(NULL),
109     deformSwitch_(readScalar(engTime().engineDict().lookup("deformAngle"))),
110     valveTopTol_(readScalar(engTime().engineDict().lookup("valveTopTol"))),
111     pistonPosition_(-GREAT),
112     virtualPistonPosition_(-GREAT),
113     valveTopPosition_(nValves(),-GREAT),
114     valveBottomPosition_(nValves(),GREAT), 
115     valvePistonPosition_(nValves(),GREAT), 
116     deckHeight_(GREAT),
117     minValveZ_(nValves()),
118     poppetValveTol_(readScalar(engTime().engineDict().lookup("poppetValveTol"))),
119     bottomValveTol_(readScalar(engTime().engineDict().lookup("bottomValveTol"))),
120     msPtr_(motionSolver::New(*this)),
121     isReallyClosed_(valves().size(), false),
122     correctPointsMotion_(engTime().engineDict().lookup("correctPointsMotion"))
124     
126     // Add zones and modifiers if not already there.
127     addZonesAndModifiers();
131 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
134 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
137 void Foam::thoboisSliding::setBoundaryVelocity(volVectorField& U)
139     
140     
141     // Set valve velociaty
142     forAll (valves(), valveI)
143     {
144             
145         vector valveVel =
146             valves()[valveI].curVelocity()*valves()[valveI].cs().axis();
148         // If valve is present in geometry, set the motion
149         if (valves()[valveI].curtainInPortPatchID().active())
150         {
151             // Bottom of the valve moves with given velocity
152             U.boundaryField()[valves()[valveI].curtainInPortPatchID().index()] ==
153 //                valveVel;
154                 vector::zero;
155         }
157         // If valve is present in geometry, set the motion
158         if (valves()[valveI].curtainInCylinderPatchID().active())
159         {
160             // Bottom of the valve moves with given velocity
161             U.boundaryField()[valves()[valveI].curtainInCylinderPatchID().index()] ==
162 //                valveVel;
163                 vector::zero;
164         }
166         // If valve is present in geometry, set the motion
167         if (valves()[valveI].poppetPatchID().active())
168         {
169             // Bottom of the valve moves with given velocity
170             U.boundaryField()[valves()[valveI].poppetPatchID().index()] ==
171                 valveVel;
172         }
174         if (valves()[valveI].bottomPatchID().active())
175         {
176             // Bottom of the valve moves with given velocity
177             U.boundaryField()[valves()[valveI].bottomPatchID().index()] ==
178                 valveVel;
179         }
181         
182         // If valve is present in geometry, set the motion
183         if (valves()[valveI].stemPatchID().active())
184         {
185             // Bottom of the valve moves with given velocity
186             U.boundaryField()[valves()[valveI].stemPatchID().index()] ==
187                 valveVel;
188         }
190      
191     }
195 bool Foam::thoboisSliding::inValve(const point& p, const label& i) const
197     scalar valveX = valves_[i].cs().origin().x();
198     scalar valveY = valves_[i].cs().origin().y();
199     return (sqrt(sqr(p.x()-valveX)+sqr(p.y()-valveY)) < 0.5*valves_[i].diameter());
202 bool Foam::thoboisSliding::inPiston(const point& p) const
204     scalar pistonX = piston_.cs().origin().x();
205     scalar pistonY = piston_.cs().origin().y();
206     return (sqrt(sqr(p.x()-pistonX)+sqr(p.y()-pistonY)) < 0.5*engTime().bore().value());
210 bool Foam::thoboisSliding::isACylinderHeadFace
212     const labelList& cylHeadFaces, 
213     const label face
216     forAll(cylHeadFaces, i)
217     {
218         if(cylHeadFaces[i] == face)
219         {
220             return true;
221         }
222     }
223     
224     return false;
229 // ************************************************************************* //