wallShearStress.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) 2017-2020 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 "wallShearStress.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
34 #include "wallPolyPatch.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 namespace functionObjects
42 {
43  defineTypeNameAndDebug(wallShearStress, 0);
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
50 
52 {
53  writeHeader(os, "Wall shear stress");
54  writeCommented(os, "Time");
55  writeTabbed(os, "patch");
56  writeTabbed(os, "min");
57  writeTabbed(os, "max");
58  os << endl;
59 }
60 
61 
63 (
64  const volSymmTensorField& Reff,
65  volVectorField& shearStress
66 )
67 {
68  shearStress.dimensions().reset(Reff.dimensions());
69 
70  for (const label patchi : patchSet_)
71  {
72  vectorField& ssp = shearStress.boundaryFieldRef()[patchi];
73  const vectorField& Sfp = mesh_.Sf().boundaryField()[patchi];
74  const scalarField& magSfp = mesh_.magSf().boundaryField()[patchi];
75  const symmTensorField& Reffp = Reff.boundaryField()[patchi];
76 
77  ssp = (-Sfp/magSfp) & Reffp;
78  }
79 }
80 
81 
82 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
83 
85 (
86  const word& name,
87  const Time& runTime,
88  const dictionary& dict
89 )
90 :
91  fvMeshFunctionObject(name, runTime, dict),
92  writeFile(mesh_, name, typeName, dict),
93  patchSet_()
94 {
95  read(dict);
96 
98 
99  volVectorField* wallShearStressPtr
100  (
101  new volVectorField
102  (
103  IOobject
104  (
105  scopedName(typeName),
106  mesh_.time().timeName(),
107  mesh_,
110  ),
111  mesh_,
113  )
114  );
116  mesh_.objectRegistry::store(wallShearStressPtr);
117 }
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
123 {
126 
127  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
128 
129  patchSet_ =
130  mesh_.boundaryMesh().patchSet
131  (
132  dict.getOrDefault<wordRes>("patches", wordRes())
133  );
134 
135  Info<< type() << " " << name() << ":" << nl;
136 
137  if (patchSet_.empty())
138  {
139  forAll(pbm, patchi)
140  {
141  if (isA<wallPolyPatch>(pbm[patchi]))
142  {
143  patchSet_.insert(patchi);
144  }
145  }
146 
147  Info<< " processing all wall patches" << nl << endl;
148  }
149  else
150  {
151  Info<< " processing wall patches: " << nl;
152  labelHashSet filteredPatchSet;
153  for (const label patchi : patchSet_)
154  {
155  if (isA<wallPolyPatch>(pbm[patchi]))
156  {
157  filteredPatchSet.insert(patchi);
158  Info<< " " << pbm[patchi].name() << endl;
159  }
160  else
161  {
163  << "Requested wall shear stress on non-wall boundary "
164  << "type patch: " << pbm[patchi].name() << endl;
165  }
166  }
167 
168  Info<< endl;
169 
170  patchSet_ = filteredPatchSet;
171  }
172 
173  return true;
174 }
175 
176 
178 {
179  auto& wallShearStress =
180  mesh_.lookupObjectRef<volVectorField>(scopedName(typeName));
181 
182  // Compressible
183  {
184  typedef compressible::turbulenceModel turbType;
185 
186  const turbType* modelPtr =
187  findObject<turbType>(turbulenceModel::propertiesName);
188 
189  if (modelPtr)
190  {
191  calcShearStress(modelPtr->devRhoReff(), wallShearStress);
192  return true;
193  }
194  }
195 
196  // Incompressible
197  {
198  typedef incompressible::turbulenceModel turbType;
199 
200  const turbType* modelPtr =
201  findObject<turbType>(turbulenceModel::propertiesName);
202 
203  if (modelPtr)
204  {
205  calcShearStress(modelPtr->devReff(), wallShearStress);
206  return true;
207  }
208  }
209 
211  << "Unable to find turbulence model in the "
212  << "database" << exit(FatalError);
213 
214  return false;
215 }
216 
217 
219 {
220  const auto& wallShearStress =
221  obr_.lookupObject<volVectorField>(scopedName(typeName));
222 
223  Log << type() << " " << name() << " write:" << nl
224  << " writing field " << wallShearStress.name() << endl;
225 
227 
228  const fvPatchList& patches = mesh_.boundary();
229 
230  for (const label patchi : patchSet_)
231  {
232  const fvPatch& pp = patches[patchi];
233 
234  const vectorField& ssp = wallShearStress.boundaryField()[patchi];
235 
236  vector minSsp = gMin(ssp);
237  vector maxSsp = gMax(ssp);
238 
239  if (Pstream::master())
240  {
241  writeCurrentTime(file());
242 
243  file()
244  << token::TAB << pp.name()
245  << token::TAB << minSsp
246  << token::TAB << maxSsp
247  << endl;
248  }
249 
250  Log << " min/max(" << pp.name() << ") = "
251  << minSsp << ", " << maxSsp << endl;
252  }
253 
254  return true;
255 }
256 
257 
258 // ************************************************************************* //
Foam::surfaceFields.
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:264
dictionary dict
defineTypeNameAndDebug(ObukhovLength, 0)
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:339
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
virtual bool read(const dictionary &)
Read the wallShearStress data.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
Type gMin(const FieldField< Field, Type > &f)
Tab [isspace].
Definition: token.H:126
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:150
dimensionedSymmTensor sqr(const dimensionedVector &dv)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:68
wallShearStress(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
IncompressibleTurbulenceModel< transportModel > turbulenceModel
Ignore writing from objectRegistry::writeObject()
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:361
Abstract base-class for Time/database function objects.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:227
const ObjectType & lookupObject(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
const word & name() const noexcept
Return the name of this functionObject.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
virtual bool execute()
Calculate the wall shear-stress.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:752
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:313
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
static const word propertiesName
Default name of the turbulence properties dictionary.
void calcShearStress(const volSymmTensorField &Reff, volVectorField &shearStress)
Calculate the shear-stress.
A class for handling words, derived from Foam::string.
Definition: word.H:63
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:47
Computes the wall-shear stress at selected wall patches.
virtual void writeFileHeader(Ostream &os) const
File header information.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
void reset(const dimensionSet &ds)
Copy assign the exponents from the dimensionSet.
Definition: dimensionSet.C:142
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
Definition: Time.C:760
Type gMax(const FieldField< Field, Type > &f)
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:241
virtual bool write()
Write the wall shear-stress.
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
static bool master(const label communicator=worldComm)
Am I the master rank.
Definition: UPstream.H:672
const polyBoundaryMesh & patches
Nothing to be read.
#define Log
Definition: PDRblock.C:28
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool read(const dictionary &dict)
Read optional controls.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
virtual const word & name() const
Return name.
Definition: fvPatch.H:208
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
word scopedName(const word &name) const
Return a scoped (prefixed) name.
const fvMesh & mesh_
Reference to the fvMesh.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
Namespace for OpenFOAM.
const dimensionSet & dimensions() const noexcept
Return dimensions.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:157
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:329