fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / verticalValves / verticalValves.C
blobff8107f2ba39ebd7ce376e186579f896330a274b
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     verticalValves
28 \*---------------------------------------------------------------------------*/
30 #include "verticalValves.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"
43 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
45 namespace Foam
47     defineTypeNameAndDebug(verticalValves, 0);
48     addToRunTimeSelectionTable(engineTopoChangerMesh, verticalValves, IOobject);
52 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
54 bool Foam::verticalValves::realDeformation() const
57     bool deformationValve = false;
58     forAll(valves(), valveI)
59     {
60         scalar maxLayer = piston().minLayer();
62         if(valves()[valveI].bottomPatchID().active())
63         {
64             maxLayer = max(maxLayer, valves()[valveI].minBottomLayer());
65         }
67         scalar valveDisplacement = valves_[valveI].curVelocity()*valves_[valveI].cs().axis().z()*engTime().deltaT().value()  ;
68         if(valvePistonPosition()[valveI] + engTime().pistonDisplacement().value() >
69         valveBottomPosition_[valveI] + valveDisplacement - 5.0*maxLayer - 0.001 )
70         {
71             deformationValve = true;
72         }
73     }
75     if(deformationValve)
76     {
77         return true;
78     }
79     else  if (virtualPistonPosition() + engTime().pistonDisplacement().value() > deckHeight_ - SMALL)
80     {
81         return true;
82     }
83     else
84     {
85         return deformation();
86     }
89 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
91 // Construct from components
92 Foam::verticalValves::verticalValves
94     const IOobject& io
97     engineTopoChangerMesh(io),
98     piston_(*this, engTime().engineDict().subDict("piston")),
99     valves_(*this, engTime().engineDict().lookup("verticalValves")),
100     movingPointsMaskTopPtr_(NULL),
101     movingPointsMaskBottomPtr_(NULL),
102     deformSwitch_(readScalar(engTime().engineDict().lookup("deformAngle"))),
103     delta_(readScalar(engTime().engineDict().lookup("delta"))),
104     offSet_(readScalar(engTime().engineDict().lookup("offSet"))),
105     valveTopTol_(readScalar(engTime().engineDict().lookup("valveTopTol"))),
106     pistonPosition_(-GREAT),
107     virtualPistonPosition_(-GREAT),
108     valveTopPosition_(nValves(),-GREAT),
109     valveBottomPosition_(nValves(),GREAT), 
110     valvePistonPosition_(nValves(),GREAT), 
111     deckHeight_(GREAT),
112     minValveZ_(nValves()),
113     poppetValveTol_(readScalar(engTime().engineDict().lookup("poppetValveTol"))),
114     bottomValveTol_(readScalar(engTime().engineDict().lookup("bottomValveTol"))),
115     msPtr_(motionSolver::New(*this)),
116     isReallyClosed_(valves().size(), false),
117     correctPointsMotion_(engTime().engineDict().lookup("correctPointsMotion"))
119     forAll(valves_, valveI)
120     {
121         if(valves_[valveI].valveHeadID().active())
122         {
123             minValveZ_[valveI] =
124             min
125             (
126                 boundary()
127                 [
128                     valves_[valveI].valveHeadID().index()
129                 ].patch().localPoints()
130             ).z();
131         }
132     }
134     // Add zones and modifiers if not already there.
135     addZonesAndModifiers();
139 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
142 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
145 void Foam::verticalValves::setBoundaryVelocity(volVectorField& U)
147     // Set valve velociaty
148     forAll (valves(), valveI)
149     {
150         vector valveVel =
151             valves()[valveI].curVelocity()*valves()[valveI].cs().axis();
153         // If valve is present in geometry, set the motion
154         if (valves()[valveI].curtainInPortPatchID().active())
155         {
156             // Bottom of the valve moves with given velocity
157             U.boundaryField()[valves()[valveI].curtainInPortPatchID().index()] ==
158 //                valveVel;
159                 vector::zero;
160         }
162         // If valve is present in geometry, set the motion
163         if (valves()[valveI].curtainInCylinderPatchID().active())
164         {
165             // Bottom of the valve moves with given velocity
166             U.boundaryField()[valves()[valveI].curtainInCylinderPatchID().index()] ==
167 //                valveVel;
168                 vector::zero;
169         }
171         // If valve is present in geometry, set the motion
172         if (valves()[valveI].poppetPatchID().active())
173         {
174             // Bottom of the valve moves with given velocity
175             U.boundaryField()[valves()[valveI].poppetPatchID().index()] ==
176                 valveVel;
177         }
179         if (valves()[valveI].bottomPatchID().active())
180         {
181             // Bottom of the valve moves with given velocity
182             U.boundaryField()[valves()[valveI].bottomPatchID().index()] ==
183                 valveVel;
184         }
186         
187         // If valve is present in geometry, set the motion
188         if (valves()[valveI].stemPatchID().active())
189         {
190             // Bottom of the valve moves with given velocity
191             U.boundaryField()[valves()[valveI].stemPatchID().index()] ==
192                 valveVel;
193         }
195         // If valve is present in geometry, set the motion
196         if (valves()[valveI].detachInPortPatchID().active())
197         {
198             // Bottom of the valve moves with given velocity
199             U.boundaryField()[valves()[valveI].detachInPortPatchID().index()] ==
200                 vector::zero;
201             U.oldTime().boundaryField()[valves()[valveI].detachInPortPatchID().index()] ==
202                 vector::zero;
203         }
205         // If valve is present in geometry, set the motion
206         if (valves()[valveI].detachInCylinderPatchID().active())
207         {
208             // Bottom of the valve moves with given velocity
209             U.boundaryField()[valves()[valveI].detachInCylinderPatchID().index()] ==
210                vector::zero;
211             U.oldTime().boundaryField()[valves()[valveI].detachInCylinderPatchID().index()] ==
212                vector::zero;
213         }
214      
215     }
219 bool Foam::verticalValves::inValve(const point& p, const label& i) const
221     scalar valveX = valves_[i].cs().origin().x();
222     scalar valveY = valves_[i].cs().origin().y();
223     return (sqrt(sqr(p.x()-valveX)+sqr(p.y()-valveY)) < 0.5*valves_[i].diameter());
226 bool Foam::verticalValves::inPiston(const point& p) const
228     scalar pistonX = piston_.cs().origin().x();
229     scalar pistonY = piston_.cs().origin().y();
230     return (sqrt(sqr(p.x()-pistonX)+sqr(p.y()-pistonY)) < 0.5*engTime().bore().value());
234 bool Foam::verticalValves::isACylinderHeadFace
236     const labelList& cylHeadFaces, 
237     const label face
240     forAll(cylHeadFaces, i)
241     {
242         if(cylHeadFaces[i] == face)
243         {
244             return true;
245         }
246     }
247     
248     return false;
253 // ************************************************************************* //