initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / engine / engineTime / engineTime.C
blob226334d308bba565458d8a625a93c507f7248da4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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_);
37     if
38     (
39         writeControl_ == wcRunTime
40      || writeControl_ == wcAdjustableRunTime
41     )
42     {
43         writeInterval_ = degToTime(writeInterval_);
44     }
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 //- Construct from objectRegistry arguments
51 Foam::engineTime::engineTime
53     const word& name,
54     const fileName& rootPath,
55     const fileName& caseName,
56     const fileName& systemName,
57     const fileName& constantName,
58     const fileName& dictName
61     Time
62     (
63         name,
64         rootPath,
65         caseName,
66         systemName,
67         constantName
68     ),
69     dict_
70     (
71         IOobject
72         (
73             "engineGeometry",
74             constant(),
75             *this,
76             IOobject::MUST_READ,
77             IOobject::NO_WRITE,
78             false
79         )
80     ),
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_);
93     timeAdjustment();
95     startTime_ = degToTime(startTime_);
96     value()    = degToTime(value());
97     deltaT0_   = deltaT_;
101 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
103 // Read the controlDict and set all the parameters
104 void Foam::engineTime::readDict()
106     Time::readDict();
107     timeAdjustment();
111 // Read the controlDict and set all the parameters
112 bool Foam::engineTime::read()
114     if (Time::read())
115     {
116         timeAdjustment();
117         return true;
118     }
119     else
120     {
121         return false;
122     }
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
134     // 6 * rpm => deg/s
135     return theta/(6.0*rpm_.value());
139 Foam::scalar Foam::engineTime::timeToDeg(const scalar t) const
141     // 6 * rpm => deg/s
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
156     scalar t = theta();
158     while (t > 180.0)
159     {
160         t -= 360.0;
161     }
163     while (t < -180.0)
164     {
165         t += 360.0;
166     }
168     return t;
172 Foam::scalar Foam::engineTime::deltaTheta() const
174     return timeToDeg(deltaT().value());
178 Foam::scalar Foam::engineTime::pistonPosition(const scalar theta) const
180     return
181     (
182         conRodLength_.value()
183       + stroke_.value()/2.0
184       + clearance_.value()
185     )
186   - (
187         stroke_.value()*::cos(degToRad(theta))/2.0
188       + ::sqrt
189         (
190             sqr(conRodLength_.value())
191             - sqr(stroke_.value()*::sin(degToRad(theta))/2.0)
192         )
193     );
197 Foam::dimensionedScalar Foam::engineTime::pistonPosition() const
199     return dimensionedScalar
200     (
201         "pistonPosition",
202         dimLength,
203         pistonPosition(theta())
204     );
208 Foam::dimensionedScalar Foam::engineTime::pistonDisplacement() const
210     return dimensionedScalar
211     (
212         "pistonDisplacement",
213         dimLength,
214         pistonPosition(theta() - deltaTheta()) - pistonPosition().value()
215     );
219 Foam::dimensionedScalar Foam::engineTime::pistonSpeed() const
221     return dimensionedScalar
222     (
223         "pistonSpeed",
224         dimVelocity,
225         pistonDisplacement().value()/(deltaT().value() + VSMALL)
226     );
230 Foam::scalar Foam::engineTime::userTimeToTime(const scalar theta) const
232     return degToTime(theta);
236 Foam::scalar Foam::engineTime::timeToUserTime(const scalar t) const
238     return timeToDeg(t);
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 // ************************************************************************* //