1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 void Foam::engineTime::timeAdjustment()
34 deltaT_ = degToTime(deltaT_);
35 endTime_ = degToTime(endTime_);
39 writeControl_ == wcRunTime
40 || writeControl_ == wcAdjustableRunTime
43 writeInterval_ = degToTime(writeInterval_);
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 //- Construct from objectRegistry arguments
51 Foam::engineTime::engineTime
54 const fileName& rootPath,
55 const fileName& caseName,
56 const fileName& systemName,
57 const fileName& constantName,
58 const fileName& dictName
81 rpm_(dict_.lookup("rpm")),
82 conRodLength_(dimensionedScalar("conRodLength", dimLength, 0)),
83 bore_(dimensionedScalar("bore", dimLength, 0)),
84 stroke_(dimensionedScalar("stroke", dimLength, 0)),
85 clearance_(dimensionedScalar("clearance", dimLength, 0))
87 // geometric parameters are not strictly required for Time
88 dict_.readIfPresent("conRodLength", conRodLength_);
89 dict_.readIfPresent("bore", bore_);
90 dict_.readIfPresent("stroke", stroke_);
91 dict_.readIfPresent("clearance", clearance_);
95 startTime_ = degToTime(startTime_);
96 value() = degToTime(value());
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 // Read the controlDict and set all the parameters
104 void Foam::engineTime::readDict()
111 // Read the controlDict and set all the parameters
112 bool Foam::engineTime::read()
126 Foam::scalar Foam::engineTime::degToRad(const scalar deg) const
128 return mathematicalConstant::pi*deg/180.0;
132 Foam::scalar Foam::engineTime::degToTime(const scalar theta) const
135 return theta/(6.0*rpm_.value());
139 Foam::scalar Foam::engineTime::timeToDeg(const scalar t) const
142 return t*(6.0*rpm_.value());
146 Foam::scalar Foam::engineTime::theta() const
148 return timeToDeg(value());
152 // Return current crank-angle translated to a single revolution
153 // (value between -180 and 180 with 0 = top dead centre)
154 Foam::scalar Foam::engineTime::thetaRevolution() const
172 Foam::scalar Foam::engineTime::deltaTheta() const
174 return timeToDeg(deltaT().value());
178 Foam::scalar Foam::engineTime::pistonPosition(const scalar theta) const
182 conRodLength_.value()
183 + stroke_.value()/2.0
187 stroke_.value()*::cos(degToRad(theta))/2.0
190 sqr(conRodLength_.value())
191 - sqr(stroke_.value()*::sin(degToRad(theta))/2.0)
197 Foam::dimensionedScalar Foam::engineTime::pistonPosition() const
199 return dimensionedScalar
203 pistonPosition(theta())
208 Foam::dimensionedScalar Foam::engineTime::pistonDisplacement() const
210 return dimensionedScalar
212 "pistonDisplacement",
214 pistonPosition(theta() - deltaTheta()) - pistonPosition().value()
219 Foam::dimensionedScalar Foam::engineTime::pistonSpeed() const
221 return dimensionedScalar
225 pistonDisplacement().value()/(deltaT().value() + VSMALL)
230 Foam::scalar Foam::engineTime::userTimeToTime(const scalar theta) const
232 return degToTime(theta);
236 Foam::scalar Foam::engineTime::timeToUserTime(const scalar t) const
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 // ************************************************************************* //