From eee9507e550b600c370d5827dc562be242660826 Mon Sep 17 00:00:00 2001 From: Vuko Vukcevic Date: Mon, 12 Jun 2017 14:50:25 +0200 Subject: [PATCH] Reorganisation of improved wall functions Instead of calculating pressure gradient and convection terms in each wall function (for each patch), function objects pressureGradient and velocityConvection will update them and register them in the database and we only fetch the data when updating wall functions. --- .../incompressible/RAS/Make/files | 3 + .../pressureGradientFunctionObject.C | 150 ++++++++++++++++ .../pressureGradientFunctionObject.H | 131 ++++++++++++++ .../velocityConvectionFunctionObject.C | 170 ++++++++++++++++++ .../velocityConvectionFunctionObject.H | 135 ++++++++++++++ .../nutCWTWallFunctionFvPatchScalarField.C | 92 ++++++---- .../nutMEWTWallFunctionFvPatchScalarField.C | 89 +++++---- .../omegaCWTWallFunctionFvPatchScalarField.C | 84 ++++++--- .../omegaMEWTWallFunctionFvPatchScalarField.C | 82 ++++++--- 9 files changed, 816 insertions(+), 120 deletions(-) create mode 100644 src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/pressureGradient/pressureGradientFunctionObject.C create mode 100644 src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/pressureGradient/pressureGradientFunctionObject.H create mode 100644 src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/velocityConvection/velocityConvectionFunctionObject.C create mode 100644 src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/velocityConvection/velocityConvectionFunctionObject.H diff --git a/src/turbulenceModels/incompressible/RAS/Make/files b/src/turbulenceModels/incompressible/RAS/Make/files index 1f56b67bc..81bc14284 100644 --- a/src/turbulenceModels/incompressible/RAS/Make/files +++ b/src/turbulenceModels/incompressible/RAS/Make/files @@ -51,6 +51,9 @@ $(kqRWallFunctions)/kNonEqWallFunction/kNonEqWallFunctionFvPatchScalarField.C RWallFunctions = $(wallFunctions)/RWallFunctions $(RWallFunctions)/RWallFunction/RWallFunctionFvPatchSymmTensorField.C +wallFunctionFunctionObjects = $(wallFunctions)/functionObjects +$(wallFunctionFunctionObjects)/pressureGradient/pressureGradientFunctionObject.C +$(wallFunctionFunctionObjects)/velocityConvection/velocityConvectionFunctionObject.C /* Patch fields */ derivedFvPatchFields/turbulentHeatFluxTemperature/turbulentHeatFluxTemperatureFvPatchScalarField.C diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/pressureGradient/pressureGradientFunctionObject.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/pressureGradient/pressureGradientFunctionObject.C new file mode 100644 index 000000000..82e76f349 --- /dev/null +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/pressureGradient/pressureGradientFunctionObject.C @@ -0,0 +1,150 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Author + Vuko Vukcevic, Wikki Ltd. All rights reserved + +\*---------------------------------------------------------------------------*/ + +#include "pressureGradientFunctionObject.H" +#include "addToRunTimeSelectionTable.H" +#include "fvcGrad.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(pressureGradientFunctionObject, 0); + + addToRunTimeSelectionTable + ( + functionObject, + pressureGradientFunctionObject, + dictionary + ); +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pressureGradientFunctionObject::pressureGradientFunctionObject +( + const word& name, + const Time& t, + const dictionary& dict +) +: + functionObject(name), + name_(name), + time_(t), + regionName_(dict.lookupOrDefault("region", polyMesh::defaultRegion)), + pName_(dict.lookup("pName")), + gradp_ + ( + IOobject + ( + "pressureGradient", + time_.timeName(), + time_.lookupObject(regionName_), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + time_.lookupObject(regionName_), + // Note: dimensions reset in the constructor body + dimensionedVector("zero", dimless, vector::zero) + ) +{ + Info<< "Creating pressureGradientFunctionObject for " + << pName_ << " field." << endl; + + // Reset dimensions + const fvMesh& mesh = time_.lookupObject(regionName_); + + if (mesh.foundObject(pName_)) + { + // Found pressure, reset dimensions for pressure gradient + const volScalarField& p = + mesh.lookupObject(pName_); + + gradp_.dimensions().reset(p.dimensions()/dimLength); + } + else + { + WarningIn + ( + "pressureGradientFunctionObject::" + "pressureGradientFunctionObject" + "\n(" + "\n const word& name," + "\n const Time& t," + "\n const dictionary& dict" + "\n)" + ) << "Could not find " << pName_ << " field." + << " Possible dimensions mismatch." + << endl; + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::pressureGradientFunctionObject::start() +{ + return true; +} + + +bool Foam::pressureGradientFunctionObject::execute() +{ + const fvMesh& mesh = + time_.lookupObject(regionName_); + + if (mesh.foundObject(pName_)) + { + const volScalarField& p = + mesh.lookupObject(pName_); + + gradp_ = fvc::grad(p); + + return true; + } + else + { + InfoIn("bool pressureGradientFunctionObject::execute()") + << "Field " << pName_ << " not found. Returning." + << endl; + + return false; + } +} + + +bool Foam::pressureGradientFunctionObject::read(const dictionary& dict) +{ + pName_ = word(dict.lookup("pName")); + + return false; +} + + +// ************************************************************************* // diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/pressureGradient/pressureGradientFunctionObject.H b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/pressureGradient/pressureGradientFunctionObject.H new file mode 100644 index 000000000..d47931b90 --- /dev/null +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/pressureGradient/pressureGradientFunctionObject.H @@ -0,0 +1,131 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + pressureGradientFunctionObject + +Description + FunctionObject that calculates the pressure gradient given a name for the + pressure field and registers it into the database. Useful for pressure + sensitised wall functions (see omega/nutCWT/MEWT wall functions). + +Author + Vuko Vukcevic, Wikki Ltd. All rights reserved + +SourceFiles + pressureGradientFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef pressureGradientFunctionObject_H +#define pressureGradientFunctionObject_H + +#include "functionObject.H" +#include "dictionary.H" +#include "fvMesh.H" +#include "volFields.H" +#include "OFstream.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class pressureGradientFunctionObject Declaration +\*---------------------------------------------------------------------------*/ + +class pressureGradientFunctionObject +: + public functionObject +{ + // Private data + + //- Name + const word name_; + + //- Reference to main object registry + const Time& time_; + + //- Region name + word regionName_; + + //- Name of the pressure field + word pName_; + + //- Pressure gradient field + volVectorField gradp_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + pressureGradientFunctionObject + ( + const pressureGradientFunctionObject& + ); + + //- Disallow default bitwise assignment + void operator=(const pressureGradientFunctionObject&); + + +public: + + //- Runtime type information + TypeName("pressureGradient"); + + + // Constructors + + //- Construct from components + pressureGradientFunctionObject + ( + const word& name, + const Time&, + const dictionary& + ); + + + // Member Functions + + //- start is called at the start of the time-loop + virtual bool start(); + + //- execute is called at each ++ or += of the time-loop + virtual bool execute(); + + //- Read and set the function object if its data has changed + virtual bool read(const dictionary& dict); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/velocityConvection/velocityConvectionFunctionObject.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/velocityConvection/velocityConvectionFunctionObject.C new file mode 100644 index 000000000..62710d88e --- /dev/null +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/velocityConvection/velocityConvectionFunctionObject.C @@ -0,0 +1,170 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Author + Vuko Vukcevic, Wikki Ltd. All rights reserved + +\*---------------------------------------------------------------------------*/ + +#include "velocityConvectionFunctionObject.H" +#include "addToRunTimeSelectionTable.H" +#include "fvcDiv.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(velocityConvectionFunctionObject, 0); + + addToRunTimeSelectionTable + ( + functionObject, + velocityConvectionFunctionObject, + dictionary + ); +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::velocityConvectionFunctionObject::velocityConvectionFunctionObject +( + const word& name, + const Time& t, + const dictionary& dict +) +: + functionObject(name), + name_(name), + time_(t), + regionName_(dict.lookupOrDefault("region", polyMesh::defaultRegion)), + UName_(dict.lookup("UName")), + phiName_(dict.lookup("phiName")), + convection_ + ( + IOobject + ( + "velocityConvection", + time_.timeName(), + time_.lookupObject(regionName_), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + time_.lookupObject(regionName_), + // Note: dimensions will be overwritten on start + dimensionedVector("zero", dimless, vector::zero) + ) +{ + Info<< "Creating velocityConvectionFunctionObject for " + << UName_ << " and " << phiName_ << " field." << endl; + + // Reset dimensions + const fvMesh& mesh = time_.lookupObject(regionName_); + + if + ( + mesh.foundObject(UName_) + && mesh.foundObject(phiName_) + ) + { + // Found velocity and flux, reset dimensions for convection + const volVectorField& U = + mesh.lookupObject(UName_); + + const surfaceScalarField& phi = + mesh.lookupObject(phiName_); + + convection_.dimensions().reset + ( + phi.dimensions()*U.dimensions()/dimArea/dimLength + ); + } + else + { + WarningIn + ( + "velocityConvectionFunctionObject::" + "velocityConvectionFunctionObject" + "\n(" + "\n const word& name," + "\n const Time& t," + "\n const dictionary& dict" + "\n)" + ) << "Could not find " << UName_ << " and " << phiName_ + << " fields. Possible dimensions mismatch." + << endl; + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::velocityConvectionFunctionObject::start() +{ + return true; +} + + +bool Foam::velocityConvectionFunctionObject::execute() +{ + const fvMesh& mesh = time_.lookupObject(regionName_); + + if + ( + mesh.foundObject(UName_) + && mesh.foundObject(phiName_) + ) + { + // Found velocity and flux, reset dimensions for convection + const volVectorField& U = + mesh.lookupObject(UName_); + + const surfaceScalarField& phi = + mesh.lookupObject(phiName_); + + convection_ = fvc::div(phi, U); + + return true; + } + else + { + InfoIn("bool velocityConvectionFunctionObject::execute()") + << "Field " << UName_ << " or " << phiName_ << " not found." + << " Returning." + << endl; + + return false; + } +} + + +bool Foam::velocityConvectionFunctionObject::read(const dictionary& dict) +{ + UName_ = word(dict.lookup("UName")); + phiName_ = word(dict.lookup("phiName")); + + return false; +} + + +// ************************************************************************* // diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/velocityConvection/velocityConvectionFunctionObject.H b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/velocityConvection/velocityConvectionFunctionObject.H new file mode 100644 index 000000000..191d89d0b --- /dev/null +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/functionObjects/velocityConvection/velocityConvectionFunctionObject.H @@ -0,0 +1,135 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + velocityConvectionFunctionObject + +Description + FunctionObject that calculates the velocity convection given names for the + velocity field and the flux field and registers it into the database. Useful + for convection sensitised wall functions (see omega/nutCWT/MEWT wall + functions). + +Author + Vuko Vukcevic, Wikki Ltd. All rights reserved + +SourceFiles + velocityConvectionFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef velocityConvectionFunctionObject_H +#define velocityConvectionFunctionObject_H + +#include "functionObject.H" +#include "dictionary.H" +#include "fvMesh.H" +#include "volFields.H" +#include "OFstream.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class velocityConvectionFunctionObject Declaration +\*---------------------------------------------------------------------------*/ + +class velocityConvectionFunctionObject +: + public functionObject +{ + // Private data + + //- Name + const word name_; + + //- Reference to main object registry + const Time& time_; + + //- Region name + word regionName_; + + //- Name of the velocity field + word UName_; + + //- Name of the flux field + word phiName_; + + //- Convection field + volVectorField convection_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + velocityConvectionFunctionObject + ( + const velocityConvectionFunctionObject& + ); + + //- Disallow default bitwise assignment + void operator=(const velocityConvectionFunctionObject&); + + +public: + + //- Runtime type information + TypeName("velocityConvection"); + + + // Constructors + + //- Construct from components + velocityConvectionFunctionObject + ( + const word& name, + const Time&, + const dictionary& + ); + + + // Member Functions + + //- start is called at the start of the time-loop + virtual bool start(); + + //- execute is called at each ++ or += of the time-loop + virtual bool execute(); + + //- Read and set the function object if its data has changed + virtual bool read(const dictionary& dict); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutCWTWallFunction/nutCWTWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutCWTWallFunction/nutCWTWallFunctionFvPatchScalarField.C index c6f33360d..71ed3a929 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutCWTWallFunction/nutCWTWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutCWTWallFunction/nutCWTWallFunctionFvPatchScalarField.C @@ -98,53 +98,79 @@ tmp nutCWTWallFunctionFvPatchScalarField::calcNut() const const scalarField magUwInTang = mag(UwInTang); // Calculate tangential direction for patch cells - const vectorField tDir = UwInTang/magUwInTang; + const vectorField tDir = UwInTang/(magUwInTang + SMALL); // Wall-velocity vector field tangential to the wall const vectorField UwTang = Uw - (Uw & n)*n; const scalarField magUwTang = mag(UwTang); - // Pressure terms - const volScalarField& p = - this->dimensionedInternalField().mesh().lookupObject - < - volScalarField - >(pName_); + // Pressure effects. Lookup the pressure gradient field from the registry + // (created with pressureGradient function object) - // Pressure gradient - const volVectorField gradp = fvc::grad(p); + // Pressure gradient projected on the wall parallel velocity direction + scalarField gradpTang(magGradUw.size(), 0.0); - // Pressure gradient in wall adjacent cell - const vectorField gradPIn = - gradp.boundaryField()[this->patch().index()].patchInternalField(); - - // Pressure gradient projected on the wall parallel velocity - const scalarField gradpTang= gradPIn & tDir; - - - // Convective terms - const volVectorField& U = - this->dimensionedInternalField().mesh().lookupObject + if + ( + this->dimensionedInternalField().mesh().foundObject < volVectorField - >(UName_); + >("pressureGradient") + ) + { + const volVectorField& gradP = + this->dimensionedInternalField().mesh().lookupObject + ("pressureGradient"); - const surfaceScalarField& phi = - this->dimensionedInternalField().mesh().lookupObject + // Update pressure gradient projected on the wall parallel velocity + gradpTang = + gradP.boundaryField()[this->patch().index()].patchInternalField() + & tDir; + } + else + { + Info<< "Field pressureGradient not found. Neglecting pressure gradient " + << "effects for wall functions at patch: " << patch().name() + << endl; + } + + + // Convective terms. Lookup the convection field from the registry (created + // with velocityConvection function object) + + // Velocity convection projected on the wall parallel velocity direction + scalarField convectionTang(magGradUw.size(), 0.0); + + if + ( + this->dimensionedInternalField().mesh().foundObject < - surfaceScalarField - >("phi"); + volVectorField + >("velocityConvection") + ) + { + const volVectorField& convection = + this->dimensionedInternalField().mesh().lookupObject + ("velocityConvection"); - const volVectorField convection = fvc::div(phi, U); + // Upate convection term projected on the wall parallel velocity + convectionTang = + convection.boundaryField() + [ + this->patch().index() + ].patchInternalField() + & tDir; + } + else + { + Info<< "Field velocityConvection not found. Neglecting convection " + << "effects for wall functions at patch: " << patch().name() + << endl; + } - const vectorField convectionIn = - convection.boundaryField()[this->patch().index()].patchInternalField(); - // Convection term projected on the wall parallel velocity - const scalarField convectionTang = convectionIn & tDir; - - tmp tnutw(new scalarField(patch().size())); + tmp tnutw(new scalarField(patch().size(), SMALL)); scalarField& nutw = tnutw(); // Get face cells @@ -171,7 +197,7 @@ tmp nutCWTWallFunctionFvPatchScalarField::calcNut() const const scalar gamma = -0.01*pow(yPlus, 4)/(1.0 + 5.0*yPlus); const scalar tauw = tauwVis*exp(gamma) + tauwLog*exp(1.0/gamma); - nutw[faceI] = tauw/magGradUw[faceI] - nuw[faceI]; + nutw[faceI] = tauw/(magGradUw[faceI] + SMALL) - nuw[faceI]; } return tnutw; diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutMEWTWallFunction/nutMEWTWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutMEWTWallFunction/nutMEWTWallFunctionFvPatchScalarField.C index 5fe8aa937..58bddeb9e 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutMEWTWallFunction/nutMEWTWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutMEWTWallFunction/nutMEWTWallFunctionFvPatchScalarField.C @@ -109,51 +109,76 @@ tmp nutMEWTWallFunctionFvPatchScalarField::calcNut() const const scalarField magUwInTang = mag(UwInTang); // Calculate tangential direction for patch cells - const vectorField tDir = UwInTang/magUwInTang; + const vectorField tDir = UwInTang/(magUwInTang + SMALL); // Wall-velocity vector field tangential to the wall const vectorField UwTang = Uw - (Uw & n)*n; const scalarField magUwTang = mag(UwTang); - // Pressure terms - const volScalarField& p = - this->dimensionedInternalField().mesh().lookupObject - < - volScalarField - >(pName_); + // Pressure effects. Lookup the pressure gradient field from the registry + // (created with pressureGradient function object) - // Pressure gradient - const volVectorField gradp = fvc::grad(p); + // Pressure gradient projected on the wall parallel velocity direction + scalarField gradpTang(magGradUw.size(), 0.0); - // Pressure gradient in wall adjacent cell - const vectorField gradPIn = - gradp.boundaryField()[this->patch().index()].patchInternalField(); - - // Pressure gradient projected on the wall parallel velocity - const scalarField gradpTang= gradPIn & tDir; - - - // Convective terms - const volVectorField& U = - this->dimensionedInternalField().mesh().lookupObject + if + ( + this->dimensionedInternalField().mesh().foundObject < volVectorField - >(UName_); + >("pressureGradient") + ) + { + const volVectorField& gradP = + this->dimensionedInternalField().mesh().lookupObject + ("pressureGradient"); - const surfaceScalarField& phi = - this->dimensionedInternalField().mesh().lookupObject + // Update pressure gradient projected on the wall parallel velocity + gradpTang = + gradP.boundaryField()[this->patch().index()].patchInternalField() + & tDir; + } + else + { + Info<< "Field pressureGradient not found. Neglecting pressure gradient " + << "effects for wall functions at patch: " << patch().name() + << endl; + } + + + // Convective terms. Lookup the convection field from the registry (created + // with velocityConvection function object) + + // Velocity convection projected on the wall parallel velocity direction + scalarField convectionTang(magGradUw.size(), 0.0); + + if + ( + this->dimensionedInternalField().mesh().foundObject < - surfaceScalarField - >("phi"); + volVectorField + >("velocityConvection") + ) + { + const volVectorField& convection = + this->dimensionedInternalField().mesh().lookupObject + ("velocityConvection"); - const volVectorField convection = fvc::div(phi, U); - - const vectorField convectionIn = - convection.boundaryField()[this->patch().index()].patchInternalField(); - - // Convection term projected on the wall parallel velocity - const scalarField convectionTang = convectionIn & tDir; + // Upate convection term projected on the wall parallel velocity + convectionTang = + convection.boundaryField() + [ + this->patch().index() + ].patchInternalField() + & tDir; + } + else + { + Info<< "Field velocityConvection not found. Neglecting convection " + << "effects for wall functions at patch: " << patch().name() + << endl; + } // Needed to calculate yPlus const scalarField& eddyVis = diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaCWTWallFunction/omegaCWTWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaCWTWallFunction/omegaCWTWallFunctionFvPatchScalarField.C index d48f8a34d..f641cc3f0 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaCWTWallFunction/omegaCWTWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaCWTWallFunction/omegaCWTWallFunctionFvPatchScalarField.C @@ -227,48 +227,76 @@ void omegaCWTWallFunctionFvPatchScalarField::updateCoeffs() const scalarField magUwInTang = mag(UwInTang); // Calculate tangential direction for patch cells - const vectorField tDir = UwInTang/magUwInTang; + const vectorField tDir = UwInTang/(magUwInTang + SMALL); // Magnitude of the surface normal gradient velocity const scalarField magGradUw = mag(Uw.snGrad()); - // Pressure effects - const volScalarField& p = - this->dimensionedInternalField().mesh().lookupObject - (pName_); - - // Pressure gradient - const volVectorField gradp = fvc::grad(p); - - // Pressure gradient in wall adjacent cell - const vectorField gradPIn = - gradp.boundaryField()[this->patch().index()].patchInternalField(); + // Pressure effects. Lookup the pressure gradient field from the registry + // (created with pressureGradient function object) // Pressure gradient projected on the wall parallel velocity direction - const scalarField gradpTang= gradPIn & tDir; + scalarField gradpTang(magGradUw.size(), 0.0); - - // Convective terms - const volVectorField& U = - this->dimensionedInternalField().mesh().lookupObject + if + ( + this->dimensionedInternalField().mesh().foundObject < volVectorField - >(UName_); + >("pressureGradient") + ) + { + const volVectorField& gradP = + this->dimensionedInternalField().mesh().lookupObject + ("pressureGradient"); - const surfaceScalarField& phi = - this->dimensionedInternalField().mesh().lookupObject + // Update pressure gradient projected on the wall parallel velocity + gradpTang = + gradP.boundaryField()[this->patch().index()].patchInternalField() + & tDir; + } + else + { + Info<< "Field pressureGradient not found. Neglecting pressure gradient " + << "effects for wall functions at patch: " << patch().name() + << endl; + } + + + // Convective terms. Lookup the convection field from the registry (created + // with velocityConvection function object) + + // Velocity convection projected on the wall parallel velocity direction + scalarField convectionTang(magGradUw.size(), 0.0); + + if + ( + this->dimensionedInternalField().mesh().foundObject < - surfaceScalarField - >("phi"); + volVectorField + >("velocityConvection") + ) + { + const volVectorField& convection = + this->dimensionedInternalField().mesh().lookupObject + ("velocityConvection"); - const volVectorField convection = fvc::div(phi, U); + // Upate convection term projected on the wall parallel velocity + convectionTang = + convection.boundaryField() + [ + this->patch().index() + ].patchInternalField() + & tDir; + } + else + { + Info<< "Field velocityConvection not found. Neglecting convection " + << "effects for wall functions at patch: " << patch().name() + << endl; + } - const vectorField convectionIn = - convection.boundaryField()[this->patch().index()].patchInternalField(); - - // Convection term projected on the wall parallel velocity - const scalarField convectionTang = convectionIn & tDir; // Get face cells const unallocLabelList& fc = patch().faceCells(); diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaMEWTWallFunction/omegaMEWTWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaMEWTWallFunction/omegaMEWTWallFunctionFvPatchScalarField.C index 932a5a079..0efc45507 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaMEWTWallFunction/omegaMEWTWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaMEWTWallFunction/omegaMEWTWallFunctionFvPatchScalarField.C @@ -229,42 +229,70 @@ void omegaMEWTWallFunctionFvPatchScalarField::updateCoeffs() const scalarField magGradUw = mag(Uw.snGrad()); - // Pressure effects - const volScalarField& p = - this->dimensionedInternalField().mesh().lookupObject - (pName_); - - // Pressure gradient - const volVectorField gradp = fvc::grad(p); - - // Pressure gradient in wall adjacent cell - const vectorField gradPIn = - gradp.boundaryField()[this->patch().index()].patchInternalField(); + // Pressure effects. Lookup the pressure gradient field from the registry + // (created with pressureGradient function object) // Pressure gradient projected on the wall parallel velocity direction - const scalarField gradpTang= gradPIn & tDir; + scalarField gradpTang(magGradUw.size(), 0.0); - - // Convective terms - const volVectorField& U = - this->dimensionedInternalField().mesh().lookupObject + if + ( + this->dimensionedInternalField().mesh().foundObject < volVectorField - >(UName_); + >("pressureGradient") + ) + { + const volVectorField& gradP = + this->dimensionedInternalField().mesh().lookupObject + ("pressureGradient"); - const surfaceScalarField& phi = - this->dimensionedInternalField().mesh().lookupObject + // Update pressure gradient projected on the wall parallel velocity + gradpTang = + gradP.boundaryField()[this->patch().index()].patchInternalField() + & tDir; + } + else + { + Info<< "Field pressureGradient not found. Neglecting pressure gradient " + << "effects for wall functions at patch: " << patch().name() + << endl; + } + + + // Convective terms. Lookup the convection field from the registry (created + // with velocityConvection function object) + + // Velocity convection projected on the wall parallel velocity direction + scalarField convectionTang(magGradUw.size(), 0.0); + + if + ( + this->dimensionedInternalField().mesh().foundObject < - surfaceScalarField - >("phi"); + volVectorField + >("velocityConvection") + ) + { + const volVectorField& convection = + this->dimensionedInternalField().mesh().lookupObject + ("velocityConvection"); - const volVectorField convection = fvc::div(phi, U); + // Upate convection term projected on the wall parallel velocity + convectionTang = + convection.boundaryField() + [ + this->patch().index() + ].patchInternalField() + & tDir; + } + else + { + Info<< "Field velocityConvection not found. Neglecting convection " + << "effects for wall functions at patch: " << patch().name() + << endl; + } - const vectorField convectionIn = - convection.boundaryField()[this->patch().index()].patchInternalField(); - - // Convection term projected on the wall parallel velocity - const scalarField convectionTang = convectionIn & tDir; // Get face cells const unallocLabelList& fc = patch().faceCells();