From 7bc178f1003bc9ae6064f0812e8d6bf8463cd330 Mon Sep 17 00:00:00 2001 From: Vuko Vukcevic Date: Tue, 19 Jun 2018 11:22:57 +0200 Subject: [PATCH] Refactored nutSpalartAllmarasStandardRoughWallFunction This wall function is now the same as nutURoughWallFunction, we simply derive from it to enable backward compatibility. --- ...ndardRoughWallFunctionFvPatchScalarField.C | 216 +----------------- ...ndardRoughWallFunctionFvPatchScalarField.H | 88 +------ 2 files changed, 10 insertions(+), 294 deletions(-) diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutSpalartAllmarasStandardRoughWallFunction/nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutSpalartAllmarasStandardRoughWallFunction/nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.C index 412fc7790..b904d8993 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutSpalartAllmarasStandardRoughWallFunction/nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutSpalartAllmarasStandardRoughWallFunction/nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.C @@ -38,165 +38,6 @@ namespace incompressible namespace RASModels { -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -tmp -nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::calcNut() const -{ - const label patchI = patch().index(); - - const RASModel& rasModel = db().lookupObject("RASProperties"); - const scalarField& y = rasModel.y()[patchI]; - const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI]; - const scalarField& nuw = rasModel.nu().boundaryField()[patchI]; - - // The flow velocity at the adjacent cell centre - const scalarField magUp = mag(Uw.patchInternalField() - Uw); - - tmp tyPlus = calcYPlus(magUp); - scalarField& yPlus = tyPlus(); - - tmp tnutw(new scalarField(patch().size(), 0.0)); - scalarField& nutw = tnutw(); - - forAll(yPlus, facei) - { - if (yPlus[facei] > yPlusLam_) - { - const scalar Re = magUp[facei]*y[facei]/nuw[facei]; - nutw[facei] = nuw[facei]*(sqr(yPlus[facei])/Re - 1); - } - } - - return tnutw; -} - - -tmp -nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::calcYPlus -( - const scalarField& magUp -) const -{ - const label patchI = patch().index(); - - const RASModel& rasModel = db().lookupObject("RASProperties"); - const scalarField& y = rasModel.y()[patchI]; - const scalarField& nuw = rasModel.nu().boundaryField()[patchI]; - - tmp tyPlus(new scalarField(patch().size(), 0.0)); - scalarField& yPlus = tyPlus(); - - if (roughnessHeight_ > 0.0) - { - // Rough Walls - const scalar c_1 = 1/(90 - 2.25) + roughnessConstant_; - static const scalar c_2 = 2.25/(90 - 2.25); - static const scalar c_3 = 2.0*atan(1.0)/log(90/2.25); - static const scalar c_4 = c_3*log(2.25); - - //if (KsPlusBasedOnYPlus_) - { - // If KsPlus is based on YPlus the extra term added to the law - // of the wall will depend on yPlus - forAll(yPlus, facei) - { - const scalar magUpara = magUp[facei]; - const scalar Re = magUpara*y[facei]/nuw[facei]; - const scalar kappaRe = kappa_*Re; - - scalar yp = yPlusLam_; - const scalar ryPlusLam = 1.0/yp; - - int iter = 0; - scalar yPlusLast = 0.0; - scalar dKsPlusdYPlus = roughnessHeight_/y[facei]; - - // Enforce the roughnessHeight to be less than the distance to - // the first cell centre - if (dKsPlusdYPlus > 1) - { - dKsPlusdYPlus = 1; - } - - // Additional tuning parameter (fudge factor) - nominally = 1 - dKsPlusdYPlus *= roughnessFudgeFactor_; - - do - { - yPlusLast = yp; - - // The non-dimensional roughness height - scalar KsPlus = yp*dKsPlusdYPlus; - - // The extra term in the law-of-the-wall - scalar G = 0.0; - - scalar yPlusGPrime = 0.0; - - if (KsPlus >= 90) - { - const scalar t_1 = 1 + roughnessConstant_*KsPlus; - G = log(t_1); - yPlusGPrime = roughnessConstant_*KsPlus/t_1; - } - else if (KsPlus > 2.25) - { - const scalar t_1 = c_1*KsPlus - c_2; - const scalar t_2 = c_3*log(KsPlus) - c_4; - const scalar sint_2 = sin(t_2); - const scalar logt_1 = log(t_1); - G = logt_1*sint_2; - yPlusGPrime = - (c_1*sint_2*KsPlus/t_1) + (c_3*logt_1*cos(t_2)); - } - - scalar denom = 1.0 + log(E_*yp) - G - yPlusGPrime; - if (mag(denom) > VSMALL) - { - yp = (kappaRe + yp*(1 - yPlusGPrime))/denom; - } - } while - ( - mag(ryPlusLam*(yp - yPlusLast)) > 0.0001 - && ++iter < 10 - && yp > VSMALL - ); - - yPlus[facei] = max(0.0, yp); - } - } - } - else - { - // Smooth Walls - forAll(yPlus, facei) - { - const scalar magUpara = magUp[facei]; - const scalar Re = magUpara*y[facei]/nuw[facei]; - const scalar kappaRe = kappa_*Re; - - scalar yp = yPlusLam_; - const scalar ryPlusLam = 1.0/yp; - - int iter = 0; - scalar yPlusLast = 0.0; - - do - { - yPlusLast = yp; - yp = (kappaRe + yp)/(1.0 + log(E_*yp)); - - } while(mag(ryPlusLam*(yp - yPlusLast)) > 0.0001 && ++iter < 10); - - yPlus[facei] = max(0.0, yp); - } - } - - return tyPlus; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField:: @@ -206,10 +47,7 @@ nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField const DimensionedField& iF ) : - nutWallFunctionFvPatchScalarField(p, iF), - roughnessHeight_(pTraits::zero), - roughnessConstant_(pTraits::zero), - roughnessFudgeFactor_(pTraits::zero) + nutURoughWallFunctionFvPatchScalarField(p, iF) {} @@ -222,10 +60,7 @@ nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField const fvPatchFieldMapper& mapper ) : - nutWallFunctionFvPatchScalarField(ptf, p, iF, mapper), - roughnessHeight_(ptf.roughnessHeight_), - roughnessConstant_(ptf.roughnessConstant_), - roughnessFudgeFactor_(ptf.roughnessFudgeFactor_) + nutURoughWallFunctionFvPatchScalarField(ptf, p, iF, mapper) {} @@ -237,10 +72,7 @@ nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField const dictionary& dict ) : - nutWallFunctionFvPatchScalarField(p, iF, dict), - roughnessHeight_(readScalar(dict.lookup("roughnessHeight"))), - roughnessConstant_(readScalar(dict.lookup("roughnessConstant"))), - roughnessFudgeFactor_(readScalar(dict.lookup("roughnessFudgeFactor"))) + nutURoughWallFunctionFvPatchScalarField(p, iF, dict) {} @@ -250,10 +82,7 @@ nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField const nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField& rwfpsf ) : - nutWallFunctionFvPatchScalarField(rwfpsf), - roughnessHeight_(rwfpsf.roughnessHeight_), - roughnessConstant_(rwfpsf.roughnessConstant_), - roughnessFudgeFactor_(rwfpsf.roughnessFudgeFactor_) + nutURoughWallFunctionFvPatchScalarField(rwfpsf) {} @@ -264,45 +93,10 @@ nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField const DimensionedField& iF ) : - nutWallFunctionFvPatchScalarField(rwfpsf, iF), - roughnessHeight_(rwfpsf.roughnessHeight_), - roughnessConstant_(rwfpsf.roughnessConstant_), - roughnessFudgeFactor_(rwfpsf.roughnessFudgeFactor_) + nutURoughWallFunctionFvPatchScalarField(rwfpsf, iF) {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -tmp -nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::yPlus() const -{ - const label patchI = patch().index(); - - const RASModel& rasModel = db().lookupObject("RASProperties"); - const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI]; - const scalarField magUp = mag(Uw.patchInternalField() - Uw); - - return calcYPlus(magUp); -} - - -void nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::write -( - Ostream& os -) const -{ - fvPatchField::write(os); - writeLocalEntries(os); - os.writeKeyword("roughnessHeight") - << roughnessHeight_ << token::END_STATEMENT << nl; - os.writeKeyword("roughnessConstant") - << roughnessConstant_ << token::END_STATEMENT << nl; - os.writeKeyword("roughnessFudgeFactor") - << roughnessFudgeFactor_ << token::END_STATEMENT << nl; - writeEntry("value", os); -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // makePatchTypeField diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutSpalartAllmarasStandardRoughWallFunction/nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.H b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutSpalartAllmarasStandardRoughWallFunction/nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.H index a683c20fc..f21bda06b 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutSpalartAllmarasStandardRoughWallFunction/nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.H +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutSpalartAllmarasStandardRoughWallFunction/nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.H @@ -26,7 +26,9 @@ Class nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField Description - Wall function boundary condition for rough walls + This boundary condition is the same as nutURoughWallFunction. We will simply + derive from nutURoughWallFunctionFvPatchScalarField to enable backward + compatibility. SourceFiles nutSpalartAllmarasStandardWallFunctionFvPatchScalarField.C @@ -36,7 +38,7 @@ SourceFiles #ifndef nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField_H #define nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField_H -#include "nutWallFunctionFvPatchScalarField.H" +#include "nutURoughWallFunctionFvPatchScalarField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -53,31 +55,8 @@ Class nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField Declaration class nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField : - public nutWallFunctionFvPatchScalarField + public nutURoughWallFunctionFvPatchScalarField { - // Private data - - // Roughness model parameters - - //- Height - scalar roughnessHeight_; - - //- Constant - scalar roughnessConstant_; - - //- Scale factor - scalar roughnessFudgeFactor_; - - - // Protected member functions - - //- Calculate yPLus - virtual tmp calcYPlus(const scalarField& magUp) const; - - //- Calculate the turbulence viscosity - virtual tmp calcNut() const; - - public: //- Runtime type information @@ -152,63 +131,6 @@ public: ) ); } - - - // Member functions - - // Access - - //- Return the roughness height - const scalar& roughnessHeight() const - { - return roughnessHeight_; - } - - //- Return reference to the roughness height to allow adjustment - scalar& roughnessHeight() - { - return roughnessHeight_; - } - - - //- Return the roughness constant scale - const scalar& roughnessConstant() const - { - return roughnessConstant_; - } - - //- Return reference to the roughness constant to allow adjustment - scalar& roughnessConstant() - { - return roughnessConstant_; - } - - //- Return the roughness scale factor - const scalar& roughnessFudgeFactor() const - { - return roughnessFudgeFactor_; - } - - //- Return reference to the roughness scale factor to allow - // adjustment - scalar& roughnessFudgeFactor() - { - return roughnessFudgeFactor_; - } - - - // I-O - - // Evaluation functions - - //- Calculate and return the yPlus at the boundary - virtual tmp yPlus() const; - - - // I-O - - //- Write - virtual void write(Ostream& os) const; };