polyTopoChangeMap.H
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) 2011-2024 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 Class
25  Foam::polyTopoChangeMap
26 
27 Description
28  Class containing mesh-to-mesh mapping information after a change
29  in polyMesh topology.
30 
31  General:
32  - pointMap/faceMap/cellMap: \n
33  from current mesh back to previous mesh.
34  (so to 'pull' the information onto the current mesh)
35  - reversePointMap/faceMap/cellMap: \n
36  from previous mesh to current. (so to 'push' information)
37 
38  In the topology change points/faces/cells
39  - can be unchanged. (faces might be renumbered though)
40  - can be removed (into nothing)
41  - can be removed into/merged with existing same entity
42  (so point merged with other point, face with other face, cell with
43  other cell. Note that probably only cell with cell is relevant)
44  - can be added from existing same 'master' entity
45  (so point from point, face from face and cell from cell)
46  - can be appended: added 'out of nothing'.
47 
48  All this information is necessary to correctly map fields.
49 
50  \par points
51 
52  - unchanged:
53  - pointMap[pointi] contains old point label
54  - reversePointMap[oldPointi] contains new point label
55  - removed:
56  - reversePointMap[oldPointi] contains -1
57  - merged into point:
58  - reversePointMap[oldPointi] contains <-1 : -newPointi-2
59  - pointMap[pointi] contains the old master point label
60  - pointsFromPoints gives for pointi all the old point labels
61  (including the old master point!)
62  - added-from-same:
63  - pointMap[pointi] contains the old master point label
64  - appended:
65  - pointMap[pointi] contains -1
66 
67  \par faces
68 
69  - unchanged:
70  - faceMap[facei] contains old face label
71  - reverseFaceMap[oldFacei] contains new face label
72  - removed:
73  - reverseFaceMap[oldFacei] contains -1
74  - merged into face:
75  - reverseFaceMap[oldFacei] contains <-1 : -newFacei-2
76  - faceMap[facei] contains the old master face label
77  - facesFromFaces gives for facei all the old face labels
78  (including the old master face!)
79  - added-from-same:
80  - faceMap[facei] contains the old master face label
81  - appended:
82  - faceMap[facei] contains -1
83 
84  \par cells
85 
86  - unchanged:
87  - cellMap[celli] contains old cell label
88  - reverseCellMap[oldCelli] contains new cell label
89  - removed:
90  - reverseCellMap[oldCelli] contains -1
91  - merged into cell:
92  - reverseCellMap[oldCelli] contains <-1 : -newCelli-2
93  - cellMap[celli] contains the old master cell label
94  - cellsFromCells gives for celli all the old cell labels
95  (including the old master cell!)
96  - added-from-same:
97  - cellMap[celli] contains the old master cell label
98  - appended:
99  - cellMap[celli] contains -1
100 
101 SourceFiles
102  polyTopoChangeMap.C
103 
104 \*---------------------------------------------------------------------------*/
105 
106 #ifndef polyTopoChangeMap_H
107 #define polyTopoChangeMap_H
108 
109 #include "labelList.H"
110 #include "objectMap.H"
111 #include "pointField.H"
112 #include "HashSet.H"
113 #include "Map.H"
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 namespace Foam
118 {
119 
120 class polyMesh;
121 
122 /*---------------------------------------------------------------------------*\
123  Class polyTopoChangeMap Declaration
124 \*---------------------------------------------------------------------------*/
125 
126 class polyTopoChangeMap
127 {
128  // Private Data
129 
130  //- Reference to polyMesh
131  const polyMesh& mesh_;
132 
133  //- Number of old live points
134  const label nOldPoints_;
135 
136  //- Number of old live faces
137  const label nOldFaces_;
138 
139  //- Number of old live cells
140  const label nOldCells_;
141 
142  //- Old point map.
143  // Contains the old point label for all new points.
144  // - for preserved points this is the old point label.
145  // - for added points this is the master point ID
146  // - for points added with no master, this is -1
147  // Size of the list equals the size of new points
148  const labelList pointMap_;
149 
150  //- Points resulting from merging points
151  const List<objectMap> pointsFromPointsMap_;
152 
153  //- Old face map.
154  // Contains a list of old face labels for every new face.
155  // Size of the list equals the number of new faces
156  // - for preserved faces this is the old face label.
157  // - for faces added from faces this is the master face ID
158  // - for faces added with no master, this is -1
159  // - for faces added from points or edges, this is -1
160  const labelList faceMap_;
161 
162  //- Faces resulting from merging faces
163  const List<objectMap> facesFromFacesMap_;
164 
165  //- Old cell map.
166  // Contains old cell label for all preserved cells.
167  // Size of the list equals the number or preserved cells
168  const labelList cellMap_;
169 
170  //- Cells resulting from merging cells
171  const List<objectMap> cellsFromCellsMap_;
172 
173  //- Reverse point map
174  const labelList reversePointMap_;
175 
176  //- Reverse face map
177  const labelList reverseFaceMap_;
178 
179  //- Reverse cell map
180  const labelList reverseCellMap_;
181 
182  //- Map of flipped face flux faces
183  const labelHashSet flipFaceFlux_;
184 
185  //- Patch mesh point renumbering
186  const labelListList patchPointMap_;
187 
188  //- List of the old patch sizes
189  const labelList oldPatchSizes_;
190 
191  //- List of the old patch start labels
192  const labelList oldPatchStarts_;
193 
194  //- List of numbers of mesh points per old patch
195  const labelList oldPatchNMeshPoints_;
196 
197  //- Optional old cell volumes (for mapping)
198  autoPtr<scalarField> oldCellVolumesPtr_;
199 
200 
201 public:
202 
203  // Constructors
204 
205  //- Construct from mesh only, no topology change
207 
208  //- Construct from components reusing storage
210  (
211  const polyMesh& mesh,
212  const label nOldPoints,
213  const label nOldFaces,
214  const label nOldCells,
216  List<objectMap>&& pointsFromPoints,
217  labelList&& faceMap,
218  List<objectMap>&& facesFromFaces,
219  labelList&& cellMap,
220  List<objectMap>&& cellsFromCells,
229  autoPtr<scalarField>&& oldCellVolumesPtr
230  );
231 
232  //- Disallow default bitwise copy construction
233  polyTopoChangeMap(const polyTopoChangeMap&) = delete;
234 
235 
236  // Member Functions
237 
238  // Access
239 
240  //- Return polyMesh
241  const polyMesh& mesh() const
242  {
243  return mesh_;
244  }
245 
246  //- Number of old points
247  label nOldPoints() const
248  {
249  return nOldPoints_;
250  }
251 
252  //- Number of old internal faces
253  label nOldInternalFaces() const
254  {
255  return oldPatchStarts_[0];
256  }
257 
258  //- Number of old faces
259  label nOldFaces() const
260  {
261  return nOldFaces_;
262  }
263 
264  //- Number of old cells
265  label nOldCells() const
266  {
267  return nOldCells_;
268  }
269 
270  //- Old point map.
271  // Contains the old point label for all new points.
272  // For preserved points this is the old point label.
273  // For added points this is the master point ID
274  const labelList& pointMap() const
275  {
276  return pointMap_;
277  }
278 
279  //- Points originating from points
280  const List<objectMap>& pointsFromPointsMap() const
281  {
282  return pointsFromPointsMap_;
283  }
284 
285  //- Old face map.
286  // Contains a list of old face labels for every new face.
287  // Warning: this map contains invalid entries for new faces
288  const labelList& faceMap() const
289  {
290  return faceMap_;
291  }
292 
293  //- Faces originating from faces
294  const List<objectMap>& facesFromFacesMap() const
295  {
296  return facesFromFacesMap_;
297  }
298 
299  //- Old cell map.
300  // Contains old cell label for all preserved cells.
301  const labelList& cellMap() const
302  {
303  return cellMap_;
304  }
305 
306  //- Cells originating from cells
307  const List<objectMap>& cellsFromCellsMap() const
308  {
309  return cellsFromCellsMap_;
310  }
311 
312 
313  // Reverse maps
314 
315  //- Reverse point map
316  // Contains new point label for all old and added points
317  const labelList& reversePointMap() const
318  {
319  return reversePointMap_;
320  }
321 
322  //- If point is removed return point (on new mesh) it merged
323  // into
324  label mergedPoint(const label oldPointi) const
325  {
326  label i = reversePointMap_[oldPointi];
327 
328  if (i == -1)
329  {
330  return i;
331  }
332  else if (i < -1)
333  {
334  return -i-2;
335  }
336  else
337  {
339  << "old point label " << oldPointi
340  << " has reverseMap " << i << endl
341  << "Only call mergedPoint for removed points."
342  << abort(FatalError);
343  return -1;
344  }
345  }
346 
347  //- Reverse face map
348  // Contains new face label for all old and added faces
349  const labelList& reverseFaceMap() const
350  {
351  return reverseFaceMap_;
352  }
353 
354  //- If face is removed return face (on new mesh) it merged into
355  label mergedFace(const label oldFacei) const
356  {
357  label i = reverseFaceMap_[oldFacei];
358 
359  if (i == -1)
360  {
361  return i;
362  }
363  else if (i < -1)
364  {
365  return -i-2;
366  }
367  else
368  {
370  << "old face label " << oldFacei
371  << " has reverseMap " << i << endl
372  << "Only call mergedFace for removed faces."
373  << abort(FatalError);
374  return -1;
375  }
376  }
377 
378  //- Reverse cell map
379  // Contains new cell label for all old and added cells
380  const labelList& reverseCellMap() const
381  {
382  return reverseCellMap_;
383  }
384 
385  //- If cell is removed return cell (on new mesh) it merged into
386  label mergedCell(const label oldCelli) const
387  {
388  label i = reverseCellMap_[oldCelli];
389 
390  if (i == -1)
391  {
392  return i;
393  }
394  else if (i < -1)
395  {
396  return -i-2;
397  }
398  else
399  {
401  << "old cell label " << oldCelli
402  << " has reverseMap " << i << endl
403  << "Only call mergedCell for removed cells."
404  << abort(FatalError);
405  return -1;
406  }
407  }
408 
409  //- Map of flipped face flux faces
410  const labelHashSet& flipFaceFlux() const
411  {
412  return flipFaceFlux_;
413  }
414 
415  //- Patch point renumbering
416  // For every preserved point on a patch give the old position.
417  // For added points, the index is set to -1
418  const labelListList& patchPointMap() const
419  {
420  return patchPointMap_;
421  }
422 
423 
424  //- Return list of the old patch sizes
425  const labelList& oldPatchSizes() const
426  {
427  return oldPatchSizes_;
428  }
429 
430  //- Return list of the old patch start labels
431  const labelList& oldPatchStarts() const
432  {
433  return oldPatchStarts_;
434  }
435 
436  //- Return numbers of mesh points per old patch
437  const labelList& oldPatchNMeshPoints() const
438  {
439  return oldPatchNMeshPoints_;
440  }
441 
442 
443  // Geometric mapping data
444 
445  bool hasOldCellVolumes() const
446  {
447  return oldCellVolumesPtr_.valid();
448  }
449 
450  const scalarField& oldCellVolumes() const
451  {
452  return oldCellVolumesPtr_();
453  }
454 
455 
456  // Member Operators
457 
458  //- Disallow default bitwise assignment
459  void operator=(const polyTopoChangeMap&) = delete;
460 };
461 
462 
463 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
464 
465 } // End namespace Foam
466 
467 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
468 
469 #endif
470 
471 // ************************************************************************* //
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
Definition: autoPtrI.H:83
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
label nOldCells() const
Number of old cells.
label mergedFace(const label oldFacei) const
If face is removed return face (on new mesh) it merged into.
const labelHashSet & flipFaceFlux() const
Map of flipped face flux faces.
const labelList & cellMap() const
Old cell map.
label nOldInternalFaces() const
Number of old internal faces.
const labelList & reversePointMap() const
Reverse point map.
void operator=(const polyTopoChangeMap &)=delete
Disallow default bitwise assignment.
const labelList & pointMap() const
Old point map.
const labelList & oldPatchNMeshPoints() const
Return numbers of mesh points per old patch.
const List< objectMap > & pointsFromPointsMap() const
Points originating from points.
const labelList & reverseCellMap() const
Reverse cell map.
const labelList & reverseFaceMap() const
Reverse face map.
label mergedPoint(const label oldPointi) const
If point is removed return point (on new mesh) it merged.
label mergedCell(const label oldCelli) const
If cell is removed return cell (on new mesh) it merged into.
polyTopoChangeMap(const polyMesh &mesh)
Construct from mesh only, no topology change.
label nOldFaces() const
Number of old faces.
const scalarField & oldCellVolumes() const
label nOldPoints() const
Number of old points.
const labelList & oldPatchStarts() const
Return list of the old patch start labels.
const List< objectMap > & facesFromFacesMap() const
Faces originating from faces.
const List< objectMap > & cellsFromCellsMap() const
Cells originating from cells.
const labelListList & patchPointMap() const
Patch point renumbering.
const polyMesh & mesh() const
Return polyMesh.
const labelList & oldPatchSizes() const
Return list of the old patch sizes.
const labelList & faceMap() const
Old face map.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
Namespace for OpenFOAM.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
errorManip< error > abort(error &err)
Definition: errorManip.H:131
error FatalError