engineTime.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "engineTime.H"
00028 #include "mathematicalConstants.H"
00029
00030
00031
00032 void Foam::engineTime::timeAdjustment()
00033 {
00034 deltaT_ = degToTime(deltaT_);
00035 endTime_ = degToTime(endTime_);
00036
00037 if
00038 (
00039 writeControl_ == wcRunTime
00040 || writeControl_ == wcAdjustableRunTime
00041 )
00042 {
00043 writeInterval_ = degToTime(writeInterval_);
00044 }
00045 }
00046
00047
00048
00049
00050
00051 Foam::engineTime::engineTime
00052 (
00053 const word& name,
00054 const fileName& rootPath,
00055 const fileName& caseName,
00056 const fileName& systemName,
00057 const fileName& constantName,
00058 const fileName& dictName
00059 )
00060 :
00061 Time
00062 (
00063 name,
00064 rootPath,
00065 caseName,
00066 systemName,
00067 constantName
00068 ),
00069 dict_
00070 (
00071 IOobject
00072 (
00073 "engineGeometry",
00074 constant(),
00075 *this,
00076 IOobject::MUST_READ,
00077 IOobject::NO_WRITE,
00078 false
00079 )
00080 ),
00081 rpm_(dict_.lookup("rpm")),
00082 conRodLength_(dimensionedScalar("conRodLength", dimLength, 0)),
00083 bore_(dimensionedScalar("bore", dimLength, 0)),
00084 stroke_(dimensionedScalar("stroke", dimLength, 0)),
00085 clearance_(dimensionedScalar("clearance", dimLength, 0))
00086 {
00087
00088 dict_.readIfPresent("conRodLength", conRodLength_);
00089 dict_.readIfPresent("bore", bore_);
00090 dict_.readIfPresent("stroke", stroke_);
00091 dict_.readIfPresent("clearance", clearance_);
00092
00093 timeAdjustment();
00094
00095 startTime_ = degToTime(startTime_);
00096 value() = degToTime(value());
00097 deltaT0_ = deltaT_;
00098 }
00099
00100
00101
00102
00103
00104 void Foam::engineTime::readDict()
00105 {
00106 Time::readDict();
00107 timeAdjustment();
00108 }
00109
00110
00111
00112 bool Foam::engineTime::read()
00113 {
00114 if (Time::read())
00115 {
00116 timeAdjustment();
00117 return true;
00118 }
00119 else
00120 {
00121 return false;
00122 }
00123 }
00124
00125
00126 Foam::scalar Foam::engineTime::degToRad(const scalar deg) const
00127 {
00128 return mathematicalConstant::pi*deg/180.0;
00129 }
00130
00131
00132 Foam::scalar Foam::engineTime::degToTime(const scalar theta) const
00133 {
00134
00135 return theta/(6.0*rpm_.value());
00136 }
00137
00138
00139 Foam::scalar Foam::engineTime::timeToDeg(const scalar t) const
00140 {
00141
00142 return t*(6.0*rpm_.value());
00143 }
00144
00145
00146 Foam::scalar Foam::engineTime::theta() const
00147 {
00148 return timeToDeg(value());
00149 }
00150
00151
00152
00153
00154 Foam::scalar Foam::engineTime::thetaRevolution() const
00155 {
00156 scalar t = theta();
00157
00158 while (t > 180.0)
00159 {
00160 t -= 360.0;
00161 }
00162
00163 while (t < -180.0)
00164 {
00165 t += 360.0;
00166 }
00167
00168 return t;
00169 }
00170
00171
00172 Foam::scalar Foam::engineTime::deltaTheta() const
00173 {
00174 return timeToDeg(deltaT().value());
00175 }
00176
00177
00178 Foam::scalar Foam::engineTime::pistonPosition(const scalar theta) const
00179 {
00180 return
00181 (
00182 conRodLength_.value()
00183 + stroke_.value()/2.0
00184 + clearance_.value()
00185 )
00186 - (
00187 stroke_.value()*::cos(degToRad(theta))/2.0
00188 + ::sqrt
00189 (
00190 sqr(conRodLength_.value())
00191 - sqr(stroke_.value()*::sin(degToRad(theta))/2.0)
00192 )
00193 );
00194 }
00195
00196
00197 Foam::dimensionedScalar Foam::engineTime::pistonPosition() const
00198 {
00199 return dimensionedScalar
00200 (
00201 "pistonPosition",
00202 dimLength,
00203 pistonPosition(theta())
00204 );
00205 }
00206
00207
00208 Foam::dimensionedScalar Foam::engineTime::pistonDisplacement() const
00209 {
00210 return dimensionedScalar
00211 (
00212 "pistonDisplacement",
00213 dimLength,
00214 pistonPosition(theta() - deltaTheta()) - pistonPosition().value()
00215 );
00216 }
00217
00218
00219 Foam::dimensionedScalar Foam::engineTime::pistonSpeed() const
00220 {
00221 return dimensionedScalar
00222 (
00223 "pistonSpeed",
00224 dimVelocity,
00225 pistonDisplacement().value()/(deltaT().value() + VSMALL)
00226 );
00227 }
00228
00229
00230 Foam::scalar Foam::engineTime::userTimeToTime(const scalar theta) const
00231 {
00232 return degToTime(theta);
00233 }
00234
00235
00236 Foam::scalar Foam::engineTime::timeToUserTime(const scalar t) const
00237 {
00238 return timeToDeg(t);
00239 }
00240
00241
00242
00243
00244
Copyright © 2000-2009 OpenCFD Ltd