fieldAverage: Added periodicRestart option and rationalized naming of restart options

When restarting form a previous calculation, the averaging is continuous or
    may be restarted using the \c restartOnRestart option.

    The averaging process may be restarted after each calculation output time
    using the \c restartOnOutput option or restarted periodically using the \c
    periodicRestart option and setting \c restartPeriod to the required
    averaging period.

    Example of function object specification:
    \verbatim
    fieldAverage1
    {
        type fieldAverage;
        functionObjectLibs ("libfieldFunctionObjects.so");
        ...
        restartOnRestart  false;
        restartOnOutput   false;
        periodicRestart false;
        restartPeriod   0.002;
        fields
        (
            U
            {
                mean            on;
                prime2Mean      on;
                base            time;
                window          10.0;
                windowName      w1;
            }
            p
            {
                mean            on;
                prime2Mean      on;
                base            time;
            }
        );
    }
    \endverbatim

    \heading Function object usage
    \table
        Property        | Description           | Required    | Default value
        type            | type name: fieldAverage | yes |
        restartOnRestart  | Restart the averaging on restart | no | no
        restartOnOutput   | Restart the averaging on output | no | no
        periodicRestart | Periodically restart the averaging | no | no
        restartPeriod   | Periodic restart period | conditional |
        fields          | list of fields and averaging options | yes |
    \endtable
This commit is contained in:
Henry Weller
2016-01-30 11:23:38 +00:00
parent 6644f8343b
commit 451cc4e620
7 changed files with 79 additions and 44 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -104,6 +104,21 @@ void Foam::fieldAverage::initialize()
} }
void Foam::fieldAverage::restart()
{
Info<< " Restarting averaging at time " << obr_.time().timeName()
<< nl << endl;
totalIter_.clear();
totalIter_.setSize(faItems_.size(), 1);
totalTime_.clear();
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
initialize();
}
void Foam::fieldAverage::calcAverages() void Foam::fieldAverage::calcAverages()
{ {
if (!initialised_) if (!initialised_)
@ -111,8 +126,8 @@ void Foam::fieldAverage::calcAverages()
initialize(); initialize();
} }
const label currentTimeIndex = const label currentTimeIndex = obr_.time().timeIndex();
static_cast<const fvMesh&>(obr_).time().timeIndex(); const scalar currentTime = obr_.time().value();
if (prevTimeIndex_ == currentTimeIndex) if (prevTimeIndex_ == currentTimeIndex)
{ {
@ -123,6 +138,12 @@ void Foam::fieldAverage::calcAverages()
prevTimeIndex_ = currentTimeIndex; prevTimeIndex_ = currentTimeIndex;
} }
if (periodicRestart_ && currentTime > restartPeriod_*periodIndex_)
{
restart();
periodIndex_++;
}
Info<< type() << " " << name_ << " output:" << nl; Info<< type() << " " << name_ << " output:" << nl;
Info<< " Calculating averages" << nl; Info<< " Calculating averages" << nl;
@ -195,7 +216,7 @@ void Foam::fieldAverage::readAveragingProperties()
totalTime_.clear(); totalTime_.clear();
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue()); totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
if (resetOnRestart_ || resetOnOutput_) if (restartOnRestart_ || restartOnOutput_)
{ {
Info<< " Starting averaging at time " << obr_.time().timeName() Info<< " Starting averaging at time " << obr_.time().timeName()
<< nl; << nl;
@ -255,12 +276,15 @@ Foam::fieldAverage::fieldAverage
obr_(obr), obr_(obr),
active_(true), active_(true),
prevTimeIndex_(-1), prevTimeIndex_(-1),
resetOnRestart_(false), restartOnRestart_(false),
resetOnOutput_(false), restartOnOutput_(false),
periodicRestart_(false),
restartPeriod_(GREAT),
initialised_(false), initialised_(false),
faItems_(), faItems_(),
totalIter_(), totalIter_(),
totalTime_() totalTime_(),
periodIndex_(1)
{ {
// Only active if a fvMesh is available // Only active if a fvMesh is available
if (isA<fvMesh>(obr_)) if (isA<fvMesh>(obr_))
@ -293,10 +317,16 @@ void Foam::fieldAverage::read(const dictionary& dict)
Info<< type() << " " << name_ << ":" << nl; Info<< type() << " " << name_ << ":" << nl;
dict.readIfPresent("resetOnRestart", resetOnRestart_); dict.readIfPresent("restartOnRestart", restartOnRestart_);
dict.readIfPresent("resetOnOutput", resetOnOutput_); dict.readIfPresent("restartOnOutput", restartOnOutput_);
dict.readIfPresent("periodicRestart", periodicRestart_);
dict.lookup("fields") >> faItems_; dict.lookup("fields") >> faItems_;
if (periodicRestart_)
{
dict.lookup("restartPeriod") >> restartPeriod_;
}
readAveragingProperties(); readAveragingProperties();
Info<< endl; Info<< endl;
@ -335,18 +365,9 @@ void Foam::fieldAverage::write()
writeAverages(); writeAverages();
writeAveragingProperties(); writeAveragingProperties();
if (resetOnOutput_) if (restartOnOutput_)
{ {
Info<< " Restarting averaging at time " << obr_.time().timeName() restart();
<< nl << endl;
totalIter_.clear();
totalIter_.setSize(faItems_.size(), 1);
totalTime_.clear();
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
initialize();
} }
Info<< endl; Info<< endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -54,12 +54,13 @@ Description
time are written on a per-field basis to the time are written on a per-field basis to the
\c fieldAveragingProperties dictionary, located in \<time\>/uniform \c fieldAveragingProperties dictionary, located in \<time\>/uniform
When restarting form a previous calculation, the averaging is continuous. When restarting form a previous calculation, the averaging is continuous or
However, the averaging process can be restarted using the \c resetOnRestart may be restarted using the \c restartOnRestart option.
option.
To restart the averaging process after each calculation output time, use The averaging process may be restarted after each calculation output time
the \c resetOnOutput option. using the \c restartOnOutput option or restarted periodically using the \c
periodicRestart option and setting \c restartPeriod to the required
averaging period.
Example of function object specification: Example of function object specification:
\verbatim \verbatim
@ -68,8 +69,10 @@ Description
type fieldAverage; type fieldAverage;
functionObjectLibs ("libfieldFunctionObjects.so"); functionObjectLibs ("libfieldFunctionObjects.so");
... ...
resetOnRestart true; restartOnRestart true;
resetOnOutput false; restartOnOutput false;
periodicRestart false;
restartPeriod 0.002;
fields fields
( (
U U
@ -94,8 +97,10 @@ Description
\table \table
Property | Description | Required | Default value Property | Description | Required | Default value
type | type name: fieldAverage | yes | type | type name: fieldAverage | yes |
resetOnRestart | flag to reset the averaging on restart | yes | restartOnRestart | Restart the averaging on restart | no | no
resetOnOutput| flag to reset the averaging on output | yes | restartOnOutput | Restart the averaging on output | no | no
periodicRestart | Periodically restart the averaging | no | no
restartPeriod | Periodic restart period | conditional |
fields | list of fields and averaging options | yes | fields | list of fields and averaging options | yes |
\endtable \endtable
@ -156,11 +161,17 @@ protected:
//- Time at last call, prevents repeated averaging //- Time at last call, prevents repeated averaging
label prevTimeIndex_; label prevTimeIndex_;
//- Reset the averaging process on restart flag //- Restart the averaging process on restart
Switch resetOnRestart_; Switch restartOnRestart_;
//- Reset the averaging process on output flag //- Restart the averaging process on output
Switch resetOnOutput_; Switch restartOnOutput_;
//- Periodically restart the averaging process
Switch periodicRestart_;
//- Restart period
scalar restartPeriod_;
//- Initialised flag //- Initialised flag
bool initialised_; bool initialised_;
@ -177,6 +188,9 @@ protected:
//- Total time counter //- Total time counter
List<scalar> totalTime_; List<scalar> totalTime_;
//- Index for periodic restart
label periodIndex_;
// Private Member Functions // Private Member Functions
@ -190,6 +204,9 @@ protected:
// Check requested field averages are valid, populate field lists // Check requested field averages are valid, populate field lists
void initialize(); void initialize();
//- Restart averaging for restartOnOutput
void restart();
//- Add mean average field to database //- Add mean average field to database
template<class Type> template<class Type>
void addMeanFieldType(const label fieldI); void addMeanFieldType(const label fieldI);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -66,7 +66,7 @@ void Foam::fieldAverage::addMeanFieldType(const label fieldI)
meanFieldName, meanFieldName,
obr_.time().timeName(obr_.time().startTime().value()), obr_.time().timeName(obr_.time().startTime().value()),
obr_, obr_,
resetOnOutput_ restartOnOutput_
? IOobject::NO_READ ? IOobject::NO_READ
: IOobject::READ_IF_PRESENT, : IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE IOobject::NO_WRITE
@ -136,7 +136,7 @@ void Foam::fieldAverage::addPrime2MeanFieldType(const label fieldI)
prime2MeanFieldName, prime2MeanFieldName,
obr_.time().timeName(obr_.time().startTime().value()), obr_.time().timeName(obr_.time().startTime().value()),
obr_, obr_,
resetOnOutput_ restartOnOutput_
? IOobject::NO_READ ? IOobject::NO_READ
: IOobject::READ_IF_PRESENT, : IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE IOobject::NO_WRITE

View File

@ -54,7 +54,6 @@ functions
type fieldAverage; type fieldAverage;
functionObjectLibs ( "libfieldFunctionObjects.so" ); functionObjectLibs ( "libfieldFunctionObjects.so" );
outputControl outputTime; outputControl outputTime;
resetOnOutput off;
fields fields
( (

View File

@ -54,7 +54,7 @@ functions
type fieldAverage; type fieldAverage;
functionObjectLibs ( "libfieldFunctionObjects.so" ); functionObjectLibs ( "libfieldFunctionObjects.so" );
outputControl outputTime; outputControl outputTime;
resetOnOutput off; restartOnOutput off;
fields fields
( (

View File

@ -54,7 +54,6 @@ functions
type fieldAverage; type fieldAverage;
functionObjectLibs ( "libfieldFunctionObjects.so" ); functionObjectLibs ( "libfieldFunctionObjects.so" );
outputControl outputTime; outputControl outputTime;
resetOnOutput off;
fields fields
( (

View File

@ -54,7 +54,6 @@ functions
type fieldAverage; type fieldAverage;
functionObjectLibs ( "libfieldFunctionObjects.so" ); functionObjectLibs ( "libfieldFunctionObjects.so" );
outputControl outputTime; outputControl outputTime;
resetOnOutput off;
fields fields
( (