1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
25 \*---------------------------------------------------------------------------*/
27 #include "layerSmooth.H"
28 #include "layerAdditionRemoval.H"
29 #include "attachDetach.H"
30 #include "componentMixedTetPolyPatchVectorField.H"
31 #include "mapPolyMesh.H"
32 #include "polyTopoChange.H"
33 #include "addToRunTimeSelectionTable.H"
34 #include "GeometricField.H"
36 #include "engineTime.H"
37 #include "pointField.H"
38 #include "fvPatchField.H"
41 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
43 defineTypeNameAndDebug(Foam::layerSmooth, 0);
45 addToRunTimeSelectionTable
47 Foam::engineTopoChangerMesh,
53 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55 bool Foam::layerSmooth::realDeformation() const
60 virtualPistonPosition() + engTime().pistonDisplacement().value()
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 // Construct from components
76 Foam::layerSmooth::layerSmooth
81 engineTopoChangerMesh(io),
82 piston_(*this, engTime().engineDict().subDict("piston")),
83 valves_(*this, engTime().engineDict().lookup("layerSmooth")),
84 deformSwitch_(readScalar(engTime().engineDict().lookup("deformAngle"))),
85 delta_(readScalar(engTime().engineDict().lookup("delta"))),
86 offSet_(readScalar(engTime().engineDict().lookup("offSet"))),
87 pistonPosition_(-GREAT),
88 virtualPistonPosition_(-GREAT),
90 msPtr_(motionSolver::New(*this)),
91 valvePlaneTol_(readScalar(engTime().engineDict().lookup("valvePlaneTol")))
95 forAll(valves(), valveI)
99 valves()[valveI].stemPatchID().active()
100 && valves()[valveI].bottomPatchID().active()
103 label bottomIndex = valves()[valveI].bottomPatchID().index();
104 label stemIndex = valves()[valveI].stemPatchID().index();
106 const polyPatch& stemPatch =
107 boundaryMesh()[stemIndex];
109 const polyPatch& bottomPatch =
110 boundaryMesh()[bottomIndex];
112 point bottomPatchCentre = vector::zero;
113 point stemPatchCentre = vector::zero;
115 scalar bottomArea = 0;
118 Switch halfGeometry(engTime().engineDict().lookup("halfGeometry"));
123 stemPatch.faceCentres()[i]*mag(stemPatch.faceAreas()[i]);
125 stemArea += mag(stemPatch.faceAreas()[i]);
128 forAll(bottomPatch, i)
130 bottomPatchCentre +=bottomPatch.faceCentres()[i]*
131 mag(bottomPatch.faceAreas()[i]);
133 bottomArea += mag(bottomPatch.faceAreas()[i]);
138 Info << "half Geometry active" << endl;
145 stemPatch.faceCentres()[i].x(),
146 -1.0*stemPatch.faceCentres()[i].y(),
147 stemPatch.faceCentres()[i].z()
148 )*mag(stemPatch.faceAreas()[i]);
150 stemArea += mag(stemPatch.faceAreas()[i]);
153 forAll(bottomPatch, i)
158 bottomPatch.faceCentres()[i].x(),
159 -1.0*bottomPatch.faceCentres()[i].y(),
160 bottomPatch.faceCentres()[i].z()
161 )*mag(bottomPatch.faceAreas()[i]);
163 bottomArea += mag(bottomPatch.faceAreas()[i]);
167 stemPatchCentre /= stemArea;
168 bottomPatchCentre /= bottomArea;
171 Info<< "Foam::layerSmooth::layerSmooth"
172 << " calculated origin for valve n. " << valveI
173 << " is " << (stemPatchCentre) << endl;
175 Info<< "Foam::layerSmooth::layerSmooth"
176 << " calculated axis for valve n. " << valveI
178 << (stemPatchCentre - bottomPatchCentre)/
179 mag(stemPatchCentre-bottomPatchCentre)
184 // Add zones and modifiers if not already there.
185 addZonesAndModifiers();
189 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
192 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
195 void Foam::layerSmooth::setBoundaryVelocity(volVectorField& U)
197 // Set valve velociaty
198 forAll (valves(), valveI)
201 valves()[valveI].curVelocity()*valves()[valveI].cs().axis();
203 // If valve is present in geometry, set the motion
204 if (valves()[valveI].curtainInPortPatchID().active())
206 // Bottom of the valve moves with given velocity
208 [valves()[valveI].curtainInPortPatchID().index()] == valveVel;
211 // If valve is present in geometry, set the motion
212 if (valves()[valveI].curtainInCylinderPatchID().active())
214 // Bottom of the valve moves with given velocity
216 [valves()[valveI].curtainInCylinderPatchID().index()] ==
220 // If valve is present in geometry, set the motion
221 if (valves()[valveI].stemPatchID().active())
223 // Bottom of the valve moves with given velocity
224 U.boundaryField()[valves()[valveI].stemPatchID().index()] ==
228 // If valve is present in geometry, set the motion
229 if (valves()[valveI].detachInPortPatchID().active())
231 // Bottom of the valve moves with given velocity
233 [valves()[valveI].detachInPortPatchID().index()] ==
236 U.oldTime().boundaryField()
237 [valves()[valveI].detachInPortPatchID().index()] ==
241 // If valve is present in geometry, set the motion
242 if (valves()[valveI].detachInCylinderPatchID().active())
244 // Bottom of the valve moves with given velocity
246 [valves()[valveI].detachInCylinderPatchID().index()] ==
249 U.oldTime().boundaryField()
250 [valves()[valveI].detachInCylinderPatchID().index()] ==
257 bool Foam::layerSmooth::isACylinderHeadFace
259 const labelList& cylHeadFaces,
263 if(face >= cylHeadFaces[0] && face <= cylHeadFaces[cylHeadFaces.size()-1])
269 forAll(cylHeadFaces, i)
271 if(cylHeadFaces[i] == face)
283 // ************************************************************************* //