From acc8d7714af971bfd708b1b5ecabb4b5a262db74 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Thu, 24 Feb 2011 10:44:22 +0000 Subject: [PATCH] BUG: Time.C: adjustTimeStep overflow of scalar --- src/OpenFOAM/db/Time/Time.C | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index f7566f5f935..af3b5544d86 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -86,18 +86,25 @@ void Foam::Time::adjustDeltaT() (outputTimeIndex_ + 1)*writeInterval_ - (value() - startTime_) ); - label nStepsToNextWrite = label(timeToNextWrite/deltaT_ - SMALL) + 1; - scalar newDeltaT = timeToNextWrite/nStepsToNextWrite; + scalar nSteps = timeToNextWrite/deltaT_ - SMALL; - // Control the increase of the time step to within a factor of 2 - // and the decrease within a factor of 5. - if (newDeltaT >= deltaT_) + // For tiny deltaT the label can overflow! + if (nSteps < labelMax) { - deltaT_ = min(newDeltaT, 2.0*deltaT_); - } - else - { - deltaT_ = max(newDeltaT, 0.2*deltaT_); + label nStepsToNextWrite = label(nSteps) + 1; + + scalar newDeltaT = timeToNextWrite/nStepsToNextWrite; + + // 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_); + } } } } -- GitLab