BUG: Time.C: adjustTimeStep overflow of scalar

This commit is contained in:
mattijs 2011-02-24 10:44:22 +00:00
parent c07e9f6600
commit acc8d7714a

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) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -86,18 +86,25 @@ void Foam::Time::adjustDeltaT()
(outputTimeIndex_ + 1)*writeInterval_ - (value() - startTime_) (outputTimeIndex_ + 1)*writeInterval_ - (value() - startTime_)
); );
label nStepsToNextWrite = label(timeToNextWrite/deltaT_ - SMALL) + 1; scalar nSteps = timeToNextWrite/deltaT_ - SMALL;
scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
// Control the increase of the time step to within a factor of 2 // For tiny deltaT the label can overflow!
// and the decrease within a factor of 5. if (nSteps < labelMax)
if (newDeltaT >= deltaT_)
{ {
deltaT_ = min(newDeltaT, 2.0*deltaT_); label nStepsToNextWrite = label(nSteps) + 1;
}
else scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
{
deltaT_ = max(newDeltaT, 0.2*deltaT_); // Control the increase of the time step to within a factor of 2
// and the decrease within a factor of 5.
if (newDeltaT >= deltaT_)
{
deltaT_ = min(newDeltaT, 2.0*deltaT_);
}
else
{
deltaT_ = max(newDeltaT, 0.2*deltaT_);
}
} }
} }
} }