mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: timeControl: adds some more #423.
This commit is contained in:
@ -51,9 +51,20 @@ void Foam::functionObjects::timeControl::readControls()
|
|||||||
{
|
{
|
||||||
timeEnd_ = time_.userTimeToTime(timeEnd_);
|
timeEnd_ = time_.userTimeToTime(timeEnd_);
|
||||||
}
|
}
|
||||||
deltaTCoeff_ = dict_.lookupOrDefault("deltaTCoeff", GREAT);
|
deltaTCoeff_ = GREAT;
|
||||||
|
if (dict_.readIfPresent("deltaTCoeff", deltaTCoeff_))
|
||||||
dict_.readIfPresent("nStepsToStartTimeChange", nStepsToStartTimeChange_);
|
{
|
||||||
|
nStepsToStartTimeChange_ = labelMax;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nStepsToStartTimeChange_ = 3;
|
||||||
|
dict_.readIfPresent
|
||||||
|
(
|
||||||
|
"nStepsToStartTimeChange",
|
||||||
|
nStepsToStartTimeChange_
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -73,7 +84,6 @@ Foam::scalar Foam::functionObjects::timeControl::calcExpansion
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
scalar ratio = startRatio;
|
scalar ratio = startRatio;
|
||||||
|
|
||||||
// This function is used to calculate the 'expansion ratio' or
|
// This function is used to calculate the 'expansion ratio' or
|
||||||
// 'time step growth factor'. Inputs:
|
// 'time step growth factor'. Inputs:
|
||||||
// - ratio: wanted ratio
|
// - ratio: wanted ratio
|
||||||
@ -226,7 +236,6 @@ void Foam::functionObjects::timeControl::calcDeltaTCoeff
|
|||||||
// has reached one that is possible. Returns the new expansionratio.
|
// has reached one that is possible. Returns the new expansionratio.
|
||||||
|
|
||||||
scalar y = timeToNextMultiple/wantedDT;
|
scalar y = timeToNextMultiple/wantedDT;
|
||||||
|
|
||||||
label requiredSteps = nSteps;
|
label requiredSteps = nSteps;
|
||||||
|
|
||||||
scalar ratioEstimate = deltaTCoeff_;
|
scalar ratioEstimate = deltaTCoeff_;
|
||||||
@ -240,6 +249,7 @@ void Foam::functionObjects::timeControl::calcDeltaTCoeff
|
|||||||
if (!rampDirectionUp)
|
if (!rampDirectionUp)
|
||||||
{
|
{
|
||||||
ratioEstimate = 1/ratioEstimate;
|
ratioEstimate = 1/ratioEstimate;
|
||||||
|
ratioMax = 1/ratioMax;
|
||||||
requiredSteps *= -1;
|
requiredSteps *= -1;
|
||||||
}
|
}
|
||||||
// Provision for fall-back value if we can't satisfy requirements
|
// Provision for fall-back value if we can't satisfy requirements
|
||||||
@ -253,16 +263,18 @@ void Foam::functionObjects::timeControl::calcDeltaTCoeff
|
|||||||
y,
|
y,
|
||||||
requiredSteps
|
requiredSteps
|
||||||
);
|
);
|
||||||
const scalar deltaTLoop = wantedDT/pow(newRatio, requiredSteps-1);
|
const scalar deltaTLoop =
|
||||||
|
wantedDT
|
||||||
|
/ pow(newRatio, mag(requiredSteps)-1);
|
||||||
scalar firstDeltaRatio = deltaTLoop/deltaT0_;
|
scalar firstDeltaRatio = deltaTLoop/deltaT0_;
|
||||||
if (debug)
|
|
||||||
{
|
|
||||||
// Avoid division by zero for ratio = 1.0
|
// Avoid division by zero for ratio = 1.0
|
||||||
scalar Sn =
|
scalar Sn =
|
||||||
deltaTLoop
|
deltaTLoop
|
||||||
*(pow(newRatio, requiredSteps)-1)
|
*(pow(newRatio, mag(requiredSteps))-1)
|
||||||
/(newRatio-1+SMALL);
|
/(newRatio-1+SMALL);
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
Info<< " nSteps " << requiredSteps
|
Info<< " nSteps " << requiredSteps
|
||||||
<< " ratioEstimate " << ratioEstimate
|
<< " ratioEstimate " << ratioEstimate
|
||||||
<< " a0 " << deltaTLoop
|
<< " a0 " << deltaTLoop
|
||||||
@ -281,7 +293,7 @@ void Foam::functionObjects::timeControl::calcDeltaTCoeff
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
y += 1;
|
y += 1;
|
||||||
requiredSteps = nSteps;
|
requiredSteps = mag(nSteps);
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Info<< "firstDeltaRatio " << firstDeltaRatio << " rampDir"
|
Info<< "firstDeltaRatio " << firstDeltaRatio << " rampDir"
|
||||||
@ -291,7 +303,7 @@ void Foam::functionObjects::timeControl::calcDeltaTCoeff
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstDeltaRatio > ratioMax)
|
if (firstDeltaRatio > ratioMax && rampDirectionUp)
|
||||||
{
|
{
|
||||||
requiredSteps++;
|
requiredSteps++;
|
||||||
if (debug)
|
if (debug)
|
||||||
@ -302,7 +314,22 @@ void Foam::functionObjects::timeControl::calcDeltaTCoeff
|
|||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (newRatio > ratioMax)
|
else if (firstDeltaRatio < ratioMax && !rampDirectionUp)
|
||||||
|
{
|
||||||
|
requiredSteps--;
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
Info<< "First ratio " << firstDeltaRatio
|
||||||
|
<< " exceeds threshold " << ratioMax << nl
|
||||||
|
<< "Decreasing required steps " << requiredSteps
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if
|
||||||
|
(
|
||||||
|
(newRatio > ratioMax && rampDirectionUp)
|
||||||
|
|| (newRatio < ratioMax && !rampDirectionUp)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
y += 1;
|
y += 1;
|
||||||
requiredSteps = nSteps;
|
requiredSteps = nSteps;
|
||||||
@ -319,8 +346,19 @@ void Foam::functionObjects::timeControl::calcDeltaTCoeff
|
|||||||
// Reset future series expansion at last step
|
// Reset future series expansion at last step
|
||||||
if (requiredSteps == 1)
|
if (requiredSteps == 1)
|
||||||
{
|
{
|
||||||
|
Sn = deltaT0_*firstDeltaRatio;
|
||||||
seriesDTCoeff_ = GREAT;
|
seriesDTCoeff_ = GREAT;
|
||||||
}
|
}
|
||||||
|
// Situations where we achieve wantedDT but fail to achieve
|
||||||
|
// multiple of writeInterval
|
||||||
|
scalar jumpError =
|
||||||
|
remainder(Sn + presentTime, wantedDT) / wantedDT;
|
||||||
|
|
||||||
|
if (mag(jumpError) > ROOTSMALL)
|
||||||
|
{
|
||||||
|
requiredSteps = label(timeToNextWrite/wantedDT);
|
||||||
|
firstDeltaRatio = timeToNextWrite/requiredSteps/deltaT0_;
|
||||||
|
}
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Info<< "All conditions satisfied deltaT0_:" << deltaT0_
|
Info<< "All conditions satisfied deltaT0_:" << deltaT0_
|
||||||
@ -365,10 +403,7 @@ Foam::functionObjects::timeControl::timeControl
|
|||||||
dict_(dict),
|
dict_(dict),
|
||||||
timeStart_(-VGREAT),
|
timeStart_(-VGREAT),
|
||||||
timeEnd_(VGREAT),
|
timeEnd_(VGREAT),
|
||||||
nStepsToStartTimeChange_
|
nStepsToStartTimeChange_(labelMax),
|
||||||
(
|
|
||||||
dict.lookupOrDefault("nStepsToStartTimeChange", 3)
|
|
||||||
),
|
|
||||||
executeControl_(t, dict, "execute"),
|
executeControl_(t, dict, "execute"),
|
||||||
writeControl_(t, dict, "write"),
|
writeControl_(t, dict, "write"),
|
||||||
foPtr_(functionObject::New(name, t, dict_)),
|
foPtr_(functionObject::New(name, t, dict_)),
|
||||||
@ -494,7 +529,14 @@ bool Foam::functionObjects::timeControl::adjustTimeStep()
|
|||||||
scalar nSteps = timeToNextWrite/deltaT;
|
scalar nSteps = timeToNextWrite/deltaT;
|
||||||
|
|
||||||
// For tiny deltaT the label can overflow!
|
// For tiny deltaT the label can overflow!
|
||||||
if (nSteps < labelMax)
|
if
|
||||||
|
(
|
||||||
|
nSteps < labelMax
|
||||||
|
&& (
|
||||||
|
deltaTCoeff_ != GREAT
|
||||||
|
|| nSteps < nStepsToStartTimeChange_
|
||||||
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// nSteps can be < 1 so make sure at least 1
|
// nSteps can be < 1 so make sure at least 1
|
||||||
|
|
||||||
@ -517,6 +559,7 @@ bool Foam::functionObjects::timeControl::adjustTimeStep()
|
|||||||
clipThreshold = 1/clipThreshold;
|
clipThreshold = 1/clipThreshold;
|
||||||
deltaT = max(newDeltaT, clipThreshold*deltaT);
|
deltaT = max(newDeltaT, clipThreshold*deltaT);
|
||||||
}
|
}
|
||||||
|
|
||||||
const_cast<Time&>(time_).setDeltaT(deltaT, false);
|
const_cast<Time&>(time_).setDeltaT(deltaT, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user