Commit ce9ea1ca authored by Kutalmis Bercin's avatar Kutalmis Bercin Committed by Andrew Heather
Browse files

ENH: Integrated OpenFOAM.org developments for wall functions

OpenFOAM.org commits for
  src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/wallFunctions
were reviewed.

The parts of the commits made by OpenFOAM.org removing various code
duplications across wall functions were picked up by keeping the remaining
functionalities the same.

The duplications were mainly due to:
  - wall function model coefficients
  - yPlusLam(), checkPatch(), write() methods

The duplications were united under the base nutWallFunction.
parent 6532f275
......@@ -5,7 +5,7 @@
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
| Copyright (C) 2011-2016, 2019 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -28,10 +28,7 @@ License
#include "epsilonWallFunctionFvPatchScalarField.H"
#include "nutWallFunctionFvPatchScalarField.H"
#include "turbulenceModel.H"
#include "fvPatchFieldMapper.H"
#include "fvMatrix.H"
#include "volFields.H"
#include "wallFvPatch.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -40,31 +37,6 @@ Foam::scalar Foam::epsilonWallFunctionFvPatchScalarField::tolerance_ = 1e-5;
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::epsilonWallFunctionFvPatchScalarField::checkType()
{
if (!isA<wallFvPatch>(patch()))
{
FatalErrorInFunction
<< "Invalid wall function specification" << nl
<< " Patch type for patch " << patch().name()
<< " must be wall" << nl
<< " Current patch type is " << patch().type() << nl << endl
<< abort(FatalError);
}
}
void Foam::epsilonWallFunctionFvPatchScalarField::writeLocalEntries
(
Ostream& os
) const
{
os.writeEntry("Cmu", Cmu_);
os.writeEntry("kappa", kappa_);
os.writeEntry("E", E_);
}
void Foam::epsilonWallFunctionFvPatchScalarField::setMaster()
{
if (master_ != -1)
......@@ -213,24 +185,24 @@ void Foam::epsilonWallFunctionFvPatchScalarField::calculate
{
const label patchi = patch.index();
const scalarField& y = turbModel.y()[patchi];
const scalar Cmu25 = pow025(Cmu_);
const scalar Cmu75 = pow(Cmu_, 0.75);
const nutWallFunctionFvPatchScalarField& nutw =
nutWallFunctionFvPatchScalarField::nutw(turbModel, patchi);
const tmp<volScalarField> tk = turbModel.k();
const volScalarField& k = tk();
const scalarField& y = turbModel.y()[patchi];
const tmp<scalarField> tnuw = turbModel.nu(patchi);
const scalarField& nuw = tnuw();
const tmp<scalarField> tnutw = turbModel.nut(patchi);
const scalarField& nutw = tnutw();
const tmp<volScalarField> tk = turbModel.k();
const volScalarField& k = tk();
const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi];
const scalarField magGradUw(mag(Uw.snGrad()));
const scalar Cmu25 = pow025(nutw.Cmu());
const scalar Cmu75 = pow(nutw.Cmu(), 0.75);
// Set epsilon and G
forAll(nutw, facei)
{
......@@ -241,15 +213,15 @@ void Foam::epsilonWallFunctionFvPatchScalarField::calculate
const scalar w = cornerWeights[facei];
// Default high-Re form
scalar epsilonc = w*Cmu75*pow(k[celli], 1.5)/(kappa_*y[facei]);
scalar epsilonc = w*Cmu75*pow(k[celli], 1.5)/(nutw.kappa()*y[facei]);
scalar Gc =
w
*(nutw[facei] + nuw[facei])
*magGradUw[facei]
*Cmu25*sqrt(k[celli])
/(kappa_*y[facei]);
/(nutw.kappa()*y[facei]);
if (lowReCorrection_ && yPlus < yPlusLam_)
if (lowReCorrection_ && yPlus < nutw.yPlusLam())
{
epsilonc = w*2.0*k[celli]*nuw[facei]/sqr(y[facei]);
Gc = 0;
......@@ -272,19 +244,13 @@ epsilonWallFunctionFvPatchScalarField
)
:
fixedValueFvPatchField<scalar>(p, iF),
Cmu_(0.09),
kappa_(0.41),
E_(9.8),
yPlusLam_(nutWallFunctionFvPatchScalarField::yPlusLam(kappa_, E_)),
G_(),
epsilon_(),
lowReCorrection_(false),
initialised_(false),
master_(-1),
cornerWeights_()
{
checkType();
}
{}
Foam::epsilonWallFunctionFvPatchScalarField::
......@@ -297,19 +263,13 @@ epsilonWallFunctionFvPatchScalarField
)
:
fixedValueFvPatchField<scalar>(ptf, p, iF, mapper),
Cmu_(ptf.Cmu_),
kappa_(ptf.kappa_),
E_(ptf.E_),
yPlusLam_(ptf.yPlusLam_),
G_(),
epsilon_(),
lowReCorrection_(ptf.lowReCorrection_),
initialised_(false),
master_(-1),
cornerWeights_()
{
checkType();
}
{}
Foam::epsilonWallFunctionFvPatchScalarField::
......@@ -321,10 +281,6 @@ epsilonWallFunctionFvPatchScalarField
)
:
fixedValueFvPatchField<scalar>(p, iF, dict),
Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
E_(dict.lookupOrDefault<scalar>("E", 9.8)),
yPlusLam_(nutWallFunctionFvPatchScalarField::yPlusLam(kappa_, E_)),
G_(),
epsilon_(),
lowReCorrection_(dict.lookupOrDefault("lowReCorrection", false)),
......@@ -332,8 +288,6 @@ epsilonWallFunctionFvPatchScalarField
master_(-1),
cornerWeights_()
{
checkType();
// Apply zero-gradient condition on start-up
this->operator==(patchInternalField());
}
......@@ -346,19 +300,13 @@ epsilonWallFunctionFvPatchScalarField
)
:
fixedValueFvPatchField<scalar>(ewfpsf),
Cmu_(ewfpsf.Cmu_),
kappa_(ewfpsf.kappa_),
E_(ewfpsf.E_),
yPlusLam_(ewfpsf.yPlusLam_),
G_(),
epsilon_(),
lowReCorrection_(ewfpsf.lowReCorrection_),
initialised_(false),
master_(-1),
cornerWeights_()
{
checkType();
}
{}
Foam::epsilonWallFunctionFvPatchScalarField::
......@@ -369,19 +317,13 @@ epsilonWallFunctionFvPatchScalarField
)
:
fixedValueFvPatchField<scalar>(ewfpsf, iF),
Cmu_(ewfpsf.Cmu_),
kappa_(ewfpsf.kappa_),
E_(ewfpsf.E_),
yPlusLam_(ewfpsf.yPlusLam_),
G_(),
epsilon_(),
lowReCorrection_(ewfpsf.lowReCorrection_),
initialised_(false),
master_(-1),
cornerWeights_()
{
checkType();
}
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -582,14 +524,6 @@ void Foam::epsilonWallFunctionFvPatchScalarField::manipulateMatrix
}
void Foam::epsilonWallFunctionFvPatchScalarField::write(Ostream& os) const
{
writeLocalEntries(os);
fixedValueFvPatchField<scalar>::write(os);
os.writeEntry("lowReCorrection", lowReCorrection_);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
......
......@@ -5,7 +5,7 @@
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
| Copyright (C) 2011-2016, 2019 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -47,7 +47,7 @@ Description
The low-Re correction is activated by setting the entry
\c lowReCorrection to 'on'; in this mode the model switches between
laminar and turbulent functions based on the laminar-to-turbulent y+ value
derived from kappa and E. When the \c lowReCorrection is inactive, the
derived from the kappa and E specified in the corresponding nutWallFunction. When the \c lowReCorrection is inactive, the
wall function operates in high-Re mode.
Usage
......@@ -103,18 +103,6 @@ protected:
//- Tolerance used in weighted calculations
static scalar tolerance_;
//- Cmu coefficient
scalar Cmu_;
//- Von Karman constant
scalar kappa_;
//- E coefficient
scalar E_;
//- y+ at the edge of the laminar sublayer
scalar yPlusLam_;
//- Local copy of turbulence G field
scalarField G_;
......@@ -136,12 +124,6 @@ protected:
// Protected Member Functions
//- Check the type of the patch
virtual void checkType();
//- Write local wall function variables
virtual void writeLocalEntries(Ostream&) const;
//- Set the master patch - master is responsible for updating all
// wall function patches
virtual void setMaster();
......@@ -253,7 +235,7 @@ public:
virtual ~epsilonWallFunctionFvPatchScalarField() = default;
// Member functions
// Member Functions
// Access
......@@ -281,12 +263,6 @@ public:
fvMatrix<scalar>& matrix,
const scalarField& weights
);
// I-O
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -5,7 +5,7 @@
\\ / A nd |
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2012-2016 OpenFOAM Foundation
| Copyright (C) 2012-2016, 2019 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -26,9 +26,7 @@ License
\*---------------------------------------------------------------------------*/
#include "fWallFunctionFvPatchScalarField.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "wallFvPatch.H"
#include "nutWallFunctionFvPatchScalarField.H"
#include "v2f.H"
#include "addToRunTimeSelectionTable.H"
......@@ -39,47 +37,6 @@ namespace Foam
namespace RASModels
{
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void fWallFunctionFvPatchScalarField::checkType()
{
if (!isA<wallFvPatch>(patch()))
{
FatalErrorInFunction
<< "Invalid wall function specification" << nl
<< " Patch type for patch " << patch().name()
<< " must be wall" << nl
<< " Current patch type is " << patch().type() << nl << endl
<< abort(FatalError);
}
}
void fWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const
{
os.writeEntry("Cmu", Cmu_);
os.writeEntry("kappa", kappa_);
os.writeEntry("E", E_);
}
scalar fWallFunctionFvPatchScalarField::yPlusLam
(
const scalar kappa,
const scalar E
)
{
scalar ypl = 11.0;
for (int i=0; i<10; i++)
{
ypl = log(max(E*ypl, 1))/kappa;
}
return ypl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
......@@ -88,14 +45,8 @@ fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchField<scalar>(p, iF),
Cmu_(0.09),
kappa_(0.41),
E_(9.8),
yPlusLam_(yPlusLam(kappa_, E_))
{
checkType();
}
fixedValueFvPatchField<scalar>(p, iF)
{}
fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
......@@ -106,14 +57,8 @@ fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchField<scalar>(ptf, p, iF, mapper),
Cmu_(ptf.Cmu_),
kappa_(ptf.kappa_),
E_(ptf.E_),
yPlusLam_(ptf.yPlusLam_)
{
checkType();
}
fixedValueFvPatchField<scalar>(ptf, p, iF, mapper)
{}
fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
......@@ -123,14 +68,8 @@ fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
const dictionary& dict
)
:
fixedValueFvPatchField<scalar>(p, iF, dict),
Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
E_(dict.lookupOrDefault<scalar>("E", 9.8)),
yPlusLam_(yPlusLam(kappa_, E_))
{
checkType();
}
fixedValueFvPatchField<scalar>(p, iF, dict)
{}
fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
......@@ -138,14 +77,8 @@ fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
const fWallFunctionFvPatchScalarField& v2wfpsf
)
:
fixedValueFvPatchField<scalar>(v2wfpsf),
Cmu_(v2wfpsf.Cmu_),
kappa_(v2wfpsf.kappa_),
E_(v2wfpsf.E_),
yPlusLam_(v2wfpsf.yPlusLam_)
{
checkType();
}
fixedValueFvPatchField<scalar>(v2wfpsf)
{}
fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
......@@ -154,14 +87,8 @@ fWallFunctionFvPatchScalarField::fWallFunctionFvPatchScalarField
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchField<scalar>(v2wfpsf, iF),
Cmu_(v2wfpsf.Cmu_),
kappa_(v2wfpsf.kappa_),
E_(v2wfpsf.E_),
yPlusLam_(v2wfpsf.yPlusLam_)
{
checkType();
}
fixedValueFvPatchField<scalar>(v2wfpsf, iF)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -185,6 +112,9 @@ void fWallFunctionFvPatchScalarField::updateCoeffs()
);
const v2fBase& v2fModel = refCast<const v2fBase>(turbModel);
const nutWallFunctionFvPatchScalarField& nutw =
nutWallFunctionFvPatchScalarField::nutw(turbModel, patchi);
const scalarField& y = turbModel.y()[patchi];
const tmp<volScalarField> tk = turbModel.k();
......@@ -199,7 +129,7 @@ void fWallFunctionFvPatchScalarField::updateCoeffs()
const tmp<scalarField> tnuw = turbModel.nu(patchi);
const scalarField& nuw = tnuw();
const scalar Cmu25 = pow025(Cmu_);
const scalar Cmu25 = pow025(nutw.Cmu());
scalarField& f = *this;
......@@ -212,7 +142,7 @@ void fWallFunctionFvPatchScalarField::updateCoeffs()
scalar yPlus = uTau*y[facei]/nuw[facei];
if (yPlus > yPlusLam_)
if (yPlus > nutw.yPlusLam())
{
scalar N = 6.0;
scalar v2c = v2[celli];
......@@ -234,22 +164,6 @@ void fWallFunctionFvPatchScalarField::updateCoeffs()
}
void fWallFunctionFvPatchScalarField::evaluate
(
const Pstream::commsTypes commsType
)
{
fixedValueFvPatchField<scalar>::evaluate(commsType);
}
void fWallFunctionFvPatchScalarField::write(Ostream& os) const
{
writeLocalEntries(os);
fixedValueFvPatchField<scalar>::write(os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeField
......
......@@ -5,7 +5,7 @@
\\ / A nd |
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2012-2016 OpenFOAM Foundation
| Copyright (C) 2012-2016, 2019 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -34,7 +34,8 @@ Description
function condition for low- and high Reynolds number, turbulent flow cases
The model operates in two modes, based on the computed laminar-to-turbulent
switch-over y+ value derived from kappa and E.
switch-over y+ value derived from kappa and E specified in the corresponding
nutWallFunction.
Usage
\table
......@@ -80,34 +81,6 @@ class fWallFunctionFvPatchScalarField
:
public fixedValueFvPatchField<scalar>
{
protected:
// Protected data
//- Cmu coefficient
scalar Cmu_;
//- Von Karman constant
scalar kappa_;
//- E coefficient
scalar E_;
//- Y+ at the edge of the laminar sublayer
scalar yPlusLam_;
// Protected Member Functions
//- Check the type of the patch
virtual void checkType();
//- Write local wall function variables
virtual void writeLocalEntries(Ostream&) const;
//- Calculate the Y+ at the edge of the laminar sublayer
scalar yPlusLam(const scalar kappa, const scalar E);
public:
......@@ -177,21 +150,12 @@ public:
}