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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2011-2024 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::polyTopoChangeMap

Description
    Class containing mesh-to-mesh mapping information after a change
    in polyMesh topology.

    General:
        - pointMap/faceMap/cellMap: \n
          from current mesh back to previous mesh.
          (so to 'pull' the information onto the current mesh)
        - reversePointMap/faceMap/cellMap: \n
          from previous mesh to current. (so to 'push' information)

    In the topology change points/faces/cells
    - can be unchanged. (faces might be renumbered though)
    - can be removed (into nothing)
    - can be removed into/merged with existing same entity
      (so point merged with other point, face with other face, cell with
       other cell. Note that probably only cell with cell is relevant)
    - can be added from existing same 'master' entity
      (so point from point, face from face and cell from cell)
    - can be appended: added 'out of nothing'.

    All this information is necessary to correctly map fields.

    \par points

    - unchanged:
        - pointMap[pointi] contains old point label
        - reversePointMap[oldPointi] contains new point label
    - removed:
        - reversePointMap[oldPointi] contains -1
    - merged into point:
        - reversePointMap[oldPointi] contains <-1 : -newPointi-2
        - pointMap[pointi] contains the old master point label
        - pointsFromPoints gives for pointi all the old point labels
          (including the old master point!)
    - added-from-same:
        - pointMap[pointi] contains the old master point label
    - appended:
        - pointMap[pointi] contains -1

    \par faces

    - unchanged:
        - faceMap[facei] contains old face label
        - reverseFaceMap[oldFacei] contains new face label
    - removed:
        - reverseFaceMap[oldFacei] contains -1
    - merged into face:
        - reverseFaceMap[oldFacei] contains <-1 : -newFacei-2
        - faceMap[facei] contains the old master face label
        - facesFromFaces gives for facei all the old face labels
          (including the old master face!)
    - added-from-same:
        - faceMap[facei] contains the old master face label
    - appended:
        - faceMap[facei] contains -1

    \par cells

    - unchanged:
        - cellMap[celli] contains old cell label
        - reverseCellMap[oldCelli] contains new cell label
    - removed:
        - reverseCellMap[oldCelli] contains -1
    - merged into cell:
        - reverseCellMap[oldCelli] contains <-1 : -newCelli-2
        - cellMap[celli] contains the old master cell label
        - cellsFromCells gives for celli all the old cell labels
          (including the old master cell!)
    - added-from-same:
        - cellMap[celli] contains the old master cell label
    - appended:
        - cellMap[celli] contains -1

SourceFiles
    polyTopoChangeMap.C

\*---------------------------------------------------------------------------*/

#ifndef polyTopoChangeMap_H
#define polyTopoChangeMap_H

#include "labelList.H"
#include "objectMap.H"
#include "pointField.H"
#include "HashSet.H"
#include "Map.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

class polyMesh;

/*---------------------------------------------------------------------------*\
                         Class polyTopoChangeMap Declaration
\*---------------------------------------------------------------------------*/

class polyTopoChangeMap
{
    // Private Data

        //- Reference to polyMesh
        const polyMesh& mesh_;

        //- Number of old live points
        const label nOldPoints_;

        //- Number of old live faces
        const label nOldFaces_;

        //- Number of old live cells
        const label nOldCells_;

        //- Old point map.
        //  Contains the old point label for all new points.
        //  - for preserved points this is the old point label.
        //  - for added points this is the master point ID
        //  - for points added with no master, this is -1
        //  Size of the list equals the size of new points
        const labelList pointMap_;

        //- Points resulting from merging points
        const List<objectMap> pointsFromPointsMap_;

        //- Old face map.
        //  Contains a list of old face labels for every new face.
        //  Size of the list equals the number of new faces
        //  - for preserved faces this is the old face label.
        //  - for faces added from faces this is the master face ID
        //  - for faces added with no master, this is -1
        //  - for faces added from points or edges, this is -1
        const labelList faceMap_;

        //- Faces resulting from merging faces
        const List<objectMap> facesFromFacesMap_;

        //- Old cell map.
        //  Contains old cell label for all preserved cells.
        //  Size of the list equals the number or preserved cells
        const labelList cellMap_;

        //- Cells resulting from merging cells
        const List<objectMap> cellsFromCellsMap_;

        //- Reverse point map
        const labelList reversePointMap_;

        //- Reverse face map
        const labelList reverseFaceMap_;

        //- Reverse cell map
        const labelList reverseCellMap_;

        //- Map of flipped face flux faces
        const labelHashSet flipFaceFlux_;

        //- Patch mesh point renumbering
        const labelListList patchPointMap_;

        //- List of the old patch sizes
        const labelList oldPatchSizes_;

        //- List of the old patch start labels
        const labelList oldPatchStarts_;

        //- List of numbers of mesh points per old patch
        const labelList oldPatchNMeshPoints_;

        //- Optional old cell volumes (for mapping)
        autoPtr<scalarField> oldCellVolumesPtr_;


public:

    // Constructors

        //- Construct from mesh only, no topology change
        polyTopoChangeMap(const polyMesh& mesh);

        //- Construct from components reusing storage
        polyTopoChangeMap
        (
            const polyMesh& mesh,
            const label nOldPoints,
            const label nOldFaces,
            const label nOldCells,
            labelList&& pointMap,
            List<objectMap>&& pointsFromPoints,
            labelList&& faceMap,
            List<objectMap>&& facesFromFaces,
            labelList&& cellMap,
            List<objectMap>&& cellsFromCells,
            labelList&& reversePointMap,
            labelList&& reverseFaceMap,
            labelList&& reverseCellMap,
            labelHashSet&& flipFaceFlux,
            labelListList&& patchPointMap,
            labelList&& oldPatchSizes,
            labelList&& oldPatchStarts,
            labelList&& oldPatchNMeshPoints,
            autoPtr<scalarField>&& oldCellVolumesPtr
        );

        //- Disallow default bitwise copy construction
        polyTopoChangeMap(const polyTopoChangeMap&) = delete;


    // Member Functions

        // Access

            //- Return polyMesh
            const polyMesh& mesh() const
            {
                return mesh_;
            }

            //- Number of old points
            label nOldPoints() const
            {
                return nOldPoints_;
            }

            //- Number of old internal faces
            label nOldInternalFaces() const
            {
                return oldPatchStarts_[0];
            }

            //- Number of old faces
            label nOldFaces() const
            {
                return nOldFaces_;
            }

            //- Number of old cells
            label nOldCells() const
            {
                return nOldCells_;
            }

            //- Old point map.
            //  Contains the old point label for all new points.
            //  For preserved points this is the old point label.
            //  For added points this is the master point ID
            const labelList& pointMap() const
            {
                return pointMap_;
            }

            //- Points originating from points
            const List<objectMap>& pointsFromPointsMap() const
            {
                return pointsFromPointsMap_;
            }

            //- Old face map.
            //  Contains a list of old face labels for every new face.
            //  Warning: this map contains invalid entries for new faces
            const labelList& faceMap() const
            {
                return faceMap_;
            }

            //- Faces originating from faces
            const List<objectMap>& facesFromFacesMap() const
            {
                return facesFromFacesMap_;
            }

            //- Old cell map.
            //  Contains old cell label for all preserved cells.
            const labelList& cellMap() const
            {
                return cellMap_;
            }

            //- Cells originating from cells
            const List<objectMap>& cellsFromCellsMap() const
            {
                return cellsFromCellsMap_;
            }


            // Reverse maps

                //- Reverse point map
                //  Contains new point label for all old and added points
                const labelList& reversePointMap() const
                {
                    return reversePointMap_;
                }

                //- If point is removed return point (on new mesh) it merged
                //  into
                label mergedPoint(const label oldPointi) const
                {
                    label i = reversePointMap_[oldPointi];

                    if (i == -1)
                    {
                        return i;
                    }
                    else if (i < -1)
                    {
                        return -i-2;
                    }
                    else
                    {
                        FatalErrorInFunction
                            << "old point label " << oldPointi
                            << " has reverseMap " << i << endl
                            << "Only call mergedPoint for removed points."
                            << abort(FatalError);
                        return -1;
                    }
                }

                //- Reverse face map
                //  Contains new face label for all old and added faces
                const labelList& reverseFaceMap() const
                {
                    return reverseFaceMap_;
                }

                //- If face is removed return face (on new mesh) it merged into
                label mergedFace(const label oldFacei) const
                {
                    label i = reverseFaceMap_[oldFacei];

                    if (i == -1)
                    {
                        return i;
                    }
                    else if (i < -1)
                    {
                        return -i-2;
                    }
                    else
                    {
                        FatalErrorInFunction
                            << "old face label " << oldFacei
                            << " has reverseMap " << i << endl
                            << "Only call mergedFace for removed faces."
                            << abort(FatalError);
                        return -1;
                    }
                }

                //- Reverse cell map
                //  Contains new cell label for all old and added cells
                const labelList& reverseCellMap() const
                {
                    return reverseCellMap_;
                }

                //- If cell is removed return cell (on new mesh) it merged into
                label mergedCell(const label oldCelli) const
                {
                    label i = reverseCellMap_[oldCelli];

                    if (i == -1)
                    {
                        return i;
                    }
                    else if (i < -1)
                    {
                        return -i-2;
                    }
                    else
                    {
                        FatalErrorInFunction
                            << "old cell label " << oldCelli
                            << " has reverseMap " << i << endl
                            << "Only call mergedCell for removed cells."
                            << abort(FatalError);
                        return -1;
                    }
                }

                //- Map of flipped face flux faces
                const labelHashSet& flipFaceFlux() const
                {
                    return flipFaceFlux_;
                }

                //- Patch point renumbering
                //  For every preserved point on a patch give the old position.
                //  For added points, the index is set to -1
                const labelListList& patchPointMap() const
                {
                    return patchPointMap_;
                }


            //- Return list of the old patch sizes
            const labelList& oldPatchSizes() const
            {
                return oldPatchSizes_;
            }

            //- Return list of the old patch start labels
            const labelList& oldPatchStarts() const
            {
                return oldPatchStarts_;
            }

            //- Return numbers of mesh points per old patch
            const labelList& oldPatchNMeshPoints() const
            {
                return oldPatchNMeshPoints_;
            }


            // Geometric mapping data

                bool hasOldCellVolumes() const
                {
                    return oldCellVolumesPtr_.valid();
                }

                const scalarField& oldCellVolumes() const
                {
                    return oldCellVolumesPtr_();
                }


    // Member Operators

        //- Disallow default bitwise assignment
        void operator=(const polyTopoChangeMap&) = delete;
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //