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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2015 OpenFOAM Foundation
9  Copyright (C) 2015 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "surfaceZonesInfo.H"
30 #include "searchableSurface.H"
31 #include "searchableSurfaces.H"
32 #include "polyMesh.H"
33 #include "dictionary.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 const Foam::Enum
38 <
40 >
42 ({
43  { areaSelectionAlgo::INSIDE, "inside" },
44  { areaSelectionAlgo::OUTSIDE, "outside" },
45  { areaSelectionAlgo::INSIDEPOINT, "insidePoint" },
46  { areaSelectionAlgo::NONE, "none" },
47 });
48 
49 
50 const Foam::Enum
51 <
53 >
55 ({
56  { faceZoneType::INTERNAL, "internal" },
57  { faceZoneType::BAFFLE, "baffle" },
58  { faceZoneType::BOUNDARY, "boundary" },
59 });
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
65 (
66  const searchableSurface& surface,
67  const dictionary& surfacesDict
68 )
69 :
70  faceZoneName_(),
71  cellZoneName_(),
72  zoneInside_(NONE),
73  zoneInsidePoint_(point::min),
74  faceType_(INTERNAL)
75 {
76  // Global zone names per surface
77  if (surfacesDict.readIfPresent("faceZone", faceZoneName_))
78  {
79  // Read optional entry to determine inside of faceZone
80 
81  word method;
82  bool hasSide = surfacesDict.readIfPresent("cellZoneInside", method);
83  if (hasSide)
84  {
85  zoneInside_ = areaSelectionAlgoNames[method];
86  if (zoneInside_ == INSIDEPOINT)
87  {
88  surfacesDict.readEntry("insidePoint", zoneInsidePoint_);
89  }
90 
91  }
92  else
93  {
94  // Check old syntax
95  bool inside;
96  if (surfacesDict.readIfPresent("zoneInside", inside))
97  {
98  hasSide = true;
99  zoneInside_ = (inside ? INSIDE : OUTSIDE);
100  }
101  }
102 
103  // Read optional cellZone name
104 
105  if (surfacesDict.readIfPresent("cellZone", cellZoneName_))
106  {
107  if
108  (
109  (
110  zoneInside_ == INSIDE
111  || zoneInside_ == OUTSIDE
112  )
113  && !surface.hasVolumeType()
114  )
115  {
116  IOWarningInFunction(surfacesDict)
117  << "Illegal entry zoneInside "
118  << areaSelectionAlgoNames[zoneInside_]
119  << " for faceZone "
120  << faceZoneName_
121  << " since surface is not closed." << endl;
122  }
123  }
124  else if (hasSide)
125  {
126  IOWarningInFunction(surfacesDict)
127  << "Unused entry zoneInside for faceZone "
128  << faceZoneName_
129  << " since no cellZone specified."
130  << endl;
131  }
132 
133  // How to handle faces on faceZone
134  word faceTypeMethod;
135  if (surfacesDict.readIfPresent("faceType", faceTypeMethod))
136  {
137  faceType_ = faceZoneTypeNames[faceTypeMethod];
138  }
139  }
140 }
141 
142 
144 (
145  const word& faceZoneName,
146  const word& cellZoneName,
147  const areaSelectionAlgo& zoneInside,
148  const point& zoneInsidePoint,
149  const faceZoneType& faceType
150 )
151 :
152  faceZoneName_(faceZoneName),
153  cellZoneName_(cellZoneName),
154  zoneInside_(zoneInside),
155  zoneInsidePoint_(zoneInsidePoint),
156  faceType_(faceType)
157 {}
158 
159 
161 :
162  faceZoneName_(surfZone.faceZoneName()),
163  cellZoneName_(surfZone.cellZoneName()),
164  zoneInside_(surfZone.zoneInside()),
165  zoneInsidePoint_(surfZone.zoneInsidePoint()),
166  faceType_(surfZone.faceType())
167 {}
168 
169 
171 (
172  const PtrList<surfaceZonesInfo>& surfList
173 )
174 {
175  labelList anonymousSurfaces(surfList.size());
176 
177  label i = 0;
178  forAll(surfList, surfI)
179  {
180  if (surfList[surfI].faceZoneName().empty())
181  {
182  anonymousSurfaces[i++] = surfI;
183  }
184  }
185  anonymousSurfaces.setSize(i);
186 
187  return anonymousSurfaces;
188 }
189 
190 
192 (
193  const PtrList<surfaceZonesInfo>& surfList
194 )
195 {
196  labelList namedSurfaces(surfList.size());
197 
198  label namedI = 0;
199  forAll(surfList, surfI)
200  {
201  if
202  (
203  surfList.set(surfI)
204  && surfList[surfI].faceZoneName().size()
205  )
206  {
207  namedSurfaces[namedI++] = surfI;
208  }
209  }
210  namedSurfaces.setSize(namedI);
211 
212  return namedSurfaces;
213 }
214 
215 
217 (
218  const PtrList<surfaceZonesInfo>& surfList
219 )
220 {
221  labelList namedSurfaces(surfList.size());
222 
223  label namedI = 0;
224  forAll(surfList, surfI)
225  {
226  if
227  (
228  surfList.set(surfI)
229  && surfList[surfI].faceZoneName().size()
230  && !surfList[surfI].cellZoneName().size()
231  )
232  {
233  namedSurfaces[namedI++] = surfI;
234  }
235  }
236  namedSurfaces.setSize(namedI);
237 
238  return namedSurfaces;
239 }
240 
241 
243 (
244  const PtrList<surfaceZonesInfo>& surfList,
245  const searchableSurfaces& allGeometry,
246  const labelList& surfaces
247 )
248 {
249  labelList closed(surfList.size());
250 
251  label closedI = 0;
252  forAll(surfList, surfI)
253  {
254  if
255  (
256  surfList.set(surfI)
257  && surfList[surfI].cellZoneName().size()
258  && (
259  surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDE
260  || surfList[surfI].zoneInside() == surfaceZonesInfo::OUTSIDE
261  )
262  && allGeometry[surfaces[surfI]].hasVolumeType()
263  )
264  {
265  closed[closedI++] = surfI;
266  }
267  }
268  closed.setSize(closedI);
269 
270  return closed;
271 }
272 
273 
275 (
276  const PtrList<surfaceZonesInfo>& surfList,
277  const searchableSurfaces& allGeometry,
278  const labelList& surfaces
279 )
280 {
281  labelList unclosed(surfList.size());
282 
283  label unclosedI = 0;
284  forAll(surfList, surfI)
285  {
286  if
287  (
288  surfList.set(surfI)
289  && !allGeometry[surfaces[surfI]].hasVolumeType()
290  )
291  {
292  unclosed[unclosedI++] = surfI;
293  }
294  }
295  unclosed.setSize(unclosedI);
296 
297  return unclosed;
298 }
299 
300 
302 (
303  const PtrList<surfaceZonesInfo>& surfList,
304  const searchableSurfaces& allGeometry,
305  const labelList& surfaces
306 )
307 {
308  labelList closed(surfList.size());
309 
310  label closedI = 0;
311  forAll(surfList, surfI)
312  {
313  if
314  (
315  surfList.set(surfI)
316  && surfList[surfI].cellZoneName().size()
317  && allGeometry[surfaces[surfI]].hasVolumeType()
318  )
319  {
320  closed[closedI++] = surfI;
321  }
322  }
323  closed.setSize(closedI);
324 
325  return closed;
326 }
327 
328 
330 (
331  const PtrList<surfaceZonesInfo>& surfList
332 )
333 {
334  labelList closed(surfList.size());
335 
336  label closedI = 0;
337  forAll(surfList, surfI)
338  {
339  if
340  (
341  surfList.set(surfI)
342  && surfList[surfI].cellZoneName().size()
343  && surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDEPOINT
344  )
345  {
346  closed[closedI++] = surfI;
347  }
348  }
349  closed.setSize(closedI);
350 
351  return closed;
352 }
353 
354 
356 (
357  const word& name,
358  const labelList& addressing,
359  polyMesh& mesh
360 )
361 {
362  cellZoneMesh& cellZones = mesh.cellZones();
363 
364  label zoneI = cellZones.findZoneID(name);
365 
366  if (zoneI == -1)
367  {
368  zoneI = cellZones.size();
369  cellZones.setSize(zoneI+1);
370  cellZones.set
371  (
372  zoneI,
373  new cellZone
374  (
375  name, // name
376  addressing, // addressing
377  zoneI, // index
378  cellZones // cellZoneMesh
379  )
380  );
381  }
382  return zoneI;
383 }
384 
385 
387 (
388  const PtrList<surfaceZonesInfo>& surfList,
389  const labelList& namedSurfaces,
390  polyMesh& mesh
391 )
392 {
393  labelList surfaceToCellZone(surfList.size(), -1);
394 
395  forAll(namedSurfaces, i)
396  {
397  label surfI = namedSurfaces[i];
398 
399  const word& cellZoneName = surfList[surfI].cellZoneName();
400 
401  if (cellZoneName != word::null)
402  {
403  label zoneI = addCellZone
404  (
405  cellZoneName,
406  labelList(0), // addressing
407  mesh
408  );
409 
410  surfaceToCellZone[surfI] = zoneI;
411  }
412  }
413 
414  // Check they are synced
415  List<wordList> allCellZones(Pstream::nProcs());
416  allCellZones[Pstream::myProcNo()] = mesh.cellZones().names();
417  Pstream::gatherList(allCellZones);
418  Pstream::scatterList(allCellZones);
419 
420  for (label proci = 1; proci < allCellZones.size(); proci++)
421  {
422  if (allCellZones[proci] != allCellZones[0])
423  {
425  << "Zones not synchronised among processors." << nl
426  << " Processor0 has cellZones:" << allCellZones[0]
427  << " , processor" << proci
428  << " has cellZones:" << allCellZones[proci]
429  << exit(FatalError);
430  }
431  }
432 
433  return surfaceToCellZone;
434 }
435 
436 
437 
439 (
440  const word& name,
441  const labelList& addressing,
442  const boolList& flipMap,
443  polyMesh& mesh
444 )
445 {
446  faceZoneMesh& faceZones = mesh.faceZones();
447 
448  label zoneI = faceZones.findZoneID(name);
449 
450  if (zoneI == -1)
451  {
452  zoneI = faceZones.size();
453  faceZones.setSize(zoneI+1);
454  faceZones.set
455  (
456  zoneI,
457  new faceZone
458  (
459  name, // name
460  addressing, // addressing
461  flipMap, // flipMap
462  zoneI, // index
463  faceZones // faceZoneMesh
464  )
465  );
466  }
467  return zoneI;
468 }
469 
470 
472 (
473  const PtrList<surfaceZonesInfo>& surfList,
474  const labelList& namedSurfaces,
475  polyMesh& mesh
476 )
477 {
478  labelList surfaceToFaceZone(surfList.size(), -1);
479 
480  faceZoneMesh& faceZones = mesh.faceZones();
481 
482  forAll(namedSurfaces, i)
483  {
484  label surfI = namedSurfaces[i];
485 
486  const word& faceZoneName = surfList[surfI].faceZoneName();
487 
488  label zoneI = addFaceZone
489  (
490  faceZoneName, //name
491  labelList(0), //addressing
492  boolList(0), //flipmap
493  mesh
494  );
495 
496  surfaceToFaceZone[surfI] = zoneI;
497  }
498 
499  // Check they are synced
500  List<wordList> allFaceZones(Pstream::nProcs());
501  allFaceZones[Pstream::myProcNo()] = faceZones.names();
502  Pstream::gatherList(allFaceZones);
503  Pstream::scatterList(allFaceZones);
504 
505  for (label proci = 1; proci < allFaceZones.size(); proci++)
506  {
507  if (allFaceZones[proci] != allFaceZones[0])
508  {
510  << "Zones not synchronised among processors." << nl
511  << " Processor0 has faceZones:" << allFaceZones[0]
512  << " , processor" << proci
513  << " has faceZones:" << allFaceZones[proci]
514  << exit(FatalError);
515  }
516  }
517 
518  return surfaceToFaceZone;
519 }
520 
521 
522 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:51
Foam::surfaceZonesInfo::faceZoneType
faceZoneType
What to do with faceZone faces.
Definition: surfaceZonesInfo.H:76
Foam::surfaceZonesInfo::surfaceZonesInfo
surfaceZonesInfo(const searchableSurface &surface, const dictionary &surfacesDict)
Construct from surfaces and dictionary.
Definition: surfaceZonesInfo.C:65
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::surfaceZonesInfo::getInsidePointNamedSurfaces
static labelList getInsidePointNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of surfaces with a cellZone that have 'insidePoint'.
Definition: surfaceZonesInfo.C:330
searchableSurface.H
Foam::Pstream::scatterList
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
Definition: gatherScatterList.C:215
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:426
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:483
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:72
Foam::surfaceZonesInfo::getNamedSurfaces
static labelList getNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces (surfaces with faceZoneName)
Definition: surfaceZonesInfo.C:192
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::surfaceZonesInfo::INSIDE
Definition: surfaceZonesInfo.H:67
Foam::surfaceZonesInfo::getAllClosedNamedSurfaces
static labelList getAllClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed.
Definition: surfaceZonesInfo.C:302
polyMesh.H
Foam::surfaceZonesInfo::addFaceZonesToMesh
static labelList addFaceZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
Definition: surfaceZonesInfo.C:472
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:62
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:477
Foam::surfaceZonesInfo::getStandaloneNamedSurfaces
static labelList getStandaloneNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces without a cellZone.
Definition: surfaceZonesInfo.C:217
searchableSurfaces.H
Foam::label
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:62
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:65
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:69
Foam::surfaceZonesInfo::areaSelectionAlgo
areaSelectionAlgo
Types of selection of area.
Definition: surfaceZonesInfo.H:65
Foam::ZoneMesh< cellZone, polyMesh >
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::surfaceZonesInfo::OUTSIDE
Definition: surfaceZonesInfo.H:68
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:65
Foam::surfaceZonesInfo
Definition: surfaceZonesInfo.H:60
surfaceZonesInfo.H
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::surfaceZonesInfo::INSIDEPOINT
Definition: surfaceZonesInfo.H:69
Foam::searchableSurface::hasVolumeType
virtual bool hasVolumeType() const
Whether supports volume type (below).
Definition: searchableSurface.C:76
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::PtrList::set
const T * set(const label i) const
Return const pointer to element (if set) or nullptr.
Definition: PtrListI.H:143
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index given a name, return -1 if not found.
Definition: ZoneMesh.C:484
Foam::surfaceZonesInfo::getClosedNamedSurfaces
static labelList getClosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are closed and.
Definition: surfaceZonesInfo.C:243
Foam::ZoneMesh::names
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:340
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::surfaceZonesInfo::getUnclosedNamedSurfaces
static labelList getUnclosedNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList, const searchableSurfaces &allGeometry, const labelList &surfaces)
Get indices of surfaces with a cellZone that are unclosed.
Definition: surfaceZonesInfo.C:275
Foam::surfaceZonesInfo::getUnnamedSurfaces
static labelList getUnnamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of unnamed surfaces (surfaces without faceZoneName)
Definition: surfaceZonesInfo.C:171
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:444
Foam::surfaceZonesInfo::faceZoneTypeNames
static const Enum< faceZoneType > faceZoneTypeNames
Definition: surfaceZonesInfo.H:83
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::Pstream::gatherList
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Definition: gatherScatterList.C:52
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::Vector< scalar >
Foam::List< label >
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:65
Foam::searchableSurfaces
Container for searchableSurfaces. The collection is specified as a dictionary. For example,...
Definition: searchableSurfaces.H:92
dictionary.H
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:306
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::surfaceZonesInfo::areaSelectionAlgoNames
static const Enum< areaSelectionAlgo > areaSelectionAlgoNames
Definition: surfaceZonesInfo.H:73
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417
Foam::surfaceZonesInfo::addCellZone
static label addCellZone(const word &name, const labelList &addressing, polyMesh &mesh)
Definition: surfaceZonesInfo.C:356
Foam::surfaceZonesInfo::addCellZonesToMesh
static labelList addCellZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
Definition: surfaceZonesInfo.C:387
Foam::surfaceZonesInfo::addFaceZone
static label addFaceZone(const word &name, const labelList &addressing, const boolList &flipMap, polyMesh &mesh)
Definition: surfaceZonesInfo.C:439