mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve controls for Time (issue #910)
- relocate some standard functionality to TimePaths to allow a lighter means of managing time directories without using the entire Time mechanism. - optional enableLibs for Time construction (default is on) and a corresponding argList::noLibs() and "-no-libs" option STYLE: - mark Time::outputTime() as deprecated MAY-2016 - use pre-increment for runTime, although there is no difference in behaviour or performance.
This commit is contained in:
@ -286,7 +286,6 @@ $(Time)/TimePaths.C
|
||||
$(Time)/TimeState.C
|
||||
$(Time)/Time.C
|
||||
$(Time)/TimeIO.C
|
||||
$(Time)/findTimes.C
|
||||
$(Time)/subCycleTime.C
|
||||
$(Time)/subLoopTime.C
|
||||
$(Time)/timeSelector.C
|
||||
|
||||
@ -244,21 +244,42 @@ void inplaceUniqueSort
|
||||
);
|
||||
|
||||
|
||||
//- Extract elements of List when select is true
|
||||
// eg, to extract all selected elements:
|
||||
//- Extract elements of the input List when select is true.
|
||||
//
|
||||
// \param select the bool-list selector, for which the operator[]
|
||||
// returns true or false. A labelHashSet can also be used since
|
||||
// it satisfies these requirements
|
||||
// \param input the list input values. Cannot be a FixedList since
|
||||
// it doesn't resize.
|
||||
// \param invert set as true to invert the selection logic
|
||||
//
|
||||
// Eg, to extract all selected elements:
|
||||
// \code
|
||||
// subset<boolList, labelList>(selectedElems, list);
|
||||
// Note a labelHashSet can also be used as the bool-list.
|
||||
// Do not use FixedList for the input list, since it doesn't resize.
|
||||
// \endcode
|
||||
template<class BoolListType, class ListType>
|
||||
ListType subset(const BoolListType& select, const ListType& input);
|
||||
ListType subset
|
||||
(
|
||||
const BoolListType& select,
|
||||
const ListType& input,
|
||||
const bool invert=false
|
||||
);
|
||||
|
||||
//- Inplace extract elements of List when select is true
|
||||
// eg, to extract all selected elements:
|
||||
// inplaceSubset<boolList, labelList>(selectedElems, list);
|
||||
// Note a labelHashSet can also be used as the bool-list.
|
||||
// Do not use FixedList for the input list, since it doesn't resize.
|
||||
//- Inplace extract elements of the input List when select is true.
|
||||
//
|
||||
// \param select the bool-list selector, for which the operator[]
|
||||
// returns true or false. A labelHashSet can also be used since
|
||||
// it satisfies these requirements
|
||||
// \param input the list input values. Cannot be a FixedList since
|
||||
// it doesn't resize.
|
||||
// \param invert set as true to invert the selection logic
|
||||
template<class BoolListType, class ListType>
|
||||
void inplaceSubset(const BoolListType& select, ListType& input);
|
||||
void inplaceSubset
|
||||
(
|
||||
const BoolListType& select,
|
||||
ListType& input,
|
||||
const bool invert=false
|
||||
);
|
||||
|
||||
|
||||
//- Copy a subset of the input list when predicate is true.
|
||||
|
||||
@ -474,7 +474,8 @@ template<class BoolListType, class ListType>
|
||||
ListType Foam::subset
|
||||
(
|
||||
const BoolListType& select,
|
||||
const ListType& input
|
||||
const ListType& input,
|
||||
const bool invert
|
||||
)
|
||||
{
|
||||
const label len = input.size();
|
||||
@ -487,7 +488,7 @@ ListType Foam::subset
|
||||
label count = 0;
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
if (select[i])
|
||||
if (select[i] ? !invert : invert)
|
||||
{
|
||||
output[count] = input[i];
|
||||
++count;
|
||||
@ -503,7 +504,8 @@ template<class BoolListType, class ListType>
|
||||
void Foam::inplaceSubset
|
||||
(
|
||||
const BoolListType& select,
|
||||
ListType& input
|
||||
ListType& input,
|
||||
const bool invert
|
||||
)
|
||||
{
|
||||
const label len = input.size();
|
||||
@ -513,7 +515,7 @@ void Foam::inplaceSubset
|
||||
label count = 0;
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
if (select[i])
|
||||
if (select[i] ? !invert : invert)
|
||||
{
|
||||
if (count != i)
|
||||
{
|
||||
|
||||
@ -156,23 +156,22 @@ void Foam::Time::setControls()
|
||||
// Search directory for valid time directories
|
||||
instantList timeDirs = findTimes(path(), constant());
|
||||
|
||||
const label nTimes = timeDirs.size();
|
||||
|
||||
if (startFrom == "firstTime")
|
||||
{
|
||||
if (timeDirs.size())
|
||||
if (nTimes > 1 && timeDirs.first().name() == constant())
|
||||
{
|
||||
if (timeDirs[0].name() == constant() && timeDirs.size() >= 2)
|
||||
{
|
||||
startTime_ = timeDirs[1].value();
|
||||
}
|
||||
else
|
||||
{
|
||||
startTime_ = timeDirs[0].value();
|
||||
}
|
||||
startTime_ = timeDirs[1].value();
|
||||
}
|
||||
else if (nTimes)
|
||||
{
|
||||
startTime_ = timeDirs.first().value();
|
||||
}
|
||||
}
|
||||
else if (startFrom == "latestTime")
|
||||
{
|
||||
if (timeDirs.size())
|
||||
if (nTimes)
|
||||
{
|
||||
startTime_ = timeDirs.last().value();
|
||||
}
|
||||
@ -204,7 +203,7 @@ void Foam::Time::setControls()
|
||||
(
|
||||
precision_ = maxPrecision_;
|
||||
precision_ > oldPrecision;
|
||||
precision_--
|
||||
--precision_
|
||||
)
|
||||
{
|
||||
// Update the time formatting
|
||||
@ -407,12 +406,13 @@ void Foam::Time::setMonitoring(const bool forceProfiling)
|
||||
|
||||
Foam::Time::Time
|
||||
(
|
||||
const word& controlDictName,
|
||||
const word& ctrlDictName,
|
||||
const fileName& rootPath,
|
||||
const fileName& caseName,
|
||||
const word& systemName,
|
||||
const word& constantName,
|
||||
const bool enableFunctionObjects
|
||||
const bool enableFunctionObjects,
|
||||
const bool enableLibs
|
||||
)
|
||||
:
|
||||
TimePaths
|
||||
@ -432,7 +432,7 @@ Foam::Time::Time
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
controlDictName,
|
||||
ctrlDictName,
|
||||
system(),
|
||||
*this,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
@ -456,10 +456,17 @@ Foam::Time::Time
|
||||
writeStreamOption_(IOstream::ASCII),
|
||||
graphFormat_("raw"),
|
||||
runTimeModifiable_(false),
|
||||
|
||||
functionObjects_(*this, enableFunctionObjects)
|
||||
functionObjects_(*this, false)
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
if (enableFunctionObjects)
|
||||
{
|
||||
functionObjects_.on();
|
||||
}
|
||||
|
||||
if (enableLibs)
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
}
|
||||
|
||||
// Explicitly set read flags on objectRegistry so anything constructed
|
||||
// from it reads as well (e.g. fvSolution).
|
||||
@ -472,22 +479,13 @@ Foam::Time::Time
|
||||
|
||||
Foam::Time::Time
|
||||
(
|
||||
const word& controlDictName,
|
||||
const word& ctrlDictName,
|
||||
const argList& args,
|
||||
const word& systemName,
|
||||
const word& constantName
|
||||
)
|
||||
:
|
||||
TimePaths
|
||||
(
|
||||
args.parRunControl().parRun(),
|
||||
args.rootPath(),
|
||||
args.distributed(),
|
||||
args.globalCaseName(),
|
||||
args.caseName(),
|
||||
systemName,
|
||||
constantName
|
||||
),
|
||||
TimePaths(args, systemName, constantName),
|
||||
|
||||
objectRegistry(*this),
|
||||
|
||||
@ -498,7 +496,7 @@ Foam::Time::Time
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
controlDictName,
|
||||
ctrlDictName,
|
||||
system(),
|
||||
*this,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
@ -522,18 +520,38 @@ Foam::Time::Time
|
||||
writeStreamOption_(IOstream::ASCII),
|
||||
graphFormat_("raw"),
|
||||
runTimeModifiable_(false),
|
||||
|
||||
functionObjects_
|
||||
functionObjects_(*this, false)
|
||||
{
|
||||
// Enable/disable functions
|
||||
//
|
||||
// '-withFunctionObjects' exists and used = enable
|
||||
// '-noFunctionObjects' exists and used = disable
|
||||
// default: no functions if there is no way to enable/disable them
|
||||
if
|
||||
(
|
||||
*this,
|
||||
argList::validOptions.found("withFunctionObjects")
|
||||
? args.found("withFunctionObjects")
|
||||
: argList::validOptions.found("noFunctionObjects")
|
||||
? !args.found("noFunctionObjects")
|
||||
: false
|
||||
)
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
{
|
||||
functionObjects_.on();
|
||||
}
|
||||
|
||||
// Allow/disallow libs
|
||||
//
|
||||
// '-no-libs' exists and used = disable
|
||||
// default: enable
|
||||
if
|
||||
(
|
||||
argList::validOptions.found("no-libs")
|
||||
? !args.found("no-libs")
|
||||
: true
|
||||
)
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
}
|
||||
|
||||
// Explicitly set read flags on objectRegistry so anything constructed
|
||||
// from it reads as well (e.g. fvSolution).
|
||||
@ -553,7 +571,8 @@ Foam::Time::Time
|
||||
const fileName& caseName,
|
||||
const word& systemName,
|
||||
const word& constantName,
|
||||
const bool enableFunctionObjects
|
||||
const bool enableFunctionObjects,
|
||||
const bool enableLibs
|
||||
)
|
||||
:
|
||||
TimePaths
|
||||
@ -599,9 +618,18 @@ Foam::Time::Time
|
||||
graphFormat_("raw"),
|
||||
runTimeModifiable_(false),
|
||||
|
||||
functionObjects_(*this, enableFunctionObjects)
|
||||
functionObjects_(*this, false)
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
if (enableFunctionObjects)
|
||||
{
|
||||
functionObjects_.on();
|
||||
}
|
||||
|
||||
if (enableLibs)
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
}
|
||||
|
||||
|
||||
// Explicitly set read flags on objectRegistry so anything constructed
|
||||
// from it reads as well (e.g. fvSolution).
|
||||
@ -621,7 +649,8 @@ Foam::Time::Time
|
||||
const fileName& caseName,
|
||||
const word& systemName,
|
||||
const word& constantName,
|
||||
const bool enableFunctionObjects
|
||||
const bool enableFunctionObjects,
|
||||
const bool enableLibs
|
||||
)
|
||||
:
|
||||
TimePaths
|
||||
@ -664,9 +693,18 @@ Foam::Time::Time
|
||||
graphFormat_("raw"),
|
||||
runTimeModifiable_(false),
|
||||
|
||||
functionObjects_(*this, enableFunctionObjects)
|
||||
functionObjects_(*this, false)
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
if (enableFunctionObjects)
|
||||
{
|
||||
functionObjects_.on();
|
||||
}
|
||||
|
||||
if (enableLibs)
|
||||
{
|
||||
libs_.open(controlDict_, "libs");
|
||||
}
|
||||
|
||||
setMonitoring(); // for profiling etc
|
||||
}
|
||||
|
||||
@ -708,12 +746,6 @@ Foam::word Foam::Time::timeName() const
|
||||
}
|
||||
|
||||
|
||||
Foam::instantList Foam::Time::times() const
|
||||
{
|
||||
return findTimes(path(), constant());
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::Time::findInstance
|
||||
(
|
||||
const fileName& dir,
|
||||
@ -779,68 +811,6 @@ Foam::word Foam::Time::findInstancePath(const instant& t) const
|
||||
}
|
||||
|
||||
|
||||
Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
||||
{
|
||||
instantList timeDirs = findTimes(path(), constant());
|
||||
|
||||
// There is only one time (likely "constant") so return it
|
||||
if (timeDirs.size() == 1)
|
||||
{
|
||||
return timeDirs[0];
|
||||
}
|
||||
|
||||
if (t < timeDirs[1].value())
|
||||
{
|
||||
return timeDirs[1];
|
||||
}
|
||||
else if (t > timeDirs.last().value())
|
||||
{
|
||||
return timeDirs.last();
|
||||
}
|
||||
|
||||
label nearestIndex = -1;
|
||||
scalar deltaT = GREAT;
|
||||
|
||||
for (label timei=1; timei < timeDirs.size(); ++timei)
|
||||
{
|
||||
scalar diff = mag(timeDirs[timei].value() - t);
|
||||
if (diff < deltaT)
|
||||
{
|
||||
deltaT = diff;
|
||||
nearestIndex = timei;
|
||||
}
|
||||
}
|
||||
|
||||
return timeDirs[nearestIndex];
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::Time::findClosestTimeIndex
|
||||
(
|
||||
const instantList& timeDirs,
|
||||
const scalar t,
|
||||
const word& constantName
|
||||
)
|
||||
{
|
||||
label nearestIndex = -1;
|
||||
scalar deltaT = GREAT;
|
||||
|
||||
forAll(timeDirs, timei)
|
||||
{
|
||||
if (timeDirs[timei].name() == constantName) continue;
|
||||
|
||||
scalar diff = mag(timeDirs[timei].value() - t);
|
||||
if (diff < deltaT)
|
||||
{
|
||||
deltaT = diff;
|
||||
nearestIndex = timei;
|
||||
}
|
||||
}
|
||||
|
||||
return nearestIndex;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::Time::startTimeIndex() const
|
||||
{
|
||||
return startTimeIndex_;
|
||||
|
||||
@ -143,7 +143,9 @@ protected:
|
||||
// Protected data
|
||||
|
||||
label startTimeIndex_;
|
||||
|
||||
scalar startTime_;
|
||||
|
||||
mutable scalar endTime_;
|
||||
|
||||
mutable stopAtControls stopAt_;
|
||||
@ -225,7 +227,7 @@ public:
|
||||
//- Construct given name of dictionary to read and argument list
|
||||
Time
|
||||
(
|
||||
const word& name,
|
||||
const word& ctrlDictName,
|
||||
const argList& args,
|
||||
const word& systemName = "system",
|
||||
const word& constantName = "constant"
|
||||
@ -234,12 +236,13 @@ public:
|
||||
//- Construct given name of dictionary to read, rootPath and casePath
|
||||
Time
|
||||
(
|
||||
const word& name,
|
||||
const word& ctrlDictName,
|
||||
const fileName& rootPath,
|
||||
const fileName& caseName,
|
||||
const word& systemName = "system",
|
||||
const word& constantName = "constant",
|
||||
const bool enableFunctionObjects = true
|
||||
const bool enableFunctionObjects = true,
|
||||
const bool enableLibs = true
|
||||
);
|
||||
|
||||
//- Construct given dictionary, rootPath and casePath
|
||||
@ -250,7 +253,8 @@ public:
|
||||
const fileName& caseName,
|
||||
const word& systemName = "system",
|
||||
const word& constantName = "constant",
|
||||
const bool enableFunctionObjects = true
|
||||
const bool enableFunctionObjects = true,
|
||||
const bool enableLibs = true
|
||||
);
|
||||
|
||||
//- Construct given endTime, rootPath and casePath
|
||||
@ -260,7 +264,8 @@ public:
|
||||
const fileName& caseName,
|
||||
const word& systemName = "system",
|
||||
const word& constantName = "constant",
|
||||
const bool enableFunctionObjects = true
|
||||
const bool enableFunctionObjects = true,
|
||||
const bool enableLibs = true
|
||||
);
|
||||
|
||||
|
||||
@ -273,16 +278,10 @@ public:
|
||||
// Database functions
|
||||
|
||||
//- Return root path
|
||||
const fileName& rootPath() const
|
||||
{
|
||||
return TimePaths::rootPath();
|
||||
}
|
||||
using TimePaths::rootPath;
|
||||
|
||||
//- Return case name
|
||||
const fileName& caseName() const
|
||||
{
|
||||
return TimePaths::caseName();
|
||||
}
|
||||
using TimePaths::caseName;
|
||||
|
||||
//- Return path
|
||||
fileName path() const
|
||||
@ -290,6 +289,7 @@ public:
|
||||
return rootPath()/caseName();
|
||||
}
|
||||
|
||||
//- Return read access to the controlDict dictionary
|
||||
const dictionary& controlDict() const
|
||||
{
|
||||
return controlDict_;
|
||||
@ -343,7 +343,7 @@ public:
|
||||
void readModifiedObjects();
|
||||
|
||||
//- Return the location of "dir" containing the file "name".
|
||||
// (eg, used in reading mesh data)
|
||||
//- (eg, used in reading mesh data)
|
||||
// If name is null, search for the directory "dir" only.
|
||||
// Does not search beyond stopInstance (if set) or constant.
|
||||
word findInstance
|
||||
@ -354,11 +354,8 @@ public:
|
||||
const word& stopInstance = word::null
|
||||
) const;
|
||||
|
||||
//- Search the case for valid time directories
|
||||
instantList times() const;
|
||||
|
||||
//- Search the case for the time directory path
|
||||
// corresponding to the given instance
|
||||
//- corresponding to the given instance
|
||||
word findInstancePath
|
||||
(
|
||||
const fileName& directory,
|
||||
@ -366,20 +363,9 @@ public:
|
||||
) const;
|
||||
|
||||
//- Search the case for the time directory path
|
||||
// corresponding to the given instance
|
||||
//- corresponding to the given instance
|
||||
word findInstancePath(const instant& t) const;
|
||||
|
||||
//- Search the case for the time closest to the given time
|
||||
instant findClosestTime(const scalar t) const;
|
||||
|
||||
//- Search instantList for the time index closest to the given time
|
||||
static label findClosestTimeIndex
|
||||
(
|
||||
const instantList& timeDirs,
|
||||
const scalar t,
|
||||
const word& constantName = "constant"
|
||||
);
|
||||
|
||||
//- Write time dictionary to the \<time\>/uniform directory
|
||||
virtual bool writeTimeDict() const;
|
||||
|
||||
@ -392,8 +378,8 @@ public:
|
||||
const bool valid
|
||||
) const;
|
||||
|
||||
//- Write the objects now (not at end of iteration) and continue
|
||||
// the run
|
||||
//- Write the objects immediately (not at end of iteration)
|
||||
//- and continue the run
|
||||
bool writeNow();
|
||||
|
||||
//- Write the objects now (not at end of iteration) and end the run
|
||||
@ -409,7 +395,7 @@ public:
|
||||
// Access
|
||||
|
||||
//- Return time name of given scalar time
|
||||
// formatted with given precision
|
||||
//- formatted with the given precision
|
||||
static word timeName
|
||||
(
|
||||
const scalar t,
|
||||
@ -419,13 +405,6 @@ public:
|
||||
//- Return current time name
|
||||
virtual word timeName() const;
|
||||
|
||||
//- Search a given directory for valid time directories
|
||||
static instantList findTimes
|
||||
(
|
||||
const fileName& directory,
|
||||
const word& constantName = "constant"
|
||||
);
|
||||
|
||||
//- Return start time index
|
||||
virtual label startTimeIndex() const;
|
||||
|
||||
@ -484,7 +463,7 @@ public:
|
||||
// \code
|
||||
// while (runTime.run())
|
||||
// {
|
||||
// runTime++;
|
||||
// ++runTime;
|
||||
// solve;
|
||||
// runTime.write();
|
||||
// }
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,6 +24,8 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "TimePaths.H"
|
||||
#include "argList.H"
|
||||
#include "fileOperation.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
@ -36,8 +38,8 @@ bool Foam::TimePaths::detectProcessorCase()
|
||||
}
|
||||
|
||||
// Look for "processor", but should really check for following digits too
|
||||
const std::string::size_type sep = globalCaseName_.rfind('/');
|
||||
const std::string::size_type pos = globalCaseName_.find
|
||||
const auto sep = globalCaseName_.rfind('/');
|
||||
const auto pos = globalCaseName_.find
|
||||
(
|
||||
"processor",
|
||||
(sep == string::npos ? 0 : sep)
|
||||
@ -60,6 +62,28 @@ bool Foam::TimePaths::detectProcessorCase()
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::TimePaths::TimePaths
|
||||
(
|
||||
const argList& args,
|
||||
const word& systemName,
|
||||
const word& constantName
|
||||
)
|
||||
:
|
||||
processorCase_(args.parRunControl().parRun()),
|
||||
rootPath_(args.rootPath()),
|
||||
distributed_(args.distributed()),
|
||||
globalCaseName_(args.globalCaseName()),
|
||||
case_(args.caseName()),
|
||||
system_(systemName),
|
||||
constant_(constantName)
|
||||
{
|
||||
// For convenience: find out from case name whether it is a
|
||||
// processor directory and set processorCase flag so file searching
|
||||
// goes up one level.
|
||||
detectProcessorCase();
|
||||
}
|
||||
|
||||
|
||||
Foam::TimePaths::TimePaths
|
||||
(
|
||||
const fileName& rootPath,
|
||||
@ -115,10 +139,8 @@ Foam::fileName Foam::TimePaths::caseSystem() const
|
||||
{
|
||||
return ".."/system();
|
||||
}
|
||||
else
|
||||
{
|
||||
return system();
|
||||
}
|
||||
|
||||
return system();
|
||||
}
|
||||
|
||||
|
||||
@ -128,12 +150,91 @@ Foam::fileName Foam::TimePaths::caseConstant() const
|
||||
{
|
||||
return ".."/constant();
|
||||
}
|
||||
else
|
||||
{
|
||||
return constant();
|
||||
}
|
||||
|
||||
return constant();
|
||||
}
|
||||
|
||||
|
||||
Foam::instantList Foam::TimePaths::findTimes
|
||||
(
|
||||
const fileName& directory,
|
||||
const word& constantName
|
||||
)
|
||||
{
|
||||
return fileHandler().findTimes(directory, constantName);
|
||||
}
|
||||
|
||||
|
||||
Foam::instantList Foam::TimePaths::times() const
|
||||
{
|
||||
return findTimes(path(), constant());
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::TimePaths::findClosestTimeIndex
|
||||
(
|
||||
const instantList& timeDirs,
|
||||
const scalar t,
|
||||
const word& constantName
|
||||
)
|
||||
{
|
||||
const label nTimes = timeDirs.size();
|
||||
|
||||
label nearestIndex = -1;
|
||||
scalar deltaT = GREAT;
|
||||
|
||||
for (label timei=0; timei < nTimes; ++timei)
|
||||
{
|
||||
if (timeDirs[timei].name() == constantName) continue;
|
||||
|
||||
const scalar diff = mag(timeDirs[timei].value() - t);
|
||||
if (diff < deltaT)
|
||||
{
|
||||
deltaT = diff;
|
||||
nearestIndex = timei;
|
||||
}
|
||||
}
|
||||
|
||||
return nearestIndex;
|
||||
}
|
||||
|
||||
|
||||
Foam::instant Foam::TimePaths::findClosestTime(const scalar t) const
|
||||
{
|
||||
instantList timeDirs = findTimes(path(), constant());
|
||||
|
||||
const label nTimes = timeDirs.size();
|
||||
|
||||
// There is only one time (likely "constant") so return it
|
||||
if (nTimes == 1)
|
||||
{
|
||||
return timeDirs.first();
|
||||
}
|
||||
|
||||
if (t < timeDirs[1].value())
|
||||
{
|
||||
return timeDirs[1];
|
||||
}
|
||||
else if (t > timeDirs.last().value())
|
||||
{
|
||||
return timeDirs.last();
|
||||
}
|
||||
|
||||
label nearestIndex = -1;
|
||||
scalar deltaT = GREAT;
|
||||
|
||||
for (label timei=1; timei < nTimes; ++timei)
|
||||
{
|
||||
const scalar diff = mag(timeDirs[timei].value() - t);
|
||||
if (diff < deltaT)
|
||||
{
|
||||
deltaT = diff;
|
||||
nearestIndex = timei;
|
||||
}
|
||||
}
|
||||
|
||||
return timeDirs[nearestIndex];
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,7 +25,7 @@ Class
|
||||
Foam::TimePaths
|
||||
|
||||
Description
|
||||
A class for addressing time paths without using the Time class.
|
||||
Address the time paths without using the Time class.
|
||||
|
||||
SourceFiles
|
||||
TimePaths.C
|
||||
@ -36,12 +36,16 @@ SourceFiles
|
||||
#define TimePaths_H
|
||||
|
||||
#include "fileName.H"
|
||||
#include "instantList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class argList;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class TimePaths Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -70,13 +74,21 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct using characteristics given by the argList
|
||||
TimePaths
|
||||
(
|
||||
const argList& args,
|
||||
const word& systemName = "system",
|
||||
const word& constantName = "constant"
|
||||
);
|
||||
|
||||
//- Construct given database name, rootPath and casePath
|
||||
TimePaths
|
||||
(
|
||||
const fileName& rootPath,
|
||||
const fileName& caseName,
|
||||
const word& systemName,
|
||||
const word& constantName
|
||||
const word& systemName = "system",
|
||||
const word& constantName = "constant"
|
||||
);
|
||||
|
||||
|
||||
@ -88,87 +100,113 @@ public:
|
||||
const bool distributed,
|
||||
const fileName& globalCaseName,
|
||||
const fileName& caseName,
|
||||
const word& systemName,
|
||||
const word& constantName
|
||||
const word& systemName = "system",
|
||||
const word& constantName = "constant"
|
||||
);
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Return true if this is a processor case
|
||||
bool processorCase() const
|
||||
{
|
||||
return processorCase_;
|
||||
}
|
||||
//- Return true if this is a processor case
|
||||
bool processorCase() const
|
||||
{
|
||||
return processorCase_;
|
||||
}
|
||||
|
||||
//- Return root path
|
||||
const fileName& rootPath() const
|
||||
{
|
||||
return rootPath_;
|
||||
}
|
||||
//- Return root path
|
||||
const fileName& rootPath() const
|
||||
{
|
||||
return rootPath_;
|
||||
}
|
||||
|
||||
//- Return global case name
|
||||
const fileName& globalCaseName() const
|
||||
{
|
||||
return globalCaseName_;
|
||||
}
|
||||
//- Return global case name
|
||||
const fileName& globalCaseName() const
|
||||
{
|
||||
return globalCaseName_;
|
||||
}
|
||||
|
||||
//- Return case name
|
||||
const fileName& caseName() const
|
||||
{
|
||||
return case_;
|
||||
}
|
||||
//- Return case name
|
||||
const fileName& caseName() const
|
||||
{
|
||||
return case_;
|
||||
}
|
||||
|
||||
//- Return case name
|
||||
fileName& caseName()
|
||||
{
|
||||
return case_;
|
||||
}
|
||||
//- Return case name
|
||||
fileName& caseName()
|
||||
{
|
||||
return case_;
|
||||
}
|
||||
|
||||
//- Return system name
|
||||
const word& system() const
|
||||
{
|
||||
return system_;
|
||||
}
|
||||
//- Return system name
|
||||
const word& system() const
|
||||
{
|
||||
return system_;
|
||||
}
|
||||
|
||||
//- Return system name for the case
|
||||
// which for parallel runs returns ../system()
|
||||
fileName caseSystem() const;
|
||||
//- Return the system name for the case, which is
|
||||
//- \c ../system() for parallel runs.
|
||||
fileName caseSystem() const;
|
||||
|
||||
//- Return constant name
|
||||
const word& constant() const
|
||||
{
|
||||
return constant_;
|
||||
}
|
||||
//- Return constant name
|
||||
const word& constant() const
|
||||
{
|
||||
return constant_;
|
||||
}
|
||||
|
||||
//- Is case running with parallel distributed directories
|
||||
// (i.e. not NFS mounted)
|
||||
bool distributed() const
|
||||
{
|
||||
return distributed_;
|
||||
}
|
||||
//- Is case running with parallel distributed directories
|
||||
// (i.e. not NFS mounted)
|
||||
bool distributed() const
|
||||
{
|
||||
return distributed_;
|
||||
}
|
||||
|
||||
//- Return constant name for the case
|
||||
// which for parallel runs returns ../constant()
|
||||
fileName caseConstant() const;
|
||||
//- Return the constant name for the case, which is
|
||||
//- \c ../constant() for parallel runs.
|
||||
fileName caseConstant() const;
|
||||
|
||||
//- Return path
|
||||
fileName path() const
|
||||
{
|
||||
return rootPath()/caseName();
|
||||
}
|
||||
//- Return path
|
||||
fileName path() const
|
||||
{
|
||||
return rootPath()/caseName();
|
||||
}
|
||||
|
||||
//- Return system path
|
||||
fileName systemPath() const
|
||||
{
|
||||
return path()/system();
|
||||
}
|
||||
//- Return system path
|
||||
fileName systemPath() const
|
||||
{
|
||||
return path()/system();
|
||||
}
|
||||
|
||||
//- Return constant path
|
||||
fileName constantPath() const
|
||||
{
|
||||
return path()/constant();
|
||||
}
|
||||
|
||||
|
||||
// Searching
|
||||
|
||||
//- Search a given directory for valid time directories
|
||||
// Forwards to the current fileHandler
|
||||
static instantList findTimes
|
||||
(
|
||||
const fileName& directory,
|
||||
const word& constantName = "constant"
|
||||
);
|
||||
|
||||
//- Search instantList for the time index closest to the specified time
|
||||
static label findClosestTimeIndex
|
||||
(
|
||||
const instantList& timeDirs,
|
||||
const scalar t,
|
||||
const word& constantName = "constant"
|
||||
);
|
||||
|
||||
//- Search the case for valid time directories
|
||||
instantList times() const;
|
||||
|
||||
//- Search the case for the time closest to the given time
|
||||
instant findClosestTime(const scalar t) const;
|
||||
|
||||
//- Return constant path
|
||||
fileName constantPath() const
|
||||
{
|
||||
return path()/constant();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,21 +32,15 @@ Foam::TimeState::TimeState()
|
||||
:
|
||||
dimensionedScalar(Time::timeName(0), dimTime, 0),
|
||||
timeIndex_(0),
|
||||
deltaT_(0),
|
||||
deltaTSave_(0),
|
||||
deltaT0_(0),
|
||||
deltaTchanged_(false),
|
||||
writeTimeIndex_(0),
|
||||
deltaT_(0),
|
||||
deltaT0_(0),
|
||||
deltaTSave_(0),
|
||||
deltaTchanged_(false),
|
||||
writeTime_(false)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::TimeState::~TimeState()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::scalar Foam::TimeState::userTimeToTime(const scalar theta) const
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -50,15 +50,16 @@ class TimeState
|
||||
:
|
||||
public dimensionedScalar
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
label timeIndex_;
|
||||
scalar deltaT_;
|
||||
scalar deltaTSave_;
|
||||
scalar deltaT0_;
|
||||
bool deltaTchanged_;
|
||||
label writeTimeIndex_;
|
||||
|
||||
scalar deltaT_;
|
||||
scalar deltaT0_;
|
||||
scalar deltaTSave_;
|
||||
|
||||
bool deltaTchanged_;
|
||||
bool writeTime_;
|
||||
|
||||
|
||||
@ -66,11 +67,12 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct a zero time state, using the current time formattin
|
||||
TimeState();
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~TimeState();
|
||||
virtual ~TimeState() = default;
|
||||
|
||||
|
||||
// Member functions
|
||||
@ -108,8 +110,8 @@ public:
|
||||
inline bool writeTime() const;
|
||||
|
||||
//- Return true if this is a write time.
|
||||
// Provided for backward-compatibility
|
||||
inline bool outputTime() const;
|
||||
// \deprecated in favour of writeTime() - MAY-2016
|
||||
inline bool outputTime() const { return this->writeTime(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -68,10 +68,4 @@ inline bool Foam::TimeState::writeTime() const
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::TimeState::outputTime() const
|
||||
{
|
||||
return writeTime_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Searches the current case directory for valid times
|
||||
and sets the time list to these.
|
||||
This is done if a times File does not exist.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Time.H"
|
||||
#include "OSspecific.H"
|
||||
#include "StringStream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::instantList Foam::Time::findTimes
|
||||
(
|
||||
const fileName& directory,
|
||||
const word& constantName
|
||||
)
|
||||
{
|
||||
return fileHandler().findTimes(directory, constantName);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -52,14 +52,14 @@ bool Foam::timeSelector::selected(const instant& value) const
|
||||
|
||||
Foam::List<bool> Foam::timeSelector::selected(const instantList& times) const
|
||||
{
|
||||
List<bool> lst(times.size(), false);
|
||||
List<bool> selectTimes(times.size(), false);
|
||||
|
||||
// Check ranges, avoid false positive on constant/
|
||||
forAll(times, timei)
|
||||
{
|
||||
if (times[timei].name() != "constant" && selected(times[timei]))
|
||||
{
|
||||
lst[timei] = true;
|
||||
selectTimes[timei] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,29 +70,26 @@ Foam::List<bool> Foam::timeSelector::selected(const instantList& times) const
|
||||
{
|
||||
const scalar target = range.value();
|
||||
|
||||
int nearestIndex = -1;
|
||||
scalar nearestDiff = Foam::GREAT;
|
||||
int nearestIndex =
|
||||
TimePaths::findClosestTimeIndex
|
||||
(
|
||||
times,
|
||||
target
|
||||
);
|
||||
|
||||
forAll(times, timei)
|
||||
{
|
||||
if (times[timei].name() == "constant") continue;
|
||||
|
||||
scalar diff = fabs(times[timei].value() - target);
|
||||
if (diff < nearestDiff)
|
||||
{
|
||||
nearestDiff = diff;
|
||||
nearestIndex = timei;
|
||||
}
|
||||
}
|
||||
// Note could also test if the index is too far away.
|
||||
// Eg, for times (0 10 20 30 40) selecting 100 will currently
|
||||
// return the closest time (40), but perhaps we should limit that
|
||||
// to the last deltaT?
|
||||
|
||||
if (nearestIndex >= 0)
|
||||
{
|
||||
lst[nearestIndex] = true;
|
||||
selectTimes[nearestIndex] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lst;
|
||||
return selectTimes;
|
||||
}
|
||||
|
||||
|
||||
@ -271,7 +268,7 @@ Foam::instantList Foam::timeSelector::select0
|
||||
times.append(instant(0, runTime.constant()));
|
||||
}
|
||||
|
||||
runTime.setTime(times[0], 0);
|
||||
runTime.setTime(times.first(), 0);
|
||||
|
||||
return times;
|
||||
}
|
||||
@ -296,7 +293,7 @@ Foam::instantList Foam::timeSelector::selectIfPresent
|
||||
}
|
||||
|
||||
// No timeSelector option specified. Do not change runTime.
|
||||
return instantList{ instant(runTime.value(), runTime.timeName()) };
|
||||
return instantList(one(), instant(runTime.value(), runTime.timeName()));
|
||||
}
|
||||
|
||||
|
||||
@ -309,11 +306,13 @@ Foam::instantList Foam::timeSelector::select
|
||||
{
|
||||
instantList times(timeSelector::select0(runTime, args));
|
||||
|
||||
if (times.size() && args.found("newTimes"))
|
||||
{
|
||||
List<bool> selectTimes(times.size(), true);
|
||||
const label nTimes = times.size();
|
||||
|
||||
forAll(times, timei)
|
||||
if (nTimes && args.found("newTimes"))
|
||||
{
|
||||
List<bool> selectTimes(nTimes, true);
|
||||
|
||||
for (label timei=0; timei < nTimes; ++timei)
|
||||
{
|
||||
selectTimes[timei] =
|
||||
!fileHandler().exists
|
||||
|
||||
@ -37,7 +37,7 @@ Description
|
||||
#include "createTime.H"
|
||||
instantList timeDirs = timeSelector::select0(runTime, args);
|
||||
...
|
||||
forAll(timeDirs, timeI)
|
||||
forAll(timeDirs, timei)
|
||||
{
|
||||
...
|
||||
}
|
||||
@ -79,7 +79,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
// Forward declarations
|
||||
class argList;
|
||||
class Time;
|
||||
|
||||
@ -146,8 +146,8 @@ public:
|
||||
);
|
||||
|
||||
//- Return the set of times selected based on the argList options
|
||||
// also set the runTime to the first instance or the
|
||||
// \c constant/ directory if no instances are specified or available
|
||||
//- and also set the runTime to the first instance or the
|
||||
//- \c constant/ directory if no instances are specified or available
|
||||
static instantList select0
|
||||
(
|
||||
Time& runTime,
|
||||
@ -155,7 +155,7 @@ public:
|
||||
);
|
||||
|
||||
//- If any time option provided return the set of times (as select0)
|
||||
// otherwise return just the current time.
|
||||
//- otherwise return just the current time.
|
||||
// Also set the runTime to the first instance
|
||||
static instantList selectIfPresent
|
||||
(
|
||||
@ -164,8 +164,8 @@ public:
|
||||
);
|
||||
|
||||
//- Return the set of times selected based on the argList options
|
||||
// including support for \b -newTimes in which times are selected
|
||||
// if the file 'fName' does not exist in the time directory.
|
||||
//- including support for \b -newTimes in which times are selected
|
||||
//- if the file 'fName' does not exist in the time directory.
|
||||
// Also set the runTime to the first instance or the
|
||||
// \c constant/ directory if no instances are specified or available
|
||||
static instantList select
|
||||
|
||||
@ -325,6 +325,16 @@ void Foam::argList::noJobInfo()
|
||||
}
|
||||
|
||||
|
||||
void Foam::argList::noLibs()
|
||||
{
|
||||
addBoolOption
|
||||
(
|
||||
"no-libs",
|
||||
"disable use of the controlDict libs entry"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void Foam::argList::noParallel()
|
||||
{
|
||||
removeOption("parallel");
|
||||
|
||||
@ -506,6 +506,9 @@ public:
|
||||
//- Suppress JobInfo, overriding controlDict setting
|
||||
static void noJobInfo();
|
||||
|
||||
//- Add the '-no-libs' command line option
|
||||
static void noLibs();
|
||||
|
||||
//- Remove the parallel options
|
||||
static void noParallel();
|
||||
|
||||
|
||||
@ -7,5 +7,5 @@ if
|
||||
&& (Times[startTime].name() == "constant")
|
||||
)
|
||||
{
|
||||
startTime++;
|
||||
++startTime;
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ diffusionMulticomponent<ReactionThermo, ThermoType>::correct()
|
||||
|
||||
Rijk.relax(alpha_);
|
||||
|
||||
if (this->mesh_.time().outputTime() && debug)
|
||||
if (debug && this->mesh_.time().writeTime())
|
||||
{
|
||||
Rijk.write();
|
||||
ft.write();
|
||||
|
||||
@ -92,7 +92,7 @@ Foam::Map<Foam::label> Foam::refinementIterator::setRefinement
|
||||
if (writeMesh_)
|
||||
{
|
||||
// Need different times to write meshes.
|
||||
runTime++;
|
||||
++runTime;
|
||||
}
|
||||
|
||||
polyTopoChange meshMod(mesh_);
|
||||
|
||||
@ -1096,7 +1096,7 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::updateCoeffs()
|
||||
writeEddyOBJ();
|
||||
}
|
||||
|
||||
if (debug && db().time().outputTime())
|
||||
if (debug && db().time().writeTime())
|
||||
{
|
||||
writeLumleyCoeffs();
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ void Foam::fv::directionalPressureGradientExplicitSource::writeProps
|
||||
) const
|
||||
{
|
||||
// Only write on output time
|
||||
if (mesh_.time().outputTime())
|
||||
if (mesh_.time().writeTime())
|
||||
{
|
||||
IOdictionary propsDict
|
||||
(
|
||||
|
||||
@ -2800,7 +2800,7 @@ void Foam::meshRefinement::handleSnapProblems
|
||||
|
||||
if (debug)
|
||||
{
|
||||
runTime++;
|
||||
++runTime;
|
||||
}
|
||||
|
||||
// Create baffles with same owner and neighbour for now.
|
||||
@ -3679,7 +3679,7 @@ void Foam::meshRefinement::baffleAndSplitMesh
|
||||
|
||||
if (debug)
|
||||
{
|
||||
runTime++;
|
||||
++runTime;
|
||||
}
|
||||
|
||||
splitMeshRegions
|
||||
@ -3702,7 +3702,7 @@ void Foam::meshRefinement::baffleAndSplitMesh
|
||||
|
||||
if (debug&MESH)
|
||||
{
|
||||
runTime++;
|
||||
++runTime;
|
||||
Pout<< "Writing subsetted mesh to time " << timeName()
|
||||
<< endl;
|
||||
write
|
||||
@ -3787,7 +3787,7 @@ void Foam::meshRefinement::mergeFreeStandingBaffles
|
||||
|
||||
if (debug)
|
||||
{
|
||||
runTime++;
|
||||
++runTime;
|
||||
}
|
||||
|
||||
splitMeshRegions
|
||||
|
||||
@ -968,7 +968,7 @@ void Foam::radiation::solarLoad::calculate()
|
||||
|
||||
if (debug)
|
||||
{
|
||||
if (mesh_.time().outputTime())
|
||||
if (mesh_.time().writeTime())
|
||||
{
|
||||
Ru_.write();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user