fieldExtents.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) 2018-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "fieldExtents.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
37  defineTypeNameAndDebug(fieldExtents, 0);
38  addToRunTimeSelectionTable(functionObject, fieldExtents, dictionary);
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 
46 {
48  {
49  return;
50  }
51 
52  if (writtenHeader_)
53  {
54  writeBreak(os);
55  }
56  else
57  {
58  writeHeader(os, "Field extents");
59  writeHeaderValue(os, "Reference position", C0_);
60  writeHeaderValue(os, "Threshold", threshold_);
61  }
62 
63  writeCommented(os, "Time");
64 
65  for (const word& fieldName : fieldSet_.selectionNames())
66  {
67  if (internalField_)
68  {
69  writeTabbed(os, fieldName + "_internal");
70  }
71  for (const label patchi : patchIDs_)
72  {
73  const word& patchName = mesh_.boundaryMesh()[patchi].name();
74  writeTabbed(os, fieldName + "_" + patchName);
75  }
76  }
77 
78  os << endl;
79 
80  writtenHeader_ = true;
81 }
82 
83 
84 template<>
86 (
88 ) const
89 {
90  return
91  pos
92  (
93  field
94  - dimensionedScalar("t", field.dimensions(), threshold_)
95  );
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 
102 (
103  const word& name,
104  const Time& runTime,
105  const dictionary& dict
106 )
107 :
109  writeFile(mesh_, name, typeName, dict),
110  internalField_(true),
111  threshold_(0),
112  C0_(Zero),
113  fieldSet_(mesh_),
114  patchIDs_()
115 {
116  read(dict);
117 
118  // Note: delay creating the output file header to handle field names
119  // specified using regular expressions
120 }
121 
122 
123 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
124 
126 {
128  {
129  dict.readIfPresent<bool>("internalField", internalField_);
130 
131  threshold_ = dict.get<scalar>("threshold");
132 
133  dict.readIfPresent<vector>("referencePosition", C0_);
134 
135  patchIDs_.clear();
136  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
137 
139  if (dict.readIfPresent("patches", patchNames))
140  {
141  for (const wordRe& name : patchNames)
142  {
143  patchIDs_.insert(pbm.indices(name));
144  }
145  }
146  else
147  {
148  // Add all non-processor and non-empty patches
149  forAll(pbm, patchi)
150  {
151  const polyPatch& pp = pbm[patchi];
152  if (!isA<processorPolyPatch>(pp) && !isA<emptyPolyPatch>(pp))
153  {
154  patchIDs_.insert(patchi);
155  }
156  }
157  }
158 
159  if (!internalField_ && patchIDs_.empty())
160  {
162  << "No internal field or patches selected - no field extent "
163  << "information will be generated" << endl;
164  }
165 
166  fieldSet_.read(dict);
167 
168  return true;
169  }
170 
171  return false;
172 }
173 
174 
176 {
177  return true;
178 }
179 
180 
182 {
183  writeFileHeader(file());
184 
185  Log << type() << " " << name() << " write:" << nl;
186 
187  for (const word& fieldName : fieldSet_.selectionNames())
188  {
189  calcFieldExtents<scalar>(fieldName, true);
190  calcFieldExtents<vector>(fieldName);
191  calcFieldExtents<sphericalTensor>(fieldName);
192  calcFieldExtents<symmTensor>(fieldName);
193  calcFieldExtents<tensor>(fieldName);
194  }
195 
196  Log << endl;
197 
198  return true;
199 }
200 
201 
202 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::fieldExtents::patchIDs_
labelHashSet patchIDs_
Patches to assess.
Definition: fieldExtents.H:206
Log
#define Log
Definition: PDRblock.C:35
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::fieldExtents::calcMask
tmp< volScalarField > calcMask(const GeometricField< Type, fvPatchField, volMesh > &field) const
Return the field mask.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::functionObjects::writeFile::writtenHeader_
bool writtenHeader_
Flag to identify whether the header has been written.
Definition: writeFile.H:148
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
fieldExtents.H
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::fieldExtents::fieldSet_
volFieldSelection fieldSet_
Fields to assess.
Definition: fieldExtents.H:203
Foam::functionObjects::fieldExtents::execute
virtual bool execute()
Execute, currently does nothing.
Definition: fieldExtents.C:175
Foam::functionObjects::fieldSelection::selectionNames
wordHashSet selectionNames() const
Return the current field selection.
Definition: fieldSelectionI.H:50
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::writeFile::writeHeaderValue
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
Definition: writeFileTemplates.C:32
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:80
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:298
Foam::functionObjects::writeFile::writeBreak
virtual void writeBreak(Ostream &os) const
Write a break marker to the stream.
Definition: writeFile.C:321
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:213
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::functionObjects::fieldExtents::internalField_
bool internalField_
Flag to write the internal field extents.
Definition: fieldExtents.H:194
Foam::functionObjects::fieldExtents::C0_
point C0_
Reference position.
Definition: fieldExtents.H:200
Foam::functionObjects::fieldExtents::writeFileHeader
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: fieldExtents.C:45
Foam::functionObjects::volFieldSelection::updateSelection
virtual bool updateSelection()
Update the selection using current contents of obr_.
Definition: volFieldSelection.C:46
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
field
rDeltaTY field()
patchNames
wordList patchNames(nPatches)
Foam::functionObjects::fieldExtents::fieldExtents
fieldExtents(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: fieldExtents.C:102
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::functionObjects::fieldExtents::threshold_
scalar threshold_
Threshold value.
Definition: fieldExtents.H:197
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
Foam::functionObjects::fieldExtents::read
virtual bool read(const dictionary &)
Read the field extents data.
Definition: fieldExtents.C:125
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:272
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::Vector< scalar >
Foam::polyBoundaryMesh::indices
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) patch indices for all matches.
Definition: polyBoundaryMesh.C:642
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::functionObjects::fvMeshFunctionObject::mesh_
const fvMesh & mesh_
Reference to the fvMesh.
Definition: fvMeshFunctionObject.H:73
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::functionObjects::fieldExtents::write
virtual bool write()
Write the fieldExtents.
Definition: fieldExtents.C:181
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:340
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:288
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177