intersection.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) 2025 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 "intersection.H"
27 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  namespace zoneGenerators
35  {
38  }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::zoneGenerators::intersection::countIntersections
45 (
46  labelList& nIntersections,
47  const labelList& indices
48 ) const
49 {
50  forAll(indices, i)
51  {
52  nIntersections[indices[i]]++;
53  }
54 }
55 
56 
57 void Foam::zoneGenerators::intersection::countIntersections
58 (
59  labelList& nIntersections,
60  boolList& flipMap,
61  const labelList& indices,
62  const boolList& zoneFlipMap
63 ) const
64 {
65  forAll(indices, i)
66  {
67  nIntersections[indices[i]]++;
68  flipMap[indices[i]] = zoneFlipMap[i];
69  }
70 }
71 
72 
73 Foam::labelList Foam::zoneGenerators::intersection::indices
74 (
75  const labelList& nIntersections
76 ) const
77 {
78  const label nZones = zoneGenerators_.size();
79  label nSelected = 0;
80  forAll(nIntersections, i)
81  {
82  if (nIntersections[i] == nZones)
83  {
84  nSelected++;
85  }
86  }
87 
88  labelList intersectionIndices(nSelected);
89 
90  label ui = 0;
91  forAll(nIntersections, i)
92  {
93  if (nIntersections[i] == nZones)
94  {
95  intersectionIndices[ui++] = i;
96  }
97  }
98 
99  return intersectionIndices;
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104 
106 (
107  const word& name,
108  const polyMesh& mesh,
109  const dictionary& dict
110 )
111 :
113  zoneType_
114  (
115  zoneTypesAllNames.lookupOrDefault("zoneType", dict, zoneTypesAll::all)
116  ),
117  zoneGenerators_(mesh, dict)
118 {
119  moveUpdate_ = zoneGenerators_.moveUpdate();
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
124 
126 {}
127 
128 
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 
132 {
133  labelList nPointIntersections;
134  labelList nCellIntersections;
135  labelList nFaceIntersections;
136  boolList flipMap;
137 
138  forAll(zoneGenerators_, i)
139  {
140  zoneSet zs(zoneGenerators_[i].generate());
141 
142  if
143  (
144  zoneType_ == zoneTypesAll::point
145  || (zoneType_ == zoneTypesAll::all && zs.pValid())
146  )
147  {
148  nPointIntersections.setSize(mesh_.nPoints(), 0);
149  countIntersections(nPointIntersections, zs.pZone());
150  }
151 
152  if
153  (
154  zoneType_ == zoneTypesAll::cell
155  || (zoneType_ == zoneTypesAll::all && zs.cValid())
156  )
157  {
158  nCellIntersections.setSize(mesh_.nCells(), 0);
159  countIntersections(nCellIntersections, zs.cZone());
160  }
161 
162  if
163  (
164  zoneType_ == zoneTypesAll::face
165  || (zoneType_ == zoneTypesAll::all && zs.fValid())
166  )
167  {
168  nFaceIntersections.setSize(mesh_.nFaces(), 0);
169 
170  if (zs.fZone().oriented())
171  {
172  flipMap.setSize(mesh_.nFaces(), false);
173  countIntersections
174  (
175  nFaceIntersections,
176  flipMap,
177  zs.fZone(),
178  zs.fZone().flipMap()
179  );
180  }
181  else
182  {
183  countIntersections(nFaceIntersections, zs.fZone());
184  }
185  }
186  }
187 
188  moveUpdate_ = zoneGenerators_.moveUpdate();
189 
190  const labelList faceIndices(indices(nFaceIntersections));
191 
192  return zoneSet
193  (
194  nPointIntersections.size()
195  ? new pointZone
196  (
197  zoneName_,
198  indices(nPointIntersections),
199  mesh_.pointZones(),
200  moveUpdate_,
201  true
202  )
203  : nullptr,
204  nCellIntersections.size()
205  ? new cellZone
206  (
207  zoneName_,
208  indices(nCellIntersections),
209  mesh_.cellZones(),
210  moveUpdate_,
211  true
212  )
213  : nullptr,
214  nFaceIntersections.size()
215  ? flipMap.size()
216  ? new faceZone
217  (
218  zoneName_,
219  faceIndices,
220  boolList(flipMap, faceIndices),
221  mesh_.faceZones(),
222  moveUpdate_,
223  true
224  )
225  : new faceZone
226  (
227  zoneName_,
228  faceIndices,
229  mesh_.faceZones(),
230  moveUpdate_,
231  true
232  )
233  : nullptr
234  );
235 }
236 
237 
238 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
Named list of cell indices representing a sub-set of the mesh.
Definition: cellZone.H:61
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Named list of face indices representing a sub-set of the mesh faces.
Definition: faceZone.H:66
const boolList & flipMap() const
Return face flip map.
Definition: faceZone.H:262
bool oriented() const
Return true if the faceZone is oriented, i.e. the flipMap is set.
Definition: faceZone.H:256
Named list of point indices representing a sub-set of the mesh faces.
Definition: pointZone.H:60
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A class for handling words, derived from string.
Definition: word.H:62
bool moveUpdate() const
Return true if any of the zoneGenerators updates any of the zones.
Abstract base class for all zoneGenerators, providing runtime selection.
Definition: zoneGenerator.H:57
bool moveUpdate_
Switch to update the zones if the mesh points are moved.
Definition: zoneGenerator.H:75
A zoneGenerator which selects the elements which are in all the zones generated by the given list of ...
Definition: intersection.H:128
virtual zoneSet generate() const
Generate and return the zoneSet.
Definition: intersection.C:131
virtual ~intersection()
Destructor.
Definition: intersection.C:125
intersection(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: intersection.C:106
Zone container returned by zoneGenerator::generate.
Definition: zoneSet.H:94
const faceZone & fZone() const
Return a reference to the faceZone if allocated.
Definition: zoneSetI.H:230
const cellZone & cZone() const
Return a reference to the cellZone if allocated.
Definition: zoneSetI.H:223
bool pValid() const
Return true if the pointZone is allocated.
Definition: zoneSetI.H:167
const pointZone & pZone() const
Return a reference to the pointZone if allocated.
Definition: zoneSetI.H:216
bool fValid() const
Return true if the faceZone is allocated.
Definition: zoneSetI.H:181
bool cValid() const
Return true if the cellZone is allocated.
Definition: zoneSetI.H:174
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
defineTypeNameAndDebug(cylinderHeadPoints, 0)
addToRunTimeSelectionTable(zoneGenerator, cylinderHeadPoints, dictionary)
Namespace for OpenFOAM.
zoneTypesAll
Enumeration defining the zone types with an option for all the types.
Definition: zoneSet.H:77
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
const NamedEnum< zoneTypesAll, 4 > zoneTypesAllNames
Named enumeration defining the zone type names.
Definition: zoneSet.C:43
dictionary dict