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 | Copyright (C) 2013-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "yPlus.H"
27 #include "volFields.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::yPlus::writeFileHeader(const label i)
42 {
43  writeHeader(file(), "y+ ()");
44 
45  writeCommented(file(), "Time");
46  writeTabbed(file(), "patch");
47  writeTabbed(file(), "min");
48  writeTabbed(file(), "max");
49  writeTabbed(file(), "average");
50  file() << endl;
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
56 Foam::yPlus::yPlus
57 (
58  const word& name,
59  const objectRegistry& obr,
60  const dictionary& dict,
61  const bool loadFromFiles
62 )
63 :
64  functionObjectFile(obr, name, typeName),
65  name_(name),
66  obr_(obr),
67  active_(true),
68  log_(true),
69  phiName_("phi")
70 {
71  // Check if the available mesh is an fvMesh, otherwise deactivate
72  if (!isA<fvMesh>(obr_))
73  {
74  active_ = false;
75  WarningIn
76  (
77  "yPlus::yPlus"
78  "("
79  "const word&, "
80  "const objectRegistry&, "
81  "const dictionary&, "
82  "const bool"
83  ")"
84  ) << "No fvMesh available, deactivating " << name_ << nl
85  << endl;
86  }
87 
88  if (active_)
89  {
90  const fvMesh& mesh = refCast<const fvMesh>(obr_);
91 
92  volScalarField* yPlusPtr
93  (
94  new volScalarField
95  (
96  IOobject
97  (
98  type(),
99  mesh.time().timeName(),
100  mesh,
103  ),
104  mesh,
105  dimensionedScalar("0", dimless, 0.0)
106  )
107  );
108 
109  mesh.objectRegistry::store(yPlusPtr);
110  }
111 }
112 
113 
114 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
115 
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
122 void Foam::yPlus::read(const dictionary& dict)
123 {
124  if (active_)
125  {
126  log_ = dict.lookupOrDefault<Switch>("log", true);
127  phiName_ = dict.lookupOrDefault<word>("phiName", "phi");
128  }
129 }
130 
131 
133 {
134  typedef compressible::turbulenceModel cmpModel;
135  typedef incompressible::turbulenceModel icoModel;
136 
137  if (active_)
138  {
140 
141  const fvMesh& mesh = refCast<const fvMesh>(obr_);
142 
144  const_cast<volScalarField&>
145  (
147  );
148 
149  if (log_) Info<< type() << " " << name_ << " output:" << nl;
150 
152  if (mesh.foundObject<cmpModel>(turbulenceModel::propertiesName))
153  {
154  const cmpModel& model =
156 
157  calcYPlus(model, mesh, yPlus);
158  }
159  else if (mesh.foundObject<icoModel>(turbulenceModel::propertiesName))
160  {
161  const icoModel& model =
163 
164  calcYPlus(model, mesh, yPlus);
165  }
166  else
167  {
168  FatalErrorIn("void Foam::yPlus::write()")
169  << "Unable to find turbulence model in the "
170  << "database" << exit(FatalError);
171  }
172  }
173 }
174 
175 
177 {
178  if (active_)
179  {
180  execute();
181  }
182 }
183 
184 
186 {
187  // Do nothing
188 }
189 
190 
192 {
193  if (active_)
194  {
196 
197  const volScalarField& yPlus =
198  obr_.lookupObject<volScalarField>(type());
199 
200  if (log_) Info<< " writing field " << yPlus.name() << nl << endl;
201 
202  yPlus.write();
203  }
204 }
205 
206 
207 // ************************************************************************* //
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
bool foundObject(const word &name) const
Is the named Type found?
Templated abstract base class for single-phase incompressible turbulence models.
A class for handling words, derived from string.
Definition: word.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
messageStream Info
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
virtual bool write() const
Write using setting from DB.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define WarningIn(functionName)
Report a warning using Foam::Warning.
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: yPlus.C:185
virtual void read(const dictionary &)
Read the yPlus data.
Definition: yPlus.C:122
virtual void execute()
Execute, currently does nothing.
Definition: yPlus.C:132
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
const word & name() const
Return name.
Definition: IOobject.H:260
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: yPlus.C:176
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
virtual void write()
Write function.
scalar yPlus
error FatalError
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Registry of regIOobjects.
static const word propertiesName
Default name of the turbulence properties dictionary.
Base class for output file data handling.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
virtual ~yPlus()
Destructor.
Definition: yPlus.C:116
Evaluates and outputs turbulence y+ for models. Values written to time directories as field &#39;yPlus&#39;...
Definition: yPlus.H:63
virtual void write()
Calculate the yPlus and write.
Definition: yPlus.C:191
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A class for managing temporary objects.
Definition: PtrList.H:118
defineTypeNameAndDebug(combustionModel, 0)