surfaceZonesInfo.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2025 OpenFOAM Foundation
6  \\/ M anipulation |
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 "surfaceZonesInfo.H"
27 #include "searchableSurface.H"
28 #include "searchableSurfaceList.H"
29 #include "polyMesh.H"
30 #include "dictionary.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
36 {
37  "inside",
38  "outside",
39  "insidePoint",
40  "none"
41 };
42 
45 {
46  "internal",
47  "baffle",
48  "boundary"
49 };
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const searchableSurface& surface,
57  const dictionary& surfacesDict
58 )
59 :
60  faceZoneName_(),
61  cellZoneName_(),
62  zoneInside_(NONE),
63  zoneInsidePoint_(point::min),
64  faceType_(INTERNAL)
65 {
66  // Global zone names per surface
67  if (surfacesDict.readIfPresent("faceZone", faceZoneName_))
68  {
69  // Read optional entry to determine inside of faceZone
70 
71  word method;
72  bool hasSide =
73  surfacesDict.readIfPresent("mode", method)
74  || surfacesDict.readIfPresent("cellZoneInside", method);
75 
76  if (hasSide)
77  {
78  zoneInside_ = areaSelectionAlgoNames[method];
79  if (zoneInside_ == INSIDEPOINT)
80  {
81  zoneInsidePoint_ =
82  surfacesDict.lookup<point>("insidePoint", dimLength);
83  }
84  }
85 
86  // Read optional cellZone name
87 
88  if (surfacesDict.readIfPresent("cellZone", cellZoneName_))
89  {
90  if
91  (
92  (
93  zoneInside_ == INSIDE
94  || zoneInside_ == OUTSIDE
95  )
96  && !surface.hasVolumeType()
97  )
98  {
100  (
101  surfacesDict
102  ) << "Illegal entry zoneInside "
103  << areaSelectionAlgoNames[zoneInside_]
104  << " for faceZone "
105  << faceZoneName_
106  << " since surface is not closed." << endl;
107  }
108  }
109  else if (hasSide)
110  {
112  (
113  surfacesDict
114  ) << "Unused entry zoneInside for faceZone "
115  << faceZoneName_
116  << " since no cellZone specified."
117  << endl;
118  }
119 
120  // How to handle faces on faceZone
121  word faceTypeMethod;
122  if (surfacesDict.readIfPresent("faceType", faceTypeMethod))
123  {
124  faceType_ = faceZoneTypeNames[faceTypeMethod];
125  }
126  }
127 }
128 
129 
131 (
132  const word& faceZoneName,
133  const word& cellZoneName,
134  const areaSelectionAlgo& zoneInside,
135  const point& zoneInsidePoint,
136  const faceZoneType& faceType
137 )
138 :
139  faceZoneName_(faceZoneName),
140  cellZoneName_(cellZoneName),
141  zoneInside_(zoneInside),
142  zoneInsidePoint_(zoneInsidePoint),
143  faceType_(faceType)
144 {}
145 
146 
148 :
149  faceZoneName_(surfZone.faceZoneName()),
150  cellZoneName_(surfZone.cellZoneName()),
151  zoneInside_(surfZone.zoneInside()),
152  zoneInsidePoint_(surfZone.zoneInsidePoint()),
153  faceType_(surfZone.faceType())
154 {}
155 
156 
158 (
159  const PtrList<surfaceZonesInfo>& surfList
160 )
161 {
162  labelList anonymousSurfaces(surfList.size());
163 
164  label i = 0;
165  forAll(surfList, surfi)
166  {
167  if (surfList[surfi].faceZoneName().empty())
168  {
169  anonymousSurfaces[i++] = surfi;
170  }
171  }
172  anonymousSurfaces.setSize(i);
173 
174  return anonymousSurfaces;
175 }
176 
177 
179 (
180  const PtrList<surfaceZonesInfo>& surfList
181 )
182 {
183  labelList namedSurfaces(surfList.size());
184 
185  label namedI = 0;
186  forAll(surfList, surfi)
187  {
188  if
189  (
190  surfList.set(surfi)
191  && surfList[surfi].faceZoneName().size()
192  )
193  {
194  namedSurfaces[namedI++] = surfi;
195  }
196  }
197  namedSurfaces.setSize(namedI);
198 
199  return namedSurfaces;
200 }
201 
202 
204 (
205  const PtrList<surfaceZonesInfo>& surfList,
206  const searchableSurfaceList& allGeometry,
207  const labelList& surfaces
208 )
209 {
210  labelList closed(surfList.size());
211 
212  label closedI = 0;
213  forAll(surfList, surfi)
214  {
215  if
216  (
217  surfList.set(surfi)
218  && surfList[surfi].cellZoneName().size()
219  && (
220  surfList[surfi].zoneInside() == surfaceZonesInfo::INSIDE
221  || surfList[surfi].zoneInside() == surfaceZonesInfo::OUTSIDE
222  )
223  && allGeometry[surfaces[surfi]].hasVolumeType()
224  )
225  {
226  closed[closedI++] = surfi;
227  }
228  }
229  closed.setSize(closedI);
230 
231  return closed;
232 }
233 
234 
236 (
237  const PtrList<surfaceZonesInfo>& surfList,
238  const searchableSurfaceList& allGeometry,
239  const labelList& surfaces
240 )
241 {
242  labelList unclosed(surfList.size());
243 
244  label unclosedI = 0;
245  forAll(surfList, surfi)
246  {
247  if
248  (
249  surfList.set(surfi)
250  && !allGeometry[surfaces[surfi]].hasVolumeType()
251  )
252  {
253  unclosed[unclosedI++] = surfi;
254  }
255  }
256  unclosed.setSize(unclosedI);
257 
258  return unclosed;
259 }
260 
261 
263 (
264  const PtrList<surfaceZonesInfo>& surfList,
265  const searchableSurfaceList& allGeometry,
266  const labelList& surfaces
267 )
268 {
269  labelList closed(surfList.size());
270 
271  label closedI = 0;
272  forAll(surfList, surfi)
273  {
274  if
275  (
276  surfList.set(surfi)
277  && surfList[surfi].cellZoneName().size()
278  && allGeometry[surfaces[surfi]].hasVolumeType()
279  )
280  {
281  closed[closedI++] = surfi;
282  }
283  }
284  closed.setSize(closedI);
285 
286  return closed;
287 }
288 
289 
291 (
292  const PtrList<surfaceZonesInfo>& surfList
293 )
294 {
295  labelList closed(surfList.size());
296 
297  label closedI = 0;
298  forAll(surfList, surfi)
299  {
300  if
301  (
302  surfList.set(surfi)
303  && surfList[surfi].cellZoneName().size()
304  && surfList[surfi].zoneInside() == surfaceZonesInfo::INSIDEPOINT
305  )
306  {
307  closed[closedI++] = surfi;
308  }
309  }
310  closed.setSize(closedI);
311 
312  return closed;
313 }
314 
315 
317 (
318  const PtrList<surfaceZonesInfo>& surfList,
319  const labelList& namedSurfaces,
320  polyMesh& mesh
321 )
322 {
323  labelList surfaceToCellZone(surfList.size(), -1);
324 
325  cellZoneList& cellZones = mesh.cellZones();
326 
327  forAll(namedSurfaces, i)
328  {
329  label surfi = namedSurfaces[i];
330 
331  const word& cellZoneName = surfList[surfi].cellZoneName();
332 
333  if (cellZoneName != word::null)
334  {
335  label zonei = cellZones.findIndex(cellZoneName);
336 
337  if (zonei == -1)
338  {
339  zonei = cellZones.size();
340  cellZones.setSize(zonei+1);
341  cellZones.set
342  (
343  zonei,
344  new cellZone
345  (
346  cellZoneName, // name
347  labelList(0), // addressing
348  cellZones // cellZones
349  )
350  );
351  }
352 
353  surfaceToCellZone[surfi] = zonei;
354  }
355  }
356 
357  // Check they are synced
358  List<wordList> allCellZones(Pstream::nProcs());
359  allCellZones[Pstream::myProcNo()] = cellZones.toc();
360  Pstream::gatherList(allCellZones);
361  Pstream::scatterList(allCellZones);
362 
363  for (label proci = 1; proci < allCellZones.size(); proci++)
364  {
365  if (allCellZones[proci] != allCellZones[0])
366  {
368  << "Zones not synchronised among processors." << nl
369  << " Processor0 has cellZones:" << allCellZones[0]
370  << " , processor" << proci
371  << " has cellZones:" << allCellZones[proci]
372  << exit(FatalError);
373  }
374  }
375 
376  return surfaceToCellZone;
377 }
378 
379 
381 (
382  const PtrList<surfaceZonesInfo>& surfList,
383  const labelList& namedSurfaces,
384  polyMesh& mesh
385 )
386 {
387  labelList surfaceToFaceZone(surfList.size(), -1);
388 
389  faceZoneList& faceZones = mesh.faceZones();
390 
391  forAll(namedSurfaces, i)
392  {
393  label surfi = namedSurfaces[i];
394 
395  const word& faceZoneName = surfList[surfi].faceZoneName();
396 
397  label zonei = faceZones.findIndex(faceZoneName);
398 
399  if (zonei == -1)
400  {
401  zonei = faceZones.size();
402  faceZones.setSize(zonei+1);
403  faceZones.set
404  (
405  zonei,
406  new faceZone
407  (
408  faceZoneName, // name
409  labelList(0), // addressing
410  boolList(0), // flipmap
411  faceZones // faceZones
412  )
413  );
414  }
415 
416  surfaceToFaceZone[surfi] = zonei;
417  }
418 
419  // Check they are synced
420  List<wordList> allFaceZones(Pstream::nProcs());
421  allFaceZones[Pstream::myProcNo()] = faceZones.toc();
422  Pstream::gatherList(allFaceZones);
423  Pstream::scatterList(allFaceZones);
424 
425  for (label proci = 1; proci < allFaceZones.size(); proci++)
426  {
427  if (allFaceZones[proci] != allFaceZones[0])
428  {
430  << "Zones not synchronised among processors." << nl
431  << " Processor0 has faceZones:" << allFaceZones[0]
432  << " , processor" << proci
433  << " has faceZones:" << allFaceZones[proci]
434  << exit(FatalError);
435  }
436  }
437 
438  return surfaceToFaceZone;
439 }
440 
441 
442 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
wordList toc() const
Return the table of contents.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
autoPtr< T > set(const label, const word &key, T *)
Set element to pointer provided and return old element.
label findIndex(const word &key) const
Return the index of the given the key or -1 if not found.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
bool set(const label) const
Is element set.
Definition: PtrListI.H:62
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
Named list of cell indices representing a sub-set of the mesh.
Definition: cellZone.H:61
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:740
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Named list of face indices representing a sub-set of the mesh faces.
Definition: faceZone.H:66
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const cellZoneList & cellZones() const
Return cell zones.
Definition: polyMesh.H:449
const faceZoneList & faceZones() const
Return face zones.
Definition: polyMesh.H:443
Container for searchableSurfaces.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
virtual bool hasVolumeType() const =0
Whether supports volume type below.
A surface zone on a MeshedSurface.
Definition: surfZone.H:65
static labelList getInsidePointNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of surfaces with a cellZone that have 'insidePoint'.
areaSelectionAlgo
Types of selection of area.
static const NamedEnum< faceZoneType, 3 > faceZoneTypeNames
static labelList getUnnamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of unnamed surfaces (surfaces without faceZoneName)
faceZoneType
What to do with faceZone faces.
static labelList getNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces (surfaces with faceZoneName)
static const NamedEnum< areaSelectionAlgo, 4 > areaSelectionAlgoNames
static labelList getClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaceList &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed and.
surfaceZonesInfo(const searchableSurface &surface, const dictionary &surfacesDict)
Construct from surfaces and dictionary.
static labelList getAllClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaceList &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed.
static labelList addFaceZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
static labelList getUnclosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaceList &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are unclosed.
static labelList addCellZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
const dimensionSet dimLength
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
error FatalError
static const char nl
Definition: Ostream.H:267