1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | 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 "dieselEngineValve.H"
27 #include "engineTime.H"
29 #include "interpolateXY.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 Foam::scalar Foam::dieselEngineValve::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::dieselEngineValve::dieselEngineValve
72 const autoPtr<coordinateSystem>& valveCS,
73 const word& bottomPatchName,
74 const word& poppetPatchName,
75 const word& sidePatchName,
76 const word& stemPatchName,
77 const word& downInPortPatchName,
78 const word& downInCylinderPatchName,
79 const word& upInPortPatchName,
80 const word& upInCylinderPatchName,
81 const word& detachInCylinderPatchName,
82 const word& detachInPortPatchName,
83 const labelList& detachFaces,
84 const scalar& detachTol,
85 const graph& liftProfile,
92 engineDB_(refCast<const engineTime>(mesh.time())),
94 bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
95 poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
96 sidePatch_(sidePatchName, mesh.boundaryMesh()),
97 stemPatch_(stemPatchName, mesh.boundaryMesh()),
98 downInPortPatch_(downInPortPatchName, mesh.boundaryMesh()),
99 downInCylinderPatch_(downInCylinderPatchName, mesh.boundaryMesh()),
100 upInPortPatch_(upInPortPatchName, mesh.boundaryMesh()),
101 upInCylinderPatch_(upInCylinderPatchName, mesh.boundaryMesh()),
102 detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
103 detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
104 detachFaces_(detachFaces),
105 detachTol_(detachTol),
106 liftProfile_(liftProfile),
107 liftProfileStart_(min(liftProfile_.x())),
108 liftProfileEnd_(max(liftProfile_.x())),
114 // Construct from dictionary
115 Foam::dieselEngineValve::dieselEngineValve
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 sidePatch_(dict.lookup("sidePatch"), mesh.boundaryMesh()),
136 stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
139 dict.lookup("downInPortPatch"),
144 dict.lookup("downInCylinderPatch"),
149 dict.lookup("upInPortPatch"),
154 dict.lookup("upInCylinderPatch"),
157 detachInCylinderPatch_
159 dict.lookup("detachInCylinderPatch"),
164 dict.lookup("detachInPortPatch"),
167 detachFaces_(dict.lookup("detachFaces")),
168 detachTol_(readScalar(dict.lookup("detachTol"))),
176 mesh.time().path()/mesh.time().constant()/
177 word(dict.lookup("liftProfileFile"))
180 liftProfileStart_(min(liftProfile_.x())),
181 liftProfileEnd_(max(liftProfile_.x())),
182 minLift_(readScalar(dict.lookup("minLift"))),
183 diameter_(readScalar(dict.lookup("diameter")))
187 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
190 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 Foam::scalar Foam::dieselEngineValve::lift(const scalar theta) const
196 adjustCrankAngle(theta),
203 bool Foam::dieselEngineValve::isOpen() const
205 return lift(engineDB_.theta()) >= minLift_;
209 Foam::scalar Foam::dieselEngineValve::curLift() const
213 lift(engineDB_.theta()),
219 Foam::scalar Foam::dieselEngineValve::curVelocity() const
226 lift(engineDB_.theta() - engineDB_.deltaTheta()),
229 )/(engineDB_.deltaT().value() + VSMALL);
233 Foam::labelList Foam::dieselEngineValve::movingPatchIDs() const
238 if (bottomPatch_.active())
240 mpIDs[nMpIDs] = bottomPatch_.index();
244 if (poppetPatch_.active())
246 mpIDs[nMpIDs] = poppetPatch_.index();
250 mpIDs.setSize(nMpIDs);
256 void Foam::dieselEngineValve::writeDict(Ostream& os) const
258 os << nl << name() << nl << token::BEGIN_BLOCK;
262 os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
263 << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
264 << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
265 << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
266 << "downInPortPatch " << downInPortPatch_.name()
267 << token::END_STATEMENT << nl
268 << "downInCylinderPatch " << downInCylinderPatch_.name()
269 << token::END_STATEMENT << nl
270 << "upInPortPatch " << upInPortPatch_.name()
271 << token::END_STATEMENT << nl
272 << "upInCylinderPatch " << upInCylinderPatch_.name()
273 << token::END_STATEMENT << nl
274 << "detachInCylinderPatch " << detachInCylinderPatch_.name()
275 << token::END_STATEMENT << nl
276 << "detachInPortPatch " << detachInPortPatch_.name()
277 << token::END_STATEMENT << nl
278 << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
279 << "liftProfile " << nl << token::BEGIN_BLOCK
280 << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
281 << "minLift " << minLift_ << token::END_STATEMENT << nl
282 << "diameter " << diameter_ << token::END_STATEMENT << nl
283 << token::END_BLOCK << endl;
287 // ************************************************************************* //