1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "engineValve.H"
27 #include "engineTime.H"
29 #include "interpolateXY.H"
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 Foam::scalar Foam::engineValve::adjustCrankAngle(const scalar theta) const
35 if (theta < liftProfileStart_)
37 scalar adjustedTheta = theta;
39 while (adjustedTheta < liftProfileStart_)
41 adjustedTheta += liftProfileEnd_ - liftProfileStart_;
46 else if (theta > liftProfileEnd_)
48 scalar adjustedTheta = theta;
50 while (adjustedTheta > liftProfileEnd_)
52 adjustedTheta -= liftProfileEnd_ - liftProfileStart_;
64 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66 // Construct from components
67 Foam::engineValve::engineValve
71 const autoPtr<coordinateSystem>& valveCS,
72 const word& bottomPatchName,
73 const word& poppetPatchName,
74 const word& stemPatchName,
75 const word& curtainInPortPatchName,
76 const word& curtainInCylinderPatchName,
77 const word& detachInCylinderPatchName,
78 const word& detachInPortPatchName,
79 const labelList& detachFaces,
80 const graph& liftProfile,
82 const scalar minTopLayer,
83 const scalar maxTopLayer,
84 const scalar minBottomLayer,
85 const scalar maxBottomLayer,
91 engineDB_(refCast<const engineTime>(mesh.time())),
93 bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
94 poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
95 stemPatch_(stemPatchName, mesh.boundaryMesh()),
96 curtainInPortPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
97 curtainInCylinderPatch_(curtainInCylinderPatchName, mesh.boundaryMesh()),
98 detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
99 detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
100 detachFaces_(detachFaces),
101 liftProfile_(liftProfile),
102 liftProfileStart_(min(liftProfile_.x())),
103 liftProfileEnd_(max(liftProfile_.x())),
105 minTopLayer_(minTopLayer),
106 maxTopLayer_(maxTopLayer),
107 minBottomLayer_(minBottomLayer),
108 maxBottomLayer_(maxBottomLayer),
113 // Construct from dictionary
114 Foam::engineValve::engineValve
117 const polyMesh& mesh,
118 const dictionary& dict
123 engineDB_(refCast<const engineTime>(mesh_.time())),
126 coordinateSystem::New
129 dict.subDict("coordinateSystem")
132 bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
133 poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
134 stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
137 dict.lookup("curtainInPortPatch"),
140 curtainInCylinderPatch_
142 dict.lookup("curtainInCylinderPatch"),
145 detachInCylinderPatch_
147 dict.lookup("detachInCylinderPatch"),
152 dict.lookup("detachInPortPatch"),
155 detachFaces_(dict.lookup("detachFaces")),
156 liftProfile_("theta", "lift", name_, dict.lookup("liftProfile")),
157 liftProfileStart_(min(liftProfile_.x())),
158 liftProfileEnd_(max(liftProfile_.x())),
159 minLift_(readScalar(dict.lookup("minLift"))),
160 minTopLayer_(readScalar(dict.lookup("minTopLayer"))),
161 maxTopLayer_(readScalar(dict.lookup("maxTopLayer"))),
162 minBottomLayer_(readScalar(dict.lookup("minBottomLayer"))),
163 maxBottomLayer_(readScalar(dict.lookup("maxBottomLayer"))),
164 diameter_(readScalar(dict.lookup("diameter")))
168 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173 Foam::scalar Foam::engineValve::lift(const scalar theta) const
177 adjustCrankAngle(theta),
184 bool Foam::engineValve::isOpen() const
186 return lift(engineDB_.theta()) >= minLift_;
190 Foam::scalar Foam::engineValve::curLift() const
194 lift(engineDB_.theta()),
200 Foam::scalar Foam::engineValve::curVelocity() const
207 lift(engineDB_.theta() - engineDB_.deltaTheta()),
210 )/(engineDB_.deltaTValue() + VSMALL);
214 Foam::labelList Foam::engineValve::movingPatchIDs() const
219 if (bottomPatch_.active())
221 mpIDs[nMpIDs] = bottomPatch_.index();
225 if (poppetPatch_.active())
227 mpIDs[nMpIDs] = poppetPatch_.index();
231 mpIDs.setSize(nMpIDs);
237 void Foam::engineValve::writeDict(Ostream& os) const
239 os << nl << name() << nl << token::BEGIN_BLOCK;
243 os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
244 << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
245 << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
246 << "curtainInPortPatch " << curtainInPortPatch_.name()
247 << token::END_STATEMENT << nl
248 << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
249 << token::END_STATEMENT << nl
250 << "detachInCylinderPatch " << detachInCylinderPatch_.name()
251 << token::END_STATEMENT << nl
252 << "detachInPortPatch " << detachInPortPatch_.name()
253 << token::END_STATEMENT << nl
254 << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
255 << "liftProfile " << nl << token::BEGIN_BLOCK
256 << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
257 << "minLift " << minLift_ << token::END_STATEMENT << nl
258 << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
259 << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
260 << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
261 << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
262 << "diameter " << diameter_ << token::END_STATEMENT << nl
263 << token::END_BLOCK << endl;
267 // ************************************************************************* //