union.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 "union.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::Union::select
45 (
46  boolList& selected,
47  const labelList& indices,
48  const bool select
49 ) const
50 {
51  forAll(indices, i)
52  {
53  selected[indices[i]] = select;
54  }
55 }
56 
57 
58 void Foam::zoneGenerators::Union::select
59 (
60  boolList& selected,
61  boolList& flipMap,
62  const labelList& indices,
63  const boolList& zoneFlipMap,
64  const bool select
65 ) const
66 {
67  forAll(indices, i)
68  {
69  selected[indices[i]] = select;
70  flipMap[indices[i]] = zoneFlipMap[i];
71  }
72 }
73 
74 
76 (
77  const bool diff,
78  const bool all
79 ) const
80 {
81  boolList selectedPoints;
82  boolList selectedCells;
83  boolList selectedFaces;
84  boolList flipMap;
85 
86  forAll(zoneGenerators_, i)
87  {
88  zoneSet zs(zoneGenerators_[i].generate());
89 
90  // Select or deselect
91  const bool sel = all ? false : (diff ? i == 0 : true);
92 
93  if
94  (
95  zoneType_ == zoneTypesAll::point
96  || (zoneType_ == zoneTypesAll::all && zs.pValid())
97  )
98  {
99  selectedPoints.setSize(mesh_.nPoints(), all);
100  select(selectedPoints, zs.pZone(), sel);
101  }
102 
103  if
104  (
105  zoneType_ == zoneTypesAll::cell
106  || (zoneType_ == zoneTypesAll::all && zs.cValid())
107  )
108  {
109  selectedCells.setSize(mesh_.nCells(), all);
110  select(selectedCells, zs.cZone(), sel);
111  }
112 
113  if
114  (
115  zoneType_ == zoneTypesAll::face
116  || (zoneType_ == zoneTypesAll::all && zs.fValid())
117  )
118  {
119  const bool oriented = !all && zs.fZone().oriented();
120 
121  // If selecting faces check the status of the orientation
122  // of the supplied and current faceZones
123  if (sel)
124  {
125  if (!oriented && flipMap.size())
126  {
128  << "faceZone " << zs.fZone().name()
129  << " is not oriented"
130  " so the resulting faceZone will not be oriented"
131  << endl;
132  flipMap.clear();
133  }
134  else if (oriented && selectedFaces.size() && !flipMap.size())
135  {
137  << "faceZone " << zs.fZone().name()
138  << " is oriented but a previous faceZone is not "
139  " so the resulting faceZone will not be oriented"
140  << endl;
141  }
142  }
143 
144  selectedFaces.setSize(mesh_.nFaces(), all);
145 
146  if (oriented)
147  {
148  flipMap.setSize(mesh_.nFaces(), false);
149 
150  select
151  (
152  selectedFaces,
153  flipMap,
154  zs.fZone(),
155  zs.fZone().flipMap(),
156  sel
157  );
158  }
159  else
160  {
161  select(selectedFaces, zs.fZone(), sel);
162  }
163  }
164  }
165 
166  moveUpdate_ = zoneGenerators_.moveUpdate();
167 
168  const labelList faceIndices(indices(selectedFaces));
169 
170  return zoneSet
171  (
172  selectedPoints.size()
173  ? new pointZone
174  (
175  zoneName_,
176  indices(selectedPoints),
177  mesh_.pointZones(),
178  moveUpdate_,
179  true
180  )
181  : nullptr,
182  selectedCells.size()
183  ? new cellZone
184  (
185  zoneName_,
186  indices(selectedCells),
187  mesh_.cellZones(),
188  moveUpdate_,
189  true
190  )
191  : nullptr,
192  selectedFaces.size()
193  ? flipMap.size()
194  ? new faceZone
195  (
196  zoneName_,
197  faceIndices,
198  boolList(flipMap, faceIndices),
199  mesh_.faceZones(),
200  moveUpdate_,
201  true
202  )
203  : new faceZone
204  (
205  zoneName_,
206  faceIndices,
207  mesh_.faceZones(),
208  moveUpdate_,
209  true
210  )
211  : nullptr
212  );
213 }
214 
215 
216 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
217 
219 (
220  const word& name,
221  const polyMesh& mesh,
222  const dictionary& dict
223 )
224 :
226  zoneType_
227  (
228  zoneTypesAllNames.lookupOrDefault("zoneType", dict, zoneTypesAll::all)
229  ),
230  zoneGenerators_(mesh, dict)
231 {}
232 
233 
234 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
235 
237 {}
238 
239 
240 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
241 
243 {
244  return generate(false, false);
245 }
246 
247 
248 // ************************************************************************* //
#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 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
const word & name() const
Return name.
Definition: Zone.H:171
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
Abstract base class for all zoneGenerators, providing runtime selection.
Definition: zoneGenerator.H:57
static labelList indices(const boolList &selected)
Return the list of selected indices.
A zoneGenerator which selects all the elements from the zones generated by the given list of zoneGene...
Definition: union.H:127
virtual zoneSet generate() const
Generate and return the zoneSet.
Definition: union.C:242
virtual ~Union()
Destructor.
Definition: union.C:236
Union(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: union.C:219
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)
#define WarningInFunction
Report a warning using Foam::Warning.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:409
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