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 "accordionValve.H"
27 #include "engineTime.H"
29 #include "interpolateXY.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 Foam::scalar Foam::accordionValve::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::accordionValve::accordionValve
72 const autoPtr<coordinateSystem>& valveCS,
73 const word& bottomPatchName,
74 const word& poppetPatchName,
75 const word& sidePatchName,
76 const word& stemPatchName,
77 const word& detachInCylinderPatchName,
78 const word& detachInPortPatchName,
79 const word& detachFacesName,
80 const graph& liftProfile,
82 const scalar diameter,
83 const word& staticCellsName,
84 const word& movingCellsName
89 engineDB_(refCast<const engineTime>(mesh.time())),
91 bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
92 poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
93 sidePatch_(sidePatchName, mesh.boundaryMesh()),
94 stemPatch_(stemPatchName, mesh.boundaryMesh()),
95 detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
96 detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
97 detachFacesName_(detachFacesName),
98 liftProfile_(liftProfile),
99 liftProfileStart_(min(liftProfile_.x())),
100 liftProfileEnd_(max(liftProfile_.x())),
103 staticCellsName_(staticCellsName),
104 movingCellsName_(movingCellsName)
108 // Construct from dictionary
109 Foam::accordionValve::accordionValve
112 const polyMesh& mesh,
113 const dictionary& dict
118 engineDB_(refCast<const engineTime>(mesh_.time())),
121 coordinateSystem::New
124 dict.subDict("coordinateSystem")
127 bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
128 poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
129 sidePatch_(dict.lookup("sidePatch"), mesh.boundaryMesh()),
130 stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
131 detachInCylinderPatch_
133 dict.lookup("detachInCylinderPatch"),
138 dict.lookup("detachInPortPatch"),
141 detachFacesName_(dict.lookup("detachFaces")),
149 mesh.time().path()/mesh.time().caseConstant()/
150 word(dict.lookup("liftProfileFile"))
153 liftProfileStart_(min(liftProfile_.x())),
154 liftProfileEnd_(max(liftProfile_.x())),
155 minLift_(readScalar(dict.lookup("minLift"))),
156 diameter_(readScalar(dict.lookup("diameter"))),
157 staticCellsName_(dict.lookup("staticCells")),
158 movingCellsName_(dict.lookup("movingCells"))
162 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
165 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
167 Foam::scalar Foam::accordionValve::lift(const scalar theta) const
170 label curCycle = theta/720.0;
171 scalar curTheta = theta - curCycle * 720.0;
182 bool Foam::accordionValve::isOpen() const
184 return lift(engineDB_.theta()) >= minLift_;
188 Foam::scalar Foam::accordionValve::curLift() const
192 lift(engineDB_.theta()),
198 Foam::scalar Foam::accordionValve::curVelocity() const
205 lift(engineDB_.theta() - engineDB_.deltaTheta()),
208 )/(engineDB_.deltaT().value() + VSMALL);
211 Foam::labelList Foam::accordionValve::movingPatchIDs() const
216 if (bottomPatch_.active())
218 mpIDs[nMpIDs] = bottomPatch_.index();
222 if (poppetPatch_.active())
224 mpIDs[nMpIDs] = poppetPatch_.index();
228 if (sidePatch_.active())
230 mpIDs[nMpIDs] = sidePatch_.index();
234 mpIDs.setSize(nMpIDs);
240 void Foam::accordionValve::writeDict(Ostream& os) const
242 os << nl << name() << nl << token::BEGIN_BLOCK;
246 os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
247 << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
248 << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
249 << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
250 << "detachInCylinderPatch " << detachInCylinderPatch_.name()
251 << token::END_STATEMENT << nl
252 << "detachInPortPatch " << detachInPortPatch_.name()
253 << token::END_STATEMENT << nl
254 << "detachFaces " << detachFacesName_ << 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 << "diameter " << diameter_ << token::END_STATEMENT << nl
259 << "staticCells " << staticCellsName_ << token::END_STATEMENT << nl
260 << "movingCells " << movingCellsName_ << token::END_STATEMENT << nl
261 << token::END_BLOCK << endl;
264 // ************************************************************************* //