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  );
115 
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::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:191
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
wallShearStress.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:165
Log
#define Log
Definition: PDRblock.C:28
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::functionObjects::writeFile::file
virtual OFstream & file()
Definition: writeFile.C:229
Foam::functionObjects::wallShearStress::read
virtual bool read(const dictionary &)
Definition: wallShearStress.C:115
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:59
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
Foam::functionObjects::regionFunctionObject::lookupObject
const ObjectType & lookupObject(const word &fieldName) const
Definition: regionFunctionObjectTemplates.C:80
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::read
bool read(const char *buf, int32_t &val)
Definition: int32.H:125
Foam::functionObjects::regionFunctionObject::lookupObjectRef
ObjectType & lookupObjectRef(const word &fieldName) const
Definition: regionFunctionObjectTemplates.C:90
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:773
turbulentTransportModel.H
Foam::turbulenceModel::propertiesName
static const word propertiesName
Definition: turbulenceModel.H:96
wallPolyPatch.H
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Definition: UPstream.H:453
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
surfaceFields.H
Foam::surfaceFields.
Foam::fvPatch::name
virtual const word & name() const
Definition: fvPatch.H:163
Foam::HashSet
A HashTable with keys but without contents that is similar to std::unordered_set.
Definition: HashSet.H:73
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:60
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:329
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Definition: writeFile.C:291
Foam::functionObjects::wallShearStress::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Definition: wallShearStress.C:44
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Definition: writeFile.C:206
Foam::functionObjects::wallShearStress::execute
virtual bool execute()
Definition: wallShearStress.C:170
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::functionObjects::wallShearStress
Computes the wall-shear stress at selected wall patches.
Definition: wallShearStress.H:169
Foam::Info
messageStream Info
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:55
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Definition: regionFunctionObject.C:166
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:36
Foam
Definition: atmBoundaryLayer.C:26
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
Foam::functionObject::scopedName
word scopedName(const word &name) const
Definition: functionObject.C:44
Foam::IOobject::name
const word & name() const noexcept
Definition: IOobjectI.H:58
FatalErrorInFunction
#define FatalErrorInFunction
Definition: error.H:465
Foam::functionObject::name
const word & name() const noexcept
Definition: functionObject.C:136
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:44
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Definition: writeFile.C:265
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::GeometricField::boundaryFieldRef
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Definition: GeometricField.C:776
Foam::Vector< scalar >
Foam::ThermalDiffusivity
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Definition: phaseCompressibleTurbulenceModelFwd.H:41
Foam::functionObjects::wallShearStress::write
virtual bool write()
Definition: wallShearStress.C:211
Foam::token::TAB
@ TAB
Tab [isspace].
Definition: token.H:119
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Definition: POSIX.C:717
Foam::functionObjects::fvMeshFunctionObject::mesh_
const fvMesh & mesh_
Definition: fvMeshFunctionObject.H:69
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:47
Foam::polyBoundaryMesh::patchSet
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Definition: polyBoundaryMesh.C:857
Foam::HashSet::insert
bool insert(const Key &key)
Definition: HashSet.H:191
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:59
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::fvMesh::time
const Time & time() const
Definition: fvMesh.H:276
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:115
Foam::IncompressibleTurbulenceModel
Templated abstract base class for single-phase incompressible turbulence models.
Definition: IncompressibleTurbulenceModel.H:51
Foam::functionObjects::wallShearStress::wallShearStress
wallShearStress(const word &name, const Time &runTime, const dictionary &)
Definition: wallShearStress.C:78
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:586
Foam::incompressible::turbulenceModel
IncompressibleTurbulenceModel< transportModel > turbulenceModel
Definition: turbulentTransportModel.H:56
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:49
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:184
WarningInFunction
#define WarningInFunction
Definition: messageStream.H:353
Foam::functionObjects::wallShearStress::calcShearStress
void calcShearStress(const volSymmTensorField &Reff, volVectorField &shearStress)
Definition: wallShearStress.C:56
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Definition: writeFile.C:281
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:585
turbulentFluidThermoModel.H
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Definition: GeometricFieldI.H:55