ENH: allow specific restart time for field averaging (issue #282)

- Can currently have a periodic restart, but for simulations with a
  known run-up, it can be useful to have a specific time to restart
  the averaging.

- Note that the restartTime acts as a 'single-shot'. If the
  restartTime is already in the past when a simulation is started, it
  is ignored. If, during a simulation, the restartTime is crossed, it
  will be triggered and then set itself to be ignored in the future.
This commit is contained in:
Mark Olesen
2016-10-31 08:26:06 +01:00
parent a05493db41
commit c836a017e6
2 changed files with 38 additions and 2 deletions

View File

@ -141,12 +141,24 @@ void Foam::functionObjects::fieldAverage::calcAverages()
prevTimeIndex_ = currentTimeIndex; prevTimeIndex_ = currentTimeIndex;
} }
bool doRestart = false;
if (periodicRestart_ && currentTime > restartPeriod_*periodIndex_) if (periodicRestart_ && currentTime > restartPeriod_*periodIndex_)
{ {
restart(); doRestart = true;
periodIndex_++; periodIndex_++;
} }
if (currentTime >= restartTime_)
{
doRestart = true; // Restart is overdue.
restartTime_ = GREAT; // Avoid triggering again
}
if (doRestart)
{
restart();
}
Log Log
<< type() << " " << name() << " write:" << nl << type() << " " << name() << " write:" << nl
<< " Calculating averages" << nl; << " Calculating averages" << nl;
@ -262,6 +274,7 @@ Foam::functionObjects::fieldAverage::fieldAverage
restartOnOutput_(false), restartOnOutput_(false),
periodicRestart_(false), periodicRestart_(false),
restartPeriod_(GREAT), restartPeriod_(GREAT),
restartTime_(GREAT),
initialised_(false), initialised_(false),
faItems_(), faItems_(),
totalIter_(), totalIter_(),
@ -296,6 +309,25 @@ bool Foam::functionObjects::fieldAverage::read(const dictionary& dict)
if (periodicRestart_) if (periodicRestart_)
{ {
dict.lookup("restartPeriod") >> restartPeriod_; dict.lookup("restartPeriod") >> restartPeriod_;
Log
<< " Restart period " << restartPeriod_
<< nl << endl;
}
restartTime_ = GREAT;
if (dict.readIfPresent("restartTime", restartTime_))
{
if (restartTime_ < obr_.time().value())
{
// The restart time is already in the past - ignore
restartTime_ = GREAT;
}
else
{
Log
<< " Restart scheduled at time " << restartTime_
<< nl << endl;
}
} }
readAveragingProperties(); readAveragingProperties();

View File

@ -3,7 +3,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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -106,6 +106,7 @@ Usage
restartOnOutput | Restart the averaging on output | no | no restartOnOutput | Restart the averaging on output | no | no
periodicRestart | Periodically restart the averaging | no | no periodicRestart | Periodically restart the averaging | no | no
restartPeriod | Periodic restart period | conditional | restartPeriod | Periodic restart period | conditional |
restartTime | One-shot reset of the averaging | no | great
fields | list of fields and averaging options | yes | fields | list of fields and averaging options | yes |
\endtable \endtable
@ -166,6 +167,9 @@ protected:
//- Restart period //- Restart period
scalar restartPeriod_; scalar restartPeriod_;
//- Specific restart time
scalar restartTime_;
//- Initialised flag //- Initialised flag
bool initialised_; bool initialised_;