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-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 (
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 )
233 {
234  labelList namedSurfaces(surfList.size());
235 
236  label namedI = 0;
237  forAll(surfList, surfI)
238  {
239  if
240  (
241  surfList.set(surfI)
242  && surfList[surfI].faceZoneName().size()
243  && !surfList[surfI].cellZoneName().size()
244  )
245  {
246  namedSurfaces[namedI++] = surfI;
247  }
248  }
249  namedSurfaces.setSize(namedI);
250 
251  return namedSurfaces;
252 }
253 
254 
256 (
257  const PtrList<surfaceZonesInfo>& surfList,
258  const searchableSurfaces& allGeometry,
259  const labelList& surfaces
260 )
261 {
262  labelList closed(surfList.size());
263 
264  label closedI = 0;
265  forAll(surfList, surfI)
266  {
267  if
268  (
269  surfList.set(surfI)
270  && surfList[surfI].cellZoneName().size()
271  && (
272  surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDE
273  || surfList[surfI].zoneInside() == surfaceZonesInfo::OUTSIDE
274  )
275  && allGeometry[surfaces[surfI]].hasVolumeType()
276  )
277  {
278  closed[closedI++] = surfI;
279  }
280  }
281  closed.setSize(closedI);
282 
283  return closed;
284 }
285 
286 
288 (
289  const PtrList<surfaceZonesInfo>& surfList,
290  const searchableSurfaces& allGeometry,
291  const labelList& surfaces
292 )
293 {
294  labelList unclosed(surfList.size());
295 
296  label unclosedI = 0;
297  forAll(surfList, surfI)
298  {
299  if
300  (
301  surfList.set(surfI)
302  && !allGeometry[surfaces[surfI]].hasVolumeType()
303  )
304  {
305  unclosed[unclosedI++] = surfI;
306  }
307  }
308  unclosed.setSize(unclosedI);
309 
310  return unclosed;
311 }
312 
313 
315 (
316  const PtrList<surfaceZonesInfo>& surfList,
317  const searchableSurfaces& allGeometry,
318  const labelList& surfaces
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  && allGeometry[surfaces[surfI]].hasVolumeType()
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 )
346 {
347  labelList closed(surfList.size());
348 
349  label closedI = 0;
350  forAll(surfList, surfI)
351  {
352  if
353  (
354  surfList.set(surfI)
355  && surfList[surfI].cellZoneName().size()
356  && surfList[surfI].zoneInside() == surfaceZonesInfo::INSIDEPOINT
357  )
358  {
359  closed[closedI++] = surfI;
360  }
361  }
362  closed.setSize(closedI);
363 
364  return closed;
365 }
366 
367 
369 (
370  const word& name,
371  const labelList& addressing,
372  polyMesh& mesh
373 )
374 {
375  cellZoneMesh& cellZones = mesh.cellZones();
376 
377  label zoneI = cellZones.findZoneID(name);
378 
379  if (zoneI == -1)
380  {
381  zoneI = cellZones.size();
382  cellZones.setSize(zoneI+1);
383  cellZones.set
384  (
385  zoneI,
386  new cellZone
387  (
388  name, // name
389  addressing, // addressing
390  zoneI, // index
391  cellZones // cellZoneMesh
392  )
393  );
394  }
395  return zoneI;
396 }
397 
398 
400 (
401  const PtrList<surfaceZonesInfo>& surfList,
402  const labelList& namedSurfaces,
403  polyMesh& mesh
404 )
405 {
406  labelList surfaceToCellZone(surfList.size(), -1);
407 
408  forAll(namedSurfaces, i)
409  {
410  label surfI = namedSurfaces[i];
411 
412  const word& cellZoneName = surfList[surfI].cellZoneName();
413 
414  if (cellZoneName != word::null)
415  {
416  label zoneI = addCellZone
417  (
418  cellZoneName,
419  labelList(0), // addressing
420  mesh
421  );
422 
423  surfaceToCellZone[surfI] = zoneI;
424  }
425  }
426 
427  // Check they are synced
428  List<wordList> allCellZones(Pstream::nProcs());
429  allCellZones[Pstream::myProcNo()] = mesh.cellZones().names();
430  Pstream::gatherList(allCellZones);
431  Pstream::scatterList(allCellZones);
432 
433  for (label procI = 1; procI < allCellZones.size(); procI++)
434  {
435  if (allCellZones[procI] != allCellZones[0])
436  {
438  << "Zones not synchronised among processors." << nl
439  << " Processor0 has cellZones:" << allCellZones[0]
440  << " , processor" << procI
441  << " has cellZones:" << allCellZones[procI]
442  << exit(FatalError);
443  }
444  }
445 
446  return surfaceToCellZone;
447 }
448 
449 
450 
452 (
453  const word& name,
454  const labelList& addressing,
455  const boolList& flipMap,
456  polyMesh& mesh
457 )
458 {
459  faceZoneMesh& faceZones = mesh.faceZones();
460 
461  label zoneI = faceZones.findZoneID(name);
462 
463  if (zoneI == -1)
464  {
465  zoneI = faceZones.size();
466  faceZones.setSize(zoneI+1);
467  faceZones.set
468  (
469  zoneI,
470  new faceZone
471  (
472  name, // name
473  addressing, // addressing
474  flipMap, // flipMap
475  zoneI, // index
476  faceZones // faceZoneMesh
477  )
478  );
479  }
480  return zoneI;
481 }
482 
483 
485 (
486  const PtrList<surfaceZonesInfo>& surfList,
487  const labelList& namedSurfaces,
488  polyMesh& mesh
489 )
490 {
491  labelList surfaceToFaceZone(surfList.size(), -1);
492 
493  faceZoneMesh& faceZones = mesh.faceZones();
494 
495  forAll(namedSurfaces, i)
496  {
497  label surfI = namedSurfaces[i];
498 
499  const word& faceZoneName = surfList[surfI].faceZoneName();
500 
501  label zoneI = addFaceZone
502  (
503  faceZoneName, //name
504  labelList(0), //addressing
505  boolList(0), //flipmap
506  mesh
507  );
508 
509  surfaceToFaceZone[surfI] = zoneI;
510  }
511 
512  // Check they are synced
513  List<wordList> allFaceZones(Pstream::nProcs());
514  allFaceZones[Pstream::myProcNo()] = faceZones.names();
515  Pstream::gatherList(allFaceZones);
516  Pstream::scatterList(allFaceZones);
517 
518  for (label procI = 1; procI < allFaceZones.size(); procI++)
519  {
520  if (allFaceZones[procI] != allFaceZones[0])
521  {
523  << "Zones not synchronised among processors." << nl
524  << " Processor0 has faceZones:" << allFaceZones[0]
525  << " , processor" << procI
526  << " has faceZones:" << allFaceZones[procI]
527  << exit(FatalError);
528  }
529  }
530 
531  return surfaceToFaceZone;
532 }
533 
534 
535 // ************************************************************************* //
Foam::surfaceZonesInfo::areaSelectionAlgoNames
static const NamedEnum< areaSelectionAlgo, 4 > areaSelectionAlgoNames
Definition: surfaceZonesInfo.H:70
Foam::surfaceZonesInfo::faceZoneType
faceZoneType
What to do with faceZone faces.
Definition: surfaceZonesInfo.H:73
Foam::surfaceZonesInfo::surfaceZonesInfo
surfaceZonesInfo(const searchableSurface &surface, const dictionary &surfacesDict)
Construct from surfaces and dictionary.
Definition: surfaceZonesInfo.C:74
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::surfaceZonesInfo::getInsidePointNamedSurfaces
static labelList getInsidePointNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of surfaces with a cellZone that have 'insidePoint'.
Definition: surfaceZonesInfo.C:343
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
searchableSurface.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
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:205
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:387
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:469
Foam::surfaceZonesInfo::getNamedSurfaces
static labelList getNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces (surfaces with faceZoneName)
Definition: surfaceZonesInfo.C:205
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::surfaceZonesInfo::INSIDE
@ INSIDE
Definition: surfaceZonesInfo.H:64
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:315
polyMesh.H
Foam::surfaceZonesInfo::addFaceZonesToMesh
static labelList addFaceZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
Definition: surfaceZonesInfo.C:485
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:61
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
Foam::surfaceZonesInfo::getStandaloneNamedSurfaces
static labelList getStandaloneNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces without a cellZone.
Definition: surfaceZonesInfo.C:230
searchableSurfaces.H
Foam::PtrList::set
bool set(const label) const
Is element set.
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:59
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:66
Foam::surfaceZonesInfo::areaSelectionAlgo
areaSelectionAlgo
Types of selection of area.
Definition: surfaceZonesInfo.H:62
Foam::ZoneMesh< cellZone, polyMesh >
Foam::surfaceZonesInfo::OUTSIDE
@ OUTSIDE
Definition: surfaceZonesInfo.H:65
Foam::PtrList
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
Foam::surfaceZonesInfo
Definition: surfaceZonesInfo.H:57
surfaceZonesInfo.H
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::surfaceZonesInfo::INSIDEPOINT
@ INSIDEPOINT
Definition: surfaceZonesInfo.H:66
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::surfaceZonesInfo::faceZoneTypeNames
static const NamedEnum< faceZoneType, 3 > faceZoneTypeNames
Definition: surfaceZonesInfo.H:80
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:348
Foam::boolList
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
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:256
Foam::ZoneMesh::names
wordList names() const
Return a list of zone names.
Definition: ZoneMesh.C:263
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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:288
Foam::surfaceZonesInfo::getUnnamedSurfaces
static labelList getUnnamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of unnamed surfaces (surfaces without faceZoneName)
Definition: surfaceZonesInfo.C:184
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::List::setSize
void setSize(const label)
Reset size of List.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
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:49
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:62
Foam::searchableSurfaces
Container for searchableSurfaces.
Definition: searchableSurfaces.H:53
dictionary.H
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::surface
Definition: surface.H:55
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:271
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
Foam::surfaceZonesInfo::addCellZone
static label addCellZone(const word &name, const labelList &addressing, polyMesh &mesh)
Definition: surfaceZonesInfo.C:369
Foam::surfaceZonesInfo::addCellZonesToMesh
static labelList addCellZonesToMesh(const PtrList< surfaceZonesInfo > &surfList, const labelList &namedSurfaces, polyMesh &mesh)
Definition: surfaceZonesInfo.C:400
Foam::surfaceZonesInfo::addFaceZone
static label addFaceZone(const word &name, const labelList &addressing, const boolList &flipMap, polyMesh &mesh)
Definition: surfaceZonesInfo.C:452