yPlus.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2016 OpenFOAM Foundation
9  Copyright (C) 2016 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "yPlus.H"
30 #include "volFields.H"
31 #include "turbulenceModel.H"
33 #include "wallFvPatch.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace functionObjects
41 {
43 
45  (
46  functionObject,
47  yPlus,
48  dictionary
49  );
50 }
51 }
52 
53 
54 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55 
56 void Foam::functionObjects::yPlus::writeFileHeader(Ostream& os) const
57 {
58  writeHeader(os, "y+ ()");
59 
60  writeCommented(os, "Time");
61  writeTabbed(os, "patch");
62  writeTabbed(os, "min");
63  writeTabbed(os, "max");
64  writeTabbed(os, "average");
65  os << endl;
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
70 
71 Foam::functionObjects::yPlus::yPlus
72 (
73  const word& name,
74  const Time& runTime,
75  const dictionary& dict
76 )
77 :
79  writeFile(obr_, name, typeName, dict)
80 {
81  read(dict);
82 
83  writeFileHeader(file());
84 
85  volScalarField* yPlusPtr
86  (
87  new volScalarField
88  (
89  IOobject
90  (
91  typeName,
92  mesh_.time().timeName(),
93  mesh_,
96  ),
97  mesh_,
99  )
100  );
101 
102  mesh_.objectRegistry::store(yPlusPtr);
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
107 
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
115 {
118 
119  return true;
120 }
121 
122 
124 {
126  lookupObjectRef<volScalarField>(typeName);
127 
128  if (foundObject<turbulenceModel>(turbulenceModel::propertiesName))
129  {
130  volScalarField::Boundary& yPlusBf = yPlus.boundaryFieldRef();
131 
132  const turbulenceModel& model =
133  lookupObject<turbulenceModel>
134  (
136  );
137 
138  const nearWallDist nwd(mesh_);
139  const volScalarField::Boundary& d = nwd.y();
140 
141  // nut needed for wall function patches
142  tmp<volScalarField> tnut = model.nut();
143  const volScalarField::Boundary& nutBf = tnut().boundaryField();
144 
145  // U needed for plain wall patches
146  const volVectorField::Boundary& UBf = model.U().boundaryField();
147 
148  const fvPatchList& patches = mesh_.boundary();
149 
150  forAll(patches, patchi)
151  {
152  const fvPatch& patch = patches[patchi];
153 
154  if (isA<nutWallFunctionFvPatchScalarField>(nutBf[patchi]))
155  {
156  const nutWallFunctionFvPatchScalarField& nutPf =
157  dynamic_cast<const nutWallFunctionFvPatchScalarField&>
158  (
159  nutBf[patchi]
160  );
161 
162  yPlusBf[patchi] = nutPf.yPlus();
163  }
164  else if (isA<wallFvPatch>(patch))
165  {
166  yPlusBf[patchi] =
167  d[patchi]
168  *sqrt
169  (
170  model.nuEff(patchi)
171  *mag(UBf[patchi].snGrad())
172  )/model.nu(patchi);
173  }
174  }
175  }
176  else
177  {
179  << "Unable to find turbulence model in the "
180  << "database: yPlus will not be calculated" << endl;
181  return false;
182  }
183 
184  return true;
185 }
186 
187 
189 {
190  const volScalarField& yPlus =
192 
193  Log << type() << " " << name() << " write:" << nl
194  << " writing field " << yPlus.name() << endl;
195 
196  yPlus.write();
197 
198  const volScalarField::Boundary& yPlusBf = yPlus.boundaryField();
199  const fvPatchList& patches = mesh_.boundary();
200 
201  forAll(patches, patchi)
202  {
203  const fvPatch& patch = patches[patchi];
204 
205  if (isA<wallFvPatch>(patch))
206  {
207  const scalarField& yPlusp = yPlusBf[patchi];
208 
209  const scalar minYplus = gMin(yPlusp);
210  const scalar maxYplus = gMax(yPlusp);
211  const scalar avgYplus = gAverage(yPlusp);
212 
213  if (Pstream::master())
214  {
215  Log << " patch " << patch.name()
216  << " y+ : min = " << minYplus << ", max = " << maxYplus
217  << ", average = " << avgYplus << nl;
218 
219  writeCurrentTime(file());
220  file()
221  << token::TAB << patch.name()
222  << token::TAB << minYplus
223  << token::TAB << maxYplus
224  << token::TAB << avgYplus
225  << endl;
226  }
227  }
228  }
229 
230  return true;
231 }
232 
233 
234 // ************************************************************************* //
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::fvc::snGrad
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:47
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::turbulenceModel::nu
virtual tmp< volScalarField > nu() const =0
Return the laminar viscosity.
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::yPlus::read
virtual bool read(const dictionary &)
Read the yPlus data.
Definition: yPlus.C:114
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::regionFunctionObject::lookupObject
const ObjectType & lookupObject(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
Definition: regionFunctionObjectTemplates.C:87
Foam::tmp< volScalarField >
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::turbulenceModel::nut
virtual tmp< volScalarField > nut() const =0
Return the turbulence viscosity.
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:604
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::turbulenceModel::propertiesName
static const word propertiesName
Default name of the turbulence properties dictionary.
Definition: turbulenceModel.H:100
nutWallFunctionFvPatchScalarField.H
Foam::nutWallFunctionFvPatchScalarField::yPlus
virtual tmp< scalarField > yPlus() const =0
Calculate and return the yPlus at the boundary.
wallFvPatch.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, add, dictionary)
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:284
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:212
Foam::functionObjects::yPlus::~yPlus
virtual ~yPlus()
Destructor.
Definition: yPlus.C:108
yPlus.H
Foam::Field< scalar >
Foam::functionObjects::yPlus::write
virtual bool write()
Write the yPlus field.
Definition: yPlus.C:188
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:65
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::turbulenceModel
Abstract base class for turbulence models (RAS, LES and laminar).
Definition: turbulenceModel.H:63
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:166
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::functionObjects::yPlus
Evaluates and outputs turbulence y+ for turbulence models.
Definition: yPlus.H:108
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Foam::functionObjects::yPlus::execute
virtual bool execute()
Calculate the yPlus field.
Definition: yPlus.C:123
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:258
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::token::TAB
Tab [isspace].
Definition: token.H:113
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::nearWallDist
Distance calculation for cells with face on a wall. Searches pointNeighbours to find closest.
Definition: nearWallDist.H:53
Foam::nearWallDist::y
const volScalarField::Boundary & y() const
Definition: nearWallDist.H:89
Foam::functionObjects::writeFile
functionObject base class for writing single files
Definition: writeFile.H:59
yPlus
scalar yPlus
Definition: evaluateNearWall.H:16
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:593
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::turbulenceModel::nuEff
virtual tmp< volScalarField > nuEff() const =0
Return the effective viscosity.
Foam::nutWallFunctionFvPatchScalarField
The class nutWallFunction is a base class that parents the derived boundary conditions which provide ...
Definition: nutWallFunctionFvPatchScalarField.H:110
Foam::IOobject::NO_READ
Definition: IOobject.H:123
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:274
turbulenceModel.H
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62
Foam::turbulenceModel::U
const volVectorField & U() const
Access function to velocity field.
Definition: turbulenceModel.H:144