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-2020 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  Given the original mesh and the list of selected cells, it creates the
32  mesh consisting only of the desired cells, with the mapping list for
33  points, faces, and cells.
34 
35  Puts all exposed internal faces into either
36  - a user supplied patch
37  - a newly created patch "oldInternalFaces"
38 
39  - setCellSubset does coupled patch subsetting as well. If it detects
40  a face on a coupled patch 'losing' its neighbour it will move the
41  face into the oldInternalFaces patch.
42 
43  - if a user supplied patch is used it is up to the destination
44  patchField to handle exposed internal faces (mapping from face -1).
45  If not provided the default is to assign the internalField. All the
46  basic patch field types (e.g. fixedValue) will give a warning and
47  preferably derived patch field types should be used that know how to
48  handle exposed faces (e.g. use uniformFixedValue instead of fixedValue)
49 
50 SourceFiles
51  fvMeshSubset.C
52 
53 \*---------------------------------------------------------------------------*/
54 
55 #ifndef fvMeshSubset_H
56 #define fvMeshSubset_H
57 
58 #include "fvMesh.H"
59 #include "pointMesh.H"
60 #include "GeometricField.H"
61 #include "bitSet.H"
62 #include "HashSet.H"
63 #include "surfaceMesh.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 
70 /*---------------------------------------------------------------------------*\
71  Class fvMeshSubset Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 class fvMeshSubset
75 {
76  // Private Data
77 
78  //- Mesh to subset from
79  const fvMesh& baseMesh_;
80 
81  //- Demand-driven subset mesh pointer
82  autoPtr<fvMesh> fvMeshSubsetPtr_;
83 
84  //- Optional face mapping array with flip encoded (-1/+1)
85  mutable autoPtr<labelList> faceFlipMapPtr_;
86 
87  //- Point mapping array
88  labelList pointMap_;
89 
90  //- Face mapping array
91  labelList faceMap_;
92 
93  //- Cell mapping array
94  labelList cellMap_;
95 
96  //- Patch mapping array
97  labelList patchMap_;
98 
99 
100  // Private Member Functions
101 
102  //- Check if subset has been performed
103  bool checkCellSubset() const;
104 
105  //- Calculate face flip map
106  void calcFaceFlipMap() const;
107 
108  //- Adapt nCellsUsingFace for coupled faces becoming 'uncoupled'.
109  void doCoupledPatches
110  (
111  const bool syncPar,
112  labelList& nCellsUsingFace
113  ) const;
114 
115  //- Forwarding to Foam::removeCells
116  void removeCellsImpl
117  (
118  const bitSet& cellsToRemove,
119  const labelList& exposedFaces,
120  const labelList& patchIDs,
121  const bool syncCouples
122  );
123 
124 
125  //- Subset of subset
126  static labelList subsetSubset
127  (
128  const label nElems,
129  const labelUList& selectedElements,
130  const labelUList& subsetMap
131  );
132 
133  //- Create zones for submesh
134  void subsetZones();
135 
136  //- Helper: extract cells-to-remove from cells-to-keep
137  bitSet getCellsToRemove
138  (
139  const bitSet& selectedCells
140  ) const;
141 
142  //- Helper: extract cells-to-remove from cells-to-keep
143  bitSet getCellsToRemove
144  (
145  const label regioni,
146  const labelUList& regions
147  ) const;
148 
149 
150  //- No copy construct
151  fvMeshSubset(const fvMeshSubset&) = delete;
152 
153  //- No copy assignment
154  void operator=(const fvMeshSubset&) = delete;
155 
156 
157 public:
158 
159  // Static Data Members
160 
161  //- Name for exposed internal faces (default: oldInternalFaces)
162  static word exposedPatchName;
163 
164 
165  // Constructors
166 
167  //- Construct given a mesh to subset
168  explicit fvMeshSubset(const fvMesh& baseMesh);
169 
170  //- Construct for a cell-subset of the given mesh
171  // See setCellSubset() for more details.
173  (
174  const fvMesh& baseMesh,
175  const bitSet& selectedCells,
176  const label patchID = -1,
177  const bool syncPar = true
178  );
179 
180  //- Construct for a cell-subset of the given mesh
181  // See setCellSubset() for more details.
183  (
184  const fvMesh& baseMesh,
185  const labelUList& selectedCells,
186  const label patchID = -1,
187  const bool syncPar = true
188  );
189 
190  //- Construct for a cell-subset of the given mesh
191  // See setCellSubset() for more details.
193  (
194  const fvMesh& baseMesh,
195  const labelHashSet& selectedCells,
196  const label patchID = -1,
197  const bool syncPar = true
198  );
199 
200  //- Construct for a cell-subset of the given mesh
201  // See setCellSubset() for more details.
203  (
204  const fvMesh& baseMesh,
205  const label regioni,
206  const labelUList& regions,
207  const label patchID = -1,
208  const bool syncPar = true
209  );
210 
211 
212  // Member Functions
213 
214  // Access
215 
216  //- Original mesh
217  inline const fvMesh& baseMesh() const noexcept;
218 
219  //- Return baseMesh or subMesh, depending on the current state.
220  inline const fvMesh& mesh() const noexcept;
221 
222  //- Have subMesh?
223  inline bool hasSubMesh() const noexcept;
224 
225  //- Return reference to subset mesh
226  inline const fvMesh& subMesh() const;
227 
228  //- Return reference to subset mesh
229  inline fvMesh& subMesh();
230 
231  //- Return point map
232  inline const labelList& pointMap() const;
233 
234  //- Return face map
235  inline const labelList& faceMap() const;
236 
237  //- Return face map with sign to encode flipped faces
238  inline const labelList& faceFlipMap() const;
239 
240  //- Return cell map
241  inline const labelList& cellMap() const;
242 
243  //- Return patch map
244  inline const labelList& patchMap() const;
245 
246 
247  // Edit
248 
249  //- Reset maps and subsetting
250  void clear();
251 
252 
253  //- Define cell subset based on the selectedCells.
254  // Create "oldInternalFaces" patch for exposed
255  // internal faces (patchID==-1) or use supplied patch.
256  // Handles coupled patches if necessary by making coupled patch
257  // face part of patchID (so uncoupled)
258  void setCellSubset
259  (
260  const bitSet& selectedCells,
261  const label patchID = -1,
262  const bool syncPar = true
263  );
264 
265  //- Define cell subset, using the specified cells
266  //- to define the selection
267  void setCellSubset
268  (
269  const labelUList& selectedCells,
270  const label patchID = -1,
271  const bool syncPar = true
272  );
273 
274  //- Define cell subset, using the specified cells
275  //- labelHashSet to define the selection
276  void setCellSubset
277  (
278  const labelHashSet& selectedCells,
279  const label patchID = -1,
280  const bool syncPar = true
281  );
282 
283  //- Define cell subset, using the cells for which region == regioni.
284  void setCellSubset
285  (
286  const label regioni,
287  const labelUList& regions,
288  const label patchID = -1,
289  const bool syncCouples = true
290  );
291 
292 
293  // Two-step subsetting
294 
295  //- Get labels of exposed faces.
296  // These are
297  // - internal faces that become boundary faces
298  // - coupled faces that become uncoupled (since one of the
299  // sides gets deleted)
301  (
302  const bitSet& selectedCells,
303  const bool syncCouples = true
304  ) const;
305 
306  //- Get labels of exposed faces.
307  // These are
308  // - internal faces that become boundary faces
309  // - coupled faces that become uncoupled (since one of the
310  // sides gets deleted)
312  (
313  const label regioni,
314  const labelUList& regions,
315  const bool syncCouples = true
316  ) const;
317 
318  //- For every exposed face (from above getExposedFaces)
319  // used supplied (existing!) patch
320  void setCellSubset
321  (
322  const bitSet& selectedCells,
323  const labelList& exposedFaces,
324  const labelList& patchIDs,
325  const bool syncCouples = true
326  );
327 
328  //- For every exposed face (from above getExposedFaces)
329  // used supplied (existing!) patch
330  void setCellSubset
331  (
332  const label regioni,
333  const labelList& regions,
334  const labelList& exposedFaces,
335  const labelList& patchIDs,
336  const bool syncCouples = true
337  );
338 
339 
340  // Field Mapping
341 
342  //- Map volume field. Optionally allow unmapped faces not to produce
343  // a warning
344  template<class Type>
345  static tmp<GeometricField<Type, fvPatchField, volMesh>>
347  (
348  const GeometricField<Type, fvPatchField, volMesh>&,
349  const fvMesh& sMesh,
350  const labelUList& patchMap,
351  const labelUList& cellMap,
352  const labelUList& faceMap,
353  const bool allowUnmapped = false
354  );
355 
356  template<class Type>
359  (
360  const GeometricField<Type, fvPatchField, volMesh>&,
361  const bool allowUnmapped = false
362  ) const;
363 
364  //- Map surface field. Optionally negates value if flipping
365  // a face (from exposing an internal face)
366  template<class Type>
369  (
371  const fvMesh& sMesh,
372  const labelUList& patchMap,
373  const labelUList& cellMap,
374  const labelUList& faceMap
375  );
376 
377  //- Map surface field. Optionally allow unmapped faces not to produce
378  // a warning (not currently used)
379  template<class Type>
382  (
384  const bool allowUnmapped = false
385  ) const;
386 
387  //- Map point field
388  template<class Type>
391  (
393  const pointMesh& sMesh,
394  const labelUList& patchMap,
395  const labelUList& pointMap
396  );
397 
398  //- Map point field. Optionally allow unmapped points not to produce
399  // a warning (not currently used)
400  template<class Type>
403  (
405  const bool allowUnmapped = false
406  ) const;
407 
408  //- Map dimensioned field
409  template<class Type>
410  static tmp<DimensionedField<Type, volMesh>>
412  (
413  const DimensionedField<Type, volMesh>&,
414  const fvMesh& sMesh,
415  const labelUList& cellMap
416  );
417 
418  //- Map Dimensioned. Optional unmapped argument not used
419  template<class Type>
422  (
423  const DimensionedField<Type, volMesh>&,
424  const bool allowUnmapped = false
425  ) const;
426 
427 
428  // Compatibility
429 
430  //- Deprecated(2018-07) old method name and old parameter ordering.
431  // \deprecated(2018-07) - use setCellSubset() method
432  inline void setLargeCellSubset
433  (
434  const labelUList& region,
435  const label currentRegion,
436  const label patchID = -1,
437  const bool syncCouples = true
438  )
439  {
440  Info<< "WARNING: using highly deprecated method: "
441  << "fvMeshSubset::setLargeCellSubset()" << nl;
442 
444  (
445  currentRegion,
446  region,
447  patchID,
448  syncCouples
449  );
450  }
451 
452 
453  //- Deprecated(2018-07) old method name
454  // \deprecated(2018-07) - use setCellSubset() method
455  inline void setLargeCellSubset
456  (
457  const labelHashSet& globalCellMap,
458  const label patchID = -1,
459  const bool syncPar = true
460  )
461  {
462  Info<< "WARNING: using highly deprecated method: "
463  << "fvMeshSubset::setLargeCellSubset()" << nl;
464 
465  setCellSubset(globalCellMap, patchID, syncPar);
466  }
467 
468 
469  //- Deprecated(2018-07) method
470  // For every exposed face (from getExposedFaces) use supplied
471  // (existing!) patch ids
472  // \deprecated(2018-07) - use setCellSubset() method
473  inline void setLargeCellSubset
474  (
475  const labelList& regions,
476  const label regioni,
477  const labelList& exposedFaces,
478  const labelList& patchIDs,
479  const bool syncCouples = true
480  )
481  {
482  Info<< "WARNING: using highly deprecated method: "
483  << "fvMeshSubset::setLargeCellSubset()" << nl;
484 
486  (
487  regioni,
488  regions,
489  exposedFaces,
490  patchIDs,
491  syncCouples
492  );
493  }
494 };
495 
496 
497 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
498 
499 } // End namespace Foam
500 
501 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
502 
503 #include "fvMeshSubsetI.H"
504 
505 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
506 
507 #ifdef NoRepository
508  #include "fvMeshSubsetInterpolate.C"
509 #endif
510 
511 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
512 
513 #endif
514 
515 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::fvMeshSubset::cellMap
const labelList & cellMap() const
Return cell map.
Definition: fvMeshSubsetI.H:91
Foam::fvMeshSubset::pointMap
const labelList & pointMap() const
Return point map.
Definition: fvMeshSubsetI.H:64
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::fvMeshSubset
Given the original mesh and the list of selected cells, it creates the mesh consisting only of the de...
Definition: fvMeshSubset.H:73
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:51
Foam::surfaceMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: surfaceMesh.H:49
Foam::fvsPatchField
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:68
Foam::fvMeshSubset::exposedPatchName
static word exposedPatchName
Name for exposed internal faces (default: oldInternalFaces)
Definition: fvMeshSubset.H:161
Foam::fvMeshSubset::setCellSubset
void setCellSubset(const bitSet &selectedCells, const label patchID=-1, const bool syncPar=true)
Define cell subset based on the selectedCells.
Definition: fvMeshSubset.C:558
Foam::HashSet< label, Hash< label > >
bitSet.H
Foam::pointPatchField
Abstract base class for point-mesh patch fields.
Definition: pointMVCWeight.H:60
Foam::fvMeshSubset::faceFlipMap
const labelList & faceFlipMap() const
Return face map with sign to encode flipped faces.
Definition: fvMeshSubsetI.H:80
Foam::fvMeshSubset::clear
void clear()
Reset maps and subsetting.
Definition: fvMeshSubset.C:545
Foam::fvMeshSubset::subMesh
const fvMesh & subMesh() const
Return reference to subset mesh.
Definition: fvMeshSubsetI.H:48
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
fvMeshSubsetInterpolate.C
patchID
label patchID
Definition: boundaryProcessorFaPatchPoints.H:5
HashSet.H
surfaceMesh.H
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:51
Foam::fvMeshSubset::baseMesh
const fvMesh & baseMesh() const noexcept
Original mesh.
Definition: fvMeshSubsetI.H:30
Foam::fvMeshSubset::setLargeCellSubset
void setLargeCellSubset(const labelUList &region, const label currentRegion, const label patchID=-1, const bool syncCouples=true)
Deprecated(2018-07) old method name and old parameter ordering.
Definition: fvMeshSubset.H:432
Foam::fvMeshSubset::hasSubMesh
bool hasSubMesh() const noexcept
Have subMesh?
Definition: fvMeshSubsetI.H:42
GeometricField.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::fvMeshSubset::interpolate
static tmp< GeometricField< Type, fvPatchField, volMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &, const fvMesh &sMesh, const labelUList &patchMap, const labelUList &cellMap, const labelUList &faceMap, const bool allowUnmapped=false)
Map volume field. Optionally allow unmapped faces not to produce.
Foam::fvMeshSubset::getExposedFaces
labelList getExposedFaces(const bitSet &selectedCells, const bool syncCouples=true) const
Get labels of exposed faces.
Definition: fvMeshSubset.C:1245
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
Foam::UList< label >
Foam::fvMeshSubset::faceMap
const labelList & faceMap() const
Return face map.
Definition: fvMeshSubsetI.H:72
Foam::fvMeshSubset::patchMap
const labelList & patchMap() const
Return patch map.
Definition: fvMeshSubsetI.H:99
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::fvMeshSubset::mesh
const fvMesh & mesh() const noexcept
Return baseMesh or subMesh, depending on the current state.
Definition: fvMeshSubsetI.H:36
pointMesh.H
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
fvMeshSubsetI.H