mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: update handling of "writeTime" in timeControl class
- handle zero or negative values as being identical to 1.
As per timeStep control and what the comments suggested.
- drop old outputTime enumeration, since this is covered by the
writeTime enumeration and a corresponding Enum name.
- support construction of a "pass-through" control object that always
executes and add some method to test for these conditions and be able
to output some meaning full information.
Eg,
if (ctrl.execute())
{
if (!ctrl.always())
{
Info<< "Sampling executed based on " << ctrl.type() << nl;
}
...
}
To produce "Sampling executed based on runTime"
This commit is contained in:
@ -62,30 +62,31 @@ Description
|
|||||||
|
|
||||||
Where:
|
Where:
|
||||||
\table
|
\table
|
||||||
Property | Description | Required | Default
|
Property | Description | Required | Default
|
||||||
type | Type of function object | yes |
|
type | Type of function object | yes |
|
||||||
libs | Libraries containing implementation | yes |
|
libs | Libraries containing implementation | yes |
|
||||||
region | Name of region for multi-region cases | no |
|
region | Name of region for multi-region cases | no |
|
||||||
enabled | On/off switch | no | yes
|
enabled | On/off switch | no | yes
|
||||||
log | Log information to standard output | no | yes
|
log | Log information to standard output | no | yes
|
||||||
timeStart| Start time | no |
|
timeStart| Start time | no |
|
||||||
timeEnd | End time | no |
|
timeEnd | End time | no |
|
||||||
executeControl | See time controls below | no | timeStep
|
executeControl | See time controls below | no | timeStep
|
||||||
executeInterval | Steps between each execute phase | no |
|
executeInterval | Steps/time between execute phases | no | 1
|
||||||
writeControl | See time controls below | no | timeStep
|
writeControl | See time controls below | no | timeStep
|
||||||
writeInterval | Steps between each write phase | no |
|
writeInterval | Steps/time between write phases | no | 1
|
||||||
\endtable
|
\endtable
|
||||||
|
|
||||||
Time controls:
|
Time controls:
|
||||||
\table
|
\table
|
||||||
Option | Description
|
Option | Description
|
||||||
timeStep | Execute/write every 'Interval' time-steps
|
none | Trigger is disabled
|
||||||
writeTime | Execute/write every 'Interval' output times
|
timeStep | Trigger every 'Interval' time-steps
|
||||||
adjustableRunTime | Execute/write every 'Interval' run time period
|
writeTime | Trigger every 'Interval' output times
|
||||||
runTime | Execute/write every 'Interval' run time period
|
runTime | Trigger every 'Interval' run time period
|
||||||
clockTime | Execute/write every 'Interval' clock time period
|
adjustableRunTime | Currently identical to "runTime"
|
||||||
cpuTime | Execute/write every 'Interval' CPU time period
|
clockTime | Trigger every 'Interval' clock time period
|
||||||
none | Execute/write disabled
|
cpuTime | Trigger every 'Interval' CPU time period
|
||||||
|
onEnd | Trigger on end of run
|
||||||
\endtable
|
\endtable
|
||||||
|
|
||||||
The sub-dictionary name \c \<functionObjectName\> is chosen by the user, and
|
The sub-dictionary name \c \<functionObjectName\> is chosen by the user, and
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2016 OpenCFD Ltd.
|
Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -35,18 +35,19 @@ const Foam::Enum
|
|||||||
<
|
<
|
||||||
Foam::timeControl::timeControls
|
Foam::timeControl::timeControls
|
||||||
>
|
>
|
||||||
Foam::timeControl::timeControlNames_
|
Foam::timeControl::controlNames_
|
||||||
({
|
({
|
||||||
|
{ timeControl::ocNone, "none" },
|
||||||
|
{ timeControl::ocAlways, "always" },
|
||||||
{ timeControl::ocTimeStep, "timeStep" },
|
{ timeControl::ocTimeStep, "timeStep" },
|
||||||
{ timeControl::ocWriteTime, "writeTime" },
|
{ timeControl::ocWriteTime, "writeTime" },
|
||||||
{ timeControl::ocOutputTime, "outputTime" },
|
{ timeControl::ocWriteTime, "outputTime" },
|
||||||
|
{ timeControl::ocRunTime, "runTime" },
|
||||||
{ timeControl::ocAdjustableRunTime, "adjustable" },
|
{ timeControl::ocAdjustableRunTime, "adjustable" },
|
||||||
{ timeControl::ocAdjustableRunTime, "adjustableRunTime" },
|
{ timeControl::ocAdjustableRunTime, "adjustableRunTime" },
|
||||||
{ timeControl::ocRunTime, "runTime" },
|
|
||||||
{ timeControl::ocClockTime, "clockTime" },
|
{ timeControl::ocClockTime, "clockTime" },
|
||||||
{ timeControl::ocCpuTime, "cpuTime" },
|
{ timeControl::ocCpuTime, "cpuTime" },
|
||||||
{ timeControl::ocOnEnd, "onEnd" },
|
{ timeControl::ocOnEnd, "onEnd" },
|
||||||
{ timeControl::ocNone, "none" },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -54,17 +55,27 @@ Foam::timeControl::timeControlNames_
|
|||||||
|
|
||||||
Foam::timeControl::timeControl
|
Foam::timeControl::timeControl
|
||||||
(
|
(
|
||||||
const Time& t,
|
const Time& runTime,
|
||||||
|
const word& prefix
|
||||||
|
)
|
||||||
|
:
|
||||||
|
time_(runTime),
|
||||||
|
prefix_(prefix),
|
||||||
|
timeControl_(ocAlways),
|
||||||
|
intervalSteps_(0),
|
||||||
|
interval_(-1),
|
||||||
|
executionIndex_(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::timeControl::timeControl
|
||||||
|
(
|
||||||
|
const Time& runTime,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const word& prefix
|
const word& prefix
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
time_(t),
|
timeControl(runTime, prefix)
|
||||||
prefix_(prefix),
|
|
||||||
timeControl_(ocTimeStep),
|
|
||||||
intervalSteps_(0),
|
|
||||||
interval_(-1),
|
|
||||||
executionIndex_(0)
|
|
||||||
{
|
{
|
||||||
read(dict);
|
read(dict);
|
||||||
}
|
}
|
||||||
@ -97,27 +108,21 @@ void Foam::timeControl::read(const dictionary& dict)
|
|||||||
<< "Using deprecated 'outputControl'" << nl
|
<< "Using deprecated 'outputControl'" << nl
|
||||||
<< " Please use 'writeControl' with 'writeInterval'"
|
<< " Please use 'writeControl' with 'writeInterval'"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
error::warnAboutAge("outputControl", 1606);
|
||||||
|
|
||||||
// Change to the old names for this option
|
// Change to the old names for this option
|
||||||
controlName = "outputControl";
|
controlName = "outputControl";
|
||||||
intervalName = "outputInterval";
|
intervalName = "outputInterval";
|
||||||
}
|
}
|
||||||
|
|
||||||
timeControl_ =
|
timeControl_ = controlNames_.getOrDefault(controlName, dict, ocTimeStep);
|
||||||
timeControlNames_.lookupOrDefault(controlName, dict, ocTimeStep);
|
|
||||||
|
|
||||||
switch (timeControl_)
|
switch (timeControl_)
|
||||||
{
|
{
|
||||||
case ocTimeStep:
|
case ocTimeStep:
|
||||||
{
|
|
||||||
intervalSteps_ = dict.lookupOrDefault<label>(intervalName, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ocWriteTime:
|
case ocWriteTime:
|
||||||
case ocOutputTime:
|
|
||||||
{
|
{
|
||||||
intervalSteps_ = dict.lookupOrDefault<label>(intervalName, 1);
|
intervalSteps_ = dict.getOrDefault<label>(intervalName, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +136,6 @@ void Foam::timeControl::read(const dictionary& dict)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ocOnEnd:
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@ -144,6 +148,18 @@ bool Foam::timeControl::execute()
|
|||||||
{
|
{
|
||||||
switch (timeControl_)
|
switch (timeControl_)
|
||||||
{
|
{
|
||||||
|
case ocNone:
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ocAlways:
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ocTimeStep:
|
case ocTimeStep:
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
@ -155,12 +171,15 @@ bool Foam::timeControl::execute()
|
|||||||
}
|
}
|
||||||
|
|
||||||
case ocWriteTime:
|
case ocWriteTime:
|
||||||
case ocOutputTime:
|
|
||||||
{
|
{
|
||||||
if (time_.writeTime())
|
if (time_.writeTime())
|
||||||
{
|
{
|
||||||
executionIndex_++;
|
++executionIndex_;
|
||||||
return !(executionIndex_ % intervalSteps_);
|
return
|
||||||
|
(
|
||||||
|
(intervalSteps_ <= 1)
|
||||||
|
|| !(executionIndex_ % intervalSteps_)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -222,16 +241,11 @@ bool Foam::timeControl::execute()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ocNone:
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Undefined time control: "
|
<< "Undefined time control: "
|
||||||
<< timeControlNames_[timeControl_] << nl
|
<< controlNames_[timeControl_] << nl
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -28,7 +29,16 @@ Class
|
|||||||
|
|
||||||
Description
|
Description
|
||||||
General time dependent execution controller.
|
General time dependent execution controller.
|
||||||
The default to execute every time-step.
|
The execution parameters are given by the "Control" and (optionally)
|
||||||
|
the "Interval", with the default being to execute every time-step.
|
||||||
|
|
||||||
|
For example, an "execute" control every tenth write time:
|
||||||
|
\verbatim
|
||||||
|
executeControl writeTime;
|
||||||
|
executeInterval 10;
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
See Foam::functionObject for a list of known selection types.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
timeControl.C
|
timeControl.C
|
||||||
@ -56,39 +66,40 @@ public:
|
|||||||
//- The time control options
|
//- The time control options
|
||||||
enum timeControls
|
enum timeControls
|
||||||
{
|
{
|
||||||
ocTimeStep, //!< execution is coupled to the time-step
|
ocNone = 0, //!< No execution
|
||||||
ocWriteTime, //!< execution is coupled to the write-time
|
ocAlways, //!< Always execute
|
||||||
ocOutputTime, //!< execution is coupled to the output-time
|
ocTimeStep, //!< Execution coupled to time-step (default)
|
||||||
ocAdjustableRunTime, //!< Adjust time step for execution
|
ocWriteTime, //!< Execution coupled to write-time
|
||||||
ocRunTime, //!< run time for execution
|
ocRunTime, //!< Use run-time for execution
|
||||||
ocClockTime, //!< clock time for execution
|
ocAdjustableRunTime, //!< Currently identical to "runTime"
|
||||||
ocCpuTime, //!< CPU time for execution
|
ocClockTime, //!< Use clock time for execution
|
||||||
ocOnEnd, //!< on end of run
|
ocCpuTime, //!< Use CPU time for execution
|
||||||
ocNone //!< no execution
|
ocOnEnd //!< Execute on end of run
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Private data
|
//- The selection names for timeControls enumerations
|
||||||
|
static const Enum<timeControls> controlNames_;
|
||||||
|
|
||||||
|
|
||||||
|
// Private Data
|
||||||
|
|
||||||
//- Time object
|
//- Time object
|
||||||
const Time& time_;
|
const Time& time_;
|
||||||
|
|
||||||
//- Prefix
|
//- The prefix for the control name (eg, "write", "execute", ...)
|
||||||
const word prefix_;
|
const word prefix_;
|
||||||
|
|
||||||
//- String representation of timeControls enums
|
|
||||||
static const Enum<timeControls> timeControlNames_;
|
|
||||||
|
|
||||||
//- Type of time control
|
//- Type of time control
|
||||||
timeControls timeControl_;
|
timeControls timeControl_;
|
||||||
|
|
||||||
//- Execution interval steps for timeStep mode
|
//- Execution interval steps (timeStep | writeTime).
|
||||||
// a value <= 1 means execute at every time step
|
// A value <= 1 means execute at every time-step or writeTime.
|
||||||
label intervalSteps_;
|
label intervalSteps_;
|
||||||
|
|
||||||
//- Execution interval
|
//- Execution interval (clockTime | runTime | cpuTime | adjustable)
|
||||||
scalar interval_;
|
scalar interval_;
|
||||||
|
|
||||||
//- Index of previous execution
|
//- Index of previous execution
|
||||||
@ -108,11 +119,17 @@ public:
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from Time object and dictionary
|
//- Construct a control object that executes each time-step.
|
||||||
|
// For places where a time control object is required, but should
|
||||||
|
// not actually intervene.
|
||||||
|
explicit timeControl(const Time& runTime, const word& prefix = "");
|
||||||
|
|
||||||
|
//- Construct from Time object, dictionary and the prefix for the
|
||||||
|
//- control name.
|
||||||
timeControl
|
timeControl
|
||||||
(
|
(
|
||||||
const Time&,
|
const Time& runTime,
|
||||||
const dictionary&,
|
const dictionary& dict,
|
||||||
const word& prefix
|
const word& prefix
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -123,22 +140,31 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Helper function to identify if a timeControl object is present
|
//- Identify if a timeControl object is present in the dictionary
|
||||||
// in the dictionary
|
// Matches prefix + "Control"
|
||||||
static bool entriesPresent(const dictionary& dict, const word& prefix);
|
static bool entriesPresent(const dictionary& dict, const word& prefix);
|
||||||
|
|
||||||
//- Read from dictionary
|
//- Read from dictionary
|
||||||
void read(const dictionary&);
|
void read(const dictionary& dict);
|
||||||
|
|
||||||
//- Return Time
|
//- Return the Time
|
||||||
inline const Time& time() const;
|
inline const Time& time() const;
|
||||||
|
|
||||||
|
//- Return the name (prefix)
|
||||||
|
inline const word& name() const;
|
||||||
|
|
||||||
|
//- Return the named control enumeration as its 'type'
|
||||||
|
inline const word& type() const;
|
||||||
|
|
||||||
|
//- Return the control enumeration
|
||||||
|
inline timeControls control() const;
|
||||||
|
|
||||||
|
//- Return true if the control will always execute - ie, no intervention
|
||||||
|
inline bool always() const;
|
||||||
|
|
||||||
//- Flag to indicate whether to execute
|
//- Flag to indicate whether to execute
|
||||||
bool execute();
|
bool execute();
|
||||||
|
|
||||||
//- Return control
|
|
||||||
inline timeControls control() const;
|
|
||||||
|
|
||||||
//- Return interval
|
//- Return interval
|
||||||
inline scalar interval() const;
|
inline scalar interval() const;
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016 OpenFOAM Foundation
|
Copyright (C) 2016 OpenFOAM Foundation
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -33,12 +34,34 @@ inline const Foam::Time& Foam::timeControl::time() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline const Foam::word& Foam::timeControl::name() const
|
||||||
|
{
|
||||||
|
return prefix_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline const Foam::word& Foam::timeControl::type() const
|
||||||
|
{
|
||||||
|
return controlNames_[timeControl_];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::timeControl::timeControls Foam::timeControl::control() const
|
inline Foam::timeControl::timeControls Foam::timeControl::control() const
|
||||||
{
|
{
|
||||||
return timeControl_;
|
return timeControl_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::timeControl::always() const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
(
|
||||||
|
(timeControls::ocAlways == timeControl_)
|
||||||
|
|| (timeControls::ocTimeStep == timeControl_ && intervalSteps_ <= 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::scalar Foam::timeControl::interval() const
|
inline Foam::scalar Foam::timeControl::interval() const
|
||||||
{
|
{
|
||||||
return interval_;
|
return interval_;
|
||||||
|
|||||||
Reference in New Issue
Block a user