ENH: yPlus FO updated follwing changes to functionObjectFile

Also
- added documentation to header
- added 'resultName' to enable user to specify alternative name for
  output field
This commit is contained in:
Andrew Heather 2015-10-06 12:19:20 +01:00
parent b3cea1beab
commit 4f4fc3fab5
3 changed files with 120 additions and 59 deletions

View File

@ -3,7 +3,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) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -38,16 +38,15 @@ namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::yPlus::writeFileHeader(const label i) void Foam::yPlus::writeFileHeader(Ostream& os) const
{ {
writeHeader(file(), "y+ ()"); writeHeader(os, "y+");
writeCommented(os, "Time");
writeCommented(file(), "Time"); writeTabbed(os, "patch");
writeTabbed(file(), "patch"); writeTabbed(os, "min");
writeTabbed(file(), "min"); writeTabbed(os, "max");
writeTabbed(file(), "max"); writeTabbed(os, "average");
writeTabbed(file(), "average"); os << endl;
file() << endl;
} }
@ -61,12 +60,13 @@ Foam::yPlus::yPlus
const bool loadFromFiles const bool loadFromFiles
) )
: :
functionObjectFile(obr, name, typeName), functionObjectFile(obr, name, typeName, dict),
name_(name), name_(name),
obr_(obr), obr_(obr),
active_(true), active_(true),
log_(true), phiName_("phi"),
phiName_("phi") resultName_(name),
log_(true)
{ {
// Check if the available mesh is an fvMesh, otherwise deactivate // Check if the available mesh is an fvMesh, otherwise deactivate
if (!isA<fvMesh>(obr_)) if (!isA<fvMesh>(obr_))
@ -87,6 +87,8 @@ Foam::yPlus::yPlus
if (active_) if (active_)
{ {
read(dict);
const fvMesh& mesh = refCast<const fvMesh>(obr_); const fvMesh& mesh = refCast<const fvMesh>(obr_);
volScalarField* yPlusPtr volScalarField* yPlusPtr
@ -95,7 +97,7 @@ Foam::yPlus::yPlus
( (
IOobject IOobject
( (
type(), resultName_,
mesh.time().timeName(), mesh.time().timeName(),
mesh, mesh,
IOobject::NO_READ, IOobject::NO_READ,
@ -107,6 +109,8 @@ Foam::yPlus::yPlus
); );
mesh.objectRegistry::store(yPlusPtr); mesh.objectRegistry::store(yPlusPtr);
writeFileHeader(file());
} }
} }
@ -123,51 +127,81 @@ void Foam::yPlus::read(const dictionary& dict)
{ {
if (active_) if (active_)
{ {
log_ = dict.lookupOrDefault<Switch>("log", true); functionObjectFile::read(dict);
phiName_ = dict.lookupOrDefault<word>("phiName", "phi");
log_.readIfPresent("log", dict);
dict.readIfPresent("resultName", resultName_);
dict.readIfPresent("phiName", phiName_);
} }
} }
void Foam::yPlus::execute() void Foam::yPlus::execute()
{ {
typedef compressible::turbulenceModel cmpModel; typedef compressible::turbulenceModel cmpTurbModel;
typedef incompressible::turbulenceModel icoModel; typedef incompressible::turbulenceModel icoTurbModel;
if (active_) if (active_)
{ {
functionObjectFile::write(); const surfaceScalarField& phi =
obr_.lookupObject<surfaceScalarField>(phiName_);
const fvMesh& mesh = refCast<const fvMesh>(obr_); const fvMesh& mesh = refCast<const fvMesh>(obr_);
volScalarField& yPlus = volScalarField& yPlus =
const_cast<volScalarField&> const_cast<volScalarField&>
( (
mesh.lookupObject<volScalarField>(type()) mesh.lookupObject<volScalarField>(resultName_)
); );
if (log_) Info<< type() << " " << name_ << " output:" << nl; if (log_) Info << type() << " " << name_ << " output:" << nl;
tmp<volSymmTensorField> Reff; if (phi.dimensions() == dimMass/dimTime)
if (mesh.foundObject<cmpModel>(turbulenceModel::propertiesName))
{ {
const cmpModel& model = if (mesh.foundObject<cmpTurbModel>(turbulenceModel::propertiesName))
mesh.lookupObject<cmpModel>(turbulenceModel::propertiesName); {
const cmpTurbModel& model =
mesh.lookupObject<cmpTurbModel>
(
turbulenceModel::propertiesName
);
calcYPlus(model, mesh, yPlus); calcYPlus(model, mesh, yPlus);
}
else
{
WarningIn("void Foam::yPlus::execute()")
<< "Unable to find compressible turbulence model in the "
<< "database: yPlus will not be calculated" << endl;
}
} }
else if (mesh.foundObject<icoModel>(turbulenceModel::propertiesName)) else if (phi.dimensions() == dimVolume/dimTime)
{ {
const icoModel& model = if (mesh.foundObject<icoTurbModel>(turbulenceModel::propertiesName))
mesh.lookupObject<icoModel>(turbulenceModel::propertiesName); {
const icoTurbModel& model =
mesh.lookupObject<icoTurbModel>
(
turbulenceModel::propertiesName
);
calcYPlus(model, mesh, yPlus); calcYPlus(model, mesh, yPlus);
}
else
{
WarningIn("void Foam::yPlus::execute()")
<< "Unable to find incompressible turbulence model in the "
<< "database: yPlus will not be calculated" << endl;
}
} }
else else
{ {
FatalErrorIn("void Foam::yPlus::write()") WarningIn("void Foam::yPlus::execute()")
<< "Unable to find turbulence model in the " << "Unknown " << phiName_ << " dimensions: "
<< "database" << exit(FatalError); << phi.dimensions() << nl
<< "Expected either " << dimMass/dimTime << " or "
<< dimVolume/dimTime << nl
<< "yPlus will not be calculated" << endl;
} }
} }
} }
@ -192,12 +226,16 @@ void Foam::yPlus::write()
{ {
if (active_) if (active_)
{ {
functionObjectFile::write();
const volScalarField& yPlus = const volScalarField& yPlus =
obr_.lookupObject<volScalarField>(type()); obr_.lookupObject<volScalarField>(resultName_);
if (log_) Info<< " writing field " << yPlus.name() << nl << endl; if (log_)
{
Info
<< type() << " " << name_ << " output:" << nl
<< " writing field " << yPlus.name() << nl
<< endl;
}
yPlus.write(); yPlus.write();
} }

View File

@ -3,7 +3,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) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,8 +28,29 @@ Group
grpUtilitiesFunctionObjects grpUtilitiesFunctionObjects
Description Description
Evaluates and outputs turbulence y+ for models. Values written to This function object evaluates and outputs turbulence y+ for turbulence
time directories as field 'yPlus' models. The field is stored on the mesh database so that it can be
retrieved and used for other applications.
Example of function object specification to calculate the y+ (LES):
\verbatim
yPlus1
{
type yPlus;
functionObjectLibs ("libutilityFunctionObjects.so");
...
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | Type name: yPlus | yes |
phiName | Name of flux field | no | phi
resultName | Name of y+ field | no | <function name>
log | Log to standard output | no | yes
\endtable
SourceFiles SourceFiles
yPlus.C yPlus.C
@ -44,6 +65,7 @@ SourceFiles
#include "volFieldsFwd.H" #include "volFieldsFwd.H"
#include "Switch.H" #include "Switch.H"
#include "OFstream.H" #include "OFstream.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,7 +80,7 @@ class mapPolyMesh;
class fvMesh; class fvMesh;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class yPlus Declaration Class yPlus Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class yPlus class yPlus
@ -75,17 +97,20 @@ class yPlus
//- on/off switch //- on/off switch
bool active_; bool active_;
//- Switch to send output to Info as well as to file
Switch log_;
//- Name of mass/volume flux field (optional, default = phi) //- Name of mass/volume flux field (optional, default = phi)
word phiName_; word phiName_;
//- Result name
word resultName_;
//- Switch to send output to Info as well as to file
Switch log_;
// Private Member Functions // Private Member Functions
//- File header information //- File header information
virtual void writeFileHeader(const label i); virtual void writeFileHeader(Ostream& os) const;
//- Calculate y+ //- Calculate y+
template<class TurbulenceModel> template<class TurbulenceModel>

View File

@ -2,8 +2,8 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -23,10 +23,9 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "yPlus.H" #include "wallFvPatch.H"
#include "nutWallFunctionFvPatchScalarField.H" #include "nutWallFunctionFvPatchScalarField.H"
#include "nearWallDist.H" #include "nearWallDist.H"
#include "wallFvPatch.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -70,20 +69,19 @@ void Foam::yPlus::calcYPlus
const scalar maxYplus = gMax(yPlusp); const scalar maxYplus = gMax(yPlusp);
const scalar avgYplus = gAverage(yPlusp); const scalar avgYplus = gAverage(yPlusp);
if (Pstream::master()) if (log_)
{ {
if (log_) Info Info<< " patch " << patch.name()
<< " patch " << patch.name()
<< " y+ : min = " << minYplus << ", max = " << maxYplus << " y+ : min = " << minYplus << ", max = " << maxYplus
<< ", average = " << avgYplus << nl; << ", average = " << avgYplus << nl;
file() << obr_.time().value()
<< token::TAB << patch.name()
<< token::TAB << minYplus
<< token::TAB << maxYplus
<< token::TAB << avgYplus
<< endl;
} }
file() << obr_.time().value()
<< token::TAB << patch.name()
<< token::TAB << minYplus
<< token::TAB << maxYplus
<< token::TAB << avgYplus
<< endl;
} }
else if (isA<wallFvPatch>(patch)) else if (isA<wallFvPatch>(patch))
{ {