1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 "engineValve.H"
28 #include "engineTime.H"
30 #include "interpolateXY.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 Foam::scalar Foam::engineValve::adjustCrankAngle(const scalar theta) const
36 if (theta < liftProfileStart_)
38 scalar adjustedTheta = theta;
40 while (adjustedTheta < liftProfileStart_)
42 adjustedTheta += liftProfileEnd_ - liftProfileStart_;
47 else if (theta > liftProfileEnd_)
49 scalar adjustedTheta = theta;
51 while (adjustedTheta > liftProfileEnd_)
53 adjustedTheta -= liftProfileEnd_ - liftProfileStart_;
65 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 // Construct from components
68 Foam::engineValve::engineValve
72 const autoPtr<coordinateSystem>& valveCS,
73 const word& bottomPatchName,
74 const word& poppetPatchName,
75 const word& stemPatchName,
76 const word& curtainInPortPatchName,
77 const word& curtainInCylinderPatchName,
78 const word& detachInCylinderPatchName,
79 const word& detachInPortPatchName,
80 const labelList& detachFaces,
81 const graph& liftProfile,
83 const scalar minTopLayer,
84 const scalar maxTopLayer,
85 const scalar minBottomLayer,
86 const scalar maxBottomLayer,
92 engineDB_(refCast<const engineTime>(mesh.time())),
94 bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
95 poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
96 stemPatch_(stemPatchName, mesh.boundaryMesh()),
97 curtainInPortPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
98 curtainInCylinderPatch_(curtainInCylinderPatchName, mesh.boundaryMesh()),
99 detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
100 detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
101 detachFaces_(detachFaces),
102 liftProfile_(liftProfile),
103 liftProfileStart_(min(liftProfile_.x())),
104 liftProfileEnd_(max(liftProfile_.x())),
106 minTopLayer_(minTopLayer),
107 maxTopLayer_(maxTopLayer),
108 minBottomLayer_(minBottomLayer),
109 maxBottomLayer_(maxBottomLayer),
114 // Construct from dictionary
115 Foam::engineValve::engineValve
118 const polyMesh& mesh,
119 const dictionary& dict
124 engineDB_(refCast<const engineTime>(mesh_.time())),
127 coordinateSystem::New
130 dict.subDict("coordinateSystem")
133 bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
134 poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
135 stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
138 dict.lookup("curtainInPortPatch"),
141 curtainInCylinderPatch_
143 dict.lookup("curtainInCylinderPatch"),
146 detachInCylinderPatch_
148 dict.lookup("detachInCylinderPatch"),
153 dict.lookup("detachInPortPatch"),
156 detachFaces_(dict.lookup("detachFaces")),
157 liftProfile_("theta", "lift", name_, dict.lookup("liftProfile")),
158 liftProfileStart_(min(liftProfile_.x())),
159 liftProfileEnd_(max(liftProfile_.x())),
160 minLift_(readScalar(dict.lookup("minLift"))),
161 minTopLayer_(readScalar(dict.lookup("minTopLayer"))),
162 maxTopLayer_(readScalar(dict.lookup("maxTopLayer"))),
163 minBottomLayer_(readScalar(dict.lookup("minBottomLayer"))),
164 maxBottomLayer_(readScalar(dict.lookup("maxBottomLayer"))),
165 diameter_(readScalar(dict.lookup("diameter")))
169 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
172 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
174 Foam::scalar Foam::engineValve::lift(const scalar theta) const
178 adjustCrankAngle(theta),
185 bool Foam::engineValve::isOpen() const
187 return lift(engineDB_.theta()) >= minLift_;
191 Foam::scalar Foam::engineValve::curLift() const
195 lift(engineDB_.theta()),
201 Foam::scalar Foam::engineValve::curVelocity() const
208 lift(engineDB_.theta() - engineDB_.deltaTheta()),
211 )/(engineDB_.deltaT().value() + VSMALL);
215 Foam::labelList Foam::engineValve::movingPatchIDs() const
220 if (bottomPatch_.active())
222 mpIDs[nMpIDs] = bottomPatch_.index();
226 if (poppetPatch_.active())
228 mpIDs[nMpIDs] = poppetPatch_.index();
232 mpIDs.setSize(nMpIDs);
238 void Foam::engineValve::writeDict(Ostream& os) const
240 os << nl << name() << nl << token::BEGIN_BLOCK;
244 os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
245 << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
246 << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
247 << "curtainInPortPatch " << curtainInPortPatch_.name()
248 << token::END_STATEMENT << nl
249 << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
250 << token::END_STATEMENT << nl
251 << "detachInCylinderPatch " << detachInCylinderPatch_.name()
252 << token::END_STATEMENT << nl
253 << "detachInPortPatch " << detachInPortPatch_.name()
254 << token::END_STATEMENT << nl
255 << "detachFaces " << detachFaces_ << 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 << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
260 << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
261 << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
262 << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
263 << "diameter " << diameter_ << token::END_STATEMENT << nl
264 << token::END_BLOCK << endl;
268 // ************************************************************************* //