1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "engineValve.H"
27 #include "engineTime.H"
29 #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")),
164 mesh.time().path()/mesh.time().constant()/
165 word(dict.lookup("liftProfileFile"))
168 liftProfileStart_(min(liftProfile_.x())),
169 liftProfileEnd_(max(liftProfile_.x())),
170 minLift_(readScalar(dict.lookup("minLift"))),
171 minTopLayer_(readScalar(dict.lookup("minTopLayer"))),
172 maxTopLayer_(readScalar(dict.lookup("maxTopLayer"))),
173 minBottomLayer_(readScalar(dict.lookup("minBottomLayer"))),
174 maxBottomLayer_(readScalar(dict.lookup("maxBottomLayer"))),
175 diameter_(readScalar(dict.lookup("diameter")))
179 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
182 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
184 Foam::scalar Foam::engineValve::lift(const scalar theta) const
188 adjustCrankAngle(theta),
195 bool Foam::engineValve::isOpen() const
197 return lift(engineDB_.theta()) >= minLift_;
201 Foam::scalar Foam::engineValve::curLift() const
205 lift(engineDB_.theta()),
211 Foam::scalar Foam::engineValve::curVelocity() const
218 lift(engineDB_.theta() - engineDB_.deltaTheta()),
221 )/(engineDB_.deltaT().value() + VSMALL);
225 Foam::labelList Foam::engineValve::movingPatchIDs() const
230 if (bottomPatch_.active())
232 mpIDs[nMpIDs] = bottomPatch_.index();
236 if (poppetPatch_.active())
238 mpIDs[nMpIDs] = poppetPatch_.index();
242 mpIDs.setSize(nMpIDs);
248 void Foam::engineValve::writeDict(Ostream& os) const
250 os << nl << name() << nl << token::BEGIN_BLOCK;
254 os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
255 << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
256 << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
257 << "curtainInPortPatch " << curtainInPortPatch_.name()
258 << token::END_STATEMENT << nl
259 << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
260 << token::END_STATEMENT << nl
261 << "detachInCylinderPatch " << detachInCylinderPatch_.name()
262 << token::END_STATEMENT << nl
263 << "detachInPortPatch " << detachInPortPatch_.name()
264 << token::END_STATEMENT << nl
265 << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
266 << "liftProfile " << nl << token::BEGIN_BLOCK
267 << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
268 << "minLift " << minLift_ << token::END_STATEMENT << nl
269 << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
270 << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
271 << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
272 << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
273 << "diameter " << diameter_ << token::END_STATEMENT << nl
274 << token::END_BLOCK << endl;
278 // ************************************************************************* //