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-2018 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;
218 
219  //- Return baseMesh or subMesh, depending on the current state.
220  inline const fvMesh& mesh() const;
221 
222  //- Have subMesh?
223  inline bool hasSubMesh() const;
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
343  template<class Type>
346  (
348  const fvMesh& sMesh,
349  const labelUList& patchMap,
350  const labelUList& cellMap,
351  const labelUList& faceMap
352  );
353 
354  template<class Type>
357  (
359  ) const;
360 
361  //- Map surface field. Optionally negates value if flipping
362  // a face (from exposing an internal face)
363  template<class Type>
366  (
368  const fvMesh& sMesh,
369  const labelUList& patchMap,
370  const labelUList& cellMap,
371  const labelUList& faceMap
372  );
373 
374  template<class Type>
377  (
379  ) const;
380 
381  //- Map point field
382  template<class Type>
385  (
387  const pointMesh& sMesh,
388  const labelUList& patchMap,
389  const labelUList& pointMap
390  );
391 
392  template<class Type>
395  (
397  ) const;
398 
399  //- Map dimensioned field
400  template<class Type>
403  (
405  const fvMesh& sMesh,
406  const labelUList& cellMap
407  );
408 
409  template<class Type>
412 
413 
414  // Compatibility
415 
416  //- Deprecated(2018-07) old method name and old parameter ordering.
417  // \deprecated(2018-07) - use setCellSubset() method
418  inline void setLargeCellSubset
419  (
420  const labelUList& region,
421  const label currentRegion,
422  const label patchID = -1,
423  const bool syncCouples = true
424  )
425  {
426  Info<< "WARNING: using highly deprecated method: "
427  << "fvMeshSubset::setLargeCellSubset()" << nl;
428 
430  (
431  currentRegion,
432  region,
433  patchID,
434  syncCouples
435  );
436  }
437 
438 
439  //- Deprecated(2018-07) old method name
440  // \deprecated(2018-07) - use setCellSubset() method
441  inline void setLargeCellSubset
442  (
443  const labelHashSet& globalCellMap,
444  const label patchID = -1,
445  const bool syncPar = true
446  )
447  {
448  Info<< "WARNING: using highly deprecated method: "
449  << "fvMeshSubset::setLargeCellSubset()" << nl;
450 
451  setCellSubset(globalCellMap, patchID, syncPar);
452  }
453 
454 
455  //- Deprecated(2018-07) method
456  // For every exposed face (from getExposedFaces) use supplied
457  // (existing!) patch ids
458  // \deprecated(2018-07) - use setCellSubset() method
459  inline void setLargeCellSubset
460  (
461  const labelList& regions,
462  const label regioni,
463  const labelList& exposedFaces,
464  const labelList& patchIDs,
465  const bool syncCouples = true
466  )
467  {
468  Info<< "WARNING: using highly deprecated method: "
469  << "fvMeshSubset::setLargeCellSubset()" << nl;
470 
472  (
473  regioni,
474  regions,
475  exposedFaces,
476  patchIDs,
477  syncCouples
478  );
479  }
480 
481 };
482 
483 
484 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
485 
486 } // End namespace Foam
487 
488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
489 
490 #include "fvMeshSubsetI.H"
491 
492 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
493 
494 #ifdef NoRepository
495  #include "fvMeshSubsetInterpolate.C"
496 #endif
497 
498 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
499 
500 #endif
501 
502 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
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:59
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::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:560
Foam::HashSet< label, Hash< label > >
bitSet.H
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:547
Foam::fvMeshSubset::baseMesh
const fvMesh & baseMesh() const
Original mesh.
Definition: fvMeshSubsetI.H:30
Foam::label
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:62
Foam::fvMeshSubset::subMesh
const fvMesh & subMesh() const
Return reference to subset mesh.
Definition: fvMeshSubsetI.H:48
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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:84
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:50
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:418
GeometricField.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::fvMeshSubset::getExposedFaces
labelList getExposedFaces(const bitSet &selectedCells, const bool syncCouples=true) const
Get labels of exposed faces.
Definition: fvMeshSubset.C:1200
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::List< label >
Foam::UList< label >
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)
Map volume field.
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< Type, fvPatchField, volMesh >
Foam::fvMeshSubset::mesh
const fvMesh & mesh() const
Return baseMesh or subMesh, depending on the current state.
Definition: fvMeshSubsetI.H:36
Foam::fvMeshSubset::hasSubMesh
bool hasSubMesh() const
Have subMesh?
Definition: fvMeshSubsetI.H:42
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