From 4f4fc3fab5d2bbf7a91e8cf810c414e98a17c4f0 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 6 Oct 2015 12:19:20 +0100 Subject: [PATCH] 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 --- .../functionObjects/utilities/yPlus/yPlus.C | 112 ++++++++++++------ .../functionObjects/utilities/yPlus/yPlus.H | 41 +++++-- .../utilities/yPlus/yPlusTemplates.C | 26 ++-- 3 files changed, 120 insertions(+), 59 deletions(-) diff --git a/src/postProcessing/functionObjects/utilities/yPlus/yPlus.C b/src/postProcessing/functionObjects/utilities/yPlus/yPlus.C index 119a0f895d..01630313c8 100644 --- a/src/postProcessing/functionObjects/utilities/yPlus/yPlus.C +++ b/src/postProcessing/functionObjects/utilities/yPlus/yPlus.C @@ -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(obr_)) @@ -87,6 +87,8 @@ Foam::yPlus::yPlus if (active_) { + read(dict); + const fvMesh& mesh = refCast(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("log", true); - phiName_ = dict.lookupOrDefault("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(phiName_); const fvMesh& mesh = refCast(obr_); volScalarField& yPlus = const_cast ( - mesh.lookupObject(type()) + mesh.lookupObject(resultName_) ); - if (log_) Info<< type() << " " << name_ << " output:" << nl; + if (log_) Info << type() << " " << name_ << " output:" << nl; - tmp Reff; - if (mesh.foundObject(turbulenceModel::propertiesName)) + if (phi.dimensions() == dimMass/dimTime) { - const cmpModel& model = - mesh.lookupObject(turbulenceModel::propertiesName); + if (mesh.foundObject(turbulenceModel::propertiesName)) + { + const cmpTurbModel& model = + mesh.lookupObject + ( + 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(turbulenceModel::propertiesName)) + else if (phi.dimensions() == dimVolume/dimTime) { - const icoModel& model = - mesh.lookupObject(turbulenceModel::propertiesName); + if (mesh.foundObject(turbulenceModel::propertiesName)) + { + const icoTurbModel& model = + mesh.lookupObject + ( + 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(type()); + obr_.lookupObject(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(); } diff --git a/src/postProcessing/functionObjects/utilities/yPlus/yPlus.H b/src/postProcessing/functionObjects/utilities/yPlus/yPlus.H index a2a27bf022..80ce1abb8d 100644 --- a/src/postProcessing/functionObjects/utilities/yPlus/yPlus.H +++ b/src/postProcessing/functionObjects/utilities/yPlus/yPlus.H @@ -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 | + 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 diff --git a/src/postProcessing/functionObjects/utilities/yPlus/yPlusTemplates.C b/src/postProcessing/functionObjects/utilities/yPlus/yPlusTemplates.C index 818610cfe5..0e7a625879 100644 --- a/src/postProcessing/functionObjects/utilities/yPlus/yPlusTemplates.C +++ b/src/postProcessing/functionObjects/utilities/yPlus/yPlusTemplates.C @@ -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(patch)) {