functionObject::timeControl: Added runTimes option to execute/write at specified list of run times
With
executeControl runTimes;
executeTimes (0.1 0.2 0.3);
the functionObject will be executed at 0.1s, 0.2s and 0.3s only.
With
writeControl runTimes;
writeTimes (0.1 0.2 0.3);
the functionObject will write at 0.1s, 0.2s and 0.3s only.
This commit is contained in:
@ -82,17 +82,17 @@ Foam::word Foam::Time::controlDictName("controlDict");
|
||||
|
||||
void Foam::Time::adjustDeltaT()
|
||||
{
|
||||
const scalar timeToNextWrite = min
|
||||
const scalar timeToNextAction = min
|
||||
(
|
||||
max
|
||||
(
|
||||
0,
|
||||
(writeTimeIndex_ + 1)*writeInterval_ - (value() - beginTime_)
|
||||
),
|
||||
functionObjects_.timeToNextWrite()
|
||||
functionObjects_.timeToNextAction()
|
||||
);
|
||||
|
||||
const scalar nSteps = timeToNextWrite/deltaT_;
|
||||
const scalar nSteps = timeToNextAction/deltaT_;
|
||||
|
||||
// Ensure nStepsToNextWrite does not overflow
|
||||
if (nSteps < labelMax)
|
||||
@ -101,7 +101,7 @@ void Foam::Time::adjustDeltaT()
|
||||
// to accommodate the next write time before splitting
|
||||
const label nStepsToNextWrite = label(max(nSteps, 1) + 0.99);
|
||||
|
||||
deltaT_ = timeToNextWrite/nStepsToNextWrite;
|
||||
deltaT_ = timeToNextAction/nStepsToNextWrite;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -157,7 +157,7 @@ bool Foam::functionObject::end()
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::functionObject::timeToNextWrite()
|
||||
Foam::scalar Foam::functionObject::timeToNextAction()
|
||||
{
|
||||
return vGreat;
|
||||
}
|
||||
|
||||
@ -69,21 +69,24 @@ Description
|
||||
endTime | End time | no |
|
||||
executeAtStart | Execute at start time switch | no | yes
|
||||
executeControl | See time controls below | no | timeStep
|
||||
executeInterval | Steps between each execute phase | no |
|
||||
executeInterval | Steps between each execution | no |
|
||||
executeTimes | List of execution times | no |
|
||||
writeControl | See time controls below | no | timeStep
|
||||
writeInterval | Steps between each write phase | no |
|
||||
writeInterval | Steps between each write | no |
|
||||
writeTimes | List of write times | no |
|
||||
\endtable
|
||||
|
||||
Time controls:
|
||||
\table
|
||||
Option | Description
|
||||
timeStep | Execute/write every 'Interval' time-steps
|
||||
writeTime | Execute/write every 'Interval' output times
|
||||
writeTime | Execute/write every 'Interval' write times
|
||||
adjustableRunTime | Execute/write every 'Interval' run time period
|
||||
runTime | Execute/write every 'Interval' run time period
|
||||
runTimes | Execute/write at specified list of run times
|
||||
clockTime | Execute/write every 'Interval' clock time period
|
||||
cpuTime | Execute/write every 'Interval' CPU time period
|
||||
none | Execute/write every time-step
|
||||
none | No execution
|
||||
\endtable
|
||||
|
||||
The sub-dictionary name \c \<functionObjectName\> is chosen by the user, and
|
||||
@ -244,7 +247,7 @@ public:
|
||||
//- Called by Time::adjustTimeStep(). Allows the functionObject to
|
||||
// insert a write time earlier than that already in use by the run
|
||||
// time. Returns the write time, or vGreat.
|
||||
virtual scalar timeToNextWrite();
|
||||
virtual scalar timeToNextAction();
|
||||
|
||||
//- Update topology using the given map
|
||||
virtual void movePoints(const polyMesh& mesh);
|
||||
|
||||
@ -278,7 +278,7 @@ bool Foam::functionObjectList::end()
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::functionObjectList::timeToNextWrite()
|
||||
Foam::scalar Foam::functionObjectList::timeToNextAction()
|
||||
{
|
||||
scalar result = vGreat;
|
||||
|
||||
@ -291,7 +291,7 @@ Foam::scalar Foam::functionObjectList::timeToNextWrite()
|
||||
|
||||
forAll(*this, oi)
|
||||
{
|
||||
result = min(result, operator[](oi).timeToNextWrite());
|
||||
result = min(result, operator[](oi).timeToNextAction());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -176,7 +176,7 @@ public:
|
||||
bool end();
|
||||
|
||||
//- Return the time to the next write
|
||||
scalar timeToNextWrite();
|
||||
scalar timeToNextAction();
|
||||
|
||||
//- Update topology using the given map
|
||||
virtual void movePoints(const polyMesh& mesh);
|
||||
|
||||
@ -31,7 +31,7 @@ License
|
||||
namespace Foam
|
||||
{
|
||||
template<>
|
||||
const char* NamedEnum<timeControl::timeControls, 8>::
|
||||
const char* NamedEnum<timeControl::timeControls, 9>::
|
||||
names[] =
|
||||
{
|
||||
"timeStep",
|
||||
@ -39,13 +39,14 @@ namespace Foam
|
||||
"outputTime",
|
||||
"adjustableRunTime",
|
||||
"runTime",
|
||||
"runTimes",
|
||||
"clockTime",
|
||||
"cpuTime",
|
||||
"none"
|
||||
};
|
||||
}
|
||||
|
||||
const Foam::NamedEnum<Foam::timeControl::timeControls, 8>
|
||||
const Foam::NamedEnum<Foam::timeControl::timeControls, 9>
|
||||
Foam::timeControl::timeControlNames_;
|
||||
|
||||
|
||||
@ -63,6 +64,7 @@ Foam::timeControl::timeControl
|
||||
timeControl_(timeControls::timeStep),
|
||||
intervalSteps_(0),
|
||||
interval_(-1),
|
||||
timeDelta_(0),
|
||||
executionIndex_(0)
|
||||
{
|
||||
read(dict);
|
||||
@ -81,6 +83,7 @@ void Foam::timeControl::read(const dictionary& dict)
|
||||
{
|
||||
word controlName(prefix_ + "Control");
|
||||
word intervalName(prefix_ + "Interval");
|
||||
const word timesName(prefix_ + "Times");
|
||||
|
||||
// For backward compatibility support the deprecated 'outputControl' option
|
||||
// now superseded by 'writeControl' for compatibility with Time
|
||||
@ -142,6 +145,23 @@ void Foam::timeControl::read(const dictionary& dict)
|
||||
break;
|
||||
}
|
||||
|
||||
case timeControls::runTimes:
|
||||
{
|
||||
times_ = dict.lookup<scalarList>(timesName);
|
||||
timeDelta_ = dict.lookupOrDefault("timeDelta", 1e-6);
|
||||
|
||||
forAll(times_, i)
|
||||
{
|
||||
timeIndices_.insert
|
||||
(
|
||||
int64_t((times_[i] + timeDelta_/2.0)/timeDelta_)
|
||||
);
|
||||
}
|
||||
|
||||
intervalSteps_ = dict.lookupOrDefault<label>(intervalName, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
break;
|
||||
@ -195,6 +215,16 @@ bool Foam::timeControl::execute()
|
||||
break;
|
||||
}
|
||||
|
||||
case timeControls::runTimes:
|
||||
{
|
||||
return timeIndices_.found
|
||||
(
|
||||
(time_.userTimeValue() + timeDelta_/2)/timeDelta_
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case timeControls::cpuTime:
|
||||
{
|
||||
const label executionIndex = label
|
||||
@ -244,7 +274,7 @@ bool Foam::timeControl::execute()
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::timeControl::timeToNextWrite()
|
||||
Foam::scalar Foam::timeControl::timeToNextAction()
|
||||
{
|
||||
switch (timeControl_)
|
||||
{
|
||||
@ -272,6 +302,27 @@ Foam::scalar Foam::timeControl::timeToNextWrite()
|
||||
break;
|
||||
}
|
||||
|
||||
case timeControls::runTimes:
|
||||
{
|
||||
if (time_.userTimeValue() + timeDelta_ < times_.last())
|
||||
{
|
||||
forAll(times_, i)
|
||||
{
|
||||
if (times_[i] > time_.userTimeValue() + timeDelta_)
|
||||
{
|
||||
return time_.userTimeToTime
|
||||
(
|
||||
times_[i] - time_.userTimeValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vGreat;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
|
||||
@ -54,14 +54,15 @@ public:
|
||||
//- The time control options
|
||||
enum class timeControls
|
||||
{
|
||||
timeStep, //!< execution is coupled to the time-step
|
||||
writeTime, //!< execution is coupled to the write-time
|
||||
outputTime, //!< execution is coupled to the output-time
|
||||
adjustableRunTime, //!< Adjust time step for execution
|
||||
runTime, //!< run time for execution
|
||||
clockTime, //!< clock time for execution
|
||||
cpuTime, //!< cpu time for execution
|
||||
none //!< no execution
|
||||
timeStep, //!< Execute/write every 'Interval' time-steps
|
||||
writeTime, //!< Execute/write every 'Interval' write times
|
||||
outputTime, //!< Execute/write every 'Interval' write times
|
||||
adjustableRunTime, //!< Execute/write every 'Interval' run time period
|
||||
runTime, //!< Execute/write every 'Interval' run time period
|
||||
runTimes, //!< Execute/write at specified list of run times
|
||||
clockTime, //!< Execute/write every 'Interval' CPU time period
|
||||
cpuTime, //!< Execute/write every 'Interval' CPU time period
|
||||
none //!< No execution
|
||||
};
|
||||
|
||||
|
||||
@ -76,7 +77,7 @@ private:
|
||||
const word prefix_;
|
||||
|
||||
//- String representation of timeControls enums
|
||||
static const NamedEnum<timeControls, 8> timeControlNames_;
|
||||
static const NamedEnum<timeControls, 9> timeControlNames_;
|
||||
|
||||
//- Type of time control
|
||||
timeControls timeControl_;
|
||||
@ -88,8 +89,17 @@ private:
|
||||
//- Execution interval
|
||||
scalar interval_;
|
||||
|
||||
//- List of times (for runTimes option)
|
||||
scalarList times_;
|
||||
|
||||
//- Time delta used for time -> index (for runTimes option)
|
||||
scalar timeDelta_;
|
||||
|
||||
//- Hash set of mesh mapping time indices (for runTimes option)
|
||||
HashSet<int64_t, Hash<int64_t>> timeIndices_;
|
||||
|
||||
//- Index of previous execution
|
||||
label executionIndex_;
|
||||
mutable label executionIndex_;
|
||||
|
||||
|
||||
public:
|
||||
@ -124,7 +134,7 @@ public:
|
||||
bool execute();
|
||||
|
||||
//- Return the time to the next write
|
||||
scalar timeToNextWrite();
|
||||
scalar timeToNextAction();
|
||||
|
||||
//- Return control
|
||||
inline timeControls control() const;
|
||||
|
||||
@ -157,9 +157,13 @@ bool Foam::functionObjects::timeControl::end()
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::functionObjects::timeControl::timeToNextWrite()
|
||||
Foam::scalar Foam::functionObjects::timeControl::timeToNextAction()
|
||||
{
|
||||
return writeControl_.timeToNextWrite();
|
||||
return min
|
||||
(
|
||||
executeControl_.timeToNextAction(),
|
||||
writeControl_.timeToNextAction()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2016-2023 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -151,8 +151,9 @@ public:
|
||||
//- Called when Time::run() determines that the time-loop exits
|
||||
virtual bool end();
|
||||
|
||||
//- Return the time to the next write
|
||||
virtual scalar timeToNextWrite();
|
||||
//- Return the time to the next execute or write
|
||||
// if time requires adjustment
|
||||
virtual scalar timeToNextAction();
|
||||
|
||||
//- Read and set the function object if its data have changed
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
@ -83,7 +83,8 @@ bool Foam::functionObjects::meshToMeshAdjustTimeStepFunctionObject::read
|
||||
|
||||
|
||||
Foam::scalar
|
||||
Foam::functionObjects::meshToMeshAdjustTimeStepFunctionObject::timeToNextWrite()
|
||||
Foam::functionObjects::meshToMeshAdjustTimeStepFunctionObject::
|
||||
timeToNextAction()
|
||||
{
|
||||
return meshToMesh_.timeToNextMesh();
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -98,7 +98,7 @@ public:
|
||||
}
|
||||
|
||||
//- Return the time to the next write
|
||||
virtual scalar timeToNextWrite();
|
||||
virtual scalar timeToNextAction();
|
||||
|
||||
//- Do nothing
|
||||
virtual bool execute();
|
||||
|
||||
Reference in New Issue
Block a user