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

@ -119,48 +119,27 @@ bool Foam::functionObjects::timeControl::end()
bool Foam::functionObjects::timeControl::adjustTimeStep()
Foam::scalar Foam::functionObjects::timeControl::timeToNextWrite()
{
if
(
active()
&& writeControl_.control()
== Foam::timeControl::ocAdjustableRunTime
&& writeControl_.control() == Foam::timeControl::ocAdjustableRunTime
)
{
const label writeTimeIndex = writeControl_.executionIndex();
const scalar writeInterval = writeControl_.interval();
scalar timeToNextWrite = max
(
0.0,
(writeTimeIndex + 1)*writeInterval
- (time_.value() - time_.startTime().value())
);
scalar deltaT = time_.deltaTValue();
scalar nSteps = timeToNextWrite/deltaT - small;
// functionObjects modify deltaT within nStepsToStartTimeChange
// NOTE: Potential problems arise if two function objects dump within
// the same interval
if (nSteps < nStepsToStartTimeChange_)
{
label nStepsToNextWrite = label(nSteps) + 1;
scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
// Adjust time step
if (newDeltaT < deltaT)
{
deltaT = max(newDeltaT, 0.2*deltaT);
const_cast<Time&>(time_).setDeltaT(deltaT, false);
}
}
return
max
(
0.0,
(writeTimeIndex + 1)*writeInterval
- (time_.value() - time_.startTime().value())
);
}
return true;
return vGreat;
}