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-2018 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 = surfacesDict.readIfPresent("cellZoneInside", method);
92  if (hasSide)
93  {
94  zoneInside_ = areaSelectionAlgoNames[method];
95  if (zoneInside_ == INSIDEPOINT)
96  {
97  surfacesDict.lookup("insidePoint") >> zoneInsidePoint_;
98  }
99 
100  }
101  else
102  {
103  // Check old syntax
104  bool inside;
105  if (surfacesDict.readIfPresent("zoneInside", inside))
106  {
107  hasSide = true;
108  zoneInside_ = (inside ? INSIDE : OUTSIDE);
109  }
110  }
111 
112  // Read optional cellZone name
113 
114  if (surfacesDict.readIfPresent("cellZone", cellZoneName_))
115  {
116  if
117  (
118  (
119  zoneInside_ == INSIDE
120  || zoneInside_ == OUTSIDE
121  )
122  && !surface.hasVolumeType()
123  )
124  {
126  (
127  surfacesDict
128  ) << "Illegal entry zoneInside "
129  << areaSelectionAlgoNames[zoneInside_]
130  << " for faceZone "
131  << faceZoneName_
132  << " since surface is not closed." << endl;
133  }
134  }
135  else if (hasSide)
136  {
138  (
139  surfacesDict
140  ) << "Unused entry zoneInside for faceZone "
141  << faceZoneName_
142  << " since no cellZone specified."
143  << endl;
144  }
145 
146  // How to handle faces on faceZone
147  word faceTypeMethod;
148  if (surfacesDict.readIfPresent("faceType", faceTypeMethod))
149  {
150  faceType_ = faceZoneTypeNames[faceTypeMethod];
151  }
152  }
153 }
154 
155 
157 (
158  const word& faceZoneName,
159  const word& cellZoneName,
160  const areaSelectionAlgo& zoneInside,
161  const point& zoneInsidePoint,
162  const faceZoneType& faceType
163 )
164 :
165  faceZoneName_(faceZoneName),
166  cellZoneName_(cellZoneName),
167  zoneInside_(zoneInside),
168  zoneInsidePoint_(zoneInsidePoint),
169  faceType_(faceType)
170 {}
171 
172 
174 :
175  faceZoneName_(surfZone.faceZoneName()),
176  cellZoneName_(surfZone.cellZoneName()),
177  zoneInside_(surfZone.zoneInside()),
178  zoneInsidePoint_(surfZone.zoneInsidePoint()),
179  faceType_(surfZone.faceType())
180 {}
181 
182 
184 (
185  const PtrList<surfaceZonesInfo>& surfList
186 )
187 {
188  labelList anonymousSurfaces(surfList.size());
189 
190  label i = 0;
191  forAll(surfList, surfI)
192  {
193  if (surfList[surfI].faceZoneName().empty())
194  {
195  anonymousSurfaces[i++] = surfI;
196  }
197  }
198  anonymousSurfaces.setSize(i);
199 
200  return anonymousSurfaces;
201 }
202 
203 
205 (
206  const PtrList<surfaceZonesInfo>& surfList
207 )
208 {
209  labelList namedSurfaces(surfList.size());
210 
211  label namedI = 0;
212  forAll(surfList, surfI)
213  {
214  if
215  (
216  surfList.set(surfI)
217  && surfList[surfI].faceZoneName().size()
218  )
219  {
220  namedSurfaces[namedI++] = surfI;
221  }
222  }
223  namedSurfaces.setSize(namedI);
224 
225  return namedSurfaces;
226 }
227 
228 
230 (
231  const PtrList<surfaceZonesInfo>& surfList,
232  const searchableSurfaces& allGeometry,
233  const labelList& surfaces
234 )
235 {
236  labelList closed(surfList.size());
237 
238  label closedI = 0;
239  forAll(surfList, surfI)
240  {
241  if
242  (
243  surfList.set(surfI)
244  && surfList[surfI].cellZoneName().size()
245  && (
246  surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDE
247  || surfList[surfI].zoneInside() == surfaceZonesInfo::OUTSIDE
248  )
249  && allGeometry[surfaces[surfI]].hasVolumeType()
250  )
251  {
252  closed[closedI++] = surfI;
253  }
254  }
255  closed.setSize(closedI);
256 
257  return closed;
258 }
259 
260 
262 (
263  const PtrList<surfaceZonesInfo>& surfList,
264  const searchableSurfaces& allGeometry,
265  const labelList& surfaces
266 )
267 {
268  labelList unclosed(surfList.size());
269 
270  label unclosedI = 0;
271  forAll(surfList, surfI)
272  {
273  if
274  (
275  surfList.set(surfI)
276  && !allGeometry[surfaces[surfI]].hasVolumeType()
277  )
278  {
279  unclosed[unclosedI++] = surfI;
280  }
281  }
282  unclosed.setSize(unclosedI);
283 
284  return unclosed;
285 }
286 
287 
289 (
290  const PtrList<surfaceZonesInfo>& surfList,
291  const searchableSurfaces& allGeometry,
292  const labelList& surfaces
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  && allGeometry[surfaces[surfI]].hasVolumeType()
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 )
320 {
321  labelList closed(surfList.size());
322 
323  label closedI = 0;
324  forAll(surfList, surfI)
325  {
326  if
327  (
328  surfList.set(surfI)
329  && surfList[surfI].cellZoneName().size()
330  && surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDEPOINT
331  )
332  {
333  closed[closedI++] = surfI;
334  }
335  }
336  closed.setSize(closedI);
337 
338  return closed;
339 }
340 
341 
343 (
344  const PtrList<surfaceZonesInfo>& surfList,
345  const labelList& namedSurfaces,
346  polyMesh& mesh
347 )
348 {
349  labelList surfaceToCellZone(surfList.size(), -1);
350 
351  cellZoneMesh& cellZones = mesh.cellZones();
352 
353  forAll(namedSurfaces, i)
354  {
355  label surfI = namedSurfaces[i];
356 
357  const word& cellZoneName = surfList[surfI].cellZoneName();
358 
359  if (cellZoneName != word::null)
360  {
361  label zoneI = cellZones.findZoneID(cellZoneName);
362 
363  if (zoneI == -1)
364  {
365  zoneI = cellZones.size();
366  cellZones.setSize(zoneI+1);
367  cellZones.set
368  (
369  zoneI,
370  new cellZone
371  (
372  cellZoneName, // name
373  labelList(0), // addressing
374  zoneI, // index
375  cellZones // cellZoneMesh
376  )
377  );
378  }
379 
380  surfaceToCellZone[surfI] = zoneI;
381  }
382  }
383 
384  // Check they are synced
385  List<wordList> allCellZones(Pstream::nProcs());
386  allCellZones[Pstream::myProcNo()] = cellZones.names();
387  Pstream::gatherList(allCellZones);
388  Pstream::scatterList(allCellZones);
389 
390  for (label proci = 1; proci < allCellZones.size(); proci++)
391  {
392  if (allCellZones[proci] != allCellZones[0])
393  {
395  << "Zones not synchronised among processors." << nl
396  << " Processor0 has cellZones:" << allCellZones[0]
397  << " , processor" << proci
398  << " has cellZones:" << allCellZones[proci]
399  << exit(FatalError);
400  }
401  }
402 
403  return surfaceToCellZone;
404 }
405 
406 
408 (
409  const PtrList<surfaceZonesInfo>& surfList,
410  const labelList& namedSurfaces,
411  polyMesh& mesh
412 )
413 {
414  labelList surfaceToFaceZone(surfList.size(), -1);
415 
416  faceZoneMesh& faceZones = mesh.faceZones();
417 
418  forAll(namedSurfaces, i)
419  {
420  label surfI = namedSurfaces[i];
421 
422  const word& faceZoneName = surfList[surfI].faceZoneName();
423 
424  label zoneI = faceZones.findZoneID(faceZoneName);
425 
426  if (zoneI == -1)
427  {
428  zoneI = faceZones.size();
429  faceZones.setSize(zoneI+1);
430  faceZones.set
431  (
432  zoneI,
433  new faceZone
434  (
435  faceZoneName, // name
436  labelList(0), // addressing
437  boolList(0), // flipmap
438  zoneI, // index
439  faceZones // faceZoneMesh
440  )
441  );
442  }
443 
444  surfaceToFaceZone[surfI] = zoneI;
445  }
446 
447  // Check they are synced
448  List<wordList> allFaceZones(Pstream::nProcs());
449  allFaceZones[Pstream::myProcNo()] = faceZones.names();
450  Pstream::gatherList(allFaceZones);
451  Pstream::scatterList(allFaceZones);
452 
453  for (label proci = 1; proci < allFaceZones.size(); proci++)
454  {
455  if (allFaceZones[proci] != allFaceZones[0])
456  {
458  << "Zones not synchronised among processors." << nl
459  << " Processor0 has faceZones:" << allFaceZones[0]
460  << " , processor" << proci
461  << " has faceZones:" << allFaceZones[proci]
462  << exit(FatalError);
463  }
464  }
465 
466  return surfaceToFaceZone;
467 }
468 
469 
470 // ************************************************************************* //
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
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:476
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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:163
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:256
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
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:482
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:265
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
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:583