fvModels, fvConstraints: Rational separation of fvOptions between physical modelling and numerical constraints

The new fvModels is a general interface to optional physical models in the
finite volume framework, providing sources to the governing conservation
equations, thus ensuring consistency and conservation.  This structure is used
not only for simple sources and forces but also provides a general run-time
selection interface for more complex models such as radiation and film, in the
future this will be extended to Lagrangian, reaction, combustion etc.  For such
complex models the 'correct()' function is provided to update the state of these
models at the beginning of the PIMPLE loop.

fvModels are specified in the optional constant/fvModels dictionary and
backward-compatibility with fvOption is provided by reading the
constant/fvOptions or system/fvOptions dictionary if present.

The new fvConstraints is a general interface to optional numerical constraints
applied to the matrices of the governing equations after construction and/or to
the resulting field after solution.  This system allows arbitrary changes to
either the matrix or solution to ensure numerical or other constraints and hence
violates consistency with the governing equations and conservation but it often
useful to ensure numerical stability, particularly during the initial start-up
period of a run.  Complex manipulations can be achieved with fvConstraints, for
example 'meanVelocityForce' used to maintain a specified mean velocity in a
cyclic channel by manipulating the momentum matrix and the velocity solution.

fvConstraints are specified in the optional system/fvConstraints dictionary and
backward-compatibility with fvOption is provided by reading the
constant/fvOptions or system/fvOptions dictionary if present.

The separation of fvOptions into fvModels and fvConstraints provides a rational
and consistent separation between physical and numerical models which is easier
to understand and reason about, avoids the confusing issue of location of the
controlling dictionary file, improves maintainability and easier to extend to
handle current and future requirements for optional complex physical models and
numerical constraints.
This commit is contained in:
Henry Weller
2021-03-07 22:45:01 +00:00
parent a28fd5552f
commit da3f4cc92e
444 changed files with 4427 additions and 3005 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) 2018-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2018-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -26,6 +26,8 @@ License
#include "age.H"
#include "fvmDiv.H"
#include "fvmLaplacian.H"
#include "fvModels.H"
#include "fvConstraints.H"
#include "momentumTransportModel.H"
#include "inletOutletFvPatchField.H"
#include "wallFvPatch.H"
@ -95,8 +97,7 @@ Foam::functionObjects::age::age
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
fvOptions_(mesh_)
fvMeshFunctionObject(name, runTime, dict)
{
read(dict);
}
@ -119,11 +120,6 @@ bool Foam::functionObjects::age::read(const dictionary& dict)
diffusion_ = dict.lookupOrDefault<Switch>("diffusion", false);
tolerance_ = dict.lookupOrDefault<scalar>("tolerance", 1e-5);
if (dict.found("fvOptions"))
{
fvOptions_.reset(dict.subDict("fvOptions"));
}
return true;
}
@ -159,6 +155,12 @@ bool Foam::functionObjects::age::execute()
relaxCoeff = mesh_.equationRelaxationFactor(schemesField_);
}
const Foam::fvModels& fvModels(Foam::fvModels::New(mesh_));
const Foam::fvConstraints& fvConstraints
(
Foam::fvConstraints::New(mesh_)
);
// This only works because the null constructed inletValue for an
// inletOutletFvPatchField is zero. If we needed any other value we would
// have to loop over the inletOutlet patches and explicitly set the
@ -192,7 +194,7 @@ bool Foam::functionObjects::age::execute()
{
fvScalarMatrix ageEqn
(
fvm::div(phi, age, divScheme) == rho + fvOptions_(rho, age)
fvm::div(phi, age, divScheme) == rho + fvModels.source(rho, age)
);
if (diffusion_)
@ -202,12 +204,14 @@ bool Foam::functionObjects::age::execute()
ageEqn.relax(relaxCoeff);
fvOptions_.constrain(ageEqn);
fvConstraints.constrain(ageEqn);
if (converged(i, ageEqn.solve(schemesField_).initialResidual()))
{
break;
};
fvConstraints.constrain(age);
}
}
else
@ -232,7 +236,7 @@ bool Foam::functionObjects::age::execute()
fvScalarMatrix ageEqn
(
fvm::div(phi, age, divScheme)
== dimensionedScalar(1) + fvOptions_(age)
== dimensionedScalar(1) + fvModels.source(age)
);
if (diffusion_)
@ -242,12 +246,14 @@ bool Foam::functionObjects::age::execute()
ageEqn.relax(relaxCoeff);
fvOptions_.constrain(ageEqn);
fvConstraints.constrain(ageEqn);
if (converged(i, ageEqn.solve(schemesField_).initialResidual()))
{
break;
}
fvConstraints.constrain(age);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2018-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2018-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -73,7 +73,6 @@ SourceFiles
#include "fvMeshFunctionObject.H"
#include "volFields.H"
#include "fvOptionList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -110,9 +109,6 @@ class age
//- Convergence tolerance
scalar tolerance_;
//- Run-time selectable finite volume options, e.g. sources, constraints
fv::optionList fvOptions_;
// Private Member Functions

View File

@ -8,7 +8,6 @@ EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude
LIB_LIBS = \
-lfvOptions \
-lfluidThermophysicalModels \
-lincompressibleTransportModels \
-lmomentumTransportModels \
@ -16,4 +15,6 @@ LIB_LIBS = \
-lfluidThermoMomentumTransportModels \
-lspecie \
-lfiniteVolume \
-lmeshTools
-lmeshTools \
-lfvModels \
-lfvConstraints

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2019-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -30,6 +30,8 @@ License
#include "fvmDdt.H"
#include "fvmDiv.H"
#include "fvmLaplacian.H"
#include "fvModels.H"
#include "fvConstraints.H"
#include "nonOrthogonalSolutionControl.H"
#include "phaseScalarTransport.H"
#include "surfaceFields.H"
@ -300,7 +302,6 @@ Foam::functionObjects::phaseScalarTransport::phaseScalarTransport
phaseName_(IOobject::group(fieldName_)),
nCorr_(0),
residualAlpha_(rootSmall),
fvOptions_(mesh_),
s_
(
IOobject
@ -371,11 +372,6 @@ bool Foam::functionObjects::phaseScalarTransport::read(const dictionary& dict)
dict.readIfPresent("residualAlpha", residualAlpha_);
writeAlphaField_ = dict.lookupOrDefault<bool>("writeAlphaField", true);
if (dict.found("fvOptions"))
{
fvOptions_.reset(dict.subDict("fvOptions"));
}
return true;
}
@ -406,6 +402,12 @@ bool Foam::functionObjects::phaseScalarTransport::execute()
? mesh_.equationRelaxationFactor(schemesField_)
: 0;
const Foam::fvModels& fvModels(Foam::fvModels::New(mesh_));
const Foam::fvConstraints& fvConstraints
(
Foam::fvConstraints::New(mesh_)
);
// Solve
if (alphaPhi.dimensions() == dimVolume/dimTime)
{
@ -422,14 +424,15 @@ bool Foam::functionObjects::phaseScalarTransport::execute()
laplacianScheme
)
==
fvOptions_(alpha, s_)
fvModels.source(alpha, s_)
- fvm::ddt(residualAlpha_, s_)
+ fvc::ddt(residualAlpha_, s_)
);
fieldEqn.relax(relaxCoeff);
fvOptions_.constrain(fieldEqn);
fvConstraints.constrain(fieldEqn);
fieldEqn.solve(schemesField_);
fvConstraints.constrain(s_);
}
}
else if (alphaPhi.dimensions() == dimMass/dimTime)
@ -450,14 +453,15 @@ bool Foam::functionObjects::phaseScalarTransport::execute()
laplacianScheme
)
==
fvOptions_(alpha, rho, s_)
fvModels.source(alpha, rho, s_)
- fvm::ddt(residualAlpha_*rho, s_)
+ fvc::ddt(residualAlpha_*rho, s_)
);
fieldEqn.relax(relaxCoeff);
fvOptions_.constrain(fieldEqn);
fvConstraints.constrain(fieldEqn);
fieldEqn.solve(schemesField_);
fvConstraints.constrain(s_);
}
}
else

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2019-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -99,7 +99,6 @@ SourceFiles
#include "fvMeshFunctionObject.H"
#include "volFields.H"
#include "fvOptionList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -164,9 +163,6 @@ class phaseScalarTransport
// fraction
bool writeAlphaField_;
//- Run-time selectable finite volume options, e.g. sources, constraints
fv::optionList fvOptions_;
//- The field
volScalarField s_;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -29,6 +29,8 @@ License
#include "fvmDiv.H"
#include "fvmLaplacian.H"
#include "fvmSup.H"
#include "fvModels.H"
#include "fvConstraints.H"
#include "kinematicMomentumTransportModel.H"
#include "fluidThermoMomentumTransportModel.H"
#include "addToRunTimeSelectionTable.H"
@ -115,7 +117,6 @@ Foam::functionObjects::scalarTransport::scalarTransport
fieldName_(dict.lookupOrDefault<word>("field", "s")),
D_(0),
nCorr_(0),
fvOptions_(mesh_),
s_
(
IOobject
@ -155,11 +156,6 @@ bool Foam::functionObjects::scalarTransport::read(const dictionary& dict)
dict.readIfPresent("nCorr", nCorr_);
if (dict.found("fvOptions"))
{
fvOptions_.reset(dict.subDict("fvOptions"));
}
return true;
}
@ -184,6 +180,12 @@ bool Foam::functionObjects::scalarTransport::execute()
relaxCoeff = mesh_.equationRelaxationFactor(schemesField_);
}
const Foam::fvModels& fvModels(Foam::fvModels::New(mesh_));
const Foam::fvConstraints& fvConstraints
(
Foam::fvConstraints::New(mesh_)
);
if (phi.dimensions() == dimMass/dimTime)
{
const volScalarField& rho =
@ -197,14 +199,16 @@ bool Foam::functionObjects::scalarTransport::execute()
+ fvm::div(phi, s_, divScheme)
- fvm::laplacian(D, s_, laplacianScheme)
==
fvOptions_(rho, s_)
fvModels.source(rho, s_)
);
sEqn.relax(relaxCoeff);
fvOptions_.constrain(sEqn);
fvConstraints.constrain(sEqn);
sEqn.solve(schemesField_);
fvConstraints.constrain(s_);
}
}
else if (phi.dimensions() == dimVolume/dimTime)
@ -217,14 +221,16 @@ bool Foam::functionObjects::scalarTransport::execute()
+ fvm::div(phi, s_, divScheme)
- fvm::laplacian(D, s_, laplacianScheme)
==
fvOptions_(s_)
fvModels.source(s_)
);
sEqn.relax(relaxCoeff);
fvOptions_.constrain(sEqn);
fvConstraints.constrain(sEqn);
sEqn.solve(schemesField_);
fvConstraints.constrain(s_);
}
}
else

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,7 +53,6 @@ SourceFiles
#include "fvMeshFunctionObject.H"
#include "volFields.H"
#include "fvOptionList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -99,9 +98,6 @@ class scalarTransport
//- Name of field whose schemes are used (optional)
word schemesField_;
//- Run-time selectable finite volume options, e.g. sources, constraints
fv::optionList fvOptions_;
//- The scalar field
volScalarField s_;