1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "engineTime.H"
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::engineTime, 0);
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 void Foam::engineTime::timeAdjustment()
39 deltaT_ = degToTime(deltaT_);
40 endTime_ = degToTime(endTime_);
44 writeControl_ == wcRunTime
45 || writeControl_ == wcAdjustableRunTime
48 writeInterval_ = degToTime(writeInterval_);
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 //- Construct from objectRegistry arguments
56 Foam::engineTime::engineTime
59 const fileName& rootPath,
60 const fileName& caseName,
61 const fileName& systemName,
62 const fileName& constantName,
63 const fileName& dictName
86 rpm_(dict_.lookup("rpm")),
87 conRodLength_(dimensionedScalar("conRodLength", dimLength, 0)),
88 bore_(dimensionedScalar("bore", dimLength, 0)),
89 stroke_(dimensionedScalar("stroke", dimLength, 0)),
90 clearance_(dimensionedScalar("clearance", dimLength, 0))
92 // the geometric parameters are not strictly required for Time
93 if (dict_.found("conRodLength"))
95 dict_.lookup("conRodLength") >> conRodLength_;
97 if (dict_.found("bore"))
99 dict_.lookup("bore") >> bore_;
101 if (dict_.found("stroke"))
103 dict_.lookup("stroke") >> stroke_;
105 if (dict_.found("clearance"))
107 dict_.lookup("clearance") >> clearance_;
112 startTime_ = degToTime(startTime_);
113 value() = degToTime(value());
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 // Read the controlDict and set all the parameters
121 void Foam::engineTime::readDict()
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 // Read the controlDict and set all the parameters
131 bool Foam::engineTime::read()
145 Foam::scalar Foam::engineTime::degToRad(const scalar deg) const
147 return mathematicalConstant::pi*deg/180.0;
151 Foam::scalar Foam::engineTime::degToTime(const scalar theta) const
154 return theta/(6.0*rpm_.value());
158 Foam::scalar Foam::engineTime::timeToDeg(const scalar t) const
161 return t*(6.0*rpm_.value());
165 Foam::scalar Foam::engineTime::theta() const
167 return timeToDeg(value());
171 // Return current crank-angle translated to a single revolution
172 // (value between -180 and 180 with 0 = top dead centre)
173 Foam::scalar Foam::engineTime::thetaRevolution() const
191 Foam::scalar Foam::engineTime::deltaTheta() const
193 return timeToDeg(deltaT().value());
197 Foam::scalar Foam::engineTime::pistonPosition(const scalar theta) const
201 conRodLength_.value()
202 + stroke_.value()/2.0
206 stroke_.value()*::cos(degToRad(theta))/2.0
209 sqr(conRodLength_.value())
210 - sqr(stroke_.value()*::sin(degToRad(theta))/2.0)
216 Foam::dimensionedScalar Foam::engineTime::pistonPosition() const
218 return dimensionedScalar
222 pistonPosition(theta())
227 Foam::dimensionedScalar Foam::engineTime::pistonDisplacement() const
229 return dimensionedScalar
231 "pistonDisplacement",
233 pistonPosition(theta() - deltaTheta()) - pistonPosition().value()
238 Foam::dimensionedScalar Foam::engineTime::pistonSpeed() const
240 return dimensionedScalar
244 pistonDisplacement().value()/(deltaT().value() + VSMALL)
249 Foam::scalar Foam::engineTime::userTimeToTime(const scalar theta) const
251 return degToTime(theta);
255 Foam::scalar Foam::engineTime::timeToUserTime(const scalar t) const
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 // ************************************************************************* //