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 "thoboisValve.H"
28 #include "engineTime.H"
30 #include "interpolateXY.H"
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 Foam::scalar Foam::thoboisValve::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::thoboisValve::thoboisValve
73 const autoPtr<coordinateSystem>& valveCS,
74 const word& bottomPatchName,
75 const word& poppetPatchName,
76 const word& sidePatchName,
77 const word& stemPatchName,
78 const word& detachInCylinderPatchName,
79 const word& detachInPortPatchName,
80 const word& detachFacesName,
81 const graph& liftProfile,
83 const scalar diameter,
84 const word& staticPointsName,
85 const word& movingPointsName,
86 const word& movingInternalPointsName,
87 const word& staticCellsName,
88 const word& movingCellsName
93 engineDB_(refCast<const engineTime>(mesh.time())),
95 bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
96 poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
97 sidePatch_(sidePatchName, mesh.boundaryMesh()),
98 stemPatch_(stemPatchName, mesh.boundaryMesh()),
99 detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
100 detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
101 detachFacesName_(detachFacesName),
102 liftProfile_(liftProfile),
103 liftProfileStart_(min(liftProfile_.x())),
104 liftProfileEnd_(max(liftProfile_.x())),
107 staticPointsName_(staticPointsName),
108 movingPointsName_(movingPointsName),
109 movingInternalPointsName_(movingInternalPointsName),
110 staticCellsName_(staticCellsName),
111 movingCellsName_(movingCellsName)
115 // Construct from dictionary
116 Foam::thoboisValve::thoboisValve
119 const polyMesh& mesh,
120 const dictionary& dict
125 engineDB_(refCast<const engineTime>(mesh_.time())),
128 coordinateSystem::New
131 dict.subDict("coordinateSystem")
134 bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
135 poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
136 sidePatch_(dict.lookup("sidePatch"), mesh.boundaryMesh()),
137 stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
138 detachInCylinderPatch_
140 dict.lookup("detachInCylinderPatch"),
145 dict.lookup("detachInPortPatch"),
148 detachFacesName_(dict.lookup("detachFaces")),
156 mesh.time().path()/mesh.time().constant()/
157 word(dict.lookup("liftProfileFile"))
160 liftProfileStart_(min(liftProfile_.x())),
161 liftProfileEnd_(max(liftProfile_.x())),
162 minLift_(readScalar(dict.lookup("minLift"))),
163 diameter_(readScalar(dict.lookup("diameter"))),
164 staticPointsName_(dict.lookup("staticPoints")),
165 movingPointsName_(dict.lookup("movingPoints")),
166 movingInternalPointsName_(dict.lookup("movingInternalPoints")),
167 staticCellsName_(dict.lookup("staticCells")),
168 movingCellsName_(dict.lookup("movingCells"))
172 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
175 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
177 Foam::scalar Foam::thoboisValve::lift(const scalar theta) const
181 adjustCrankAngle(theta),
188 bool Foam::thoboisValve::isOpen() const
190 return lift(engineDB_.theta()) >= minLift_;
194 Foam::scalar Foam::thoboisValve::curLift() const
198 lift(engineDB_.theta()),
204 Foam::scalar Foam::thoboisValve::curVelocity() const
211 lift(engineDB_.theta() - engineDB_.deltaTheta()),
214 )/(engineDB_.deltaT().value() + VSMALL);
218 Foam::labelList Foam::thoboisValve::movingPatchIDs() const
223 if (bottomPatch_.active())
225 mpIDs[nMpIDs] = bottomPatch_.index();
229 if (poppetPatch_.active())
231 mpIDs[nMpIDs] = poppetPatch_.index();
235 mpIDs.setSize(nMpIDs);
241 void Foam::thoboisValve::writeDict(Ostream& os) const
243 os << nl << name() << nl << token::BEGIN_BLOCK;
247 os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
248 << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
249 << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
250 << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
251 << "detachInCylinderPatch " << detachInCylinderPatch_.name()
252 << token::END_STATEMENT << nl
253 << "detachInPortPatch " << detachInPortPatch_.name()
254 << token::END_STATEMENT << nl
255 << "detachFaces " << detachFacesName_ << token::END_STATEMENT << nl
256 << "liftProfile " << nl << token::BEGIN_BLOCK
257 << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
258 << "minLift " << minLift_ << token::END_STATEMENT << nl
259 << "diameter " << diameter_ << token::END_STATEMENT << nl
260 << "staticCells " << staticCellsName_ << token::END_STATEMENT << nl
261 << "movingCells " << movingCellsName_ << token::END_STATEMENT << nl
262 << "staticPoints " << staticPointsName_ << token::END_STATEMENT << nl
263 << "movingPoints " << movingPointsName_ << token::END_STATEMENT << nl
264 << token::END_BLOCK << endl;
268 // ************************************************************************* //