mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
revived old changes to engineTime to allow dictionary modifications to be
noticed and to make the engine geometry optional
This commit is contained in:
@ -27,21 +27,35 @@ License
|
||||
#include "engineTime.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 * * * * * * * * * * * * * * //
|
||||
|
||||
//- Construct from objectRegistry arguments
|
||||
engineTime::engineTime
|
||||
Foam::engineTime::engineTime
|
||||
(
|
||||
const word& name,
|
||||
const fileName& rootPath,
|
||||
const fileName& caseName,
|
||||
const fileName& systemName,
|
||||
const fileName& constantName
|
||||
const fileName& constantName,
|
||||
const fileName& dictName
|
||||
)
|
||||
:
|
||||
Time
|
||||
@ -52,7 +66,7 @@ engineTime::engineTime
|
||||
systemName,
|
||||
constantName
|
||||
),
|
||||
engineGeometry_
|
||||
dict_
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
@ -64,78 +78,84 @@ engineTime::engineTime
|
||||
false
|
||||
)
|
||||
),
|
||||
conRodLength_(engineGeometry_.lookup("conRodLength")),
|
||||
bore_(engineGeometry_.lookup("bore")),
|
||||
stroke_(engineGeometry_.lookup("stroke")),
|
||||
clearance_(engineGeometry_.lookup("clearance")),
|
||||
rpm_(engineGeometry_.lookup("rpm"))
|
||||
rpm_(dict_.lookup("rpm")),
|
||||
conRodLength_(dimensionedScalar("conRodLength", dimLength, 0)),
|
||||
bore_(dimensionedScalar("bore", dimLength, 0)),
|
||||
stroke_(dimensionedScalar("stroke", dimLength, 0)),
|
||||
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_);
|
||||
endTime_ = degToTime(endTime_);
|
||||
|
||||
deltaT_ = degToTime(deltaT_);
|
||||
value() = degToTime(value());
|
||||
deltaT0_ = deltaT_;
|
||||
|
||||
if
|
||||
(
|
||||
writeControl_ == wcRunTime
|
||||
|| writeControl_ == wcAdjustableRunTime
|
||||
)
|
||||
{
|
||||
writeInterval_ = degToTime(writeInterval_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// 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()
|
||||
{
|
||||
return false;
|
||||
if (Time::read())
|
||||
{
|
||||
timeAdjustment();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
deltaT_ = degToTime(deltaT_);
|
||||
endTime_ = degToTime(endTime_);
|
||||
|
||||
if
|
||||
(
|
||||
writeControl_ == wcRunTime
|
||||
|| writeControl_ == wcAdjustableRunTime
|
||||
)
|
||||
{
|
||||
writeInterval_ = degToTime(writeInterval_);
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
scalar engineTime::degToRad(const scalar deg) const
|
||||
Foam::scalar Foam::engineTime::degToRad(const scalar deg) const
|
||||
{
|
||||
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());
|
||||
}
|
||||
@ -143,7 +163,7 @@ scalar engineTime::theta() const
|
||||
|
||||
// Return current crank-angle translated to a single revolution
|
||||
// (value between -180 and 180 with 0 = top dead centre)
|
||||
scalar engineTime::thetaRevolution() const
|
||||
Foam::scalar Foam::engineTime::thetaRevolution() const
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
scalar engineTime::pistonPosition(const scalar theta) const
|
||||
Foam::scalar Foam::engineTime::pistonPosition(const scalar theta) const
|
||||
{
|
||||
return
|
||||
(
|
||||
@ -186,7 +206,7 @@ scalar engineTime::pistonPosition(const scalar theta) const
|
||||
}
|
||||
|
||||
|
||||
dimensionedScalar engineTime::pistonPosition() const
|
||||
Foam::dimensionedScalar Foam::engineTime::pistonPosition() const
|
||||
{
|
||||
return dimensionedScalar
|
||||
(
|
||||
@ -197,7 +217,7 @@ dimensionedScalar engineTime::pistonPosition() const
|
||||
}
|
||||
|
||||
|
||||
dimensionedScalar engineTime::pistonDisplacement() const
|
||||
Foam::dimensionedScalar Foam::engineTime::pistonDisplacement() const
|
||||
{
|
||||
return dimensionedScalar
|
||||
(
|
||||
@ -208,24 +228,24 @@ dimensionedScalar engineTime::pistonDisplacement() const
|
||||
}
|
||||
|
||||
|
||||
dimensionedScalar engineTime::pistonSpeed() const
|
||||
Foam::dimensionedScalar Foam::engineTime::pistonSpeed() const
|
||||
{
|
||||
return dimensionedScalar
|
||||
(
|
||||
"pistonSpeed",
|
||||
dimLength/dimTime,
|
||||
dimVelocity,
|
||||
pistonDisplacement().value()/(deltaT().value() + VSMALL)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
scalar engineTime::userTimeToTime(const scalar theta) const
|
||||
Foam::scalar Foam::engineTime::userTimeToTime(const scalar theta) const
|
||||
{
|
||||
return degToTime(theta);
|
||||
}
|
||||
|
||||
|
||||
scalar engineTime::timeToUserTime(const scalar t) const
|
||||
Foam::scalar Foam::engineTime::timeToUserTime(const scalar t) const
|
||||
{
|
||||
return timeToDeg(t);
|
||||
}
|
||||
@ -233,6 +253,4 @@ scalar engineTime::timeToUserTime(const scalar t) const
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -26,7 +26,25 @@ Class
|
||||
Foam::engineTime
|
||||
|
||||
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
|
||||
engineTime.C
|
||||
@ -55,13 +73,16 @@ class engineTime
|
||||
{
|
||||
// Private data
|
||||
|
||||
IOdictionary engineGeometry_;
|
||||
IOdictionary dict_;
|
||||
|
||||
//- RPM is required
|
||||
dimensionedScalar rpm_;
|
||||
|
||||
//- Optional engine geometry parameters
|
||||
dimensionedScalar conRodLength_;
|
||||
dimensionedScalar bore_;
|
||||
dimensionedScalar stroke_;
|
||||
dimensionedScalar clearance_;
|
||||
dimensionedScalar rpm_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
@ -72,6 +93,8 @@ class engineTime
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const engineTime&);
|
||||
|
||||
//- adjust read time values
|
||||
void timeAdjustment();
|
||||
|
||||
public:
|
||||
|
||||
@ -84,7 +107,8 @@ public:
|
||||
const fileName& rootPath,
|
||||
const fileName& caseName,
|
||||
const fileName& systemName = "system",
|
||||
const fileName& constantName = "constant"
|
||||
const fileName& constantName = "constant",
|
||||
const fileName& dictName = "engineGeometry"
|
||||
);
|
||||
|
||||
// Destructor
|
||||
@ -116,7 +140,13 @@ public:
|
||||
//- Return the engine geometry dictionary
|
||||
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
|
||||
@ -143,12 +173,6 @@ public:
|
||||
return clearance_;
|
||||
}
|
||||
|
||||
//- Return the engines current operating RPM
|
||||
const dimensionedScalar& rpm() const
|
||||
{
|
||||
return rpm_;
|
||||
}
|
||||
|
||||
|
||||
//- Return current crank-angle
|
||||
scalar theta() const;
|
||||
@ -173,16 +197,19 @@ public:
|
||||
// Member functions overriding the virtual functions in time
|
||||
|
||||
//- 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)
|
||||
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
|
||||
|
||||
//- Read the controlDict and set all the parameters
|
||||
bool read();
|
||||
virtual bool read();
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user