volumeTemplates.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 "volume.H"
27 #include "polyMesh.H"
28 
29 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
30 
31 template<class ZoneType, class UnaryOp, class ZoneGenType>
33 (
34  const ZoneGenType& zoneGen,
35  const vectorField& pts,
36  const UnaryOp& uop
37 ) const
38 {
39  labelList indices(pts.size());
40 
41  label nInZone = 0;
42  forAll(pts, i)
43  {
44  if (uop(zoneGen.contains(pts[i])))
45  {
46  indices[nInZone++] = i;
47  }
48  }
49 
50  indices.setSize(nInZone);
51 
52  return indices;
53 }
54 
55 
56 template<class ZoneType, class UnaryOp, class ZoneGenType>
58 (
59  const ZoneGenType& zoneGen,
60  const zoneGeneratorList& zoneGenerators,
61  const vectorField& pts,
62  const UnaryOp& uop
63 ) const
64 {
65  if (!zoneGenerators.size())
66  {
67  return select<ZoneType, UnaryOp>(zoneGen, pts, uop);
68  }
69 
70  boolList selected(pts.size(), false);
71 
72  forAll(zoneGenerators, zgi)
73  {
74  zoneSet zs(zoneGenerators[zgi].generate());
75 
76  const labelList& zsIndices(zs.zone<ZoneType>());
77 
78  forAll(zsIndices, i)
79  {
80  if (uop(zoneGen.contains(pts[zsIndices[i]])))
81  {
82  selected[zsIndices[i]] = true;
83  }
84  }
85  }
86 
87  return indices(selected);
88 }
89 
90 
91 template<class ZoneType, class ZoneGenType>
93 (
94  const ZoneGenType& zoneGen,
95  const zoneGeneratorList& zoneGenerators,
96  const vectorField& pts
97 ) const
98 {
99  if (select_ == selection::inside)
100  {
101  return zoneGen.template select<ZoneType>
102  (
103  zoneGen,
104  zoneGenerators,
105  pts,
106  nopOp<bool>()
107  );
108  }
109  else
110  {
111  return zoneGen.template select<ZoneType>
112  (
113  zoneGen,
114  zoneGenerators,
115  pts,
116  notOp<bool>()
117  );
118  }
119 }
120 
121 
122 template<class UnaryOp, class ZoneGenType>
124 (
125  const ZoneGenType& zoneGen,
126  const zoneGeneratorList& zoneGenerators,
127  const vectorField& pts,
128  boolList& flipMap,
129  const UnaryOp& uop
130 ) const
131 {
132  if (!zoneGenerators.size())
133  {
134  return select<faceZone>(zoneGen, pts, uop);
135  }
136 
137  bool oriented = true;
138  boolList selected(pts.size(), false);
139 
140  forAll(zoneGenerators, zgi)
141  {
142  zoneSet zs(zoneGenerators[zgi].generate());
143 
144  const faceZone& fZone = zs.fZone();
145  const labelList& zsIndices(fZone);
146 
147  if (oriented && fZone.oriented())
148  {
149  flipMap.setSize(mesh_.nFaces(), false);
150  const boolList& zsFlipMap(fZone.flipMap());
151 
152  forAll(zsIndices, i)
153  {
154  if (uop(zoneGen.contains(pts[zsIndices[i]])))
155  {
156  selected[zsIndices[i]] = true;
157  flipMap[zsIndices[i]] = zsFlipMap[i];
158  }
159  }
160  }
161  else
162  {
163  oriented = false;
164  flipMap.clear();
165 
166  forAll(zsIndices, i)
167  {
168  if (uop(zoneGen.contains(pts[zsIndices[i]])))
169  {
170  selected[zsIndices[i]] = true;
171  }
172  }
173  }
174  }
175 
176  labelList faceIndices(indices(selected));
177 
178  if (oriented)
179  {
180  flipMap = boolList(flipMap, faceIndices);
181  }
182 
183  return faceIndices;
184 }
185 
186 
187 template<class ZoneGenType>
189 (
190  const ZoneGenType& zoneGen,
191  const zoneGeneratorList& zoneGenerators,
192  const vectorField& pts,
193  boolList& flipMap
194 ) const
195 {
196  if (select_ == selection::inside)
197  {
198  return zoneGen.select
199  (
200  zoneGen,
201  zoneGenerators,
202  pts,
203  flipMap,
204  nopOp<bool>()
205  );
206  }
207  else
208  {
209  return zoneGen.select
210  (
211  zoneGen,
212  zoneGenerators,
213  pts,
214  flipMap,
215  notOp<bool>()
216  );
217  }
218 }
219 
220 
221 template<class ZoneGenType>
223 (
224  const ZoneGenType& zoneGen
225 ) const
226 {
227  labelList indices;
228 
229  switch (zoneType_)
230  {
231  case zoneTypes::point:
232  {
233  return zoneSet
234  (
235  new pointZone
236  (
237  zoneName_,
238  zoneGen.template selectOp<pointZone>
239  (
240  zoneGen,
241  zoneGenerators_,
242  mesh_.points()
243  ),
244  mesh_.pointZones(),
245  moveUpdate_,
246  true
247  )
248  );
249  }
250 
251  case zoneTypes::cell:
252  {
253  return zoneSet
254  (
255  new cellZone
256  (
257  zoneName_,
258  zoneGen.template selectOp<cellZone>
259  (
260  zoneGen,
261  zoneGenerators_,
262  mesh_.cellCentres()
263  ),
264  mesh_.cellZones(),
265  moveUpdate_,
266  true
267  )
268  );
269  }
270 
271  case zoneTypes::face:
272  {
273  boolList flipMap;
274  const labelList faceIndices
275  (
276  zoneGen.selectOp
277  (
278  zoneGen,
279  zoneGenerators_,
280  mesh_.faceCentres(),
281  flipMap
282  )
283  );
284 
285  return zoneSet
286  (
287  flipMap.size()
288  ? new faceZone
289  (
290  zoneName_,
291  faceIndices,
292  flipMap,
293  mesh_.faceZones(),
294  moveUpdate_,
295  true
296  )
297  : new faceZone
298  (
299  zoneName_,
300  faceIndices,
301  mesh_.faceZones(),
302  moveUpdate_,
303  true
304  )
305  );
306  }
307  }
308 
309  return zoneSet();
310 }
311 
312 
313 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
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
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
List of zoneGenerators.
static labelList indices(const boolList &selected)
Return the list of selected indices.
labelList selectOp(const ZoneGenType &zoneGen, const zoneGeneratorList &zoneGenerators, const vectorField &pts) const
virtual zoneSet generate() const =0
Generate and return the zoneSet.
labelList select(const ZoneGenType &zoneGen, const vectorField &pts, const UnaryOp &uop) const
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 ZoneType & zone() const
Return a reference to the zone type.
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