Loading...
Searching...
No Matches
volRegion.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) 2016 OpenFOAM Foundation
9 Copyright (C) 2016-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "volRegion.H"
30#include "volMesh.H"
31#include "cellSet.H"
32#include "globalMeshData.H"
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38namespace functionObjects
39{
41}
42}
43
44
45const Foam::Enum
46<
48>
50({
51 { regionTypes::vrtAll, "all" },
52 { regionTypes::vrtCellSet, "cellSet" },
53 { regionTypes::vrtCellZone, "cellZone" },
54});
55
56
57// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
58
59void Foam::functionObjects::volRegion::calculateCache()
60{
61 cellIds_.clear();
62 regionIDs_.clear();
63
64 // Update now. Need a valid state for the cellIDs() call
65 requireUpdate_ = false;
66
67 switch (regionType_)
68 {
69 case vrtAll:
70 {
71 nCells_ = volMesh_.globalData().nTotalCells();
72 V_ = gSum(volMesh_.V());
73 return;
74 break;
75 }
76
77 case vrtCellSet:
78 {
79 cellIds_ = cellSet(volMesh_, regionName_).sortedToc();
80 break;
81 }
82
83 case vrtCellZone:
84 {
85 regionIDs_ = volMesh_.cellZones().indices(regionName_);
86
87 if (regionIDs_.empty())
88 {
90 << "Unknown cell zone: " << regionName_ << nl
91 << " Valid zones : "
92 << flatOutput(volMesh_.cellZones().names()) << nl
93 << " Valid groups: "
94 << flatOutput(volMesh_.cellZones().groupNames()) << nl
95 << exit(FatalError);
96 }
97
98 if (regionIDs_.size() > 1)
99 {
100 cellIds_ =
101 volMesh_.cellZones().selection(regionIDs_).sortedToc();
102 }
103 break;
104 }
105 }
106
107
108 // Calculate cache value for nCells() and V()
109 const labelList& selected = this->cellIDs();
110
111 V_ = 0;
112 for (const label celli : selected)
113 {
114 V_ += volMesh_.V()[celli];
115 }
116
117 nCells_ = returnReduce(selected.size(), sumOp<label>());
118 reduce(V_, sumOp<scalar>());
119
120 if (!nCells_)
121 {
124 << '(' << regionName_ << "):" << nl
125 << " Region has no cells" << nl
127 }
128}
129
130
131// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
132
134(
135 const writeFile& wf,
136 Ostream& file
137) const
138{
139 wf.writeCommented(file, "Region");
140 file<< setw(1) << ':' << setw(1) << ' '
141 << regionTypeNames_[regionType_] << ' ' << regionName_ << endl;
142 wf.writeHeaderValue(file, "Cells", nCells_);
143 wf.writeHeaderValue(file, "Volume", V_);
144}
145
146
147// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
148
150(
151 const fvMesh& mesh,
152 const dictionary& dict
153)
154:
155 volMesh_(mesh),
156 cellIds_(),
157 regionIDs_(),
158 nCells_(0),
159 V_(Zero),
160 requireUpdate_(true),
161 regionType_
162 (
163 regionTypeNames_.getOrDefault
164 (
165 "regionType",
166 dict,
167 regionTypes::vrtAll
168 )
169 ),
170 regionName_(volMesh_.name())
172 read(dict);
173}
174
175
176// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
177
179{
180 switch (regionType_)
181 {
182 case vrtAll:
183 {
184 regionName_ = volMesh_.name();
185 break;
186 }
187
188 case vrtCellSet:
189 case vrtCellZone:
190 {
191 dict.readEntry("name", regionName_);
192 break;
193 }
194
195 default:
196 {
198 << "Unknown region type. Valid region types: "
199 << flatOutput(regionTypeNames_.names()) << nl
200 << exit(FatalIOError);
201 break;
202 }
204
205 calculateCache();
206 return true;
207}
208
209
211{
212 #ifdef FULLDEBUG
213 if (requireUpdate_)
214 {
216 << "Retrieving cached values that are not up-to-date" << nl
217 << exit(FatalError);
218 }
219 #endif
220
221 switch (regionType_)
222 {
223 case vrtCellSet:
224 {
225 return cellIds_;
226 break;
227 }
228
229 case vrtCellZone:
230 {
231 if (regionIDs_.size() == 1)
232 {
233 return volMesh_.cellZones()[regionIDs_.first()];
234 }
235 else
236 {
237 return cellIds_;
238 }
239 break;
240 }
241
242 default:
243 break;
244 }
245
246 return labelList::null();
247}
248
249
251{
252 if (requireUpdate_)
253 {
254 calculateCache();
255 return true;
256 }
257
258 return false;
259}
260
263{
264 requireUpdate_ = true;
265}
266
267
269{
270 requireUpdate_ = true;
271}
272
273
274// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
void clear()
Clear all entries.
Definition EnumI.H:74
static const List< label > & null() noexcept
Definition List.H:138
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Volume (cell) region selection class.
Definition volRegion.H:112
volRegion(const fvMesh &mesh, const dictionary &dict)
Construct from fvMesh and dictionary.
Definition volRegion.C:143
wordRe regionName_
Region name (cellSet, cellZone, ...).
Definition volRegion.H:188
virtual bool read(const dictionary &dict)
Read from dictionary.
Definition volRegion.C:171
static const Enum< regionTypes > regionTypeNames_
Region type names.
Definition volRegion.H:130
bool update()
Update the cached values as required.
Definition volRegion.C:243
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition volRegion.C:261
regionTypes regionType_
Region type.
Definition volRegion.H:183
regionTypes
Region type enumeration.
Definition volRegion.H:121
void writeFileHeader(const writeFile &wf, Ostream &file) const
Output file header information.
Definition volRegion.C:127
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition volRegion.C:255
const labelList & cellIDs() const
Return the local list of cell IDs.
Definition volRegion.C:203
Base class for writing single files from the function objects.
Definition writeFile.H:113
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition writeFile.C:318
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
Type gSum(const FieldField< Field, Type > &f)
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
List< label > labelList
A List of labels.
Definition List.H:62
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Omanip< int > setw(const int i)
Definition IOmanip.H:199
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict