mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
cleanup of time handling (cosmetic changes), used timeSelector in more places
This commit is contained in:
@ -109,20 +109,20 @@ void Foam::Time::setControls()
|
||||
else
|
||||
{
|
||||
// Search directory for valid time directories
|
||||
instantList Times = findTimes(path());
|
||||
instantList timeDirs = findTimes(path());
|
||||
|
||||
if (startFrom == "firstTime")
|
||||
{
|
||||
if (Times.size())
|
||||
if (timeDirs.size())
|
||||
{
|
||||
startTime_ = Times[0].value();
|
||||
startTime_ = timeDirs[0].value();
|
||||
}
|
||||
}
|
||||
else if (startFrom == "latestTime")
|
||||
{
|
||||
if (Times.size())
|
||||
if (timeDirs.size())
|
||||
{
|
||||
startTime_ = Times[Times.size()-1].value();
|
||||
startTime_ = timeDirs[timeDirs.size()-1].value();
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -385,13 +385,13 @@ Foam::instantList Foam::Time::times() const
|
||||
|
||||
Foam::word Foam::Time::findInstancePath(const instant& t) const
|
||||
{
|
||||
instantList times = Time::findTimes(path());
|
||||
instantList timeDirs = findTimes(path());
|
||||
|
||||
forAllReverse(times, i)
|
||||
forAllReverse(timeDirs, timeI)
|
||||
{
|
||||
if (times[i] == t)
|
||||
if (timeDirs[timeI] == t)
|
||||
{
|
||||
return times[i].name();
|
||||
return timeDirs[timeI].name();
|
||||
}
|
||||
}
|
||||
|
||||
@ -401,37 +401,37 @@ Foam::word Foam::Time::findInstancePath(const instant& t) const
|
||||
|
||||
Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
||||
{
|
||||
instantList times = Time::findTimes(path());
|
||||
instantList timeDirs = findTimes(path());
|
||||
|
||||
// If there is only one time it is "constant" so return it
|
||||
if (times.size() == 1)
|
||||
// there is only one time (likely "constant") so return it
|
||||
if (timeDirs.size() == 1)
|
||||
{
|
||||
return times[0];
|
||||
return timeDirs[0];
|
||||
}
|
||||
|
||||
if (t < times[1].value())
|
||||
if (t < timeDirs[1].value())
|
||||
{
|
||||
return times[1];
|
||||
return timeDirs[1];
|
||||
}
|
||||
else if (t > times[times.size() - 1].value())
|
||||
else if (t > timeDirs[timeDirs.size()-1].value())
|
||||
{
|
||||
return times[times.size() - 1];
|
||||
return timeDirs[timeDirs.size()-1];
|
||||
}
|
||||
|
||||
label nearestIndex = -1;
|
||||
scalar deltaT = GREAT;
|
||||
|
||||
for (label i=1; i < times.size(); i++)
|
||||
for (label timeI=1; timeI < timeDirs.size(); ++timeI)
|
||||
{
|
||||
scalar diff = mag(times[i].value() - t);
|
||||
scalar diff = mag(timeDirs[timeI].value() - t);
|
||||
if (diff < deltaT)
|
||||
{
|
||||
deltaT = diff;
|
||||
nearestIndex = i;
|
||||
nearestIndex = timeI;
|
||||
}
|
||||
}
|
||||
|
||||
return times[nearestIndex];
|
||||
return timeDirs[nearestIndex];
|
||||
}
|
||||
|
||||
|
||||
@ -440,29 +440,29 @@ Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
||||
//
|
||||
// Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
||||
// {
|
||||
// instantList times = Time::findTimes(path());
|
||||
// label timeIndex = min(findClosestTimeIndex(times, t), 0);
|
||||
// return times[timeIndex];
|
||||
// instantList timeDirs = findTimes(path());
|
||||
// label timeIndex = min(findClosestTimeIndex(timeDirs, t), 0);
|
||||
// return timeDirs[timeIndex];
|
||||
// }
|
||||
|
||||
Foam::label Foam::Time::findClosestTimeIndex
|
||||
(
|
||||
const instantList& times,
|
||||
const instantList& timeDirs,
|
||||
const scalar t
|
||||
)
|
||||
{
|
||||
label nearestIndex = -1;
|
||||
scalar deltaT = GREAT;
|
||||
|
||||
forAll (times, i)
|
||||
forAll(timeDirs, timeI)
|
||||
{
|
||||
if (times[i].name() == "constant") continue;
|
||||
if (timeDirs[timeI].name() == "constant") continue;
|
||||
|
||||
scalar diff = fabs(times[i].value() - t);
|
||||
scalar diff = mag(timeDirs[timeI].value() - t);
|
||||
if (diff < deltaT)
|
||||
{
|
||||
deltaT = diff;
|
||||
nearestIndex = i;
|
||||
nearestIndex = timeI;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -170,7 +170,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select
|
||||
// determine latestTime selection (if any)
|
||||
// this must appear before the -time option processing
|
||||
label latestIdx = -1;
|
||||
if (args.options().found("latestTime"))
|
||||
if (args.optionFound("latestTime"))
|
||||
{
|
||||
selectTimes = false;
|
||||
latestIdx = timeDirs.size() - 1;
|
||||
@ -182,12 +182,12 @@ Foam::List<Foam::instant> Foam::timeSelector::select
|
||||
}
|
||||
}
|
||||
|
||||
if (args.options().found("time"))
|
||||
if (args.optionFound("time"))
|
||||
{
|
||||
// can match 0/, but can never match constant/
|
||||
selectTimes = timeSelector
|
||||
(
|
||||
IStringStream(args.options()["time"])()
|
||||
args.optionLookup("time")()
|
||||
).selected(timeDirs);
|
||||
}
|
||||
|
||||
@ -201,13 +201,13 @@ Foam::List<Foam::instant> Foam::timeSelector::select
|
||||
if (constantIdx >= 0)
|
||||
{
|
||||
// only add constant/ if specifically requested
|
||||
selectTimes[constantIdx] = args.options().found("constant");
|
||||
selectTimes[constantIdx] = args.optionFound("constant");
|
||||
}
|
||||
|
||||
// special treatment for 0/
|
||||
if (zeroIdx >= 0)
|
||||
{
|
||||
if (args.options().found("noZero"))
|
||||
if (args.optionFound("noZero"))
|
||||
{
|
||||
// exclude 0/ if specifically requested
|
||||
selectTimes[zeroIdx] = false;
|
||||
@ -215,7 +215,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select
|
||||
else if (argList::validOptions.found("zeroTime"))
|
||||
{
|
||||
// with -zeroTime enabled, drop 0/ unless specifically requested
|
||||
selectTimes[zeroIdx] = args.options().found("zeroTime");
|
||||
selectTimes[zeroIdx] = args.optionFound("zeroTime");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ class argList;
|
||||
class Time;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class timeSelector Declaration
|
||||
Class timeSelector Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class timeSelector
|
||||
@ -136,7 +136,7 @@ public:
|
||||
);
|
||||
|
||||
//- Return the set of times selected based on the argList options
|
||||
static List<Foam::instant> select
|
||||
static List<instant> select
|
||||
(
|
||||
const List<instant>&,
|
||||
const argList& args
|
||||
@ -144,7 +144,7 @@ public:
|
||||
|
||||
//- Return the set of times selected based on the argList options
|
||||
// also set the runTime to the first instance
|
||||
static List<Foam::instant> select0
|
||||
static List<instant> select0
|
||||
(
|
||||
Time& runTime,
|
||||
const argList& args
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifdef __CINT__
|
||||
#define tmp Foam::tmp
|
||||
#define UList Foam::UList
|
||||
#define List Foam::List
|
||||
#define InfoProxy Foam::InfoProxy
|
||||
# define tmp Foam::tmp
|
||||
# define UList Foam::UList
|
||||
# define List Foam::List
|
||||
# define InfoProxy Foam::InfoProxy
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifdef __CINT__
|
||||
#undef tmp
|
||||
#undef UList
|
||||
#undef List
|
||||
#undef InfoProxy
|
||||
# undef tmp
|
||||
# undef UList
|
||||
# undef List
|
||||
# undef InfoProxy
|
||||
#endif
|
||||
|
||||
@ -1 +1,5 @@
|
||||
argList::validOptions.insert("region", "name");
|
||||
//
|
||||
// addRegionOption.H
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
|
||||
Foam::argList::validOptions.insert("region", "name");
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// addTimeOptions.H
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
|
||||
argList::validOptions.insert("constant", "");
|
||||
argList::validOptions.insert("latestTime", "");
|
||||
argList::validOptions.insert("noZero", "");
|
||||
argList::validOptions.insert("time", "time");
|
||||
Foam::argList::validOptions.insert("constant", "");
|
||||
Foam::argList::validOptions.insert("latestTime", "");
|
||||
Foam::argList::validOptions.insert("noZero", "");
|
||||
Foam::argList::validOptions.insert("time", "time");
|
||||
|
||||
@ -1,4 +1,14 @@
|
||||
if (Times.size() > 1 && !args.optionFound("constant"))
|
||||
//
|
||||
// checkConstantOption.H
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
// unless -constant is present, skip startTime if it is "constant"
|
||||
|
||||
if
|
||||
(
|
||||
!args.optionFound("constant")
|
||||
&& (startTime < Times.size()-1)
|
||||
&& (Times[startTime].name() == "constant")
|
||||
)
|
||||
{
|
||||
startTime = 1;
|
||||
startTime++;
|
||||
}
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
if (args.optionFound("latestTime"))
|
||||
{
|
||||
startTime = Times.size() - 1;
|
||||
}
|
||||
@ -1,7 +1,17 @@
|
||||
//
|
||||
// checkTimeOption.H
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
// check -time and -latestTime options
|
||||
|
||||
if (args.optionFound("time"))
|
||||
{
|
||||
scalar timeValue = args.optionRead<scalar>("time");
|
||||
Foam::scalar timeValue = args.optionRead<scalar>("time");
|
||||
|
||||
startTime = Time::findClosestTimeIndex(Times, timeValue);
|
||||
startTime = Foam::Time::findClosestTimeIndex(Times, timeValue);
|
||||
endTime = startTime + 1;
|
||||
}
|
||||
|
||||
if (args.optionFound("latestTime"))
|
||||
{
|
||||
startTime = Times.size() - 1;
|
||||
}
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
label startTime = 0;
|
||||
label endTime = Times.size();
|
||||
//
|
||||
// checkTimeOptions.H
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Foam::label startTime = 0;
|
||||
Foam::label endTime = Times.size();
|
||||
|
||||
// unless -constant is present, skip startTime if it is "constant"
|
||||
# include "checkConstantOption.H"
|
||||
|
||||
// check -time and -latestTime options
|
||||
# include "checkTimeOption.H"
|
||||
# include "checkLatestTimeOption.H"
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
label startTime = 0;
|
||||
label endTime = Times.size();
|
||||
//
|
||||
// checkTimeOptionsNoConstant.H
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Foam::label startTime = 0;
|
||||
Foam::label endTime = Times.size();
|
||||
|
||||
// check -time and -latestTime options
|
||||
# include "checkTimeOption.H"
|
||||
# include "checkLatestTimeOption.H"
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
Foam::Info<< "Create mesh for time = "
|
||||
//
|
||||
// createMesh.H
|
||||
// ~~~~~~~~~~~~
|
||||
|
||||
Foam::Info
|
||||
<< "Create mesh for time = "
|
||||
<< runTime.timeName() << Foam::nl << Foam::endl;
|
||||
|
||||
Foam::fvMesh mesh
|
||||
|
||||
@ -1,13 +1,19 @@
|
||||
Info<< "Create mesh, no clear-out for time = "
|
||||
<< runTime.timeName() << nl << endl;
|
||||
//
|
||||
// createMeshNoClear.H
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
// currently identical to createMesh.H
|
||||
|
||||
fvMesh mesh
|
||||
Foam::Info
|
||||
<< "Create mesh, no clear-out for time = "
|
||||
<< runTime.timeName() << Foam::nl << Foam::endl;
|
||||
|
||||
Foam::fvMesh mesh
|
||||
(
|
||||
IOobject
|
||||
Foam::IOobject
|
||||
(
|
||||
fvMesh::defaultRegion,
|
||||
Foam::fvMesh::defaultRegion,
|
||||
runTime.timeName(),
|
||||
runTime,
|
||||
IOobject::MUST_READ
|
||||
Foam::IOobject::MUST_READ
|
||||
)
|
||||
);
|
||||
|
||||
@ -1,24 +1,30 @@
|
||||
word regionName;
|
||||
//
|
||||
// createNamedMesh.H
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
|
||||
Foam::word regionName;
|
||||
|
||||
if (args.optionReadIfPresent("region", regionName))
|
||||
{
|
||||
Info<< "Create mesh " << regionName << " for time = "
|
||||
<< runTime.timeName() << nl << endl;
|
||||
Foam::Info
|
||||
<< "Create mesh " << regionName << " for time = "
|
||||
<< runTime.timeName() << Foam::nl << Foam::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
regionName = fvMesh::defaultRegion;
|
||||
Info<< "Create mesh for time = "
|
||||
<< runTime.timeName() << nl << endl;
|
||||
regionName = Foam::fvMesh::defaultRegion;
|
||||
Foam::Info
|
||||
<< "Create mesh for time = "
|
||||
<< runTime.timeName() << Foam::nl << Foam::endl;
|
||||
}
|
||||
|
||||
fvMesh mesh
|
||||
Foam::fvMesh mesh
|
||||
(
|
||||
IOobject
|
||||
Foam::IOobject
|
||||
(
|
||||
regionName,
|
||||
runTime.timeName(),
|
||||
runTime,
|
||||
IOobject::MUST_READ
|
||||
Foam::IOobject::MUST_READ
|
||||
)
|
||||
);
|
||||
|
||||
@ -1,24 +1,30 @@
|
||||
word regionName;
|
||||
//
|
||||
// createNamedPolyMesh.H
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Foam::word regionName;
|
||||
|
||||
if (args.optionReadIfPresent("region", regionName))
|
||||
{
|
||||
Info<< "Create polyMesh " << regionName << " for time = "
|
||||
<< runTime.timeName() << nl << endl;
|
||||
Foam::Info
|
||||
<< "Create polyMesh " << regionName << " for time = "
|
||||
<< runTime.timeName() << Foam::nl << Foam::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
regionName = polyMesh::defaultRegion;
|
||||
Info<< "Create polyMesh for time = "
|
||||
<< runTime.timeName() << nl << endl;
|
||||
regionName = Foam::polyMesh::defaultRegion;
|
||||
Foam::Info
|
||||
<< "Create polyMesh for time = "
|
||||
<< runTime.timeName() << Foam::nl << Foam::endl;
|
||||
}
|
||||
|
||||
polyMesh mesh
|
||||
Foam::polyMesh mesh
|
||||
(
|
||||
IOobject
|
||||
Foam::IOobject
|
||||
(
|
||||
regionName,
|
||||
runTime.timeName(),
|
||||
runTime,
|
||||
IOobject::MUST_READ
|
||||
Foam::IOobject::MUST_READ
|
||||
)
|
||||
);
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
Info<< "Create polyMesh for time = "
|
||||
<< runTime.timeName() << nl << endl;
|
||||
//
|
||||
// createPolyMesh.H
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
|
||||
polyMesh mesh
|
||||
Foam::Info
|
||||
<< "Create polyMesh for time = "
|
||||
<< runTime.timeName() << Foam::nl << Foam::endl;
|
||||
|
||||
Foam::polyMesh mesh
|
||||
(
|
||||
IOobject
|
||||
Foam::IOobject
|
||||
(
|
||||
polyMesh::defaultRegion,
|
||||
Foam::polyMesh::defaultRegion,
|
||||
runTime.timeName(),
|
||||
runTime,
|
||||
IOobject::MUST_READ
|
||||
Foam::IOobject::MUST_READ
|
||||
)
|
||||
);
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
//
|
||||
// createTime.H
|
||||
// ~~~~~~~~~~~~
|
||||
|
||||
Foam::Info<< "Create time\n" << Foam::endl;
|
||||
|
||||
Foam::Time runTime
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
Foam::argList args(argc, argv);
|
||||
//
|
||||
// setRootCase.H
|
||||
// ~~~~~~~~~~~~~
|
||||
|
||||
if (!args.checkRootCase())
|
||||
{
|
||||
Foam::FatalError.exit();
|
||||
}
|
||||
Foam::argList args(argc, argv);
|
||||
if (!args.checkRootCase())
|
||||
{
|
||||
Foam::FatalError.exit();
|
||||
}
|
||||
|
||||
@ -232,14 +232,14 @@ void Foam::calcTypes::addSubtract::preCalc
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (args.options().found("field"))
|
||||
if (args.optionFound("field"))
|
||||
{
|
||||
addSubtractFieldName_ = args.options()["field"];
|
||||
addSubtractFieldName_ = args.option("field");
|
||||
calcType_ = FIELD;
|
||||
}
|
||||
else if (args.options().found("value"))
|
||||
else if (args.optionFound("value"))
|
||||
{
|
||||
addSubtractValueStr_ = args.options()["value"];
|
||||
addSubtractValueStr_ = args.option("value");
|
||||
calcType_ = VALUE;
|
||||
}
|
||||
else
|
||||
@ -249,9 +249,9 @@ void Foam::calcTypes::addSubtract::preCalc
|
||||
<< nl << exit(FatalError);
|
||||
}
|
||||
|
||||
if (args.options().found("resultName"))
|
||||
if (args.optionFound("resultName"))
|
||||
{
|
||||
resultName_ = args.options()["resultName"];
|
||||
resultName_ = args.option("resultName");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user