face_zoneGenerator.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 "face_zoneGenerator.H"
27 #include "polyMesh.H"
28 #include "syncTools.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  namespace zoneGenerators
36  {
39  (
41  face,
43  );
44  }
45 }
46 
47 const Foam::NamedEnum
48 <
50  4
52 {
53  "all",
54  "inner",
55  "outer",
56  "outerInternal"
57 };
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
63 (
64  const word& name,
65  const polyMesh& mesh,
66  const dictionary& dict
67 )
68 :
70  zoneGenerators_(mesh, dict),
71  cellFaces_
72  (
73  cellFacesNames.lookupOrDefault
74  (
75  "cellFaces",
76  dict,
77  cellFaces::all
78  )
79  )
80 {}
81 
82 
83 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
84 
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
92 {
93  boolList selectedFaces(mesh_.nFaces(), false);
94  boolList flipMap(mesh_.nFaces(), false);
95 
96  forAll(zoneGenerators_, i)
97  {
98  zoneSet zs(zoneGenerators_[i].generate());
99 
100  if (zs.pValid())
101  {
102  // const labelList& zonePoints = zs.pZone();
104  }
105 
106  if (zs.cValid())
107  {
108  const labelList& zoneCells = zs.cZone();
109 
110  switch (cellFaces_)
111  {
112  case cellFaces::all:
113  {
114  forAll(zoneCells, zci)
115  {
116  const labelList& cellFaces =
117  mesh_.cells()[zoneCells[zci]];
118 
119  forAll(cellFaces, cFacei)
120  {
121  selectedFaces[cellFaces[cFacei]] = true;
122  }
123  }
124  break;
125  }
126 
127  case cellFaces::inner:
128  {
129  const labelHashSet cellSet(zoneCells);
130 
131  const label nInt = mesh_.nInternalFaces();
132  const labelList& own = mesh_.faceOwner();
133  const labelList& nei = mesh_.faceNeighbour();
134  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
135 
136  // Check all internal faces
137  for (label facei = 0; facei < nInt; facei++)
138  {
139  if
140  (
141  cellSet.found(own[facei])
142  && cellSet.found(nei[facei])
143  )
144  {
145  selectedFaces[facei] = true;
146  }
147  }
148 
149 
150  // Get coupled cell status
151  boolList neiInSet(mesh_.nFaces()-nInt, false);
152 
154  {
155  const polyPatch& pp = patches[patchi];
156 
157  if (pp.coupled())
158  {
159  label facei = pp.start();
160  forAll(pp, i)
161  {
162  neiInSet[facei-nInt] =
163  cellSet.found(own[facei]);
164  facei++;
165  }
166  }
167  }
168  syncTools::swapBoundaryFaceList(mesh_, neiInSet);
169 
170  // Check all boundary faces
172  {
173  const polyPatch& pp = patches[patchi];
174 
175  if (pp.coupled())
176  {
177  label facei = pp.start();
178  forAll(pp, i)
179  {
180  if
181  (
182  cellSet.found(own[facei])
183  && neiInSet[facei-nInt]
184  )
185  {
186  selectedFaces[facei] = true;
187  }
188  facei++;
189  }
190  }
191  }
192  break;
193  }
194 
195  case cellFaces::outer:
196  case cellFaces::outerInternal:
197  {
198  const labelHashSet cellSet(zoneCells);
199 
200  const label nInt = mesh_.nInternalFaces();
201  const labelList& own = mesh_.faceOwner();
202  const labelList& nei = mesh_.faceNeighbour();
203  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
204 
205  // Check all internal faces
206  for (label facei = 0; facei < nInt; facei++)
207  {
208  const bool inOwn = cellSet.found(own[facei]);
209  const bool inNei = cellSet.found(nei[facei]);
210 
211  if (inOwn && !inNei)
212  {
213  selectedFaces[facei] = true;
214  flipMap[facei] = false;
215  }
216  else if (!inOwn && inNei)
217  {
218  selectedFaces[facei] = true;
219  flipMap[facei] = true;
220  }
221  }
222 
223 
224  // Get coupled cell status
225  boolList neiInSet(mesh_.nFaces()-nInt, false);
226 
228  {
229  const polyPatch& pp = patches[patchi];
230 
231  if (pp.coupled())
232  {
233  label facei = pp.start();
234  forAll(pp, i)
235  {
236  neiInSet[facei-nInt] =
237  cellSet.found(own[facei]);
238  facei++;
239  }
240  }
241  else if
242  (
243  cellFaces_ != cellFaces::outerInternal
244  )
245  {
246  label facei = pp.start();
247  forAll(pp, i)
248  {
249  if (cellSet.found(own[facei]))
250  {
251  selectedFaces[facei] = true;
252  }
253 
254  facei++;
255  }
256  }
257  }
258 
259  syncTools::swapBoundaryFaceList(mesh_, neiInSet);
260 
261  // Check all boundary faces
263  {
264  const polyPatch& pp = patches[patchi];
265 
266  if (pp.coupled())
267  {
268  label facei = pp.start();
269  forAll(pp, i)
270  {
271  const bool inOwn = cellSet.found(own[facei]);
272  const bool inNei = neiInSet[facei-nInt];
273 
274  if (inOwn && !inNei)
275  {
276  selectedFaces[facei] = true;
277  flipMap[facei] = false;
278  }
279  else if (!inOwn && inNei)
280  {
281  selectedFaces[facei] = true;
282  flipMap[facei] = true;
283  }
284 
285  facei++;
286  }
287  }
288  }
289  break;
290  }
291  }
292  }
293 
294  if (zs.fValid() && zs.fZone().name() != zoneName_)
295  {
296  const labelList& zoneFaces = zs.fZone();
297 
298  forAll(zoneFaces, zfi)
299  {
300  const Foam::face& f = mesh_.faces()[zoneFaces[zfi]];
301 
302  forAll(f, fp)
303  {
304  selectedFaces[f[fp]] = true;
305  }
306  }
307  }
308  }
309 
310  moveUpdate_ = zoneGenerators_.moveUpdate();
311 
312  const labelList faceIndices(indices(selectedFaces));
313 
314  return zoneSet
315  (
316  new faceZone
317  (
318  zoneName_,
319  faceIndices,
320  boolList(flipMap, faceIndices),
321  mesh_.faceZones(),
322  moveUpdate_,
323  true
324  )
325  );
326 }
327 
328 
329 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:138
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
const word & name() const
Return name.
Definition: Zone.H:171
A collection of cell labels.
Definition: cellSet.H:51
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
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Foam::polyBoundaryMesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:290
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:280
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:436
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
A zoneGenerator which converts the point, cell and face zones from a list of zoneGenerators into a fa...
face(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
virtual zoneSet generate() const
Generate and return the zoneSet.
cellFaces
Enumeration defining the valid options.
virtual ~face()
Destructor.
static const NamedEnum< cellFaces, 4 > cellFacesNames
Names of the valid options.
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
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 NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
label patchi
const fvPatchList & patches
defineTypeNameAndDebug(cylinderHeadPoints, 0)
addToRunTimeSelectionTable(zoneGenerator, cylinderHeadPoints, dictionary)
Namespace for OpenFOAM.
void outer(LagrangianPatchField< typename outerProduct< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
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.
labelList f(nPoints)
dictionary dict