mapPolyMesh.C
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) 2019-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 \*---------------------------------------------------------------------------*/
28 
29 #include "mapPolyMesh.H"
30 #include "polyMesh.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 Foam::mapPolyMesh::mapPolyMesh(const polyMesh& mesh)
35 :
36  mesh_(mesh),
37  nOldPoints_(mesh.nPoints()),
38  nOldFaces_(mesh.nFaces()),
39  nOldCells_(mesh.nCells()),
40  pointMap_(identity(mesh.nPoints())),
41  pointsFromPointsMap_(),
42  faceMap_(identity(mesh.nFaces())),
43  facesFromPointsMap_(),
44  facesFromEdgesMap_(),
45  facesFromFacesMap_(),
46  cellMap_(identity(mesh.nCells())),
47  cellsFromPointsMap_(),
48  cellsFromEdgesMap_(),
49  cellsFromFacesMap_(),
50  cellsFromCellsMap_(),
51  reversePointMap_(identity(mesh.nPoints())),
52  reverseFaceMap_(identity(mesh.nFaces())),
53  reverseCellMap_(identity(mesh.nCells())),
54  flipFaceFlux_(),
55  patchPointMap_(mesh.boundaryMesh().size()),
56  pointZoneMap_(mesh.pointZones().size()),
57  faceZonePointMap_(mesh.faceZones().size()),
58  faceZoneFaceMap_(mesh.faceZones().size()),
59  cellZoneMap_(mesh.cellZones().size()),
60  preMotionPoints_(mesh.points()),
61  oldPatchSizes_(mesh.boundaryMesh().patchSizes()),
62  oldPatchStarts_(mesh.boundaryMesh().patchStarts()),
63  oldPatchNMeshPoints_(mesh.boundaryMesh().size()),
64  oldCellVolumesPtr_()
65 {
66  // Identity map for patch points
67  forAll(patchPointMap_, patchi)
68  {
69  const label nPoints = mesh.boundaryMesh()[patchi].meshPoints().size();
70  oldPatchNMeshPoints_[patchi] = nPoints;
71  patchPointMap_[patchi] = identity(nPoints);
72  }
73 
74  // Identity maps for zones
75 
76  forAll(pointZoneMap_, zonei)
77  {
78  pointZoneMap_[zonei] = identity(mesh.pointZones()[zonei].size());
79  }
80 
81  forAll(faceZonePointMap_, zonei)
82  {
83  faceZonePointMap_[zonei] =
84  identity(mesh.faceZones()[zonei]().meshPoints().size());
85  }
86 
87  forAll(faceZoneFaceMap_, zonei)
88  {
89  faceZoneFaceMap_[zonei] = identity(mesh.faceZones()[zonei].size());
90  }
91 
92  forAll(cellZoneMap_, zonei)
93  {
94  cellZoneMap_[zonei] = identity(mesh.cellZones()[zonei].size());
95  }
96 }
97 
98 
99 Foam::mapPolyMesh::mapPolyMesh
100 (
101  const polyMesh& mesh,
102  const label nOldPoints,
103  const label nOldFaces,
104  const label nOldCells,
105  const labelList& pointMap,
106  const List<objectMap>& pointsFromPoints,
107  const labelList& faceMap,
108  const List<objectMap>& facesFromPoints,
109  const List<objectMap>& facesFromEdges,
110  const List<objectMap>& facesFromFaces,
111  const labelList& cellMap,
112  const List<objectMap>& cellsFromPoints,
113  const List<objectMap>& cellsFromEdges,
114  const List<objectMap>& cellsFromFaces,
115  const List<objectMap>& cellsFromCells,
116  const labelList& reversePointMap,
117  const labelList& reverseFaceMap,
118  const labelList& reverseCellMap,
119  const labelHashSet& flipFaceFlux,
120  const labelListList& patchPointMap,
121  const labelListList& pointZoneMap,
122  const labelListList& faceZonePointMap,
123  const labelListList& faceZoneFaceMap,
124  const labelListList& cellZoneMap,
125  const pointField& preMotionPoints,
126  const labelList& oldPatchStarts,
127  const labelList& oldPatchNMeshPoints,
128  const autoPtr<scalarField>& oldCellVolumesPtr
129 )
130 :
131  mesh_(mesh),
132  nOldPoints_(nOldPoints),
133  nOldFaces_(nOldFaces),
134  nOldCells_(nOldCells),
135  pointMap_(pointMap),
136  pointsFromPointsMap_(pointsFromPoints),
137  faceMap_(faceMap),
138  facesFromPointsMap_(facesFromPoints),
139  facesFromEdgesMap_(facesFromEdges),
140  facesFromFacesMap_(facesFromFaces),
141  cellMap_(cellMap),
142  cellsFromPointsMap_(cellsFromPoints),
143  cellsFromEdgesMap_(cellsFromEdges),
144  cellsFromFacesMap_(cellsFromFaces),
145  cellsFromCellsMap_(cellsFromCells),
146  reversePointMap_(reversePointMap),
147  reverseFaceMap_(reverseFaceMap),
148  reverseCellMap_(reverseCellMap),
149  flipFaceFlux_(flipFaceFlux),
150  patchPointMap_(patchPointMap),
151  pointZoneMap_(pointZoneMap),
152  faceZonePointMap_(faceZonePointMap),
153  faceZoneFaceMap_(faceZoneFaceMap),
154  cellZoneMap_(cellZoneMap),
155  preMotionPoints_(preMotionPoints),
156  oldPatchSizes_(oldPatchStarts.size()),
157  oldPatchStarts_(oldPatchStarts),
158  oldPatchNMeshPoints_(oldPatchNMeshPoints),
159  oldCellVolumesPtr_(oldCellVolumesPtr)
160 {
161  if (oldPatchStarts_.size())
162  {
163  // Calculate old patch sizes
164  for (label patchi = 0; patchi < oldPatchStarts_.size() - 1; patchi++)
165  {
166  oldPatchSizes_[patchi] =
167  oldPatchStarts_[patchi + 1] - oldPatchStarts_[patchi];
168  }
169 
170  // Set the last one by hand
171  const label lastPatchID = oldPatchStarts_.size() - 1;
172 
173  oldPatchSizes_[lastPatchID] = nOldFaces_ - oldPatchStarts_[lastPatchID];
174 
175  if (polyMesh::debug)
176  {
177  if (min(oldPatchSizes_) < 0)
178  {
180  << abort(FatalError);
181  }
182  }
183  }
184 }
185 
186 
187 Foam::mapPolyMesh::mapPolyMesh
188 (
189  const polyMesh& mesh,
190  const label nOldPoints,
191  const label nOldFaces,
192  const label nOldCells,
193  labelList& pointMap,
194  List<objectMap>& pointsFromPoints,
196  List<objectMap>& facesFromPoints,
197  List<objectMap>& facesFromEdges,
198  List<objectMap>& facesFromFaces,
199  labelList& cellMap,
200  List<objectMap>& cellsFromPoints,
201  List<objectMap>& cellsFromEdges,
202  List<objectMap>& cellsFromFaces,
203  List<objectMap>& cellsFromCells,
204  labelList& reversePointMap,
205  labelList& reverseFaceMap,
206  labelList& reverseCellMap,
207  labelHashSet& flipFaceFlux,
208  labelListList& patchPointMap,
209  labelListList& pointZoneMap,
210  labelListList& faceZonePointMap,
211  labelListList& faceZoneFaceMap,
212  labelListList& cellZoneMap,
213  pointField& preMotionPoints,
214  labelList& oldPatchStarts,
215  labelList& oldPatchNMeshPoints,
216  autoPtr<scalarField>& oldCellVolumesPtr,
217  const bool reuse
218 )
219 :
220  mesh_(mesh),
221  nOldPoints_(nOldPoints),
222  nOldFaces_(nOldFaces),
223  nOldCells_(nOldCells),
224  pointMap_(pointMap, reuse),
225  pointsFromPointsMap_(pointsFromPoints, reuse),
226  faceMap_(faceMap, reuse),
227  facesFromPointsMap_(facesFromPoints, reuse),
228  facesFromEdgesMap_(facesFromEdges, reuse),
229  facesFromFacesMap_(facesFromFaces, reuse),
230  cellMap_(cellMap, reuse),
231  cellsFromPointsMap_(cellsFromPoints, reuse),
232  cellsFromEdgesMap_(cellsFromEdges, reuse),
233  cellsFromFacesMap_(cellsFromFaces, reuse),
234  cellsFromCellsMap_(cellsFromCells, reuse),
235  reversePointMap_(reversePointMap, reuse),
236  reverseFaceMap_(reverseFaceMap, reuse),
237  reverseCellMap_(reverseCellMap, reuse),
238  flipFaceFlux_(flipFaceFlux),
239  patchPointMap_(patchPointMap, reuse),
240  pointZoneMap_(pointZoneMap, reuse),
241  faceZonePointMap_(faceZonePointMap, reuse),
242  faceZoneFaceMap_(faceZoneFaceMap, reuse),
243  cellZoneMap_(cellZoneMap, reuse),
244  preMotionPoints_(preMotionPoints, reuse),
245  oldPatchSizes_(oldPatchStarts.size()),
246  oldPatchStarts_(oldPatchStarts, reuse),
247  oldPatchNMeshPoints_(oldPatchNMeshPoints, reuse),
248  oldCellVolumesPtr_()
249 {
250  // Reuse old content or clone
251  if (reuse)
252  {
253  oldCellVolumesPtr_ = std::move(oldCellVolumesPtr);
254  }
255  else
256  {
257  oldCellVolumesPtr_ = oldCellVolumesPtr.clone();
258  }
259 
260  if (oldPatchStarts_.size() > 0)
261  {
262  // Calculate old patch sizes
263  for (label patchi = 0; patchi < oldPatchStarts_.size() - 1; patchi++)
264  {
265  oldPatchSizes_[patchi] =
266  oldPatchStarts_[patchi + 1] - oldPatchStarts_[patchi];
267  }
268 
269  // Set the last one by hand
270  const label lastPatchID = oldPatchStarts_.size() - 1;
271 
272  oldPatchSizes_[lastPatchID] = nOldFaces_ - oldPatchStarts_[lastPatchID];
273 
274  if (polyMesh::debug)
275  {
276  if (min(oldPatchSizes_) < 0)
277  {
279  << "Calculated negative old patch size."
280  << " Error in mapping data"
281  << abort(FatalError);
282  }
283  }
284  }
285 }
286 
287 
288 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
mapPolyMesh.H
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
polyMesh.H
Foam::HashSet< label, Hash< label > >
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::Field< vector >
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:492
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:486
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::polyMesh::pointZones
const pointZoneMesh & pointZones() const noexcept
Return point zone mesh.
Definition: polyMesh.H:480
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:62
Foam::mapPolyMesh::mesh
const polyMesh & mesh() const
Return polyMesh.
Definition: mapPolyMesh.H:363
Foam::autoPtr::clone
autoPtr< T > clone(Args &&... args) const
Copy construct by invoking clone on underlying managed object.