fvMeshSubset.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::fvMeshSubset
29 
30 Description
31  Holds a reference to the original mesh (the baseMesh)
32  and optionally to a subset of that mesh (the subMesh)
33  with mapping lists for points, faces, and cells.
34 
35  Can be constructed or reset to subset on the list of selected cells,
36  which it creates as subMesh consisting only of the desired cells,
37  with the mapping list for points, faces, and cells.
38 
39  Places all exposed internal faces into either
40  - a user supplied patch
41  - a newly created patch "oldInternalFaces"
42 
43  - reset() does coupled patch subsetting as well.
44  If it detects a face on a coupled patch 'losing' its neighbour
45  it will move the face into the oldInternalFaces patch.
46 
47  - if a user supplied patch is used, it is up to the destination
48  patchField to handle exposed internal faces (mapping from face -1).
49  If not provided the default is to assign the internalField. All the
50  basic patch field types (e.g. fixedValue) will give a warning and
51  preferably derived patch field types should be used that know how to
52  handle exposed faces (e.g. use uniformFixedValue instead of fixedValue)
53 
54 SourceFiles
55  fvMeshSubset.C
56  fvMeshSubsetI.H
57  fvMeshSubsetTemplates.C
58 
59 \*---------------------------------------------------------------------------*/
60 
61 #ifndef Foam_fvMeshSubset_H
62 #define Foam_fvMeshSubset_H
63 
64 #include "fvMesh.H"
65 #include "pointMesh.H"
66 #include "surfaceMesh.H"
67 #include "GeometricField.H"
68 #include "bitSet.H"
69 #include "HashSet.H"
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
73 namespace Foam
74 {
75 
76 /*---------------------------------------------------------------------------*\
77  Class fvMeshSubset Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 class fvMeshSubset
81 {
82  // Private Data
83 
84  //- The base mesh to subset from
85  const fvMesh& baseMesh_;
86 
87  //- Demand-driven subset mesh (pointer)
88  autoPtr<fvMesh> subMeshPtr_;
89 
90  //- Optional face mapping array with flip encoded (-1/+1)
91  mutable autoPtr<labelList> faceFlipMapPtr_;
92 
93  //- Point mapping array
94  labelList pointMap_;
95 
96  //- Face mapping array
97  labelList faceMap_;
98 
99  //- Cell mapping array
100  labelList cellMap_;
101 
102  //- Patch mapping array
103  labelList patchMap_;
104 
105  //- PointPatch mapping array
106  labelList pointPatchMap_;
107 
108 
109  // Private Member Functions
110 
111  //- Modify nCellsUsingFace for coupled faces becoming 'uncoupled.
112  void doCoupledPatches
113  (
114  const bool syncPar,
115  labelUList& nCellsUsingFace
116  ) const;
117 
118  //- Create zones for subMesh
119  void subsetZones();
120 
121  //- Calculate face flip map
122  void calcFaceFlipMap() const;
123 
124 
125 protected:
126 
127  // Protected Member Functions
128 
129  //- FatalError if subset has not been performed
130  bool checkHasSubMesh() const;
131 
132  //- No copy construct
133  fvMeshSubset(const fvMeshSubset&) = delete;
134 
135  //- No copy assignment
136  void operator=(const fvMeshSubset&) = delete;
137 
138 
139 public:
140 
141  // Declare name of the class and its debug switch
142  ClassName("fvMeshSubset");
143 
144 
145  // Static Data Members
146 
147  //- Name for exposed internal faces (default: oldInternalFaces)
148  static word exposedPatchName;
149 
150 
151  // Constructors
152 
153  //- Construct using the entire mesh (no subset)
154  explicit fvMeshSubset(const fvMesh& baseMesh);
155 
156  //- Construct a zero-sized subset mesh, non-processor patches only
157  fvMeshSubset(const fvMesh& baseMesh, const Foam::zero);
158 
159  //- Construct for a cell-subset of the given mesh
160  // See reset() for more details.
162  (
163  const fvMesh& baseMesh,
164  const bitSet& selectedCells,
165  const label patchID = -1,
166  const bool syncPar = true
167  );
168 
169  //- Construct for a cell-subset of the given mesh
170  // See reset() for more details.
172  (
173  const fvMesh& baseMesh,
174  const labelUList& selectedCells,
175  const label patchID = -1,
176  const bool syncPar = true
177  );
178 
179  //- Construct for a cell-subset of the given mesh
180  // See reset() for more details.
182  (
183  const fvMesh& baseMesh,
184  const labelHashSet& selectedCells,
185  const label patchID = -1,
186  const bool syncPar = true
187  );
188 
189  //- Construct for a cell-subset of the given mesh
190  // See reset() for more details.
192  (
193  const fvMesh& baseMesh,
194  const label regioni,
195  const labelUList& regions,
196  const label patchID = -1,
197  const bool syncPar = true
198  );
199 
200 
201  // Member Functions
202 
203  // Access
204 
205  //- Original mesh
206  inline const fvMesh& baseMesh() const noexcept;
207 
208  //- Return baseMesh or subMesh, depending on the current state.
209  inline const fvMesh& mesh() const noexcept;
210 
211  //- Have subMesh?
212  inline bool hasSubMesh() const noexcept;
213 
214  //- Return reference to subset mesh
215  inline const fvMesh& subMesh() const;
216 
217  //- Return reference to subset mesh
218  inline fvMesh& subMesh();
219 
220  //- Return point map
221  inline const labelList& pointMap() const;
222 
223  //- Return face map
224  inline const labelList& faceMap() const;
225 
226  //- Return face map with sign to encode flipped faces
227  inline const labelList& faceFlipMap() const;
228 
229  //- Return cell map
230  inline const labelList& cellMap() const;
231 
232  //- Return patch map
233  inline const labelList& patchMap() const;
234 
235  //- Return point-patch map. Usually identical to patchMap except if
236  //- additional patches are added to the pointMesh.
237  inline const labelList& pointPatchMap() const;
238 
239 
240  // Edit
241 
242  //- Reset subMesh and all maps
243  void clear();
244 
245  //- Reset subMesh and all maps. Same as clear()
246  void reset();
247 
248  //- Reset to a zero-sized subset mesh, non-processor patches only
249  void reset(const Foam::zero);
250 
251  //- Reset from components
252  void reset
253  (
254  autoPtr<fvMesh>&& subMeshPtr,
255  labelList&& pointMap,
256  labelList&& faceMap,
257  labelList&& cellMap,
259  );
260 
261  //- Use the specified subset of cells.
262  //
263  // \par selectedCells The subset of cells to use
264  // \par patchID Patch id for exposed internal faces.
265  // Uses existing or creates "oldInternalFaces" for patchID == -1.
266  // \par syncPar
267  //
268  // \note Handles coupled patches if necessary by making
269  // coupled patch faces part of patchID (ie, uncoupled)
270  void reset
271  (
272  const bitSet& selectedCells,
273  const label patchID = -1,
274  const bool syncPar = true
275  );
276 
277  //- Use the specified subset of cells.
278  void reset
279  (
280  const labelUList& selectedCells,
281  const label patchID = -1,
282  const bool syncPar = true
283  );
284 
285  //- Use the specified subset of cells.
286  void reset
287  (
288  const labelHashSet& selectedCells,
289  const label patchID = -1,
290  const bool syncPar = true
291  );
292 
293  //- Use the cells of cells corresponding to where region == regioni.
294  void reset
295  (
296  const label regioni,
297  const labelUList& regions,
298  const label patchID = -1,
299  const bool syncCouples = true
300  );
301 
302 
303  // Legacy method names (v2112 and earlier)
304 
305  //- Use the specified subset of cells. Same as reset()
306  void setCellSubset
307  (
308  const bitSet& selectedCells,
309  const label patchID = -1,
310  const bool syncPar = true
311  )
312  {
313  reset(selectedCells, patchID, syncPar);
314  }
315 
316  //- Use the specified subset of cells. Same as reset()
317  void setCellSubset
318  (
319  const labelUList& selectedCells,
320  const label patchID = -1,
321  const bool syncPar = true
322  )
323  {
324  reset(selectedCells, patchID, syncPar);
325  }
326 
327  //- Use the specified subset of cells. Same as reset()
328  void setCellSubset
329  (
330  const labelHashSet& selectedCells,
331  const label patchID = -1,
332  const bool syncPar = true
333  )
334  {
335  reset(selectedCells, patchID, syncPar);
336  }
337 
338  //- Use the specified subset of cells. Same as reset()
339  void setCellSubset
340  (
341  const label regioni,
342  const labelUList& regions,
343  const label patchID = -1,
344  const bool syncPar = true
345  )
346  {
347  reset(regioni, regions, patchID, syncPar);
348  }
349 
350 
351  // Field Mapping (static functions)
352 
353  //- Map volume internal (dimensioned) field
354  template<class Type>
355  static tmp<DimensionedField<Type, volMesh>>
357  (
358  const DimensionedField<Type, volMesh>&,
359  const fvMesh& sMesh,
360  const labelUList& cellMap
361  );
362 
363  //- Map volume field.
364  // Optionally allow unmapped faces not to produce a warning
365  template<class Type>
366  static tmp<GeometricField<Type, fvPatchField, volMesh>>
368  (
369  const GeometricField<Type, fvPatchField, volMesh>&,
370  const fvMesh& sMesh,
371  const labelUList& patchMap,
372  const labelUList& cellMap,
373  const labelUList& faceMap,
374  const bool allowUnmapped = false
375  );
376 
377  //- Map surface field.
378  // Optionally negates value if flipping a face
379  // (from exposing an internal face)
380  template<class Type>
381  static tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>
383  (
384  const GeometricField<Type, fvsPatchField, surfaceMesh>&,
385  const fvMesh& sMesh,
386  const labelUList& patchMap,
387  const labelUList& cellMap,
388  const labelUList& faceMap
389  );
390 
391  //- Map point field
392  template<class Type>
395  (
397  const pointMesh& sMesh,
398  const labelUList& patchMap,
399  const labelUList& pointMap
400  );
401 
403  // Field Mapping
404 
405  //- Map volume internal (dimensioned) field
406  //- Optional unmapped argument (currently unused)
407  template<class Type>
410  (
412  const bool allowUnmapped = false
413  ) const;
414 
415  //- Map volume field.
416  // Optionally allow unmapped faces not to produce a warning
417  template<class Type>
420  (
422  const bool allowUnmapped = false
423  ) const;
424 
425  //- Map surface field.
426  // Optionally allow unmapped faces not to produce a warning
427  // (currently unused)
428  template<class Type>
431  (
433  const bool allowUnmapped = false
434  ) const;
435 
436  //- Map point field.
437  // Optionally allow unmapped points not to produce a warning
438  // (currently unused)
439  template<class Type>
442  (
444  const bool allowUnmapped = false
445  ) const;
446 };
447 
448 
449 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
450 
451 } // End namespace Foam
452 
453 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
454 
455 #include "fvMeshSubsetI.H"
456 
457 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
458 
459 #ifdef NoRepository
460  #include "fvMeshSubsetTemplates.C"
461 #endif
462 
463 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
464 
465 #endif
466 
467 // ************************************************************************* //
static tmp< DimensionedField< Type, volMesh > > interpolate(const DimensionedField< Type, volMesh > &, const fvMesh &sMesh, const labelUList &cellMap)
Map volume internal (dimensioned) field.
static word exposedPatchName
Name for exposed internal faces (default: oldInternalFaces)
Definition: fvMeshSubset.H:173
void setCellSubset(const bitSet &selectedCells, const label patchID=-1, const bool syncPar=true)
Use the specified subset of cells. Same as reset()
Definition: fvMeshSubset.H:389
bool hasSubMesh() const noexcept
Have subMesh?
Definition: fvMeshSubsetI.H:35
const labelList & faceFlipMap() const
Return face map with sign to encode flipped faces.
Definition: fvMeshSubsetI.H:73
const fvMesh & baseMesh() const noexcept
Original mesh.
Definition: fvMeshSubsetI.H:23
const labelList & faceMap() const
Return face map.
Definition: fvMeshSubsetI.H:65
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
ClassName("fvMeshSubset")
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
const labelList & patchMap() const
Return patch map.
Definition: fvMeshSubsetI.H:92
const fvMesh & subMesh() const
Return reference to subset mesh.
Definition: fvMeshSubsetI.H:41
bool checkHasSubMesh() const
FatalError if subset has not been performed.
Definition: fvMeshSubset.C:112
A class for handling words, derived from Foam::string.
Definition: word.H:63
const labelList & pointMap() const
Return point map.
Definition: fvMeshSubsetI.H:57
void reset()
Reset subMesh and all maps. Same as clear()
Definition: fvMeshSubset.C:491
const labelList & cellMap() const
Return cell map.
Definition: fvMeshSubsetI.H:84
const direction noexcept
Definition: Scalar.H:258
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
Definition: fvMeshSubset.H:75
const labelList & pointPatchMap() const
Return point-patch map. Usually identical to patchMap except if additional patches are added to the p...
const fvMesh & mesh() const noexcept
Return baseMesh or subMesh, depending on the current state.
Definition: fvMeshSubsetI.H:29
void operator=(const fvMeshSubset &)=delete
No copy assignment.
fvMeshSubset(const fvMeshSubset &)=delete
No copy construct.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Namespace for OpenFOAM.
void clear()
Reset subMesh and all maps.
Definition: fvMeshSubset.C:479