TurbulenceModels: Added validate function

Moved correctNut call from constructors to the new validate function to
avoid problems with construction order and field availability for the
calculation of nut.

To ensure nut is physical and consistent with the turbulence fields the
validate function should be called after the construction of the
turbulence model, fvOptions and any other fields that the calculation of
nut might depend on.
This commit is contained in:
Henry Weller
2015-12-01 10:07:00 +00:00
parent 61b2bcf39b
commit 82ccde3269
37 changed files with 49 additions and 193 deletions

View File

@ -74,7 +74,6 @@ buoyantKEpsilon<BasicTurbulenceModel>::buoyantKEpsilon
{ {
if (type == typeName) if (type == typeName)
{ {
kEpsilon<BasicTurbulenceModel>::correctNut();
this->printCoeffs(type); this->printCoeffs(type);
} }
} }

View File

@ -181,14 +181,6 @@ LamBremhorstKE::LamBremhorstKE
if (type == typeName) if (type == typeName)
{ {
printCoeffs(type); printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -331,14 +331,6 @@ LienCubicKE::LienCubicKE
if (type == typeName) if (type == typeName)
{ {
printCoeffs(type); printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -225,14 +225,6 @@ LienLeschziner::LienLeschziner
if (type == typeName) if (type == typeName)
{ {
printCoeffs(type); printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -223,14 +223,6 @@ ShihQuadraticKE::ShihQuadraticKE
if (type == typeName) if (type == typeName)
{ {
printCoeffs(type); printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -593,6 +593,10 @@ bool kkLOmega::read()
} }
void kkLOmega::validate()
{}
void kkLOmega::correct() void kkLOmega::correct()
{ {
eddyViscosity<incompressible::RASModel>::correct(); eddyViscosity<incompressible::RASModel>::correct();

View File

@ -301,6 +301,10 @@ public:
return epsilon_; return epsilon_;
} }
//- Validate the turbulence fields after construction
// Update turbulence viscosity and other derived fields as requires
virtual void validate();
//- Solve the turbulence equations and correct the turbulence viscosity //- Solve the turbulence equations and correct the turbulence viscosity
virtual void correct(); virtual void correct();
}; };

View File

@ -208,14 +208,6 @@ qZeta::qZeta
if (type == typeName) if (type == typeName)
{ {
printCoeffs(type); printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -96,9 +96,6 @@ NicenoKEqn<BasicTurbulenceModel>::NicenoKEqn
{ {
if (type == typeName) if (type == typeName)
{ {
// Cannot correct nut yet: construction of the phases is not complete
// correctNut();
this->printCoeffs(type); this->printCoeffs(type);
} }
} }

View File

@ -73,9 +73,6 @@ SmagorinskyZhang<BasicTurbulenceModel>::SmagorinskyZhang
{ {
if (type == typeName) if (type == typeName)
{ {
// Cannot correct nut yet: construction of the phases is not complete
// correctNut();
this->printCoeffs(type); this->printCoeffs(type);
} }
} }

View File

@ -75,7 +75,6 @@ continuousGasKEqn<BasicTurbulenceModel>::continuousGasKEqn
{ {
if (type == typeName) if (type == typeName)
{ {
kEqn<BasicTurbulenceModel>::correctNut();
this->printCoeffs(type); this->printCoeffs(type);
} }
} }

View File

@ -107,9 +107,6 @@ LaheyKEpsilon<BasicTurbulenceModel>::LaheyKEpsilon
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Cannot correct nut yet: construction of the phases is not complete
// correctNut();
} }
} }

View File

@ -89,8 +89,6 @@ continuousGasKEpsilon<BasicTurbulenceModel>::continuousGasKEpsilon
{ {
if (type == typeName) if (type == typeName)
{ {
// Cannot correct nut yet: construction of the phases is not complete
// kEpsilon<BasicTurbulenceModel>::correctNut();
this->printCoeffs(type); this->printCoeffs(type);
} }
} }

View File

@ -76,8 +76,6 @@ kOmegaSSTSato<BasicTurbulenceModel>::kOmegaSSTSato
{ {
if (type == typeName) if (type == typeName)
{ {
// Cannot correct nut yet: construction of the phases is not complete
// correctNut();
this->printCoeffs(type); this->printCoeffs(type);
} }
} }

View File

@ -112,14 +112,6 @@ DeardorffDiffStress<BasicTurbulenceModel>::DeardorffDiffStress
{ {
this->printCoeffs(type); this->printCoeffs(type);
this->boundNormalStress(this->R_); this->boundNormalStress(this->R_);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -114,14 +114,6 @@ Smagorinsky<BasicTurbulenceModel>::Smagorinsky
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -319,14 +319,6 @@ SpalartAllmarasDES<BasicTurbulenceModel>::SpalartAllmarasDES
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -144,14 +144,6 @@ WALE<BasicTurbulenceModel>::WALE
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -186,14 +186,6 @@ dynamicKEqn<BasicTurbulenceModel>::dynamicKEqn
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -123,14 +123,6 @@ dynamicLagrangian<BasicTurbulenceModel>::dynamicLagrangian
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -114,14 +114,6 @@ kEqn<BasicTurbulenceModel>::kEqn
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -205,14 +205,6 @@ LRR<BasicTurbulenceModel>::LRR
this->boundNormalStress(this->R_); this->boundNormalStress(this->R_);
bound(epsilon_, this->epsilonMin_); bound(epsilon_, this->epsilonMin_);
k_ = 0.5*tr(this->R_); k_ = 0.5*tr(this->R_);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -205,14 +205,6 @@ LaunderSharmaKE<BasicTurbulenceModel>::LaunderSharmaKE
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -206,14 +206,6 @@ RNGkEpsilon<BasicTurbulenceModel>::RNGkEpsilon
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -214,14 +214,6 @@ SSG<BasicTurbulenceModel>::SSG
this->boundNormalStress(this->R_); this->boundNormalStress(this->R_);
bound(epsilon_, this->epsilonMin_); bound(epsilon_, this->epsilonMin_);
k_ = 0.5*tr(this->R_); k_ = 0.5*tr(this->R_);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -256,14 +256,6 @@ SpalartAllmaras<BasicTurbulenceModel>::SpalartAllmaras
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -42,6 +42,16 @@ void kEpsilon<BasicTurbulenceModel>::correctNut()
this->nut_ = Cmu_*sqr(k_)/epsilon_; this->nut_ = Cmu_*sqr(k_)/epsilon_;
this->nut_.correctBoundaryConditions(); this->nut_.correctBoundaryConditions();
// const_cast needed because the operators and functions of fvOptions
// are currently non-const.
fv::optionList& fvOptions = const_cast<fv::optionList&>
(
this->mesh_.objectRegistry::template
lookupObject<fv::optionList>("fvOptions")
);
fvOptions.correct(this->nut_);
BasicTurbulenceModel::correctNut(); BasicTurbulenceModel::correctNut();
} }
@ -189,14 +199,6 @@ kEpsilon<BasicTurbulenceModel>::kEpsilon
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }
@ -300,7 +302,6 @@ void kEpsilon<BasicTurbulenceModel>::correct()
bound(k_, this->kMin_); bound(k_, this->kMin_);
correctNut(); correctNut();
fvOptions.correct(nut);
} }

View File

@ -148,14 +148,6 @@ kOmega<BasicTurbulenceModel>::kOmega
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -351,14 +351,6 @@ kOmegaSST<BasicTurbulenceModel>::kOmegaSST
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -227,14 +227,6 @@ realizableKE<BasicTurbulenceModel>::realizableKE
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -239,14 +239,6 @@ v2f<BasicTurbulenceModel>::v2f
if (type == typeName) if (type == typeName)
{ {
this->printCoeffs(type); this->printCoeffs(type);
// Correct nut for single-phase solvers only.
// For multiphase solvers the phase construction is not complete
// at this point.
if (isType<geometricOneField>(alpha))
{
correctNut();
}
} }
} }

View File

@ -295,6 +295,13 @@ Foam::ReynoldsStress<BasicTurbulenceModel>::divDevRhoReff
} }
template<class BasicTurbulenceModel>
void Foam::ReynoldsStress<BasicTurbulenceModel>::validate()
{
correctNut();
}
template<class BasicTurbulenceModel> template<class BasicTurbulenceModel>
void Foam::ReynoldsStress<BasicTurbulenceModel>::correct() void Foam::ReynoldsStress<BasicTurbulenceModel>::correct()
{ {

View File

@ -140,6 +140,10 @@ public:
volVectorField& U volVectorField& U
) const; ) const;
//- Validate the turbulence fields after construction
// Update turbulence viscosity and other derived fields as requires
virtual void validate();
//- Solve the turbulence equations and correct the turbulence viscosity //- Solve the turbulence equations and correct the turbulence viscosity
virtual void correct() = 0; virtual void correct() = 0;
}; };

View File

@ -121,6 +121,13 @@ Foam::eddyViscosity<BasicTurbulenceModel>::R() const
} }
template<class BasicTurbulenceModel>
void Foam::eddyViscosity<BasicTurbulenceModel>::validate()
{
correctNut();
}
template<class BasicTurbulenceModel> template<class BasicTurbulenceModel>
void Foam::eddyViscosity<BasicTurbulenceModel>::correct() void Foam::eddyViscosity<BasicTurbulenceModel>::correct()
{ {

View File

@ -127,6 +127,10 @@ public:
//- Return the Reynolds stress tensor //- Return the Reynolds stress tensor
virtual tmp<volSymmTensorField> R() const; virtual tmp<volSymmTensorField> R() const;
//- Validate the turbulence fields after construction
// Update turbulence viscosity and other derived fields as requires
virtual void validate();
//- Solve the turbulence equations and correct the turbulence viscosity //- Solve the turbulence equations and correct the turbulence viscosity
virtual void correct() = 0; virtual void correct() = 0;
}; };

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) 2011-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -84,6 +84,10 @@ bool Foam::turbulenceModel::read()
} }
void Foam::turbulenceModel::validate()
{}
void Foam::turbulenceModel::correct() void Foam::turbulenceModel::correct()
{ {
if (mesh_.changing()) if (mesh_.changing())

View File

@ -205,6 +205,10 @@ public:
//- Return the Reynolds stress tensor //- Return the Reynolds stress tensor
virtual tmp<volSymmTensorField> R() const = 0; virtual tmp<volSymmTensorField> R() const = 0;
//- Validate the turbulence fields after construction
// Update derived fields as required
virtual void validate();
//- Solve the turbulence equations and correct the turbulence viscosity //- Solve the turbulence equations and correct the turbulence viscosity
virtual void correct() = 0; virtual void correct() = 0;
}; };