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-2021 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  surfacesDict.lookup("insidePoint") >> zoneInsidePoint_;
101  }
102  }
103 
104  // Read optional cellZone name
105 
106  if (surfacesDict.readIfPresent("cellZone", cellZoneName_))
107  {
108  if
109  (
110  (
111  zoneInside_ == INSIDE
112  || zoneInside_ == OUTSIDE
113  )
114  && !surface.hasVolumeType()
115  )
116  {
118  (
119  surfacesDict
120  ) << "Illegal entry zoneInside "
121  << areaSelectionAlgoNames[zoneInside_]
122  << " for faceZone "
123  << faceZoneName_
124  << " since surface is not closed." << endl;
125  }
126  }
127  else if (hasSide)
128  {
130  (
131  surfacesDict
132  ) << "Unused entry zoneInside for faceZone "
133  << faceZoneName_
134  << " since no cellZone specified."
135  << endl;
136  }
137 
138  // How to handle faces on faceZone
139  word faceTypeMethod;
140  if (surfacesDict.readIfPresent("faceType", faceTypeMethod))
141  {
142  faceType_ = faceZoneTypeNames[faceTypeMethod];
143  }
144  }
145 }
146 
147 
149 (
150  const word& faceZoneName,
151  const word& cellZoneName,
152  const areaSelectionAlgo& zoneInside,
153  const point& zoneInsidePoint,
154  const faceZoneType& faceType
155 )
156 :
157  faceZoneName_(faceZoneName),
158  cellZoneName_(cellZoneName),
159  zoneInside_(zoneInside),
160  zoneInsidePoint_(zoneInsidePoint),
161  faceType_(faceType)
162 {}
163 
164 
166 :
167  faceZoneName_(surfZone.faceZoneName()),
168  cellZoneName_(surfZone.cellZoneName()),
169  zoneInside_(surfZone.zoneInside()),
170  zoneInsidePoint_(surfZone.zoneInsidePoint()),
171  faceType_(surfZone.faceType())
172 {}
173 
174 
176 (
177  const PtrList<surfaceZonesInfo>& surfList
178 )
179 {
180  labelList anonymousSurfaces(surfList.size());
181 
182  label i = 0;
183  forAll(surfList, surfI)
184  {
185  if (surfList[surfI].faceZoneName().empty())
186  {
187  anonymousSurfaces[i++] = surfI;
188  }
189  }
190  anonymousSurfaces.setSize(i);
191 
192  return anonymousSurfaces;
193 }
194 
195 
197 (
198  const PtrList<surfaceZonesInfo>& surfList
199 )
200 {
201  labelList namedSurfaces(surfList.size());
202 
203  label namedI = 0;
204  forAll(surfList, surfI)
205  {
206  if
207  (
208  surfList.set(surfI)
209  && surfList[surfI].faceZoneName().size()
210  )
211  {
212  namedSurfaces[namedI++] = surfI;
213  }
214  }
215  namedSurfaces.setSize(namedI);
216 
217  return namedSurfaces;
218 }
219 
220 
222 (
223  const PtrList<surfaceZonesInfo>& surfList,
224  const searchableSurfaces& allGeometry,
225  const labelList& surfaces
226 )
227 {
228  labelList closed(surfList.size());
229 
230  label closedI = 0;
231  forAll(surfList, surfI)
232  {
233  if
234  (
235  surfList.set(surfI)
236  && surfList[surfI].cellZoneName().size()
237  && (
238  surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDE
239  || surfList[surfI].zoneInside() == surfaceZonesInfo::OUTSIDE
240  )
241  && allGeometry[surfaces[surfI]].hasVolumeType()
242  )
243  {
244  closed[closedI++] = surfI;
245  }
246  }
247  closed.setSize(closedI);
248 
249  return closed;
250 }
251 
252 
254 (
255  const PtrList<surfaceZonesInfo>& surfList,
256  const searchableSurfaces& allGeometry,
257  const labelList& surfaces
258 )
259 {
260  labelList unclosed(surfList.size());
261 
262  label unclosedI = 0;
263  forAll(surfList, surfI)
264  {
265  if
266  (
267  surfList.set(surfI)
268  && !allGeometry[surfaces[surfI]].hasVolumeType()
269  )
270  {
271  unclosed[unclosedI++] = surfI;
272  }
273  }
274  unclosed.setSize(unclosedI);
275 
276  return unclosed;
277 }
278 
279 
281 (
282  const PtrList<surfaceZonesInfo>& surfList,
283  const searchableSurfaces& allGeometry,
284  const labelList& surfaces
285 )
286 {
287  labelList closed(surfList.size());
288 
289  label closedI = 0;
290  forAll(surfList, surfI)
291  {
292  if
293  (
294  surfList.set(surfI)
295  && surfList[surfI].cellZoneName().size()
296  && allGeometry[surfaces[surfI]].hasVolumeType()
297  )
298  {
299  closed[closedI++] = surfI;
300  }
301  }
302  closed.setSize(closedI);
303 
304  return closed;
305 }
306 
307 
309 (
310  const PtrList<surfaceZonesInfo>& surfList
311 )
312 {
313  labelList closed(surfList.size());
314 
315  label closedI = 0;
316  forAll(surfList, surfI)
317  {
318  if
319  (
320  surfList.set(surfI)
321  && surfList[surfI].cellZoneName().size()
322  && surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDEPOINT
323  )
324  {
325  closed[closedI++] = surfI;
326  }
327  }
328  closed.setSize(closedI);
329 
330  return closed;
331 }
332 
333 
335 (
336  const PtrList<surfaceZonesInfo>& surfList,
337  const labelList& namedSurfaces,
338  polyMesh& mesh
339 )
340 {
341  labelList surfaceToCellZone(surfList.size(), -1);
342 
343  meshCellZones& cellZones = mesh.cellZones();
344 
345  forAll(namedSurfaces, i)
346  {
347  label surfI = namedSurfaces[i];
348 
349  const word& cellZoneName = surfList[surfI].cellZoneName();
350 
351  if (cellZoneName != word::null)
352  {
353  label zoneI = cellZones.findZoneID(cellZoneName);
354 
355  if (zoneI == -1)
356  {
357  zoneI = cellZones.size();
358  cellZones.setSize(zoneI+1);
359  cellZones.set
360  (
361  zoneI,
362  new cellZone
363  (
364  cellZoneName, // name
365  labelList(0), // addressing
366  zoneI, // index
367  cellZones // meshCellZones
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.names();
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  meshFaceZones& 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.findZoneID(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  zoneI, // index
431  faceZones // meshFaceZones
432  )
433  );
434  }
435 
436  surfaceToFaceZone[surfI] = zoneI;
437  }
438 
439  // Check they are synced
440  List<wordList> allFaceZones(Pstream::nProcs());
441  allFaceZones[Pstream::myProcNo()] = faceZones.names();
442  Pstream::gatherList(allFaceZones);
443  Pstream::scatterList(allFaceZones);
444 
445  for (label proci = 1; proci < allFaceZones.size(); proci++)
446  {
447  if (allFaceZones[proci] != allFaceZones[0])
448  {
450  << "Zones not synchronised among processors." << nl
451  << " Processor0 has faceZones:" << allFaceZones[0]
452  << " , processor" << proci
453  << " has faceZones:" << allFaceZones[proci]
454  << exit(FatalError);
455  }
456  }
457 
458  return surfaceToFaceZone;
459 }
460 
461 
462 // ************************************************************************* //
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
static const NamedEnum< faceZoneType, 3 > faceZoneTypeNames
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const meshCellZones & cellZones() const
Return cell zones.
Definition: polyMesh.H:482
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
A surface zone on a MeshedSurface.
Definition: surfZone.H:62
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static labelList addCellZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
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 getAllClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed.
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
A class for handling words, derived from string.
Definition: word.H:59
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
static const word null
An empty word.
Definition: word.H:77
Container for searchableSurfaces.
List< label > labelList
A List of labels.
Definition: labelList.H:56
static labelList getInsidePointNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of surfaces with a cellZone that have &#39;insidePoint&#39;.
static labelList getUnnamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of unnamed surfaces (surfaces without faceZoneName)
static const char nl
Definition: Ostream.H:260
A subset of mesh cells.
Definition: cellZone.H:61
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void setSize(const label)
Reset size of List.
Definition: List.C:281
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
const meshFaceZones & faceZones() const
Return face zones.
Definition: polyMesh.H:476
static labelList addFaceZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
static labelList getClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed and.
static labelList getNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces (surfaces with faceZoneName)
static const NamedEnum< areaSelectionAlgo, 4 > areaSelectionAlgoNames
faceZoneType
What to do with faceZone faces.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
surfaceZonesInfo(const searchableSurface &surface, const dictionary &surfacesDict)
Construct from surfaces and dictionary.
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
const word & faceZoneName() const
Per &#39;interface&#39; surface : empty or name of faceZone to put.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
areaSelectionAlgo
Types of selection of area.
virtual bool hasVolumeType() const =0
Whether supports volume type below.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844