wallShearStress.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2026 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 "wallShearStress.H"
27 #include "volFields.H"
28 #include "surfaceFields.H"
31 #include "wallPolyPatch.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
42 }
43 }
44 
45 
46 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
47 
48 void Foam::functionObjects::wallShearStress::writeFileHeader(const label i)
49 {
50  // Add headers to output data
51  writeHeader(file(), "Wall shear stress");
52  writeCommented(file(), "Time");
53  writeTabbed(file(), "patch");
54  writeTabbed(file(), "min");
55  writeTabbed(file(), "max");
56  file() << endl;
57 }
58 
59 
61 Foam::functionObjects::wallShearStress::calcShearStress
62 (
63  const surfaceVectorField& tau
64 )
65 {
66  tmp<volVectorField> twallShearStress
67  (
69  (
70  type(),
71  mesh_,
72  dimensionedVector(tau.dimensions(), Zero)
73  )
74  );
75 
76  volVectorField::Boundary& wallShearStressBf =
77  twallShearStress.ref().boundaryFieldRef();
78 
79  forAllConstIter(labelHashSet, patchSet_, iter)
80  {
81  const label patchi = iter.key();
82  wallShearStressBf[patchi] = -tau.boundaryField()[patchi];
83  }
84 
85  return twallShearStress;
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 (
93  const word& name,
94  const Time& runTime,
95  const dictionary& dict
96 )
97 :
98  fvMeshFunctionObject(name, runTime, dict),
99  logFiles(obr_, name),
100  writeLocalObjects(obr_, log),
101  phaseName_(word::null),
102  patchSet_()
103 {
104  read(dict);
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
110 
112 {}
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
118 {
121 
122  phaseName_ = dict.lookupOrDefault<word>("phase", word::null);
123 
124  patchSet_ = mesh_.poly().boundary().patchSet(dict, true);
125 
126  const polyBoundaryMesh& pbm = mesh_.poly().boundary();
127 
128  if (patchSet_.empty())
129  {
130  forAll(pbm, patchi)
131  {
132  if (isA<wallPolyPatch>(pbm[patchi]))
133  {
134  patchSet_.insert(patchi);
135  }
136  }
137 
138  Info<< indent << "processing all wall patches" << endl;
139  }
140  else
141  {
142  Info<< indent << "processing wall patches:" << nl;
143 
144  Info<< incrIndent;
145  labelHashSet filteredPatchSet;
146  forAllConstIter(labelHashSet, patchSet_, iter)
147  {
148  const label patchi = iter.key();
149  filteredPatchSet.insert(patchi);
150 
151  if (isA<wallPolyPatch>(pbm[patchi]))
152  {
153  Info<< indent << pbm[patchi].name() << endl;
154  }
155  else
156  {
157  Info<< indent
158  << pbm[patchi].name()
159  << " type " << pbm[patchi].type() << endl;
160  }
161  }
162  Info<< decrIndent;
163 
164  patchSet_ = filteredPatchSet;
165  }
166 
167  resetName(typeName);
168  resetLocalObjectName(typeName);
169 
170  return true;
171 }
172 
173 
175 {
176  const word fieldName(IOobject::groupName(type(), phaseName_));
177 
178  typedef compressible::momentumTransportModel cmpModel;
180 
181  const word momentumTransportModelName
182  (
184  );
185 
186  if (mesh_.foundObject<cmpModel>(momentumTransportModelName))
187  {
188  const cmpModel& model =
189  mesh_.lookupObject<cmpModel>(momentumTransportModelName);
190 
191  store(fieldName, calcShearStress(model.devTau()));
192 
193  return true;
194  }
195  else if (mesh_.foundObject<icoModel>(momentumTransportModelName))
196  {
197  const icoModel& model =
198  mesh_.lookupObject<icoModel>(momentumTransportModelName);
199 
200  store(fieldName, calcShearStress(model.devSigma()));
201 
202  return true;
203  }
204  else
205  {
207  << "Unable to find turbulence model in the "
208  << "database" << exit(FatalError);
209 
210  return false;
211  }
212 }
213 
214 
216 {
217  Log << type() << " " << name() << " write:" << nl;
218 
220 
221  logFiles::write();
222 
224  (
225  IOobject::groupName(type(), phaseName_)
226  );
227 
228  const fvPatchList& patches = mesh_.boundary();
229 
230  forAllConstIter(labelHashSet, patchSet_, iter)
231  {
232  label patchi = iter.key();
233  const fvPatch& pp = patches[patchi];
234 
235  const vectorField& ssp = wallShearStress.boundaryField()[patchi];
236 
237  vector minSsp = gMin(ssp);
238  vector maxSsp = gMax(ssp);
239 
240  if (Pstream::master())
241  {
242  file() << time_.userTimeValue()
243  << tab << pp.name()
244  << tab << minSsp
245  << tab << maxSsp
246  << endl;
247  }
248 
249  Log << " min/max(" << pp.name() << ") = "
250  << minSsp << ", " << maxSsp << endl;
251  }
252 
253  Log << endl;
254 
255  return true;
256 }
257 
258 
259 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Macros for easy insertion into run-time selection tables.
Generic GeometricField class.
GeometricBoundaryField< Type, GeoMesh, PrimitiveField > Boundary
Type of the boundary field.
static tmp< GeometricField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Internal &, const PtrList< Patch > &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:109
const word & name() const
Return name.
Definition: IOobject.H:307
static word groupName(Name name, const word &group)
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
Base class for single-phase compressible momentum transport models.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
virtual const word & type() const =0
Runtime type information.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:60
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:113
virtual bool write()
Write function.
Definition: logFiles.C:173
Calculates the natural logarithm of the specified scalar field.
Definition: log.H:106
const ObjectType & lookupObject(const word &fieldName) const
Lookup object from the objectRegistry.
virtual bool read(const dictionary &)
Read optional controls.
Calculates and write the shear-stress at wall patches as the volVectorField field 'wallShearStress' o...
wallShearStress(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
virtual bool execute()
Calculate the wall shear-stress.
virtual bool write()
Write the wall shear-stress.
virtual bool read(const dictionary &)
Read the wallShearStress data.
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:121
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:131
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:110
FunctionObject base class for managing a list of objects on behalf of the inheriting function object,...
void resetLocalObjectName(const word &name)
Reset the list of local object names from a single word.
virtual bool read(const dictionary &)
Read the list of objects to be written.
virtual bool write()
Write function.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:58
virtual const word & name() const
Return name.
Definition: fvPatch.H:135
Base class for single-phase incompressible momentum transport models.
Foam::polyBoundaryMesh.
A class for managing temporary objects.
Definition: tmp.H:55
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const vector tau
label patchi
const fvPatchList & patches
#define Log
Report write to Foam::Info if the local log switch is true.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
Namespace for OpenFOAM.
Type gMin(const UList< Type > &f, const label comm)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:272
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
static const char tab
Definition: Ostream.H:296
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:265
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Type gMax(const UList< Type > &f, const label comm)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:213
error FatalError
SurfaceField< vector > surfaceVectorField
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:243
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
Foam::surfaceFields.