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-2018 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);
44  addToRunTimeSelectionTable(functionObject, wallShearStress, dictionary);
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
50 
52 {
53  // Add headers to output data
54  writeHeader(os, "Wall shear stress");
55  writeCommented(os, "Time");
56  writeTabbed(os, "patch");
57  writeTabbed(os, "min");
58  writeTabbed(os, "max");
59  os << endl;
60 }
61 
62 
64 (
65  const volSymmTensorField& Reff,
66  volVectorField& shearStress
67 )
68 {
69  shearStress.dimensions().reset(Reff.dimensions());
70 
71  for (const label patchi : patchSet_)
72  {
73  vectorField& ssp = shearStress.boundaryFieldRef()[patchi];
74  const vectorField& Sfp = mesh_.Sf().boundaryField()[patchi];
75  const scalarField& magSfp = mesh_.magSf().boundaryField()[patchi];
76  const symmTensorField& Reffp = Reff.boundaryField()[patchi];
77 
78  ssp = (-Sfp/magSfp) & Reffp;
79  }
80 }
81 
82 
83 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
84 
85 Foam::functionObjects::wallShearStress::wallShearStress
86 (
87  const word& name,
88  const Time& runTime,
89  const dictionary& dict
90 )
91 :
93  writeFile(mesh_, name, typeName, dict),
94  patchSet_()
95 {
96  read(dict);
97 
98  writeFileHeader(file());
99 
100  volVectorField* wallShearStressPtr
101  (
102  new volVectorField
103  (
104  IOobject
105  (
106  typeName,
107  mesh_.time().timeName(),
108  mesh_,
111  ),
112  mesh_,
114  )
115  );
116 
117  mesh_.objectRegistry::store(wallShearStressPtr);
118 }
119 
120 
121 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
122 
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 
130 {
133 
134  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
135 
136  patchSet_ =
137  mesh_.boundaryMesh().patchSet
138  (
139  wordReList(dict.lookupOrDefault("patches", wordReList()))
140  );
141 
142  Info<< type() << " " << name() << ":" << nl;
143 
144  if (patchSet_.empty())
145  {
146  forAll(pbm, patchi)
147  {
148  if (isA<wallPolyPatch>(pbm[patchi]))
149  {
150  patchSet_.insert(patchi);
151  }
152  }
153 
154  Info<< " processing all wall patches" << nl << endl;
155  }
156  else
157  {
158  Info<< " processing wall patches: " << nl;
159  labelHashSet filteredPatchSet;
160  for (const label patchi : patchSet_)
161  {
162  if (isA<wallPolyPatch>(pbm[patchi]))
163  {
164  filteredPatchSet.insert(patchi);
165  Info<< " " << pbm[patchi].name() << endl;
166  }
167  else
168  {
170  << "Requested wall shear stress on non-wall boundary "
171  << "type patch: " << pbm[patchi].name() << endl;
172  }
173  }
174 
175  Info<< endl;
176 
177  patchSet_ = filteredPatchSet;
178  }
179 
180  return true;
181 }
182 
183 
185 {
188 
189  // Compressible
190  {
191  typedef compressible::turbulenceModel turbType;
192 
193  const turbType* modelPtr =
194  findObject<turbType>(turbulenceModel::propertiesName);
195 
196  if (modelPtr)
197  {
198  calcShearStress(modelPtr->devRhoReff(), wallShearStress);
199  return true;
200  }
201  }
202 
203  // Incompressible
204  {
205  typedef incompressible::turbulenceModel turbType;
206 
207  const turbType* modelPtr =
208  findObject<turbType>(turbulenceModel::propertiesName);
209 
210  if (modelPtr)
211  {
212  calcShearStress(modelPtr->devReff(), wallShearStress);
213  return true;
214  }
215  }
216 
218  << "Unable to find turbulence model in the "
219  << "database" << exit(FatalError);
220 
221  return false;
222 }
223 
224 
226 {
229 
230  Log << type() << " " << name() << " write:" << nl
231  << " writing field " << wallShearStress.name() << endl;
232 
234 
235  const fvPatchList& patches = mesh_.boundary();
236 
237  for (const label patchi : patchSet_)
238  {
239  const fvPatch& pp = patches[patchi];
240 
241  const vectorField& ssp = wallShearStress.boundaryField()[patchi];
242 
243  vector minSsp = gMin(ssp);
244  vector maxSsp = gMax(ssp);
245 
246  if (Pstream::master())
247  {
248  writeCurrentTime(file());
249 
250  file()
251  << token::TAB << pp.name()
252  << token::TAB << minSsp
253  << token::TAB << maxSsp
254  << endl;
255  }
256 
257  Log << " min/max(" << pp.name() << ") = "
258  << minSsp << ", " << maxSsp << endl;
259  }
260 
261  return true;
262 }
263 
264 
265 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
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:104
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:46
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::wallShearStress::read
virtual bool read(const dictionary &)
Read the wallShearStress data.
Definition: wallShearStress.C:129
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
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::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::functionObjects::regionFunctionObject::lookupObjectRef
ObjectType & lookupObjectRef(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
Definition: regionFunctionObjectTemplates.C:97
turbulentTransportModel.H
Foam::wordReList
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:52
Foam::turbulenceModel::propertiesName
static const word propertiesName
Default name of the turbulence properties dictionary.
Definition: turbulenceModel.H:100
wallPolyPatch.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
surfaceFields.H
Foam::surfaceFields.
Foam::fvPatch::name
virtual const word & name() const
Return name.
Definition: fvPatch.H:151
Foam::HashSet< label, Hash< label > >
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::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:50
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::wallShearStress::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
File header information.
Definition: wallShearStress.C:51
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:54
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:212
Foam::functionObjects::wallShearStress::execute
virtual bool execute()
Calculate the wall shear-stress.
Definition: wallShearStress.C:184
Foam::label
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:62
Foam::Field< vector >
Foam::functionObjects::wallShearStress
Calculates and write the shear-stress at wall patches as the volVectorField field 'wallShearStress'.
Definition: wallShearStress.H:134
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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::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::FatalError
error FatalError
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
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
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)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
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::GeometricField::boundaryFieldRef
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
Definition: GeometricField.C:752
Foam::Vector< scalar >
Foam::ThermalDiffusivity
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Definition: phaseCompressibleTurbulenceModelFwd.H:47
Foam::functionObjects::wallShearStress::write
virtual bool write()
Write the wall shear-stress.
Definition: wallShearStress.C:225
Foam::List< wordRe >
Foam::token::TAB
Tab [isspace].
Definition: token.H:113
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
Foam::polyBoundaryMesh::patchSet
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.
Definition: polyBoundaryMesh.C:857
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:182
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::functionObjects::writeFile
functionObject base class for writing single files
Definition: writeFile.H:59
Foam::IncompressibleTurbulenceModel
Templated abstract base class for single-phase incompressible turbulence models.
Definition: IncompressibleTurbulenceModel.H:55
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:593
Foam::GeometricField< symmTensor, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::functionObjects::wallShearStress::~wallShearStress
virtual ~wallShearStress()
Destructor.
Definition: wallShearStress.C:123
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::functionObjects::wallShearStress::calcShearStress
void calcShearStress(const volSymmTensorField &Reff, volVectorField &shearStress)
Calculate the shear-stress.
Definition: wallShearStress.C:64
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:274
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
turbulentFluidThermoModel.H
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