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 "thoboisValve.H"
27 #include "engineTime.H"
29 #include "interpolateXY.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 Foam::scalar Foam::thoboisValve::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::thoboisValve::thoboisValve
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& staticPointsName,
84 const word& movingPointsName,
85 const word& movingInternalPointsName,
86 const word& staticCellsName,
87 const word& movingCellsName
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 detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
99 detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
100 detachFacesName_(detachFacesName),
101 liftProfile_(liftProfile),
102 liftProfileStart_(min(liftProfile_.x())),
103 liftProfileEnd_(max(liftProfile_.x())),
106 staticPointsName_(staticPointsName),
107 movingPointsName_(movingPointsName),
108 movingInternalPointsName_(movingInternalPointsName),
109 staticCellsName_(staticCellsName),
110 movingCellsName_(movingCellsName)
114 // Construct from dictionary
115 Foam::thoboisValve::thoboisValve
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()),
137 detachInCylinderPatch_
139 dict.lookup("detachInCylinderPatch"),
144 dict.lookup("detachInPortPatch"),
147 detachFacesName_(dict.lookup("detachFaces")),
155 mesh.time().path()/mesh.time().constant()/
156 word(dict.lookup("liftProfileFile"))
159 liftProfileStart_(min(liftProfile_.x())),
160 liftProfileEnd_(max(liftProfile_.x())),
161 minLift_(readScalar(dict.lookup("minLift"))),
162 diameter_(readScalar(dict.lookup("diameter"))),
163 staticPointsName_(dict.lookup("staticPoints")),
164 movingPointsName_(dict.lookup("movingPoints")),
165 movingInternalPointsName_(dict.lookup("movingInternalPoints")),
166 staticCellsName_(dict.lookup("staticCells")),
167 movingCellsName_(dict.lookup("movingCells"))
171 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
174 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
176 Foam::scalar Foam::thoboisValve::lift(const scalar theta) const
180 adjustCrankAngle(theta),
187 bool Foam::thoboisValve::isOpen() const
189 return lift(engineDB_.theta()) >= minLift_;
193 Foam::scalar Foam::thoboisValve::curLift() const
197 lift(engineDB_.theta()),
203 Foam::scalar Foam::thoboisValve::curVelocity() const
210 lift(engineDB_.theta() - engineDB_.deltaTheta()),
213 )/(engineDB_.deltaT().value() + VSMALL);
217 Foam::labelList Foam::thoboisValve::movingPatchIDs() const
222 if (bottomPatch_.active())
224 mpIDs[nMpIDs] = bottomPatch_.index();
228 if (poppetPatch_.active())
230 mpIDs[nMpIDs] = poppetPatch_.index();
234 mpIDs.setSize(nMpIDs);
240 void Foam::thoboisValve::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 << "staticPoints " << staticPointsName_ << token::END_STATEMENT << nl
262 << "movingPoints " << movingPointsName_ << token::END_STATEMENT << nl
263 << token::END_BLOCK << endl;
267 // ************************************************************************* //