functionObject: Fixed bugs in function object time-step adjustment

The logic governing function objects' ability to change the time-step
has been modified so that it is compatible with the time-step adjustment
done in the Time class. The behaviour has been split into a method which
sets the step directly, and another which moidifies the time until the
next write operation (i.e., the time that the solver "aims" for).

This fixes an issue where the adjustments in Time and the function
objects interfere and cause the time step to decrease exponentially down
to machine precision. It also means that the set-time-step function
object now does not break the adjustable run-time setting.

This resolves bug report https://bugs.openfoam.org/view.php?id=2820
This commit is contained in:
Will Bainbridge
2018-02-05 15:49:14 +00:00
parent 2b76b83343
commit 139ffcc112
10 changed files with 131 additions and 118 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -75,12 +75,11 @@ Foam::functionObjects::setTimeStepFunctionObject::time() const
}
bool Foam::functionObjects::setTimeStepFunctionObject::adjustTimeStep()
bool Foam::functionObjects::setTimeStepFunctionObject::setTimeStep()
{
const_cast<Time&>(time()).setDeltaT
const_cast<Time&>(time()).setDeltaTNoAdjust
(
timeStepPtr_().value(time_.timeOutputValue()),
false
timeStepPtr_().value(time_.timeOutputValue())
);
return true;
@ -94,27 +93,20 @@ bool Foam::functionObjects::setTimeStepFunctionObject::read
{
timeStepPtr_ = Function1<scalar>::New("deltaT", dict);
// Check that adjustTimeStep is active
const dictionary& controlDict = time_.controlDict();
Switch adjust;
if
(
!controlDict.readIfPresent<Switch>("adjustTimeStep", adjust)
|| !adjust
)
{
FatalIOErrorInFunction(dict)
<< "Need to set 'adjustTimeStep' true to allow timestep control"
<< exit(FatalIOError);
}
return true;
}
bool Foam::functionObjects::setTimeStepFunctionObject::execute()
{
bool adjustTimeStep =
time().controlDict().lookupOrDefault("adjustTimeStep", false);
if (!adjustTimeStep)
{
return setTimeStep();
}
return true;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -104,8 +104,8 @@ public:
//- Return time database
const Time& time() const;
//- Called at the end of Time::adjustDeltaT() if adjustTime is true
virtual bool adjustTimeStep();
//- Override the time-step value
virtual bool setTimeStep();
//- Read and set the function object if its data have changed
virtual bool read(const dictionary&);