ENH: yPlus: support disable of field writing (#2813)

- for simulations where the yPlus is needed for other purposes or
  just for obtaining information on the patches it can be useful
  to disable field writing and save disk space.

  The 'writeFields' flag (as per some other function objects)
  has been added control writing the yPlus volume field.

  If unspecified, the default value is 'true' so that the yPlus
  function object continues to work as before.
  However, this default may change to 'false' in the future to align
  with other function objects.

ENH: wallShearStress: support disable of field writing

- similar to yPlus, the write() method combines writing information
  and writing the fields. The 'writeFields' flag allows some
  separation of that logic.
This commit is contained in:
Mark Olesen 2023-06-23 13:05:27 +02:00
parent 7edacd3ab0
commit 2afd2320ce
22 changed files with 119 additions and 66 deletions

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Version: v2212
\\ / O peration | Version: v2306
\\ / A nd | Website: www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
@ -14,6 +14,7 @@ Description
type wallShearStress;
libs (fieldFunctionObjects);
writeFields yes;
executeControl writeTime;
writeControl writeTime;

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Version: v2212
\\ / O peration | Version: v2306
\\ / A nd | Website: www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
@ -13,6 +13,7 @@ Description
type yPlus;
libs (fieldFunctionObjects);
writeFields yes;
executeControl writeTime;
writeControl writeTime;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -90,7 +90,7 @@ Foam::functionObjects::wallShearStress::wallShearStress
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(mesh_, name, typeName, dict),
patchSet_()
writeFields_(true) // May change in the future
{
read(dict);
@ -125,6 +125,9 @@ bool Foam::functionObjects::wallShearStress::read(const dictionary& dict)
fvMeshFunctionObject::read(dict);
writeFile::read(dict);
writeFields_ = true; // May change in the future
dict.readIfPresent("writeFields", writeFields_);
const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
patchSet_ =
@ -221,10 +224,13 @@ bool Foam::functionObjects::wallShearStress::write()
const auto& wallShearStress =
obr_.lookupObject<volVectorField>(scopedName(typeName));
Log << type() << " " << name() << " write:" << nl
<< " writing field " << wallShearStress.name() << endl;
Log << type() << ' ' << name() << " write:" << nl;
wallShearStress.write();
if (writeFields_)
{
Log << " writing field " << wallShearStress.name() << endl;
wallShearStress.write();
}
const fvPatchList& patches = mesh_.boundary();
@ -234,10 +240,10 @@ bool Foam::functionObjects::wallShearStress::write()
const vectorField& ssp = wallShearStress.boundaryField()[patchi];
vector minSsp = gMin(ssp);
vector maxSsp = gMax(ssp);
const vector minSsp = gMin(ssp);
const vector maxSsp = gMax(ssp);
if (Pstream::master())
if (UPstream::master())
{
writeCurrentTime(file());

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -65,8 +65,8 @@ Usage
// Optional entries (runtime modifiable)
patches (<patch1> ... <patchN>); // (wall1 "(wall2|wall3)");
// Optional (inherited) entries
...
// Optional entries
writeFields true;
}
\endverbatim
@ -76,6 +76,7 @@ Usage
type | Type name: wallShearStress | word | yes | -
libs | Library name: fieldFunctionObjects | word | yes | -
patches | Names of operand patches | wordList | no | all wall patches
writeFields | Flag to write shear stress field | bool | no | true
\endtable
The inherited entries are elaborated in:
@ -87,6 +88,12 @@ Usage
<solver> -postProcess -func wallShearStress
\endverbatim
Note
The \c writeFields flag currently defaults to \c true
(for consistency with previous versions that did not have that flag)
but this is subject to change in the near future for consistency
with other function objects.
See also
- Foam::functionObject
- Foam::functionObjects::fvMeshFunctionObject
@ -98,8 +105,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_wallShearStress_H
#define functionObjects_wallShearStress_H
#ifndef Foam_functionObjects_wallShearStress_H
#define Foam_functionObjects_wallShearStress_H
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
@ -122,6 +129,12 @@ class wallShearStress
public fvMeshFunctionObject,
public writeFile
{
// Private Data
//- Write the shear stress field ?
bool writeFields_;
protected:
// Protected Data
@ -178,7 +191,8 @@ public:
//- Calculate the wall shear-stress
virtual bool execute();
//- Write the wall shear-stress
//- Report min/max and log to file,
//- write the wall shear-stress volume field.
virtual bool write();
};

View File

@ -71,7 +71,8 @@ Foam::functionObjects::yPlus::yPlus
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(obr_, name, typeName, dict),
useWallFunction_(true)
useWallFunction_(true),
writeFields_(true) // May change in the future
{
read(dict);
@ -105,7 +106,11 @@ bool Foam::functionObjects::yPlus::read(const dictionary& dict)
{
if (fvMeshFunctionObject::read(dict) && writeFile::read(dict))
{
useWallFunction_ = dict.getOrDefault("useWallFunction", true);
useWallFunction_ = true;
writeFields_ = true; // May change in the future
dict.readIfPresent("useWallFunction", useWallFunction_);
dict.readIfPresent("writeFields", writeFields_);
return true;
}
@ -144,19 +149,12 @@ bool Foam::functionObjects::yPlus::execute()
{
const fvPatch& patch = patches[patchi];
if
(
isA<nutWallFunctionFvPatchScalarField>(nutBf[patchi])
&& useWallFunction_
)
{
const nutWallFunctionFvPatchScalarField& nutPf =
dynamic_cast<const nutWallFunctionFvPatchScalarField&>
(
nutBf[patchi]
);
const auto* nutWallPatch =
isA<nutWallFunctionFvPatchScalarField>(nutBf[patchi]);
yPlusBf[patchi] = nutPf.yPlus();
if (useWallFunction_ && nutWallPatch)
{
yPlusBf[patchi] = nutWallPatch->yPlus();
}
else if (isA<wallFvPatch>(patch))
{
@ -194,10 +192,13 @@ bool Foam::functionObjects::yPlus::write()
{
const auto& yPlus = obr_.lookupObject<volScalarField>(scopedName(typeName));
Log << type() << " " << name() << " write:" << nl
<< " writing field " << yPlus.name() << endl;
Log << type() << ' ' << name() << " write:" << nl;
yPlus.write();
if (writeFields_)
{
Log << " writing field " << yPlus.name() << endl;
yPlus.write();
}
const volScalarField::Boundary& yPlusBf = yPlus.boundaryField();
const fvPatchList& patches = mesh_.boundary();
@ -214,12 +215,8 @@ bool Foam::functionObjects::yPlus::write()
const scalar maxYplus = gMax(yPlusp);
const scalar avgYplus = gAverage(yPlusp);
if (Pstream::master())
if (UPstream::master())
{
Log << " patch " << patch.name()
<< " y+ : min = " << minYplus << ", max = " << maxYplus
<< ", average = " << avgYplus << nl;
writeCurrentTime(file());
file()
<< token::TAB << patch.name()
@ -228,6 +225,11 @@ bool Foam::functionObjects::yPlus::write()
<< token::TAB << avgYplus
<< endl;
}
Log << " patch " << patch.name()
<< " y+ : min = " << minYplus
<< ", max = " << maxYplus
<< ", average = " << avgYplus << endl;
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,7 +51,8 @@ Usage
libs (fieldFunctionObjects);
// Optional entries
useWallFunction true;
useWallFunction true;
writeFields true;
// Optional (inherited) entries
...
@ -67,6 +68,7 @@ Usage
--> the selected nut wall function to compute yPlus, <!--
--> otherwise directly compute yPlus from flow field <!--
--> | bool | no | true
writeFields | Flag to write yPlus field | bool | no | true
\endtable
The inherited entries are elaborated in:
@ -78,6 +80,12 @@ Usage
<solver> -postProcess -func yPlus
\endverbatim
Note
The \c writeFields flag currently defaults to \c true
(for consistency with previous versions that did not have that flag)
but this is subject to change in the near future for consistency
with other function objects.
See also
- Foam::functionObject
- Foam::functionObjects::fvMeshFunctionObject
@ -89,8 +97,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_yPlus_H
#define functionObjects_yPlus_H
#ifndef Foam_functionObjects_yPlus_H
#define Foam_functionObjects_yPlus_H
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
@ -100,7 +108,6 @@ SourceFiles
namespace Foam
{
namespace functionObjects
{
@ -115,9 +122,12 @@ class yPlus
{
// Private Data
//- Flag to use the wall function expressions to compute yPlus
//- Use the wall function expressions to compute yPlus ?
bool useWallFunction_;
//- Write the yPlus field ?
bool writeFields_;
// Private Member Functions
@ -160,7 +170,8 @@ public:
//- Calculate the yPlus field
virtual bool execute();
//- Write the yPlus field
//- Report min/max/avg (per patch) and log to file,
//- write the yPlus volume field.
virtual bool write();
};

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -50,6 +50,7 @@ functions
{
type yPlus;
libs ( fieldFunctionObjects );
writeFields yes;
writeControl writeTime;
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -50,6 +50,7 @@ functions
{
type yPlus;
libs (fieldFunctionObjects);
writeFields yes;
writeControl writeTime;
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -50,6 +50,7 @@ functions
{
type yPlus;
libs (fieldFunctionObjects);
writeFields yes;
writeControl writeTime;
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -50,6 +50,7 @@ functions
{
type yPlus;
libs (fieldFunctionObjects);
writeFields yes;
writeControl writeTime;
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -50,6 +50,7 @@ functions
{
type yPlus;
libs (fieldFunctionObjects);
writeFields yes;
writeControl writeTime;
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -50,6 +50,7 @@ functions
// {
// type yPlus;
// libs ("libfieldFunctionObjects.so");
// writeFields yes;
// writeControl writeTime;
// }
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -55,10 +55,11 @@ functions
{
type wallShearStress;
libs (fieldFunctionObjects);
log yes;
patches ( bottom top );
writePrecision 10;
writeFields yes;
writeToFile yes;
log yes;
executeControl timeStep;
executeInterval 1;
writeControl writeTime;

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -95,6 +95,7 @@ functions
{
type yPlus;
libs (fieldFunctionObjects);
writeFields yes;
writeControl writeTime;
}
fieldAverage1

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -12,6 +12,7 @@ wallShearStress
libs (fieldFunctionObjects);
enabled true;
writeFields yes;
writeControl writeTime;
patches ( bottomWall );
@ -23,9 +24,8 @@ yPlus
libs (fieldFunctionObjects);
enabled true;
writeFields yes;
writeControl writeTime;
patches ( bottomWall );
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -127,6 +127,7 @@ functions
type yPlus;
libs (fieldFunctionObjects);
timeStart 10;
writeFields yes;
executeControl timeStep;
executeInterval 1;
writeControl writeTime;

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -13,7 +13,8 @@ wallShearStress1
libs (fieldFunctionObjects);
// Optional entries
patches (fixedWalls);
patches (fixedWalls);
writeFields yes;
// Optional (inherited) entries
writePrecision 10;

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -22,6 +22,8 @@ yPlus1
log true;
timeStart 0;
timeEnd 1000;
writeFields yes;
executeControl timeStep;
executeInterval 1;
writeControl writeTime;

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -81,6 +81,7 @@ functions
{
type wallShearStress;
libs (fieldFunctionObjects);
writeFields yes;
writeControl writeTime;
patches (bump);
}
@ -89,8 +90,8 @@ functions
{
type yPlus;
libs (fieldFunctionObjects);
writeFields yes;
writeControl writeTime;
patches (bump);
}
cellCentres

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -59,6 +59,7 @@ functions
type yPlus;
libs (fieldFunctionObjects);
patches (fixedWall);
writeFields yes;
writeControl writeTime;
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -61,6 +61,7 @@ functions
{
type wallShearStress;
libs (fieldFunctionObjects);
writeFields yes;
patches ( bottom );
executeControl writeTime;
writeControl writeTime;
@ -70,6 +71,7 @@ functions
{
type yPlus;
libs (fieldFunctionObjects);
writeFields yes;
executeControl writeTime;
writeControl writeTime;
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2212 |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -61,6 +61,7 @@ functions
{
type wallShearStress;
libs (fieldFunctionObjects);
writeFields yes;
patches ( bottom );
executeControl writeTime;
writeControl writeTime;
@ -70,6 +71,7 @@ functions
{
type yPlus;
libs (fieldFunctionObjects);
writeFields yes;
executeControl writeTime;
writeControl writeTime;
}