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-2024 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 "searchableSurfaces.H"
29 #include "polyMesh.H"
30 #include "dictionary.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  template<>
37  const char* Foam::NamedEnum
38  <
40  4
41  >::names[] =
42  {
43  "inside",
44  "outside",
45  "insidePoint",
46  "none"
47  };
48 }
51 
52 
53 namespace Foam
54 {
55  template<>
56  const char* Foam::NamedEnum
57  <
59  3
60  >::names[] =
61  {
62  "internal",
63  "baffle",
64  "boundary"
65  };
66 }
69 
70 
71 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
72 
74 (
75  const searchableSurface& surface,
76  const dictionary& surfacesDict
77 )
78 :
79  faceZoneName_(),
80  cellZoneName_(),
81  zoneInside_(NONE),
82  zoneInsidePoint_(point::min),
83  faceType_(INTERNAL)
84 {
85  // Global zone names per surface
86  if (surfacesDict.readIfPresent("faceZone", faceZoneName_))
87  {
88  // Read optional entry to determine inside of faceZone
89 
90  word method;
91  bool hasSide =
92  surfacesDict.readIfPresent("mode", method)
93  || surfacesDict.readIfPresent("cellZoneInside", method);
94 
95  if (hasSide)
96  {
97  zoneInside_ = areaSelectionAlgoNames[method];
98  if (zoneInside_ == INSIDEPOINT)
99  {
100  zoneInsidePoint_ =
101  surfacesDict.lookup<point>("insidePoint", dimLength);
102  }
103  }
104 
105  // Read optional cellZone name
106 
107  if (surfacesDict.readIfPresent("cellZone", cellZoneName_))
108  {
109  if
110  (
111  (
112  zoneInside_ == INSIDE
113  || zoneInside_ == OUTSIDE
114  )
115  && !surface.hasVolumeType()
116  )
117  {
119  (
120  surfacesDict
121  ) << "Illegal entry zoneInside "
122  << areaSelectionAlgoNames[zoneInside_]
123  << " for faceZone "
124  << faceZoneName_
125  << " since surface is not closed." << endl;
126  }
127  }
128  else if (hasSide)
129  {
131  (
132  surfacesDict
133  ) << "Unused entry zoneInside for faceZone "
134  << faceZoneName_
135  << " since no cellZone specified."
136  << endl;
137  }
138 
139  // How to handle faces on faceZone
140  word faceTypeMethod;
141  if (surfacesDict.readIfPresent("faceType", faceTypeMethod))
142  {
143  faceType_ = faceZoneTypeNames[faceTypeMethod];
144  }
145  }
146 }
147 
148 
150 (
151  const word& faceZoneName,
152  const word& cellZoneName,
153  const areaSelectionAlgo& zoneInside,
154  const point& zoneInsidePoint,
155  const faceZoneType& faceType
156 )
157 :
158  faceZoneName_(faceZoneName),
159  cellZoneName_(cellZoneName),
160  zoneInside_(zoneInside),
161  zoneInsidePoint_(zoneInsidePoint),
162  faceType_(faceType)
163 {}
164 
165 
167 :
168  faceZoneName_(surfZone.faceZoneName()),
169  cellZoneName_(surfZone.cellZoneName()),
170  zoneInside_(surfZone.zoneInside()),
171  zoneInsidePoint_(surfZone.zoneInsidePoint()),
172  faceType_(surfZone.faceType())
173 {}
174 
175 
177 (
178  const PtrList<surfaceZonesInfo>& surfList
179 )
180 {
181  labelList anonymousSurfaces(surfList.size());
182 
183  label i = 0;
184  forAll(surfList, surfi)
185  {
186  if (surfList[surfi].faceZoneName().empty())
187  {
188  anonymousSurfaces[i++] = surfi;
189  }
190  }
191  anonymousSurfaces.setSize(i);
192 
193  return anonymousSurfaces;
194 }
195 
196 
198 (
199  const PtrList<surfaceZonesInfo>& surfList
200 )
201 {
202  labelList namedSurfaces(surfList.size());
203 
204  label namedI = 0;
205  forAll(surfList, surfi)
206  {
207  if
208  (
209  surfList.set(surfi)
210  && surfList[surfi].faceZoneName().size()
211  )
212  {
213  namedSurfaces[namedI++] = surfi;
214  }
215  }
216  namedSurfaces.setSize(namedI);
217 
218  return namedSurfaces;
219 }
220 
221 
223 (
224  const PtrList<surfaceZonesInfo>& surfList,
225  const searchableSurfaces& allGeometry,
226  const labelList& surfaces
227 )
228 {
229  labelList closed(surfList.size());
230 
231  label closedI = 0;
232  forAll(surfList, surfi)
233  {
234  if
235  (
236  surfList.set(surfi)
237  && surfList[surfi].cellZoneName().size()
238  && (
239  surfList[surfi].zoneInside() == surfaceZonesInfo::INSIDE
240  || surfList[surfi].zoneInside() == surfaceZonesInfo::OUTSIDE
241  )
242  && allGeometry[surfaces[surfi]].hasVolumeType()
243  )
244  {
245  closed[closedI++] = surfi;
246  }
247  }
248  closed.setSize(closedI);
249 
250  return closed;
251 }
252 
253 
255 (
256  const PtrList<surfaceZonesInfo>& surfList,
257  const searchableSurfaces& allGeometry,
258  const labelList& surfaces
259 )
260 {
261  labelList unclosed(surfList.size());
262 
263  label unclosedI = 0;
264  forAll(surfList, surfi)
265  {
266  if
267  (
268  surfList.set(surfi)
269  && !allGeometry[surfaces[surfi]].hasVolumeType()
270  )
271  {
272  unclosed[unclosedI++] = surfi;
273  }
274  }
275  unclosed.setSize(unclosedI);
276 
277  return unclosed;
278 }
279 
280 
282 (
283  const PtrList<surfaceZonesInfo>& surfList,
284  const searchableSurfaces& allGeometry,
285  const labelList& surfaces
286 )
287 {
288  labelList closed(surfList.size());
289 
290  label closedI = 0;
291  forAll(surfList, surfi)
292  {
293  if
294  (
295  surfList.set(surfi)
296  && surfList[surfi].cellZoneName().size()
297  && allGeometry[surfaces[surfi]].hasVolumeType()
298  )
299  {
300  closed[closedI++] = surfi;
301  }
302  }
303  closed.setSize(closedI);
304 
305  return closed;
306 }
307 
308 
310 (
311  const PtrList<surfaceZonesInfo>& surfList
312 )
313 {
314  labelList closed(surfList.size());
315 
316  label closedI = 0;
317  forAll(surfList, surfi)
318  {
319  if
320  (
321  surfList.set(surfi)
322  && surfList[surfi].cellZoneName().size()
323  && surfList[surfi].zoneInside() == surfaceZonesInfo::INSIDEPOINT
324  )
325  {
326  closed[closedI++] = surfi;
327  }
328  }
329  closed.setSize(closedI);
330 
331  return closed;
332 }
333 
334 
336 (
337  const PtrList<surfaceZonesInfo>& surfList,
338  const labelList& namedSurfaces,
339  polyMesh& mesh
340 )
341 {
342  labelList surfaceToCellZone(surfList.size(), -1);
343 
344  cellZoneList& cellZones = mesh.cellZones();
345 
346  forAll(namedSurfaces, i)
347  {
348  label surfi = namedSurfaces[i];
349 
350  const word& cellZoneName = surfList[surfi].cellZoneName();
351 
352  if (cellZoneName != word::null)
353  {
354  label zonei = cellZones.findIndex(cellZoneName);
355 
356  if (zonei == -1)
357  {
358  zonei = cellZones.size();
359  cellZones.setSize(zonei+1);
360  cellZones.set
361  (
362  zonei,
363  new cellZone
364  (
365  cellZoneName, // name
366  labelList(0), // addressing
367  cellZones // cellZones
368  )
369  );
370  }
371 
372  surfaceToCellZone[surfi] = zonei;
373  }
374  }
375 
376  // Check they are synced
377  List<wordList> allCellZones(Pstream::nProcs());
378  allCellZones[Pstream::myProcNo()] = cellZones.toc();
379  Pstream::gatherList(allCellZones);
380  Pstream::scatterList(allCellZones);
381 
382  for (label proci = 1; proci < allCellZones.size(); proci++)
383  {
384  if (allCellZones[proci] != allCellZones[0])
385  {
387  << "Zones not synchronised among processors." << nl
388  << " Processor0 has cellZones:" << allCellZones[0]
389  << " , processor" << proci
390  << " has cellZones:" << allCellZones[proci]
391  << exit(FatalError);
392  }
393  }
394 
395  return surfaceToCellZone;
396 }
397 
398 
400 (
401  const PtrList<surfaceZonesInfo>& surfList,
402  const labelList& namedSurfaces,
403  polyMesh& mesh
404 )
405 {
406  labelList surfaceToFaceZone(surfList.size(), -1);
407 
408  faceZoneList& faceZones = mesh.faceZones();
409 
410  forAll(namedSurfaces, i)
411  {
412  label surfi = namedSurfaces[i];
413 
414  const word& faceZoneName = surfList[surfi].faceZoneName();
415 
416  label zonei = faceZones.findIndex(faceZoneName);
417 
418  if (zonei == -1)
419  {
420  zonei = faceZones.size();
421  faceZones.setSize(zonei+1);
422  faceZones.set
423  (
424  zonei,
425  new faceZone
426  (
427  faceZoneName, // name
428  labelList(0), // addressing
429  boolList(0), // flipmap
430  faceZones // faceZones
431  )
432  );
433  }
434 
435  surfaceToFaceZone[surfi] = zonei;
436  }
437 
438  // Check they are synced
439  List<wordList> allFaceZones(Pstream::nProcs());
440  allFaceZones[Pstream::myProcNo()] = faceZones.toc();
441  Pstream::gatherList(allFaceZones);
442  Pstream::scatterList(allFaceZones);
443 
444  for (label proci = 1; proci < allFaceZones.size(); proci++)
445  {
446  if (allFaceZones[proci] != allFaceZones[0])
447  {
449  << "Zones not synchronised among processors." << nl
450  << " Processor0 has faceZones:" << allFaceZones[0]
451  << " , processor" << proci
452  << " has faceZones:" << allFaceZones[proci]
453  << exit(FatalError);
454  }
455  }
456 
457  return surfaceToFaceZone;
458 }
459 
460 
461 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:54
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
A subset of mesh cells.
Definition: cellZone.H:58
A list of keyword definitions, which are a keyword followed by any number of values (e....
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:710
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:59
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const cellZoneList & cellZones() const
Return cell zones.
Definition: polyMesh.H:452
const faceZoneList & faceZones() const
Return face zones.
Definition: polyMesh.H:446
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
virtual bool hasVolumeType() const =0
Whether supports volume type below.
Container for searchableSurfaces.
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
surfaceZonesInfo(const searchableSurface &surface, const dictionary &surfacesDict)
Construct from surfaces and dictionary.
static labelList addFaceZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
static labelList getAllClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed.
static labelList addCellZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
static labelList getUnclosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are unclosed.
static labelList getClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed and.
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Namespace for OpenFOAM.
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:257
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:266