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 "thoboisSlidingValve.H"
28 #include "engineTime.H"
30 #include "interpolateXY.H"
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 Foam::scalar Foam::thoboisSlidingValve::adjustCrankAngle(const scalar theta) const
37 if (theta < liftProfileStart_)
39 scalar adjustedTheta = theta;
41 while (adjustedTheta < liftProfileStart_)
43 adjustedTheta += liftProfileEnd_ - liftProfileStart_;
48 else if (theta > liftProfileEnd_)
50 scalar adjustedTheta = theta;
52 while (adjustedTheta > liftProfileEnd_)
54 adjustedTheta -= liftProfileEnd_ - liftProfileStart_;
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68 // Construct from components
69 Foam::thoboisSlidingValve::thoboisSlidingValve
73 const autoPtr<coordinateSystem>& valveCS,
74 const word& bottomPatchName,
75 const word& poppetPatchName,
76 const word& sidePatchName,
77 const word& stemPatchName,
78 const word& curtainInPortPatchName,
79 const word& curtainInCylinderPatchName,
80 const word& detachInCylinderPatchName,
81 const word& detachInPortPatchName,
82 const labelList& detachFaces,
83 const graph& liftProfile,
85 const scalar diameter,
86 const scalar deformationLift,
87 const word& layeringFacesTopName,
88 const word& layeringFacesBottomName,
89 const word& movingCellsTopName,
90 const word& movingCellsBottomName,
91 const word& movingPointsTopName,
92 const word& movingPointsBottomName,
93 const scalar minTopLayer,
94 const scalar maxTopLayer,
95 const scalar minBottomLayer,
96 const scalar maxBottomLayer,
97 const word& staticPointsName,
98 const word& movingPointsName,
99 const word& staticCellsName,
100 const word& movingCellsName
105 engineDB_(refCast<const engineTime>(mesh.time())),
107 bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
108 poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
109 sidePatch_(sidePatchName, mesh.boundaryMesh()),
110 stemPatch_(stemPatchName, mesh.boundaryMesh()),
111 curtainInCylinderPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
112 curtainInPortPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
113 detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
114 detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
115 detachFaces_(detachFaces),
116 liftProfile_(liftProfile),
117 liftProfileStart_(min(liftProfile_.x())),
118 liftProfileEnd_(max(liftProfile_.x())),
121 deformationLift_(deformationLift),
122 layeringFacesTopName_(layeringFacesTopName),
123 layeringFacesBottomName_(layeringFacesBottomName),
124 movingCellsTopName_(movingCellsTopName),
125 movingCellsBottomName_(movingCellsBottomName),
126 movingPointsTopName_(movingPointsTopName),
127 movingPointsBottomName_(movingPointsBottomName),
128 minTopLayer_(minTopLayer),
129 maxTopLayer_(maxTopLayer),
130 minBottomLayer_(minBottomLayer),
131 maxBottomLayer_(maxBottomLayer),
132 staticPointsName_(staticPointsName),
133 movingPointsName_(movingPointsName),
134 staticCellsName_(staticCellsName),
135 movingCellsName_(movingCellsName)
139 // Construct from dictionary
140 Foam::thoboisSlidingValve::thoboisSlidingValve
143 const polyMesh& mesh,
144 const dictionary& dict
149 engineDB_(refCast<const engineTime>(mesh_.time())),
152 coordinateSystem::New
155 dict.subDict("coordinateSystem")
158 bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
159 poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
160 sidePatch_(dict.lookup("sidePatch"), mesh.boundaryMesh()),
161 stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
162 curtainInCylinderPatch_
164 dict.lookup("curtainInCylinderPatch"),
169 dict.lookup("curtainInPortPatch"),
172 detachInCylinderPatch_
174 dict.lookup("detachInCylinderPatch"),
179 dict.lookup("detachInPortPatch"),
182 detachFaces_(dict.lookup("detachFaces")),
190 mesh.time().path()/mesh.time().constant()/
191 word(dict.lookup("liftProfileFile"))
194 liftProfileStart_(min(liftProfile_.x())),
195 liftProfileEnd_(max(liftProfile_.x())),
196 minLift_(readScalar(dict.lookup("minLift"))),
197 diameter_(readScalar(dict.lookup("diameter"))),
198 deformationLift_(readScalar(dict.lookup("deformationLift"))),
199 layeringFacesTopName_(dict.lookup("layeringFacesTop")),
200 layeringFacesBottomName_(dict.lookup("layeringFacesBottom")),
201 movingCellsTopName_(dict.lookup("movingCellsTop")),
202 movingCellsBottomName_(dict.lookup("movingCellsBottom")),
203 movingPointsTopName_(dict.lookup("movingPointsTop")),
204 movingPointsBottomName_(dict.lookup("movingPointsBottom")),
205 minTopLayer_(readScalar(dict.lookup("minTopLayer"))),
206 maxTopLayer_(readScalar(dict.lookup("maxTopLayer"))),
207 minBottomLayer_(readScalar(dict.lookup("minBottomLayer"))),
208 maxBottomLayer_(readScalar(dict.lookup("maxBottomLayer"))),
209 staticPointsName_(dict.lookup("staticPoints")),
210 movingPointsName_(dict.lookup("movingPoints")),
211 staticCellsName_(dict.lookup("staticCells")),
212 movingCellsName_(dict.lookup("movingCells"))
216 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
218 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
220 Foam::scalar Foam::thoboisSlidingValve::lift(const scalar theta) const
224 adjustCrankAngle(theta),
231 bool Foam::thoboisSlidingValve::isOpen() const
233 return lift(engineDB_.theta()) >= minLift_;
237 Foam::scalar Foam::thoboisSlidingValve::curLift() const
241 lift(engineDB_.theta()),
247 Foam::scalar Foam::thoboisSlidingValve::curVelocity() const
254 lift(engineDB_.theta() - engineDB_.deltaTheta()),
257 )/(engineDB_.deltaT().value() + VSMALL);
261 Foam::labelList Foam::thoboisSlidingValve::movingPatchIDs() const
266 if (bottomPatch_.active())
268 mpIDs[nMpIDs] = bottomPatch_.index();
272 if (poppetPatch_.active())
274 mpIDs[nMpIDs] = poppetPatch_.index();
278 mpIDs.setSize(nMpIDs);
284 void Foam::thoboisSlidingValve::writeDict(Ostream& os) const
286 os << nl << name() << nl << token::BEGIN_BLOCK;
290 os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
291 << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
292 << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
293 << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
294 << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
295 << token::END_STATEMENT << nl
296 << "curtainInPortPatch " << curtainInPortPatch_.name()
297 << token::END_STATEMENT << nl
298 // << "detachInCylinderPatch " << detachInCylinderPatch_.name()
299 // << token::END_STATEMENT << nl
300 << "liftProfile " << nl << token::BEGIN_BLOCK
301 << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
302 << "minLift " << minLift_ << token::END_STATEMENT << nl
303 << "diameter " << diameter_ << token::END_STATEMENT << nl
304 << token::END_BLOCK << endl;
308 // ************************************************************************* //