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

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,8 +28,29 @@ Group
grpUtilitiesFunctionObjects
Description
Evaluates and outputs turbulence y+ for models. Values written to
time directories as field 'yPlus'
This function object evaluates and outputs turbulence y+ for turbulence
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
yPlus.C
@ -44,6 +65,7 @@ SourceFiles
#include "volFieldsFwd.H"
#include "Switch.H"
#include "OFstream.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,7 +80,7 @@ class mapPolyMesh;
class fvMesh;
/*---------------------------------------------------------------------------*\
Class yPlus Declaration
Class yPlus Declaration
\*---------------------------------------------------------------------------*/
class yPlus
@ -75,17 +97,20 @@ class yPlus
//- on/off switch
bool active_;
//- Switch to send output to Info as well as to file
Switch log_;
//- Name of mass/volume flux field (optional, default = phi)
word phiName_;
//- Result name
word resultName_;
//- Switch to send output to Info as well as to file
Switch log_;
// Private Member Functions
//- File header information
virtual void writeFileHeader(const label i);
virtual void writeFileHeader(Ostream& os) const;
//- Calculate y+
template<class TurbulenceModel>

View File

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