Loading...
Searching...
No Matches
faceSetOption.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) 2019-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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 "faceSetOption.H"
29#include "faceSet.H"
30#include "areaFields.H"
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36 namespace fa
37 {
39 }
40}
41
42
43const Foam::Enum
44<
46>
48({
49 { selectionModeType::smAll, "all" },
50 { selectionModeType::smFaceSet, "faceSet" },
51 { selectionModeType::smFaceZone, "faceZone" },
53 { selectionModeType::smFaceZone, "volFaceZone" } // Compat?
54});
55
56
57// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
58
60{
62
63 switch (selectionMode_)
64 {
65 case smAll:
66 {
67 break;
68 }
69 case smFaceSet:
70 {
71 selectionNames_.resize(1);
72 dict.readEntry("faceSet", selectionNames_.first());
73 break;
74 }
75 case smFaceZone:
76 {
77 if
78 (
79 !dict.readIfPresent("faceZones", selectionNames_)
80 || selectionNames_.empty()
81 )
82 {
83 selectionNames_.resize(1);
84 dict.readEntry("faceZone", selectionNames_.first());
85 }
86 break;
87 }
88 case smPatch:
89 {
90 if
91 (
92 !dict.readIfPresent("patches", selectionNames_)
93 || selectionNames_.empty()
94 )
95 {
96 selectionNames_.resize(1);
97 dict.readEntry("patch", selectionNames_.first());
98 }
99 break;
100 }
101 default:
102 {
104 << "Unknown selectionMode "
106 << ". Valid selectionMode types : "
108 << exit(FatalError);
109 }
110 }
111}
112
113
115{
116 // Set area information
117
118 scalar sumArea = 0;
119 {
120 const auto& meshAreas = regionMesh().S();
121
122 for (const label facei : faces_)
123 {
124 sumArea += meshAreas[facei];
125 }
126 }
127 reduce(sumArea, sumOp<scalar>());
128
129 const scalar old(A_);
130 A_ = sumArea;
131
132 // Compare area values, stringified using current write precision
133 if
134 (
137 )
138 {
140 << "- selected " << returnReduce(faces_.size(), sumOp<label>())
141 << " face(s) with area " << A_ << endl;
142 }
143}
144
145
147{
148 switch (selectionMode_)
149 {
150 case smAll:
151 {
152 Info<< indent << "- selecting all faces" << endl;
153 faces_ = identity(regionMesh().nFaces());
154
155 break;
156 }
157
158 case smFaceSet:
159 {
160 Info<< indent
161 << "- selecting face subset using volume-mesh faceSet "
162 << zoneName() << nl;
163
164 const faceSet subset(mesh_, zoneName());
165
166 const labelUList& faceLabels = regionMesh().faceLabels();
167
168 faces_.resize_nocopy(faceLabels.size());
169
170 label nUsed = 0;
171 forAll(faceLabels, facei)
172 {
173 const label meshFacei = faceLabels[facei];
174
175 if (subset.test(meshFacei))
176 {
177 faces_[nUsed] = facei;
178 ++nUsed;
179 }
180 }
181 faces_.resize(nUsed);
182 break;
183 }
184
185 case smFaceZone:
186 {
187 Info<< indent
188 << "- selecting face subset using volume-mesh faceZones "
189 << flatOutput(selectionNames_) << nl;
190
191 const auto& zones = mesh_.faceZones();
192
193 // Also handles groups, multiple zones etc ...
194 labelList zoneIDs = zones.indices(selectionNames_);
195
196 if (zoneIDs.empty())
197 {
199 << "No matching faceZones: "
200 << flatOutput(selectionNames_) << nl
201 << "Valid zones : "
202 << flatOutput(zones.names()) << nl
203 << "Valid groups: "
204 << flatOutput(zones.groupNames())
205 << nl
206 << exit(FatalError);
207 }
208
209 const bitSet subset(mesh_.faceZones().selection(zoneIDs));
210
211 const labelUList& faceLabels = regionMesh().faceLabels();
212
213 faces_.resize_nocopy(faceLabels.size());
214
215 label nUsed = 0;
216 forAll(faceLabels, facei)
217 {
218 const label meshFacei = faceLabels[facei];
219
220 if (subset.test(meshFacei))
221 {
222 faces_[nUsed] = facei;
223 ++nUsed;
224 }
225 }
226 faces_.resize(nUsed);
227 break;
228 }
229
230 case smPatch:
231 {
232 Info<< indent
233 << "- selecting face subset using volume-mesh patches "
234 << flatOutput(selectionNames_) << nl;
235
236 const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
237
238 // Also handles groups, multiple patches etc ...
239 labelList patchIDs = pbm.indices(selectionNames_);
240
241 if (patchIDs.empty())
242 {
244 << "No matching patches: "
245 << flatOutput(selectionNames_) << nl
246 << "Valid patches : "
247 << flatOutput(pbm.names()) << nl
248 << "Valid groups: "
249 << flatOutput(pbm.groupNames()) << nl
250 << exit(FatalError);
251 }
252
253 const List<labelPair>& patchFaces = regionMesh().whichPatchFaces();
254
255 faces_.resize_nocopy(patchFaces.size());
256
257 label nUsed = 0;
258 forAll(patchFaces, facei)
259 {
260 const label patchi = patchFaces[facei].first();
261
262 if (patchIDs.found(patchi))
263 {
264 faces_[nUsed] = facei;
265 ++nUsed;
266 }
267 }
268 faces_.resize(nUsed);
269 break;
270 }
271
272 default:
273 {
275 << "Unknown selectionMode "
276 << selectionModeTypeNames_[selectionMode_]
277 << ". Valid selectionMode types are "
278 << selectionModeTypeNames_
279 << exit(FatalError);
280 }
281 }
282
283 if (smAll != selectionMode_ && returnReduceAnd(faces_.empty()))
284 {
286 << "No faces selected!" << endl;
287 }
288}
289
290
291// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
292
294(
295 const word& name,
296 const word& modelType,
297 const dictionary& dict,
298 const fvMesh& mesh,
299 const word& defaultAreaName
300)
301:
302 fa::option(name, modelType, dict, mesh, defaultAreaName),
303 timeStart_(-1),
304 duration_(0),
305 selectionMode_(selectionModeTypeNames_.get("selectionMode", coeffs_)),
306 selectionNames_(),
307 A_(0)
308{
309 if (isActive())
310 {
312 read(dict);
315 setArea();
317 }
318}
319
320
321// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
322
324{
325 if (fa::option::isActive() && inTimeLimits(mesh_.time().value()))
326 {
327 // Update the face set if the mesh is changing
328 if (mesh_.changing())
329 {
330 if (mesh_.topoChanging())
331 {
332 setArea();
333 // Force printing of new set area
334 A_ = -GREAT;
335 }
336
337 // Report new area (if changed)
338 setArea();
339 }
340
341 return true;
342 }
343
344 return false;
345}
346
347
349{
351 {
352 timeStart_ = -1;
353
354 if (coeffs_.readIfPresent("timeStart", timeStart_))
355 {
356 coeffs_.readEntry("duration", duration_);
357 }
358
359 return true;
360 }
361
362 return false;
363}
364
365
366// ************************************************************************* //
labelList faceLabels(nFaceLabels)
labelList patchIDs
const polyBoundaryMesh & pbm
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition IOstream.H:437
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition ListI.H:171
void clear()
Clear the list, i.e. set size to zero.
Definition ListI.H:133
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition Time.C:714
const word & timeName() const noexcept
The current time name.
Definition TimeStateI.H:30
T & first()
Access first element of the list, position [0].
Definition UList.H:957
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Intermediate abstract class for handling face-set options for the derived faOptions.
labelList faces_
Set of faces to apply source to.
void setFaceSelection()
Set face selection based on user input selection mode.
wordRes selectionNames_
Face selection names (for set, zone or patch selections).
void setSelection(const dictionary &dict)
Set face selection name from dictionary input.
scalar A_
Sum of face area.
selectionModeType
Enumeration for selection mode types.
@ smPatch
"patch" : subset with (volume) patches
@ smFaceZone
"faceZone" : subset with (volume) zone faces
@ smAll
"all" finite-area faces
@ smFaceSet
"faceSet" : subset with (volume) face set
virtual bool read(const dictionary &dict)
Read source dictionary.
scalar duration_
Duration.
scalar timeStart_
Time start.
const wordRe & zoneName() const
Return const access to the first set/zone/patch name.
virtual bool isActive()
Is the source active?
faceSetOption(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh, const word &defaultAreaName=word())
Construct from components.
selectionModeType selectionMode_
Face selection mode.
static const Enum< selectionModeType > selectionModeTypeNames_
List of selection mode type names.
bool inTimeLimits(const scalar timeValue) const
Return true if within time limits.
void setArea()
Recalculate the area.
const fvMesh & mesh() const noexcept
Return const access to the volume mesh.
Definition faOption.H:385
virtual bool read(const dictionary &dict)
Read source dictionary.
const fvMesh & mesh_
Reference to the mesh database.
Definition faOption.H:175
virtual bool isActive()
Is the source active?
dictionary coeffs_
Dictionary containing source coefficients.
Definition faOption.H:185
const word & name() const noexcept
The source name.
Definition faOption.H:380
option(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh, const word &defaultAreaName=word())
Construct from components.
const faMesh & regionMesh() const
Return the region mesh database (demand-driven).
Definition faOptionI.H:37
A list of face labels.
Definition faceSet.H:50
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const labelIOList & zoneIDs
Definition correctPhi.H:59
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for finite-area.
Definition limitHeight.C:30
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
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.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition Ostream.H:490
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
Ostream & indent(Ostream &os)
Indent stream.
Definition Ostream.H:481
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
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
UList< label > labelUList
A UList of labels.
Definition UList.H:75
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition Ostream.H:499
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299