surfaceZonesInfo.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 | Copyright (C) 2013 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  "surfaceZonesInfo::surfaceZonesInfo(..)",
128  surfacesDict
129  ) << "Illegal entry zoneInside "
130  << areaSelectionAlgoNames[zoneInside_]
131  << " for faceZone "
132  << faceZoneName_
133  << " since surface is not closed." << endl;
134  }
135  }
136  else if (hasSide)
137  {
139  (
140  "surfaceZonesInfo::surfaceZonesInfo(..)",
141  surfacesDict
142  ) << "Unused entry zoneInside for faceZone "
143  << faceZoneName_
144  << " since no cellZone specified."
145  << endl;
146  }
147 
148  // How to handle faces on faceZone
149  word faceTypeMethod;
150  if (surfacesDict.readIfPresent("faceType", faceTypeMethod))
151  {
152  faceType_ = faceZoneTypeNames[faceTypeMethod];
153  }
154  }
155 }
156 
157 
159 (
160  const word& faceZoneName,
161  const word& cellZoneName,
162  const areaSelectionAlgo& zoneInside,
163  const point& zoneInsidePoint,
164  const faceZoneType& faceType
165 )
166 :
167  faceZoneName_(faceZoneName),
168  cellZoneName_(cellZoneName),
169  zoneInside_(zoneInside),
170  zoneInsidePoint_(zoneInsidePoint),
171  faceType_(faceType)
172 {}
173 
174 
176 :
177  faceZoneName_(surfZone.faceZoneName()),
178  cellZoneName_(surfZone.cellZoneName()),
179  zoneInside_(surfZone.zoneInside()),
180  zoneInsidePoint_(surfZone.zoneInsidePoint()),
181  faceType_(surfZone.faceType())
182 {}
183 
184 
186 (
187  const PtrList<surfaceZonesInfo>& surfList
188 )
189 {
190  labelList anonymousSurfaces(surfList.size());
191 
192  label i = 0;
193  forAll(surfList, surfI)
194  {
195  if (surfList[surfI].faceZoneName().empty())
196  {
197  anonymousSurfaces[i++] = surfI;
198  }
199  }
200  anonymousSurfaces.setSize(i);
201 
202  return anonymousSurfaces;
203 }
204 
205 
207 (
208  const PtrList<surfaceZonesInfo>& surfList
209 )
210 {
211  labelList namedSurfaces(surfList.size());
212 
213  label namedI = 0;
214  forAll(surfList, surfI)
215  {
216  if
217  (
218  surfList.set(surfI)
219  && surfList[surfI].faceZoneName().size()
220  )
221  {
222  namedSurfaces[namedI++] = surfI;
223  }
224  }
225  namedSurfaces.setSize(namedI);
226 
227  return namedSurfaces;
228 }
229 
230 
232 (
233  const PtrList<surfaceZonesInfo>& surfList,
234  const searchableSurfaces& allGeometry,
235  const labelList& surfaces
236 )
237 {
238  labelList closed(surfList.size());
239 
240  label closedI = 0;
241  forAll(surfList, surfI)
242  {
243  if
244  (
245  surfList.set(surfI)
246  && surfList[surfI].cellZoneName().size()
247  && (
248  surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDE
249  || surfList[surfI].zoneInside() == surfaceZonesInfo::OUTSIDE
250  )
251  && allGeometry[surfaces[surfI]].hasVolumeType()
252  )
253  {
254  closed[closedI++] = surfI;
255  }
256  }
257  closed.setSize(closedI);
258 
259  return closed;
260 }
261 
262 
264 (
265  const PtrList<surfaceZonesInfo>& surfList,
266  const searchableSurfaces& allGeometry,
267  const labelList& surfaces
268 )
269 {
270  labelList unclosed(surfList.size());
271 
272  label unclosedI = 0;
273  forAll(surfList, surfI)
274  {
275  if
276  (
277  surfList.set(surfI)
278  && !allGeometry[surfaces[surfI]].hasVolumeType()
279  )
280  {
281  unclosed[unclosedI++] = surfI;
282  }
283  }
284  unclosed.setSize(unclosedI);
285 
286  return unclosed;
287 }
288 
289 
291 (
292  const PtrList<surfaceZonesInfo>& surfList,
293  const searchableSurfaces& allGeometry,
294  const labelList& surfaces
295 )
296 {
297  labelList closed(surfList.size());
298 
299  label closedI = 0;
300  forAll(surfList, surfI)
301  {
302  if
303  (
304  surfList.set(surfI)
305  && surfList[surfI].cellZoneName().size()
306  && allGeometry[surfaces[surfI]].hasVolumeType()
307  )
308  {
309  closed[closedI++] = surfI;
310  }
311  }
312  closed.setSize(closedI);
313 
314  return closed;
315 }
316 
317 
319 (
320  const PtrList<surfaceZonesInfo>& surfList
321 )
322 {
323  labelList closed(surfList.size());
324 
325  label closedI = 0;
326  forAll(surfList, surfI)
327  {
328  if
329  (
330  surfList.set(surfI)
331  && surfList[surfI].cellZoneName().size()
332  && surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDEPOINT
333  )
334  {
335  closed[closedI++] = surfI;
336  }
337  }
338  closed.setSize(closedI);
339 
340  return closed;
341 }
342 
343 
345 (
346  const PtrList<surfaceZonesInfo>& surfList,
347  const labelList& namedSurfaces,
348  polyMesh& mesh
349 )
350 {
351  labelList surfaceToCellZone(surfList.size(), -1);
352 
353  cellZoneMesh& cellZones = mesh.cellZones();
354 
355  forAll(namedSurfaces, i)
356  {
357  label surfI = namedSurfaces[i];
358 
359  const word& cellZoneName = surfList[surfI].cellZoneName();
360 
361  if (cellZoneName != word::null)
362  {
363  label zoneI = cellZones.findZoneID(cellZoneName);
364 
365  if (zoneI == -1)
366  {
367  zoneI = cellZones.size();
368  cellZones.setSize(zoneI+1);
369  cellZones.set
370  (
371  zoneI,
372  new cellZone
373  (
374  cellZoneName, //name
375  labelList(0), //addressing
376  zoneI, //index
377  cellZones //cellZoneMesh
378  )
379  );
380  }
381 
382  surfaceToCellZone[surfI] = zoneI;
383  }
384  }
385 
386  // Check they are synced
387  List<wordList> allCellZones(Pstream::nProcs());
388  allCellZones[Pstream::myProcNo()] = cellZones.names();
389  Pstream::gatherList(allCellZones);
390  Pstream::scatterList(allCellZones);
391 
392  for (label procI = 1; procI < allCellZones.size(); procI++)
393  {
394  if (allCellZones[procI] != allCellZones[0])
395  {
397  (
398  "meshRefinement::zonify"
399  "(const label, const point&)"
400  ) << "Zones not synchronised among processors." << nl
401  << " Processor0 has cellZones:" << allCellZones[0]
402  << " , processor" << procI
403  << " has cellZones:" << allCellZones[procI]
404  << exit(FatalError);
405  }
406  }
407 
408  return surfaceToCellZone;
409 }
410 
411 
413 (
414  const PtrList<surfaceZonesInfo>& surfList,
415  const labelList& namedSurfaces,
416  polyMesh& mesh
417 )
418 {
419  labelList surfaceToFaceZone(surfList.size(), -1);
420 
421  faceZoneMesh& faceZones = mesh.faceZones();
422 
423  forAll(namedSurfaces, i)
424  {
425  label surfI = namedSurfaces[i];
426 
427  const word& faceZoneName = surfList[surfI].faceZoneName();
428 
429  label zoneI = faceZones.findZoneID(faceZoneName);
430 
431  if (zoneI == -1)
432  {
433  zoneI = faceZones.size();
434  faceZones.setSize(zoneI+1);
435  faceZones.set
436  (
437  zoneI,
438  new faceZone
439  (
440  faceZoneName, //name
441  labelList(0), //addressing
442  boolList(0), //flipmap
443  zoneI, //index
444  faceZones //faceZoneMesh
445  )
446  );
447  }
448 
449  surfaceToFaceZone[surfI] = zoneI;
450  }
451 
452  // Check they are synced
453  List<wordList> allFaceZones(Pstream::nProcs());
454  allFaceZones[Pstream::myProcNo()] = faceZones.names();
455  Pstream::gatherList(allFaceZones);
456  Pstream::scatterList(allFaceZones);
457 
458  for (label procI = 1; procI < allFaceZones.size(); procI++)
459  {
460  if (allFaceZones[procI] != allFaceZones[0])
461  {
463  (
464  "meshRefinement::zonify"
465  "(const label, const point&)"
466  ) << "Zones not synchronised among processors." << nl
467  << " Processor0 has faceZones:" << allFaceZones[0]
468  << " , processor" << procI
469  << " has faceZones:" << allFaceZones[procI]
470  << exit(FatalError);
471  }
472  }
473 
474  return surfaceToFaceZone;
475 }
476 
477 
478 // ************************************************************************* //
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:469
static labelList getInsidePointNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of surfaces with a cellZone that have &#39;insidePoint&#39;.
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
bool set(const label) const
Is element set.
Definition: PtrListI.H:107
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
A subset of mesh cells.
Definition: cellZone.H:61
virtual bool hasVolumeType() const =0
Whether supports volume type below.
faceZoneType
What to do with faceZone faces.
surfaceZonesInfo(const searchableSurface &surface, const dictionary &surfacesDict)
Construct from surfaces and dictionary.
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.
static const NamedEnum< areaSelectionAlgo, 4 > areaSelectionAlgoNames
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
static labelList getUnnamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of unnamed surfaces (surfaces without faceZoneName)
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static labelList getNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces (surfaces with faceZoneName)
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
static const NamedEnum< faceZoneType, 3 > faceZoneTypeNames
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
static labelList getClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed and.
Namespace for OpenFOAM.
#define IOWarningIn(functionName, ios)
Report an IO warning using Foam::Warning.
const word & faceZoneName() const
Per &#39;interface&#39; surface : empty or name of faceZone to put.
static labelList addFaceZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:386
static const char nl
Definition: Ostream.H:260
void setSize(const label)
Reset size of List.
Definition: List.C:318
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
static labelList addCellZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:404
A surface zone on a MeshedSurface.
Definition: surfZone.H:62
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
static labelList getUnclosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are unclosed.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static const Vector min
Definition: Vector.H:83
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
List< label > labelList
A List of labels.
Definition: labelList.H:56
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Container for searchableSurfaces.
static const word null
An empty word.
Definition: word.H:77
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