Commit 451cc4e6 authored by Henry Weller's avatar Henry Weller
Browse files

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
parent 6644f834
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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()
{
if (!initialised_)
......@@ -111,8 +126,8 @@ void Foam::fieldAverage::calcAverages()
initialize();
}
const label currentTimeIndex =
static_cast<const fvMesh&>(obr_).time().timeIndex();
const label currentTimeIndex = obr_.time().timeIndex();
const scalar currentTime = obr_.time().value();
if (prevTimeIndex_ == currentTimeIndex)
{
......@@ -123,6 +138,12 @@ void Foam::fieldAverage::calcAverages()
prevTimeIndex_ = currentTimeIndex;
}
if (periodicRestart_ && currentTime > restartPeriod_*periodIndex_)
{
restart();
periodIndex_++;
}
Info<< type() << " " << name_ << " output:" << nl;
Info<< " Calculating averages" << nl;
......@@ -195,7 +216,7 @@ void Foam::fieldAverage::readAveragingProperties()
totalTime_.clear();
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
if (resetOnRestart_ || resetOnOutput_)
if (restartOnRestart_ || restartOnOutput_)
{
Info<< " Starting averaging at time " << obr_.time().timeName()
<< nl;
......@@ -255,12 +276,15 @@ Foam::fieldAverage::fieldAverage
obr_(obr),
active_(true),
prevTimeIndex_(-1),
resetOnRestart_(false),
resetOnOutput_(false),
restartOnRestart_(false),
restartOnOutput_(false),
periodicRestart_(false),
restartPeriod_(GREAT),
initialised_(false),
faItems_(),
totalIter_(),
totalTime_()
totalTime_(),
periodIndex_(1)
{
// Only active if a fvMesh is available
if (isA<fvMesh>(obr_))
......@@ -293,10 +317,16 @@ void Foam::fieldAverage::read(const dictionary& dict)
Info<< type() << " " << name_ << ":" << nl;
dict.readIfPresent("resetOnRestart", resetOnRestart_);
dict.readIfPresent("resetOnOutput", resetOnOutput_);
dict.readIfPresent("restartOnRestart", restartOnRestart_);
dict.readIfPresent("restartOnOutput", restartOnOutput_);
dict.readIfPresent("periodicRestart", periodicRestart_);
dict.lookup("fields") >> faItems_;
if (periodicRestart_)
{
dict.lookup("restartPeriod") >> restartPeriod_;
}
readAveragingProperties();
Info<< endl;
......@@ -335,18 +365,9 @@ void Foam::fieldAverage::write()
writeAverages();
writeAveragingProperties();
if (resetOnOutput_)
if (restartOnOutput_)
{
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();
restart();
}
Info<< endl;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -54,12 +54,13 @@ Description
time are written on a per-field basis to the
\c fieldAveragingProperties dictionary, located in \<time\>/uniform
When restarting form a previous calculation, the averaging is continuous.
However, the averaging process can be restarted using the \c resetOnRestart
option.
When restarting form a previous calculation, the averaging is continuous or
may be restarted using the \c restartOnRestart option.
To restart the averaging process after each calculation output time, use
the \c resetOnOutput 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
......@@ -68,8 +69,10 @@ Description
type fieldAverage;
functionObjectLibs ("libfieldFunctionObjects.so");
...
resetOnRestart true;
resetOnOutput false;
restartOnRestart true;
restartOnOutput false;
periodicRestart false;
restartPeriod 0.002;
fields
(
U
......@@ -92,11 +95,13 @@ Description
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: fieldAverage | yes |
resetOnRestart | flag to reset the averaging on restart | yes |
resetOnOutput| flag to reset the averaging on output | yes |
fields | list of fields and averaging options | yes |
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
......@@ -156,11 +161,17 @@ protected:
//- Time at last call, prevents repeated averaging
label prevTimeIndex_;
//- Reset the averaging process on restart flag
Switch resetOnRestart_;
//- Restart the averaging process on restart
Switch restartOnRestart_;
//- Reset the averaging process on output flag
Switch resetOnOutput_;
//- Restart the averaging process on output
Switch restartOnOutput_;
//- Periodically restart the averaging process
Switch periodicRestart_;
//- Restart period
scalar restartPeriod_;
//- Initialised flag
bool initialised_;
......@@ -177,6 +188,9 @@ protected:
//- Total time counter
List<scalar> totalTime_;
//- Index for periodic restart
label periodIndex_;
// Private Member Functions
......@@ -190,6 +204,9 @@ protected:
// Check requested field averages are valid, populate field lists
void initialize();
//- Restart averaging for restartOnOutput
void restart();
//- Add mean average field to database
template<class Type>
void addMeanFieldType(const label fieldI);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -66,7 +66,7 @@ void Foam::fieldAverage::addMeanFieldType(const label fieldI)
meanFieldName,
obr_.time().timeName(obr_.time().startTime().value()),
obr_,
resetOnOutput_
restartOnOutput_
? IOobject::NO_READ
: IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
......@@ -136,7 +136,7 @@ void Foam::fieldAverage::addPrime2MeanFieldType(const label fieldI)
prime2MeanFieldName,
obr_.time().timeName(obr_.time().startTime().value()),
obr_,
resetOnOutput_
restartOnOutput_
? IOobject::NO_READ
: IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
......
......@@ -54,7 +54,6 @@ functions
type fieldAverage;
functionObjectLibs ( "libfieldFunctionObjects.so" );
outputControl outputTime;
resetOnOutput off;
fields
(
......
......@@ -54,7 +54,7 @@ functions
type fieldAverage;
functionObjectLibs ( "libfieldFunctionObjects.so" );
outputControl outputTime;
resetOnOutput off;
restartOnOutput off;
fields
(
......
......@@ -54,7 +54,6 @@ functions
type fieldAverage;
functionObjectLibs ( "libfieldFunctionObjects.so" );
outputControl outputTime;
resetOnOutput off;
fields
(
......
......@@ -54,7 +54,6 @@ functions
type fieldAverage;
functionObjectLibs ( "libfieldFunctionObjects.so" );
outputControl outputTime;
resetOnOutput off;
fields
(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment