1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2005-2010 Tommaso Lucchini
7 -------------------------------------------------------------------------------
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
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
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"
39 #include "engineTime.H"
40 #include "pointField.H"
41 #include "fvPatchField.H"
43 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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)
60 scalar maxLayer = piston().minLayer();
62 if(valves()[valveI].bottomPatchID().active())
64 maxLayer = max(maxLayer, valves()[valveI].minBottomLayer());
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 )
71 deformationValve = true;
79 else if (virtualPistonPosition() + engTime().pistonDisplacement().value() > deckHeight_ - SMALL)
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 // Construct from components
92 Foam::verticalValves::verticalValves
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),
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)
121 if(valves_[valveI].valveHeadID().active())
128 valves_[valveI].valveHeadID().index()
129 ].patch().localPoints()
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)
151 valves()[valveI].curVelocity()*valves()[valveI].cs().axis();
153 // If valve is present in geometry, set the motion
154 if (valves()[valveI].curtainInPortPatchID().active())
156 // Bottom of the valve moves with given velocity
157 U.boundaryField()[valves()[valveI].curtainInPortPatchID().index()] ==
162 // If valve is present in geometry, set the motion
163 if (valves()[valveI].curtainInCylinderPatchID().active())
165 // Bottom of the valve moves with given velocity
166 U.boundaryField()[valves()[valveI].curtainInCylinderPatchID().index()] ==
171 // If valve is present in geometry, set the motion
172 if (valves()[valveI].poppetPatchID().active())
174 // Bottom of the valve moves with given velocity
175 U.boundaryField()[valves()[valveI].poppetPatchID().index()] ==
179 if (valves()[valveI].bottomPatchID().active())
181 // Bottom of the valve moves with given velocity
182 U.boundaryField()[valves()[valveI].bottomPatchID().index()] ==
187 // If valve is present in geometry, set the motion
188 if (valves()[valveI].stemPatchID().active())
190 // Bottom of the valve moves with given velocity
191 U.boundaryField()[valves()[valveI].stemPatchID().index()] ==
195 // If valve is present in geometry, set the motion
196 if (valves()[valveI].detachInPortPatchID().active())
198 // Bottom of the valve moves with given velocity
199 U.boundaryField()[valves()[valveI].detachInPortPatchID().index()] ==
201 U.oldTime().boundaryField()[valves()[valveI].detachInPortPatchID().index()] ==
205 // If valve is present in geometry, set the motion
206 if (valves()[valveI].detachInCylinderPatchID().active())
208 // Bottom of the valve moves with given velocity
209 U.boundaryField()[valves()[valveI].detachInCylinderPatchID().index()] ==
211 U.oldTime().boundaryField()[valves()[valveI].detachInCylinderPatchID().index()] ==
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,
240 forAll(cylHeadFaces, i)
242 if(cylHeadFaces[i] == face)
253 // ************************************************************************* //