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 | Copyright (C) 2013-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(wallShearStress, 0);
38 }
39 
40 
41 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
42 
44 {
45  // Add headers to output data
46  writeHeader(os, "Wall shear stress");
47  writeCommented(os, "Time");
48  writeTabbed(os, "patch");
49  writeTabbed(os, "min");
50  writeTabbed(os, "max");
51  os << endl;
52 }
53 
54 
56 (
57  const fvMesh& mesh,
58  const volSymmTensorField& Reff,
59  volVectorField& shearStress
60 )
61 {
62  forAllConstIter(labelHashSet, patchSet_, iter)
63  {
64  label patchI = iter.key();
65  const polyPatch& pp = mesh.boundaryMesh()[patchI];
66 
67  vectorField& ssp = shearStress.boundaryField()[patchI];
68  const vectorField& Sfp = mesh.Sf().boundaryField()[patchI];
69  const scalarField& magSfp = mesh.magSf().boundaryField()[patchI];
70  const symmTensorField& Reffp = Reff.boundaryField()[patchI];
71 
72  ssp = (-Sfp/magSfp) & Reffp;
73 
74  vector minSsp = gMin(ssp);
75  vector maxSsp = gMax(ssp);
76 
77  file() << mesh.time().value()
78  << token::TAB << pp.name()
79  << token::TAB << minSsp
80  << token::TAB << maxSsp
81  << endl;
82 
83  if (log_) Info
84  << " min/max(" << pp.name() << ") = "
85  << minSsp << ", " << maxSsp << endl;
86  }
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 
93 (
94  const word& name,
95  const objectRegistry& obr,
96  const dictionary& dict,
97  const bool loadFromFiles
98 )
99 :
100  functionObjectFile(obr, name, typeName, dict),
101  name_(name),
102  obr_(obr),
103  active_(true),
104  resultName_(name),
105  log_(true),
106  patchSet_()
107 {
108  // Check if the available mesh is an fvMesh, otherwise deactivate
109  if (!isA<fvMesh>(obr_))
110  {
111  active_ = false;
113  << "No fvMesh available, deactivating " << name_ << nl
114  << endl;
115  }
116 
117  read(dict);
118 
119  if (active_)
120  {
121  const fvMesh& mesh = refCast<const fvMesh>(obr_);
122 
123  volVectorField* wallShearStressPtr
124  (
125  new volVectorField
126  (
127  IOobject
128  (
129  resultName_,
130  mesh.time().timeName(),
131  mesh,
134  ),
135  mesh,
137  (
138  "0",
141  )
142  )
143  );
144 
145  mesh.objectRegistry::store(wallShearStressPtr);
146 
147  writeFileHeader(file());
148  }
149 }
150 
151 
152 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
153 
155 {}
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 {
162  if (active_)
163  {
165 
166  log_.readIfPresent("log", dict);
167  dict.readIfPresent("resultName", resultName_);
168 
169  const fvMesh& mesh = refCast<const fvMesh>(obr_);
170  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
171 
172  patchSet_ =
174  (
176  );
177 
178  if (log_) Info << type() << " " << name_ << " output:" << nl;
179 
180  if (patchSet_.empty())
181  {
182  forAll(pbm, patchI)
183  {
184  if (isA<wallPolyPatch>(pbm[patchI]))
185  {
186  patchSet_.insert(patchI);
187  }
188  }
189 
190  if (log_) Info << " processing all wall patches" << nl << endl;
191  }
192  else
193  {
194  if (log_) Info << " processing wall patches: " << nl;
195  labelHashSet filteredPatchSet;
196  forAllConstIter(labelHashSet, patchSet_, iter)
197  {
198  label patchI = iter.key();
199  if (isA<wallPolyPatch>(pbm[patchI]))
200  {
201  filteredPatchSet.insert(patchI);
202  if (log_) Info << " " << pbm[patchI].name() << endl;
203  }
204  else
205  {
207  << "Requested wall shear stress on non-wall boundary "
208  << "type patch: " << pbm[patchI].name() << endl;
209  }
210  }
211 
212  if (log_) Info << endl;
213 
214  patchSet_ = filteredPatchSet;
215  }
216  }
217 }
218 
219 
221 {
222  typedef compressible::turbulenceModel cmpModel;
223  typedef incompressible::turbulenceModel icoModel;
224 
225  if (active_)
226  {
227  const fvMesh& mesh = refCast<const fvMesh>(obr_);
228 
230  const_cast<volVectorField&>
231  (
232  mesh.lookupObject<volVectorField>(resultName_)
233  );
234 
235  if (log_) Info << type() << " " << name_ << " output:" << nl;
236 
237 
240  {
241  const cmpModel& model =
243 
244  Reff = model.devRhoReff();
245  }
247  {
248  const icoModel& model =
250 
251  Reff = model.devReff();
252  }
253  else
254  {
256  << "Unable to find turbulence model in the "
257  << "database" << exit(FatalError);
258  }
259 
260  calcShearStress(mesh, Reff(), wallShearStress);
261 
262  if (log_) Info << endl;
263  }
264 }
265 
266 
268 {
269  // Do nothing
270 }
271 
272 
274 {
275  // Do nothing
276 }
277 
278 
280 {
281  if (active_)
282  {
284  obr_.lookupObject<volVectorField>(resultName_);
285 
286  if (log_) Info
287  << type() << " " << name_ << " output:" << nl
288  << " writing field " << wallShearStress.name() << nl
289  << endl;
290 
292  }
293 }
294 
295 
296 // ************************************************************************* //
Foam::token::TAB
@ TAB
Definition: token.H:96
volFields.H
wallShearStress.H
Foam::wallShearStress::name
virtual const word & name() const
Return name of the set of wallShearStress.
Definition: wallShearStress.H:204
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::wallShearStress::write
virtual void write()
Calculate the wallShearStress and write.
Definition: wallShearStress.C:279
Foam::functionObjectFile::writeTabbed
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: functionObjectFile.C:230
turbulentTransportModel.H
Foam::wordReList
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
Foam::turbulenceModel::propertiesName
static const word propertiesName
Default name of the turbulence properties dictionary.
Definition: turbulenceModel.H:97
wallPolyPatch.H
Foam::wallShearStress::~wallShearStress
virtual ~wallShearStress()
Destructor.
Definition: wallShearStress.C:154
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Definition: dictionaryTemplates.C:33
Foam::GeometricField::boundaryField
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
Definition: GeometricField.C:735
Foam::functionObjectFile::read
void read(const dictionary &dict)
Read.
Definition: functionObjectFile.C:178
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
surfaceFields.H
Foam::surfaceFields.
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:261
Foam::HashSet< label, Hash< label > >
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::fvMesh::magSf
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
Definition: fvMeshGeometry.C:358
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
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:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::wallShearStress::calcShearStress
void calcShearStress(const fvMesh &mesh, const volSymmTensorField &Reff, volVectorField &shearStress)
Calculate the shear stress.
Definition: wallShearStress.C:56
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::wallShearStress::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
File header information.
Definition: wallShearStress.C:43
Foam::wallShearStress::wallShearStress
wallShearStress(const wallShearStress &)
Disallow default bitwise copy construct.
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::functionObjectFile::writeHeader
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: functionObjectFile.C:240
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::fvMesh::Sf
const surfaceVectorField & Sf() const
Return cell face area vectors.
Definition: fvMeshGeometry.C:347
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::objectRegistry::foundObject
bool foundObject(const word &name) const
Is the named Type found?
Definition: objectRegistryTemplates.C:142
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::Vector< scalar >
Foam::ThermalDiffusivity
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Definition: ThermalDiffusivity.H:48
Foam::Time::timeName
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::functionObjectFile
Base class for output file data handling.
Definition: functionObjectFile.H:57
Foam::wallShearStress::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: wallShearStress.C:267
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::IncompressibleTurbulenceModel
Templated abstract base class for single-phase incompressible turbulence models.
Definition: IncompressibleTurbulenceModel.H:52
Foam::wallShearStress::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: wallShearStress.C:273
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:563
Foam::wallShearStress::read
virtual void read(const dictionary &)
Read the wallShearStress data.
Definition: wallShearStress.C:160
Foam::polyBoundaryMesh::patchSet
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
Definition: polyBoundaryMesh.C:750
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::functionObjectFile::writeCommented
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: functionObjectFile.C:219
Foam::wallShearStress::execute
virtual void execute()
Execute, currently does nothing.
Definition: wallShearStress.C:220
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::patchIdentifier::name
const word & name() const
Return name.
Definition: patchIdentifier.H:109
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:562
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
turbulentFluidThermoModel.H
Foam::wallShearStress
This function object evaluates and outputs the shear stress at wall patches. The result is written as...
Definition: wallShearStress.H:131