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 "dieselEngineValve.H"
28 #include "engineTime.H"
30 #include "interpolateXY.H"
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 Foam::scalar Foam::dieselEngineValve::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::dieselEngineValve::dieselEngineValve
73 const autoPtr<coordinateSystem>& valveCS,
74 const word& bottomPatchName,
75 const word& poppetPatchName,
76 const word& sidePatchName,
77 const word& stemPatchName,
78 const word& downInPortPatchName,
79 const word& downInCylinderPatchName,
80 const word& upInPortPatchName,
81 const word& upInCylinderPatchName,
82 const word& detachInCylinderPatchName,
83 const word& detachInPortPatchName,
84 const labelList& detachFaces,
85 const scalar& detachTol,
86 const graph& liftProfile,
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 downInPortPatch_(downInPortPatchName, mesh.boundaryMesh()),
100 downInCylinderPatch_(downInCylinderPatchName, mesh.boundaryMesh()),
101 upInPortPatch_(upInPortPatchName, mesh.boundaryMesh()),
102 upInCylinderPatch_(upInCylinderPatchName, mesh.boundaryMesh()),
103 detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
104 detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
105 detachFaces_(detachFaces),
106 detachTol_(detachTol),
107 liftProfile_(liftProfile),
108 liftProfileStart_(min(liftProfile_.x())),
109 liftProfileEnd_(max(liftProfile_.x())),
115 // Construct from dictionary
116 Foam::dieselEngineValve::dieselEngineValve
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()),
140 dict.lookup("downInPortPatch"),
145 dict.lookup("downInCylinderPatch"),
150 dict.lookup("upInPortPatch"),
155 dict.lookup("upInCylinderPatch"),
158 detachInCylinderPatch_
160 dict.lookup("detachInCylinderPatch"),
165 dict.lookup("detachInPortPatch"),
168 detachFaces_(dict.lookup("detachFaces")),
169 detachTol_(readScalar(dict.lookup("detachTol"))),
177 mesh.time().path()/mesh.time().constant()/
178 word(dict.lookup("liftProfileFile"))
181 liftProfileStart_(min(liftProfile_.x())),
182 liftProfileEnd_(max(liftProfile_.x())),
183 minLift_(readScalar(dict.lookup("minLift"))),
184 diameter_(readScalar(dict.lookup("diameter")))
188 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
193 Foam::scalar Foam::dieselEngineValve::lift(const scalar theta) const
197 adjustCrankAngle(theta),
204 bool Foam::dieselEngineValve::isOpen() const
206 return lift(engineDB_.theta()) >= minLift_;
210 Foam::scalar Foam::dieselEngineValve::curLift() const
214 lift(engineDB_.theta()),
220 Foam::scalar Foam::dieselEngineValve::curVelocity() const
227 lift(engineDB_.theta() - engineDB_.deltaTheta()),
230 )/(engineDB_.deltaT().value() + VSMALL);
234 Foam::labelList Foam::dieselEngineValve::movingPatchIDs() const
239 if (bottomPatch_.active())
241 mpIDs[nMpIDs] = bottomPatch_.index();
245 if (poppetPatch_.active())
247 mpIDs[nMpIDs] = poppetPatch_.index();
251 mpIDs.setSize(nMpIDs);
257 void Foam::dieselEngineValve::writeDict(Ostream& os) const
259 os << nl << name() << nl << token::BEGIN_BLOCK;
263 os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
264 << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
265 << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
266 << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
267 << "downInPortPatch " << downInPortPatch_.name()
268 << token::END_STATEMENT << nl
269 << "downInCylinderPatch " << downInCylinderPatch_.name()
270 << token::END_STATEMENT << nl
271 << "upInPortPatch " << upInPortPatch_.name()
272 << token::END_STATEMENT << nl
273 << "upInCylinderPatch " << upInCylinderPatch_.name()
274 << token::END_STATEMENT << nl
275 << "detachInCylinderPatch " << detachInCylinderPatch_.name()
276 << token::END_STATEMENT << nl
277 << "detachInPortPatch " << detachInPortPatch_.name()
278 << token::END_STATEMENT << nl
279 << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
280 << "liftProfile " << nl << token::BEGIN_BLOCK
281 << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
282 << "minLift " << minLift_ << token::END_STATEMENT << nl
283 << "diameter " << diameter_ << token::END_STATEMENT << nl
284 << token::END_BLOCK << endl;
288 // ************************************************************************* //