solvers: Adjust time step even if Courant number is zero

This change means that even if the Courant number is zero, the time step
is adjusted based on maximum time step settings and/or constraints
specified by active fvModels. If none of these additional constraints
are present then adjustment is deactivated.
This commit is contained in:
Will Bainbridge
2023-01-25 13:53:00 +00:00
parent bc23162499
commit fcab778f57
13 changed files with 85 additions and 148 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -35,17 +35,19 @@ void Foam::setDeltaT(Time& runTime, const PtrList<solver>& solvers)
&& runTime.controlDict().lookupOrDefault("adjustTimeStep", false)
)
{
scalar deltaT = great;
bool transient = false;
scalar deltaT = vGreat;
forAll(solvers, i)
{
if (solvers[i].transient())
{
transient = true;
deltaT = min(deltaT, solvers[i].maxDeltaT());
}
}
if (deltaT != great)
if (transient && deltaT < rootVGreat)
{
runTime.setDeltaT(min(runTime.deltaTValue(), deltaT));
}
@ -58,9 +60,8 @@ void Foam::adjustDeltaT(Time& runTime, const PtrList<solver>& solvers)
// Update the time-step limited by the solvers maxDeltaT
if (runTime.controlDict().lookupOrDefault("adjustTimeStep", false))
{
scalar deltaT = 1.2*runTime.deltaTValue();
bool transient = false;
scalar deltaT = vGreat;
forAll(solvers, i)
{
@ -71,9 +72,9 @@ void Foam::adjustDeltaT(Time& runTime, const PtrList<solver>& solvers)
}
}
if (transient)
if (transient && deltaT < rootVGreat)
{
runTime.setDeltaT(deltaT);
runTime.setDeltaT(min(1.2*runTime.deltaTValue(), deltaT));
Info<< "deltaT = " << runTime.deltaTValue() << endl;
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -32,8 +32,9 @@ void Foam::setDeltaT(Time& runTime, const solver& solver)
if
(
runTime.timeIndex() == 0
&& solver.transient()
&& runTime.controlDict().lookupOrDefault("adjustTimeStep", false)
&& solver.transient()
&& solver.maxDeltaT() < rootVGreat
)
{
runTime.setDeltaT(min(runTime.deltaTValue(), solver.maxDeltaT()));
@ -46,8 +47,9 @@ void Foam::adjustDeltaT(Time& runTime, const solver& solver)
// Update the time-step limited by the solver maxDeltaT
if
(
solver.transient()
&& runTime.controlDict().lookupOrDefault("adjustTimeStep", false)
runTime.controlDict().lookupOrDefault("adjustTimeStep", false)
&& solver.transient()
&& solver.maxDeltaT() < rootVGreat
)
{
runTime.setDeltaT(min(1.2*runTime.deltaTValue(), solver.maxDeltaT()));

View File

@ -172,25 +172,17 @@ Foam::solvers::VoFSolver::~VoFSolver()
Foam::scalar Foam::solvers::VoFSolver::maxDeltaT() const
{
const scalar maxAlphaCo
(
runTime.controlDict().lookup<scalar>("maxAlphaCo")
);
const scalar maxAlphaCo =
runTime.controlDict().lookup<scalar>("maxAlphaCo");
const scalar deltaT = fluidSolver::maxDeltaT();
scalar deltaT = fluidSolver::maxDeltaT();
if (alphaCoNum > small)
{
return min
(
deltaT,
maxAlphaCo/(alphaCoNum + small)*runTime.deltaTValue()
);
}
else
{
return deltaT;
deltaT = min(deltaT, maxAlphaCo/alphaCoNum*runTime.deltaTValue());
}
return deltaT;
}

View File

@ -39,30 +39,19 @@ void Foam::solvers::VoFSolver::setRDeltaT()
pimpleDict.lookupOrDefault<scalar>("maxCo", 0.9)
);
const scalar maxDeltaT
(
pimpleDict.lookupOrDefault<scalar>("maxDeltaT", great)
);
const scalar minDeltaT
(
pimpleDict.lookupOrDefault<scalar>("minDeltaT", small)
);
const volScalarField rDeltaT0("rDeltaT0", rDeltaT);
// Set the reciprocal time-step from the local Courant number
// and maximum and minimum time-steps
rDeltaT.ref() = min
(
1/dimensionedScalar(dimTime, minDeltaT),
max
(
1/dimensionedScalar(dimTime, maxDeltaT),
fvc::surfaceSum(mag(phi))()()
/((2*maxCo)*mesh.V())
)
);
rDeltaT.ref() = fvc::surfaceSum(mag(phi))()()/((2*maxCo)*mesh.V());
if (pimpleDict.found("maxDeltaT"))
{
rDeltaT.max(1/pimpleDict.lookup<scalar>("maxDeltaT"));
}
if (pimpleDict.found("minDeltaT"))
{
rDeltaT.min(1/pimpleDict.lookup<scalar>("minDeltaT"));
}
Info<< "Flow time scale min/max = "
<< gMin(1/rDeltaT.primitiveField())

View File

@ -48,7 +48,7 @@ void Foam::solvers::fluidSolver::readControls()
runTime.controlDict().lookupOrDefault<scalar>("maxCo", 1.0);
maxDeltaT_ =
runTime.controlDict().lookupOrDefault<scalar>("maxDeltaT", great);
runTime.controlDict().lookupOrDefault<scalar>("maxDeltaT", vGreat);
correctPhi = pimple.dict().lookupOrDefault
(
@ -205,15 +205,14 @@ Foam::solvers::fluidSolver::~fluidSolver()
Foam::scalar Foam::solvers::fluidSolver::maxDeltaT() const
{
scalar deltaT = min(fvModels().maxDeltaT(), maxDeltaT_);
if (CoNum > small)
{
const scalar deltaT = maxCo*runTime.deltaTValue()/CoNum;
return min(min(deltaT, fvModels().maxDeltaT()), maxDeltaT_);
}
else
{
return runTime.deltaTValue();
deltaT = min(deltaT, maxCo/CoNum*runTime.deltaTValue());
}
return deltaT;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -49,30 +49,19 @@ void Foam::solvers::incompressibleFluid::setRDeltaT()
pimpleDict.lookupOrDefault<scalar>("rDeltaTDampingCoeff", 1.0)
);
const scalar maxDeltaT
(
pimpleDict.lookupOrDefault<scalar>("maxDeltaT", great)
);
const scalar minDeltaT
(
pimpleDict.lookupOrDefault<scalar>("minDeltaT", small)
);
const volScalarField rDeltaT0("rDeltaT0", rDeltaT);
// Set the reciprocal time-step from the local Courant number
// and maximum and minimum time-steps
rDeltaT.ref() = min
(
1/dimensionedScalar(dimTime, minDeltaT),
max
(
1/dimensionedScalar(dimTime, maxDeltaT),
fvc::surfaceSum(mag(phi))()()
/((2*maxCo)*mesh.V())
)
);
rDeltaT.ref() = fvc::surfaceSum(mag(phi))()()/((2*maxCo)*mesh.V());
if (pimpleDict.found("maxDeltaT"))
{
rDeltaT.max(1/pimpleDict.lookup<scalar>("maxDeltaT"));
}
if (pimpleDict.found("minDeltaT"))
{
rDeltaT.min(1/pimpleDict.lookup<scalar>("minDeltaT"));
}
// Update the boundary values of the reciprocal time-step
rDeltaT.correctBoundaryConditions();

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -47,30 +47,19 @@ void Foam::solvers::isothermalFluid::setRDeltaT()
pimpleDict.lookupOrDefault<scalar>("rDeltaTSmoothingCoeff", 0.02)
);
const scalar maxDeltaT
(
pimpleDict.lookupOrDefault<scalar>("maxDeltaT", great)
);
const scalar minDeltaT
(
pimpleDict.lookupOrDefault<scalar>("minDeltaT", small)
);
const volScalarField rDeltaT0("rDeltaT0", rDeltaT);
// Set the reciprocal time-step from the local Courant number
// and maximum and minimum time-steps
rDeltaT.ref() = min
(
1/dimensionedScalar(dimTime, minDeltaT),
max
(
1/dimensionedScalar(dimTime, maxDeltaT),
fvc::surfaceSum(mag(phi))()()
/((2*maxCo)*mesh.V()*rho())
)
);
rDeltaT.ref() = fvc::surfaceSum(mag(phi))()()/((2*maxCo)*mesh.V()*rho());
if (pimpleDict.found("maxDeltaT"))
{
rDeltaT.max(1/pimpleDict.lookup<scalar>("maxDeltaT"));
}
if (pimpleDict.found("minDeltaT"))
{
rDeltaT.min(1/pimpleDict.lookup<scalar>("minDeltaT"));
}
if (pimple.transonic())
{
@ -83,8 +72,7 @@ void Foam::solvers::isothermalFluid::setRDeltaT()
rDeltaT.ref() = max
(
rDeltaT(),
fvc::surfaceSum(mag(phid))()()
/((2*maxCo)*mesh.V()*psi())
fvc::surfaceSum(mag(phid))()()/((2*maxCo)*mesh.V()*psi())
);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -44,19 +44,14 @@ void Foam::solvers::multicomponentFluid::setRDeltaT()
// Maximum flow Courant number
const scalar maxCo(pimpleDict.lookup<scalar>("maxCo"));
// Set the reciprocal time-step from the local Courant number
// and maximum and minimum time-steps
rDeltaT.ref() =
(
fvc::surfaceSum(mag(phi))()()
/((2*maxCo)*mesh.V()*rho())
);
// Limit the largest time step
fvc::surfaceSum(mag(phi))()()/((2*maxCo)*mesh.V()*rho());
if (pimpleDict.found("maxDeltaT"))
{
rDeltaT.max(1/pimpleDict.lookup<scalar>("maxDeltaT"));
}
// Limit the smallest time step
if (pimpleDict.found("minDeltaT"))
{
rDeltaT.min(1/pimpleDict.lookup<scalar>("minDeltaT"));

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -40,16 +40,6 @@ void Foam::solvers::multiphaseEuler::setRDeltaT()
pimpleDict.lookupOrDefault<scalar>("maxCo", 0.2)
);
const scalar maxDeltaT
(
pimpleDict.lookupOrDefault<scalar>("maxDeltaT", great)
);
const scalar minDeltaT
(
pimpleDict.lookupOrDefault<scalar>("minDeltaT", small)
);
const scalar rDeltaTSmoothingCoeff
(
pimpleDict.lookupOrDefault<scalar>("rDeltaTSmoothingCoeff", 0.02)
@ -64,16 +54,15 @@ void Foam::solvers::multiphaseEuler::setRDeltaT()
// Set the reciprocal time-step from the local Courant number
// and maximum and minimum time-steps
rDeltaT.ref() = min
(
1/dimensionedScalar(dimTime, minDeltaT),
max
(
1/dimensionedScalar(dimTime, maxDeltaT),
fvc::surfaceSum(maxPhi)()()
/((2*maxCo)*mesh.V())
)
);
rDeltaT.ref() = fvc::surfaceSum(maxPhi)()()/((2*maxCo)*mesh.V());
if (pimpleDict.found("maxDeltaT"))
{
rDeltaT.max(1/pimpleDict.lookup<scalar>("maxDeltaT"));
}
if (pimpleDict.found("minDeltaT"))
{
rDeltaT.min(1/pimpleDict.lookup<scalar>("minDeltaT"));
}
// Update the boundary values of the reciprocal time-step
rDeltaT.correctBoundaryConditions();

View File

@ -48,18 +48,12 @@ void Foam::solvers::shockFluid::setRDeltaT(const surfaceScalarField& amaxSf)
)
);
const scalar maxDeltaT
(
pimpleDict.lookupOrDefault<scalar>("maxDeltaT", great)
);
// Set the reciprocal time-step from the local Courant number
rDeltaT.ref() = max
(
1/dimensionedScalar(dimTime, maxDeltaT),
fvc::surfaceSum(amaxSf)()()
/((2*maxCo)*mesh.V())
);
rDeltaT.ref() = fvc::surfaceSum(amaxSf)()()/((2*maxCo)*mesh.V());
if (pimpleDict.found("maxDeltaT"))
{
rDeltaT.max(1/pimpleDict.lookup<scalar>("maxDeltaT"));
}
// Update the boundary values of the reciprocal time-step
rDeltaT.correctBoundaryConditions();

View File

@ -47,7 +47,7 @@ void Foam::solvers::solid::readControls()
runTime.controlDict().lookupOrDefault<scalar>("maxDi", 1.0);
maxDeltaT_ =
runTime.controlDict().lookupOrDefault<scalar>("maxDeltaT", great);
runTime.controlDict().lookupOrDefault<scalar>("maxDeltaT", vGreat);
}
@ -131,15 +131,14 @@ Foam::solvers::solid::~solid()
Foam::scalar Foam::solvers::solid::maxDeltaT() const
{
scalar deltaT = min(fvModels().maxDeltaT(), maxDeltaT_);
if (DiNum > small)
{
const scalar deltaT = maxDi*runTime.deltaTValue()/DiNum;
return min(min(deltaT, fvModels().maxDeltaT()), maxDeltaT_);
}
else
{
return maxDeltaT_;
deltaT = min(deltaT, maxDi/DiNum*runTime.deltaTValue());
}
return deltaT;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -148,7 +148,7 @@ bool Foam::fvModel::addsSupToField(const word& fieldName) const
Foam::scalar Foam::fvModel::maxDeltaT() const
{
return great;
return vGreat;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -241,7 +241,7 @@ Foam::scalar Foam::fvModels::maxDeltaT() const
{
const PtrListDictionary<fvModel>& modelList(*this);
scalar maxDeltaT = great;
scalar maxDeltaT = vGreat;
forAll(modelList, i)
{