revived old changes to engineTime to allow dictionary modifications to be

noticed and to make the engine geometry optional
This commit is contained in:
Mark Olesen
2008-05-08 13:58:24 +02:00
parent 9d4b64bdbe
commit 146b67bb9f
2 changed files with 117 additions and 72 deletions

View File

@ -27,21 +27,35 @@ License
#include "engineTime.H" #include "engineTime.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
namespace Foam void Foam::engineTime::timeAdjustment()
{ {
deltaT_ = degToTime(deltaT_);
endTime_ = degToTime(endTime_);
if
(
writeControl_ == wcRunTime
|| writeControl_ == wcAdjustableRunTime
)
{
writeInterval_ = degToTime(writeInterval_);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct from objectRegistry arguments //- Construct from objectRegistry arguments
engineTime::engineTime Foam::engineTime::engineTime
( (
const word& name, const word& name,
const fileName& rootPath, const fileName& rootPath,
const fileName& caseName, const fileName& caseName,
const fileName& systemName, const fileName& systemName,
const fileName& constantName const fileName& constantName,
const fileName& dictName
) )
: :
Time Time
@ -52,7 +66,7 @@ engineTime::engineTime
systemName, systemName,
constantName constantName
), ),
engineGeometry_ dict_
( (
IOobject IOobject
( (
@ -64,78 +78,84 @@ engineTime::engineTime
false false
) )
), ),
conRodLength_(engineGeometry_.lookup("conRodLength")), rpm_(dict_.lookup("rpm")),
bore_(engineGeometry_.lookup("bore")), conRodLength_(dimensionedScalar("conRodLength", dimLength, 0)),
stroke_(engineGeometry_.lookup("stroke")), bore_(dimensionedScalar("bore", dimLength, 0)),
clearance_(engineGeometry_.lookup("clearance")), stroke_(dimensionedScalar("stroke", dimLength, 0)),
rpm_(engineGeometry_.lookup("rpm")) clearance_(dimensionedScalar("clearance", dimLength, 0))
{ {
value() = degToTime(value()); // the geometric parameters are not strictly required for Time
if (dict_.found("conRodLength"))
{
dict_.lookup("conRodLength") >> conRodLength_;
}
if (dict_.found("bore"))
{
dict_.lookup("bore") >> bore_;
}
if (dict_.found("stroke"))
{
dict_.lookup("stroke") >> stroke_;
}
if (dict_.found("clearance"))
{
dict_.lookup("clearance") >> clearance_;
}
timeAdjustment();
startTime_ = degToTime(startTime_); startTime_ = degToTime(startTime_);
endTime_ = degToTime(endTime_); value() = degToTime(value());
deltaT_ = degToTime(deltaT_);
deltaT0_ = deltaT_; deltaT0_ = deltaT_;
if
(
writeControl_ == wcRunTime
|| writeControl_ == wcAdjustableRunTime
)
{
writeInterval_ = degToTime(writeInterval_);
}
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Read the controlDict and set all the parameters // Read the controlDict and set all the parameters
bool engineTime::read() void Foam::engineTime::readDict()
{ {
if (!Time::read()) Time::readDict();
timeAdjustment();
}
// Read the controlDict and set all the parameters
bool Foam::engineTime::read()
{
if (Time::read())
{ {
return false; timeAdjustment();
return true;
} }
else else
{ {
deltaT_ = degToTime(deltaT_); return false;
endTime_ = degToTime(endTime_);
if
(
writeControl_ == wcRunTime
|| writeControl_ == wcAdjustableRunTime
)
{
writeInterval_ = degToTime(writeInterval_);
}
return true;
} }
} }
scalar engineTime::degToRad(const scalar deg) const Foam::scalar Foam::engineTime::degToRad(const scalar deg) const
{ {
return mathematicalConstant::pi*deg/180.0; return mathematicalConstant::pi*deg/180.0;
} }
scalar engineTime::degToTime(const scalar theta) const Foam::scalar Foam::engineTime::degToTime(const scalar theta) const
{ {
return theta/(360.0*rpm_.value()/60.0); // 6 * rpm => deg/s
return theta/(6.0*rpm_.value());
} }
scalar engineTime::timeToDeg(const scalar t) const Foam::scalar Foam::engineTime::timeToDeg(const scalar t) const
{ {
return t*(360.0*rpm_.value()/60.0); // 6 * rpm => deg/s
return t*(6.0*rpm_.value());
} }
scalar engineTime::theta() const Foam::scalar Foam::engineTime::theta() const
{ {
return timeToDeg(value()); return timeToDeg(value());
} }
@ -143,7 +163,7 @@ scalar engineTime::theta() const
// Return current crank-angle translated to a single revolution // Return current crank-angle translated to a single revolution
// (value between -180 and 180 with 0 = top dead centre) // (value between -180 and 180 with 0 = top dead centre)
scalar engineTime::thetaRevolution() const Foam::scalar Foam::engineTime::thetaRevolution() const
{ {
scalar t = theta(); scalar t = theta();
@ -161,13 +181,13 @@ scalar engineTime::thetaRevolution() const
} }
scalar engineTime::deltaTheta() const Foam::scalar Foam::engineTime::deltaTheta() const
{ {
return timeToDeg(deltaT().value()); return timeToDeg(deltaT().value());
} }
scalar engineTime::pistonPosition(const scalar theta) const Foam::scalar Foam::engineTime::pistonPosition(const scalar theta) const
{ {
return return
( (
@ -186,7 +206,7 @@ scalar engineTime::pistonPosition(const scalar theta) const
} }
dimensionedScalar engineTime::pistonPosition() const Foam::dimensionedScalar Foam::engineTime::pistonPosition() const
{ {
return dimensionedScalar return dimensionedScalar
( (
@ -197,7 +217,7 @@ dimensionedScalar engineTime::pistonPosition() const
} }
dimensionedScalar engineTime::pistonDisplacement() const Foam::dimensionedScalar Foam::engineTime::pistonDisplacement() const
{ {
return dimensionedScalar return dimensionedScalar
( (
@ -208,24 +228,24 @@ dimensionedScalar engineTime::pistonDisplacement() const
} }
dimensionedScalar engineTime::pistonSpeed() const Foam::dimensionedScalar Foam::engineTime::pistonSpeed() const
{ {
return dimensionedScalar return dimensionedScalar
( (
"pistonSpeed", "pistonSpeed",
dimLength/dimTime, dimVelocity,
pistonDisplacement().value()/(deltaT().value() + VSMALL) pistonDisplacement().value()/(deltaT().value() + VSMALL)
); );
} }
scalar engineTime::userTimeToTime(const scalar theta) const Foam::scalar Foam::engineTime::userTimeToTime(const scalar theta) const
{ {
return degToTime(theta); return degToTime(theta);
} }
scalar engineTime::timeToUserTime(const scalar t) const Foam::scalar Foam::engineTime::timeToUserTime(const scalar t) const
{ {
return timeToDeg(t); return timeToDeg(t);
} }
@ -233,6 +253,4 @@ scalar engineTime::timeToUserTime(const scalar t) const
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -26,7 +26,25 @@ Class
Foam::engineTime Foam::engineTime
Description Description
Foam::engineTime Manage time in terms of engine RPM and crank-angle.
When engineTime is in effect, the userTime is reported in degrees
crank-angle instead of in seconds. The RPM to be used is specified in
@c constant/engineGeometry. If only a time conversion is required,
the geometric engine parameters can be dropped or set to zero.
For example,
@verbatim
rpm rpm [0 0 -1 0 0] 2000;
conRodLength conRodLength [0 1 0 0 0] 0.0;
bore bore [0 1 0 0 0] 0.0;
stroke stroke [0 1 0 0 0] 0.0;
clearance clearance [0 1 0 0 0] 0.0;
@endverbatim
Note
The engineTime can currently only be selected at compile-time.
SourceFiles SourceFiles
engineTime.C engineTime.C
@ -55,13 +73,16 @@ class engineTime
{ {
// Private data // Private data
IOdictionary engineGeometry_; IOdictionary dict_;
//- RPM is required
dimensionedScalar rpm_;
//- Optional engine geometry parameters
dimensionedScalar conRodLength_; dimensionedScalar conRodLength_;
dimensionedScalar bore_; dimensionedScalar bore_;
dimensionedScalar stroke_; dimensionedScalar stroke_;
dimensionedScalar clearance_; dimensionedScalar clearance_;
dimensionedScalar rpm_;
// Private Member Functions // Private Member Functions
@ -72,6 +93,8 @@ class engineTime
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const engineTime&); void operator=(const engineTime&);
//- adjust read time values
void timeAdjustment();
public: public:
@ -84,7 +107,8 @@ public:
const fileName& rootPath, const fileName& rootPath,
const fileName& caseName, const fileName& caseName,
const fileName& systemName = "system", const fileName& systemName = "system",
const fileName& constantName = "constant" const fileName& constantName = "constant",
const fileName& dictName = "engineGeometry"
); );
// Destructor // Destructor
@ -116,7 +140,13 @@ public:
//- Return the engine geometry dictionary //- Return the engine geometry dictionary
const dictionary& engineDict() const const dictionary& engineDict() const
{ {
return engineGeometry_; return dict_;
}
//- Return the engines current operating RPM
const dimensionedScalar& rpm() const
{
return rpm_;
} }
//- Return the engines connecting-rod length //- Return the engines connecting-rod length
@ -143,12 +173,6 @@ public:
return clearance_; return clearance_;
} }
//- Return the engines current operating RPM
const dimensionedScalar& rpm() const
{
return rpm_;
}
//- Return current crank-angle //- Return current crank-angle
scalar theta() const; scalar theta() const;
@ -173,16 +197,19 @@ public:
// Member functions overriding the virtual functions in time // Member functions overriding the virtual functions in time
//- Convert the user-time (CA deg) to real-time (s). //- Convert the user-time (CA deg) to real-time (s).
scalar userTimeToTime(const scalar theta) const; virtual scalar userTimeToTime(const scalar theta) const;
//- Convert the real-time (s) into user-time (CA deg) //- Convert the real-time (s) into user-time (CA deg)
scalar timeToUserTime(const scalar t) const; virtual scalar timeToUserTime(const scalar t) const;
//- Read the control dictionary and set the write controls etc.
virtual void readDict();
// Edit // Edit
//- Read the controlDict and set all the parameters //- Read the controlDict and set all the parameters
bool read(); virtual bool read();
}; };