conformalVoronoiMeshIO.C 52.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2012-2013 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/>.

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

#include "conformalVoronoiMesh.H"
#include "IOstreams.H"
#include "OFstream.H"
#include "pointMesh.H"
#include "pointFields.H"
#include "ListOps.H"
#include "polyMeshFilter.H"
#include "polyTopoChange.H"
#include "PrintTable.H"
#include "pointMesh.H"
36
#include "indexedVertexOps.H"
37
#include "DelaunayMeshTools.H"
38
39
40
41
42
#include "surfaceZonesInfo.H"
#include "polyModifyCell.H"
#include "polyModifyFace.H"
#include "syncTools.H"
#include "regionSplit.H"
43
44
45
46
47
48
49
50

// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

void Foam::conformalVoronoiMesh::timeCheck
(
    const string& description
) const
{
51
    timeCheck(time(), description, foamyHexMeshControls().timeChecks());
52
53
54
55
56
57
58
59
60
61
62
}


void Foam::conformalVoronoiMesh::timeCheck
(
    const Time& runTime,
    const string& description,
    const bool check
)
{
    if (check)
63
64
    {
        Info<< nl << "--- [ cpuTime "
65
66
            << runTime.elapsedCpuTime() << " s, "
            << "delta " << runTime.cpuTimeIncrement()<< " s";
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

        if (description != word::null)
        {
            Info<< ", " << description << " ";
        }
        else
        {
            Info<< " ";
        }

        Info<< "] --- " << endl;

        memInfo m;

        if (m.valid())
        {
83
84
85
86
87
            PrintTable<word, label> memoryTable
            (
                "Memory Usage (kB): "
              + description
            );
88
89
90
91
92
93

            memoryTable.add("mSize", m.size());
            memoryTable.add("mPeak", m.peak());
            memoryTable.add("mRss", m.rss());

            Info<< incrIndent;
94
            memoryTable.print(Info, true, true);
95
96
97
98
99
100
101
102
            Info<< decrIndent;
        }
    }
}


void Foam::conformalVoronoiMesh::writeMesh(const fileName& instance)
{
103
    DelaunayMeshTools::writeInternalDelaunayVertices(instance, *this);
104
105
106
107
108

    // Per cell the Delaunay vertex
    labelList cellToDelaunayVertex;
    // Per patch, per face the Delaunay vertex
    labelListList patchToDelaunayVertex;
109

110
111
112
113
114
115
116
117
118
    labelList dualPatchStarts;

    {
        pointField points;
        labelList boundaryPts(number_of_finite_cells(), -1);
        faceList faces;
        labelList owner;
        labelList neighbour;
        wordList patchNames;
119
        PtrList<dictionary> patchDicts;
120
121
122
123
124
125
126
127
128
129
130
131
        pointField cellCentres;

        PackedBoolList boundaryFacesToRemove;

        calcDualMesh
        (
            points,
            boundaryPts,
            faces,
            owner,
            neighbour,
            patchNames,
132
            patchDicts,
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
            cellCentres,
            cellToDelaunayVertex,
            patchToDelaunayVertex,
            boundaryFacesToRemove
        );

        Info<< nl << "Writing polyMesh to " << instance << endl;

        writeMesh
        (
            Foam::polyMesh::defaultRegion,
            instance,
            points,
            boundaryPts,
            faces,
            owner,
            neighbour,
            patchNames,
151
            patchDicts,
152
153
154
            cellCentres,
            boundaryFacesToRemove
        );
155
156
157
158
159
160
161
162

        dualPatchStarts.setSize(patchDicts.size());

        forAll(dualPatchStarts, patchI)
        {
            dualPatchStarts[patchI] =
                readLabel(patchDicts[patchI].lookup("startFace"));
        }
163
164
    }

165
    if (foamyHexMeshControls().writeCellShapeControlMesh())
166
    {
167
168
        cellShapeControls().shapeControlMesh().write();
    }
169

170
171
172
    if (foamyHexMeshControls().writeBackgroundMeshDecomposition())
    {
        Info<< nl << "Writing " << "backgroundMeshDecomposition" << endl;
173

174
175
176
177
178
179
        // Have to explicitly update the mesh instance.
        const_cast<fvMesh&>(decomposition_().mesh()).setInstance
        (
            time().timeName()
        );

180
181
        decomposition_().mesh().write();
    }
182

183
184
185
186
    if (foamyHexMeshControls().writeTetDualMesh())
    {
        label cellI = 0;
        for
187
        (
188
189
190
191
            Finite_cells_iterator cit = finite_cells_begin();
            cit != finite_cells_end();
            ++cit
        )
192
        {
193
            if
194
            (
195
196
197
                !cit->hasFarPoint()
             && !is_infinite(cit)
            )
198
            {
199
                cit->cellIndex() = cellI++;
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
        Info<< nl << "Writing " << "tetDualMesh" << endl;

        DistributedDelaunayMesh<Delaunay>::labelTolabelPairHashTable vertexMap;
        labelList cellMap;
        autoPtr<polyMesh> tetMesh =
            createMesh("tetDualMesh", vertexMap, cellMap);

        tetMesh().write();

//        // Determine map from Delaunay vertex to Dual mesh
//        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//        // From all Delaunay vertices to cell (positive index)
//        // or patch face (negative index)
//        labelList vertexToDualAddressing(number_of_vertices(), 0);
//
//        forAll(cellToDelaunayVertex, cellI)
//        {
//            label vertI = cellToDelaunayVertex[cellI];
//
//            if (vertexToDualAddressing[vertI] != 0)
//            {
//                FatalErrorIn("conformalVoronoiMesh::writeMesh(..)")
//                    << "Delaunay vertex " << vertI
//                    << " from cell " << cellI
//                    << " is already mapped to "
//                    << vertexToDualAddressing[vertI]
//                    << exit(FatalError);
//            }
//            vertexToDualAddressing[vertI] = cellI+1;
//        }
//
//        forAll(patchToDelaunayVertex, patchI)
//        {
//            const labelList& patchVertices = patchToDelaunayVertex[patchI];
//
//            forAll(patchVertices, i)
//            {
//                label vertI = patchVertices[i];
//
//                if (vertexToDualAddressing[vertI] > 0)
//                {
//                    FatalErrorIn("conformalVoronoiMesh::writeMesh(..)")
//                        << "Delaunay vertex " << vertI
//                        << " from patch " << patchI
//                        << " local index " << i
//                        << " is already mapped to cell "
//                        << vertexToDualAddressing[vertI]-1
//                        << exit(FatalError);
//                }
//
//                // Vertex might be used by multiple faces. Which one to
//                // use? For now last one wins.
//                label dualFaceI = dualPatchStarts[patchI]+i;
//                vertexToDualAddressing[vertI] = -dualFaceI-1;
//            }
//        }
//
//
//        // Calculate tet mesh addressing
//        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//        pointField points;
//        labelList boundaryPts(number_of_finite_cells(), -1);
//        // From tet point back to Delaunay vertex index
//        labelList pointToDelaunayVertex;
//        faceList faces;
//        labelList owner;
//        labelList neighbour;
//        wordList patchTypes;
//        wordList patchNames;
//        PtrList<dictionary> patchDicts;
//        pointField cellCentres;
//
//        calcTetMesh
//        (
//            points,
//            pointToDelaunayVertex,
//            faces,
//            owner,
//            neighbour,
//            patchTypes,
//            patchNames,
//            patchDicts
//        );
//
//
//
//        // Calculate map from tet points to dual mesh cells/patch faces
//        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//        labelIOList pointDualAddressing
//        (
//            IOobject
//            (
//                "pointDualAddressing",
//                instance,
//                "tetDualMesh"/polyMesh::meshSubDir,
//                runTime_,
//                IOobject::NO_READ,
//                IOobject::AUTO_WRITE,
//                false
//            ),
//            UIndirectList<label>
//            (
//                vertexToDualAddressing,
//                pointToDelaunayVertex
//            )()
//        );
//
//        label pointI = findIndex(pointDualAddressing, -1);
//        if (pointI != -1)
//        {
//            WarningIn
//            (
//                "conformalVoronoiMesh::writeMesh\n"
//                "(\n"
//                "    const fileName& instance,\n"
//                "    bool filterFaces\n"
//                ")\n"
//            )   << "Delaunay vertex " << pointI
//                << " does not have a corresponding dual cell." << endl;
//        }
//
//        Info<< "Writing map from tetDualMesh points to Voronoi mesh to "
//            << pointDualAddressing.objectPath() << endl;
//        pointDualAddressing.write();
//
//
//
//        // Write tet points corresponding to the Voronoi cell/face centre
//        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//        {
//            // Read Voronoi mesh
//            fvMesh mesh
//            (
//                IOobject
//                (
//                    Foam::polyMesh::defaultRegion,
//                    instance,
//                    runTime_,
//                    IOobject::MUST_READ
//                )
//            );
//            pointIOField dualPoints
//            (
//                IOobject
//                (
//                    "dualPoints",
//                    instance,
//                    "tetDualMesh"/polyMesh::meshSubDir,
//                    runTime_,
//                    IOobject::NO_READ,
//                    IOobject::AUTO_WRITE,
//                    false
//                ),
//                points
//            );
//
//            forAll(pointDualAddressing, pointI)
//            {
//                label index = pointDualAddressing[pointI];
//
//                if (index > 0)
//                {
//                    label cellI = index-1;
//                    dualPoints[pointI] = mesh.cellCentres()[cellI];
//                }
//                else if (index < 0)
//                {
//                    label faceI = -index-1;
//                    if (faceI >= mesh.nInternalFaces())
//                    {
//                        dualPoints[pointI] = mesh.faceCentres()[faceI];
//                    }
//                }
//            }
//
//            Info<< "Writing tetDualMesh points mapped onto Voronoi mesh to "
//                << dualPoints.objectPath() << endl
//                << "Replace the polyMesh/points with these." << endl;
//            dualPoints.write();
//        }
//
//
//        Info<< nl << "Writing tetDualMesh to " << instance << endl;
//
//        PackedBoolList boundaryFacesToRemove;
//        writeMesh
//        (
//            "tetDualMesh",
//            instance,
//            points,
//            boundaryPts,
//            faces,
//            owner,
//            neighbour,
//            patchTypes,
//            patchNames,
//            patchDicts,
//            cellCentres,
//            boundaryFacesToRemove
//        );
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
void Foam::conformalVoronoiMesh::findCellZoneInsideWalk
(
    const polyMesh& mesh,
    const labelList& locationSurfaces,  // indices of surfaces with inside point
    const labelList& faceToSurface, // per face index of named surface
    labelList& cellToSurface
) const
{
    // Analyse regions. Reuse regionsplit
    boolList blockedFace(mesh.nFaces());
    //selectSeparatedCoupledFaces(blockedFace);

    forAll(faceToSurface, faceI)
    {
        if (faceToSurface[faceI] == -1)
        {
            blockedFace[faceI] = false;
        }
        else
        {
            blockedFace[faceI] = true;
        }
    }
    // No need to sync since namedSurfaceIndex already is synced

    // Set region per cell based on walking
    regionSplit cellRegion(mesh, blockedFace);
    blockedFace.clear();


    // Force calculation of face decomposition (used in findCell)
    (void)mesh.tetBasePtIs();

    const PtrList<surfaceZonesInfo>& surfZones =
        geometryToConformTo().surfZones();

    // For all locationSurface find the cell
    forAll(locationSurfaces, i)
    {
        label surfI = locationSurfaces[i];

        const Foam::point& insidePoint = surfZones[surfI].zoneInsidePoint();

        const word& surfName = geometryToConformTo().geometry().names()[surfI];

        Info<< "    For surface " << surfName
            << " finding inside point " << insidePoint
            << endl;

        // Find the region containing the insidePoint
        label keepRegionI = -1;

        label cellI = mesh.findCell(insidePoint);

        if (cellI != -1)
        {
            keepRegionI = cellRegion[cellI];
        }
        reduce(keepRegionI, maxOp<label>());

        Info<< "    For surface " << surfName
            << " found point " << insidePoint << " in cell " << cellI
            << " in global region " << keepRegionI
            << " out of " << cellRegion.nRegions() << " regions." << endl;

        if (keepRegionI == -1)
        {
            FatalErrorIn
            (
                "conformalVoronoiMesh::findCellZoneInsideWalk"
                "(const polyMesh&, const labelList&"
                ", const labelList&, labelList&)"
            )   << "Point " << insidePoint
                << " is not inside the mesh." << nl
                << "Bounding box of the mesh:" << mesh.bounds()
                << exit(FatalError);
        }

        // Set all cells with this region
        forAll(cellRegion, cellI)
        {
            if (cellRegion[cellI] == keepRegionI)
            {
                if (cellToSurface[cellI] == -2)
                {
                    cellToSurface[cellI] = surfI;
                }
                else if (cellToSurface[cellI] != surfI)
                {
                    WarningIn
                    (
                        "conformalVoronoiMesh::findCellZoneInsideWalk"
                        "(const labelList&, const labelList&"
                        ", const labelList&, const labelList&)"
                    )   << "Cell " << cellI
                        << " at " << mesh.cellCentres()[cellI]
                        << " is inside surface " << surfName
                        << " but already marked as being in zone "
                        << cellToSurface[cellI] << endl
                        << "This can happen if your surfaces are not"
                        << " (sufficiently) closed."
                        << endl;
                }
            }
        }
    }
}


Foam::labelList Foam::conformalVoronoiMesh::calcCellZones
(
    const pointField& cellCentres
) const
{
    labelList cellToSurface(cellCentres.size(), -1);

    const PtrList<surfaceZonesInfo>& surfZones =
        geometryToConformTo().surfZones();

    // Get list of closed surfaces
    labelList closedNamedSurfaces
    (
        surfaceZonesInfo::getAllClosedNamedSurfaces
        (
            surfZones,
            geometryToConformTo().geometry(),
            geometryToConformTo().surfaces()
        )
    );

    forAll(closedNamedSurfaces, i)
    {
        label surfI = closedNamedSurfaces[i];

        const searchableSurface& surface =
            allGeometry()[geometryToConformTo().surfaces()[surfI]];

        const surfaceZonesInfo::areaSelectionAlgo selectionMethod =
            surfZones[surfI].zoneInside();

        if
        (
            selectionMethod != surfaceZonesInfo::INSIDE
         && selectionMethod != surfaceZonesInfo::OUTSIDE
         && selectionMethod != surfaceZonesInfo::INSIDEPOINT
        )
        {
            FatalErrorIn("conformalVoronoiMesh::calcCellZones(..)")
                << "Trying to use surface "
                << surface.name()
                << " which has non-geometric inside selection method "
                << surfaceZonesInfo::areaSelectionAlgoNames[selectionMethod]
                << exit(FatalError);
        }

        if (surface.hasVolumeType())
        {
            List<volumeType> volType;
            surface.getVolumeType(cellCentres, volType);

            bool selectInside = true;
            if (selectionMethod == surfaceZonesInfo::INSIDEPOINT)
            {
                List<volumeType> volTypeInsidePoint;
                surface.getVolumeType
                (
                    pointField(1, surfZones[surfI].zoneInsidePoint()),
                    volTypeInsidePoint
                );

                if (volTypeInsidePoint[0] == volumeType::OUTSIDE)
                {
                    selectInside = false;
                }
            }
            else if (selectionMethod == surfaceZonesInfo::OUTSIDE)
            {
                selectInside = false;
            }

            forAll(volType, pointI)
            {
                if (cellToSurface[pointI] == -1)
                {
                    if
                    (
                        (
                            volType[pointI] == volumeType::INSIDE
                         && selectInside
                        )
                     || (
                            volType[pointI] == volumeType::OUTSIDE
                         && !selectInside
                        )
                    )
                    {
                        cellToSurface[pointI] = surfI;
                    }
                }
            }
        }
    }

    return cellToSurface;
}


void Foam::conformalVoronoiMesh::calcFaceZones
(
    const polyMesh& mesh,
    const pointField& cellCentres,
    const labelList& cellToSurface,
    labelList& faceToSurface,
    boolList& flipMap
) const
{
    faceToSurface.setSize(mesh.nFaces(), -1);
    flipMap.setSize(mesh.nFaces(), false);

    const faceList& faces = mesh.faces();
    const labelList& faceOwner = mesh.faceOwner();
    const labelList& faceNeighbour = mesh.faceNeighbour();

    forAll(faces, faceI)
    {
        const label ownerSurfaceI = cellToSurface[faceOwner[faceI]];

        if (mesh.isInternalFace(faceI))
        {
            const label neiSurfaceI = cellToSurface[faceNeighbour[faceI]];

            flipMap[faceI] =
                (
                    ownerSurfaceI == max(ownerSurfaceI, neiSurfaceI)
                  ? false
                  : true
                );

            if
            (
                (ownerSurfaceI >= 0 || neiSurfaceI >= 0)
             && ownerSurfaceI != neiSurfaceI
            )
            {
                if (ownerSurfaceI > neiSurfaceI)
                {
                    faceToSurface[faceI] = ownerSurfaceI;
                }
                else
                {
                    faceToSurface[faceI] = neiSurfaceI;
                }
            }
        }
        else
        {
            if (ownerSurfaceI >= 0)
            {
                faceToSurface[faceI] = ownerSurfaceI;
            }
        }
    }


    const PtrList<surfaceZonesInfo>& surfZones =
        geometryToConformTo().surfZones();

    labelList insidePointNamedSurfaces
    (
        surfaceZonesInfo::getInsidePointNamedSurfaces(surfZones)
    );

    // Use intersection of cellCentre connections
    forAll(faces, faceI)
    {
        if
        (
            mesh.isInternalFace(faceI)
         && faceToSurface[faceI] < 0
        )
        {
            const label own = faceOwner[faceI];
            const label nei = faceNeighbour[faceI];

            pointIndexHit surfHit;
            label hitSurface;

            geometryToConformTo().findSurfaceAnyIntersection
            (
                cellCentres[own],
                cellCentres[nei],
                surfHit,
                hitSurface
            );

            if (surfHit.hit())
            {
                if (findIndex(insidePointNamedSurfaces, hitSurface) != -1)
                {
                    faceToSurface[faceI] = hitSurface;

                    vectorField norm;
                    geometryToConformTo().getNormal
                    (
                        hitSurface,
                        List<pointIndexHit>(1, surfHit),
                        norm
                    );

                    const vector fN = faces[faceI].normal(mesh.points());

                    if ((norm[0] & fN/(mag(fN) + SMALL)) < 0)
                    {
                        flipMap[faceI] = true;
                    }
                    else
                    {
                        flipMap[faceI] = false;
                    }
                }
            }
        }
    }


    labelList neiCellSurface(mesh.nFaces()-mesh.nInternalFaces());
    const polyBoundaryMesh& patches = mesh.boundaryMesh();

    forAll(patches, patchI)
    {
        const polyPatch& pp = patches[patchI];

        if (pp.coupled())
        {
            forAll(pp, i)
            {
                label faceI = pp.start()+i;
                label ownSurface = cellToSurface[faceOwner[faceI]];
                neiCellSurface[faceI - mesh.nInternalFaces()] = ownSurface;
            }
        }
    }
    syncTools::swapBoundaryFaceList(mesh, neiCellSurface);

    forAll(patches, patchI)
    {
        const polyPatch& pp = patches[patchI];

        if (pp.coupled())
        {
            forAll(pp, i)
            {
                label faceI = pp.start()+i;
                label ownSurface = cellToSurface[faceOwner[faceI]];
                label neiSurface = neiCellSurface[faceI-mesh.nInternalFaces()];

                if (faceToSurface[faceI] == -1 && (ownSurface != neiSurface))
                {
                    // Give face the max cell zone
                    faceToSurface[faceI] =  max(ownSurface, neiSurface);
                }
            }
        }
    }

    // Sync
    syncTools::syncFaceList(mesh, faceToSurface, maxEqOp<label>());
}


780
781
782
783
Foam::autoPtr<Foam::fvMesh> Foam::conformalVoronoiMesh::createDummyMesh
(
    const IOobject& io,
    const wordList& patchNames,
784
    const PtrList<dictionary>& patchDicts
785
786
787
788
789
790
791
792
793
794
795
796
797
798
) const
{
    autoPtr<fvMesh> meshPtr
    (
        new fvMesh
        (
            io,
            xferCopy(pointField()),
            xferCopy(faceList()),
            xferCopy(cellList())
        )
    );
    fvMesh& mesh = meshPtr();

799
    List<polyPatch*> patches(patchDicts.size());
800
801
802

    forAll(patches, patchI)
    {
803
804
805
806
807
808
809
810
        if
        (
            patchDicts.set(patchI)
         && (
                word(patchDicts[patchI].lookup("type"))
             == processorPolyPatch::typeName
            )
        )
811
812
813
814
815
816
817
818
        {
            patches[patchI] = new processorPolyPatch
            (
                patchNames[patchI],
                0,          //patchSizes[p],
                0,          //patchStarts[p],
                patchI,
                mesh.boundaryMesh(),
819
820
                readLabel(patchDicts[patchI].lookup("myProcNo")),
                readLabel(patchDicts[patchI].lookup("neighbProcNo")),
821
822
823
824
825
826
827
                coupledPolyPatch::COINCIDENTFULLMATCH
            );
        }
        else
        {
            patches[patchI] = polyPatch::New
            (
828
                patchDicts[patchI].lookup("type"),
829
830
831
832
833
834
835
836
                patchNames[patchI],
                0,          //patchSizes[p],
                0,          //patchStarts[p],
                patchI,
                mesh.boundaryMesh()
            ).ptr();
        }
    }
837

838
839
840
841
842
843
844
845
    mesh.addFvPatches(patches);

    return meshPtr;
}


void Foam::conformalVoronoiMesh::checkProcessorPatchesMatch
(
846
    const PtrList<dictionary>& patchDicts
847
848
849
850
851
852
853
854
855
) const
{
    // Check patch sizes
    labelListList procPatchSizes
    (
        Pstream::nProcs(),
        labelList(Pstream::nProcs(), -1)
    );

856
    forAll(patchDicts, patchI)
857
    {
858
859
860
861
862
863
864
865
        if
        (
            patchDicts.set(patchI)
         && (
                word(patchDicts[patchI].lookup("type"))
             == processorPolyPatch::typeName
            )
        )
866
        {
867
868
869
870
871
            const label procNeighb =
                readLabel(patchDicts[patchI].lookup("neighbProcNo"));

            procPatchSizes[Pstream::myProcNo()][procNeighb]
                = readLabel(patchDicts[patchI].lookup("nFaces"));
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
        }
    }

    Pstream::gatherList(procPatchSizes);

    if (Pstream::master())
    {
        bool allMatch = true;

        forAll(procPatchSizes, procI)
        {
            const labelList& patchSizes = procPatchSizes[procI];

            forAll(patchSizes, patchI)
            {
                if (patchSizes[patchI] != procPatchSizes[patchI][procI])
                {
                    allMatch = false;

                    Info<< indent << "Patches " << procI << " and " << patchI
                        << " have different sizes: " << patchSizes[patchI]
                        << " and " << procPatchSizes[patchI][procI] << endl;
                }
            }
        }

        if (allMatch)
        {
            Info<< indent << "All processor patches have matching numbers of "
                << "faces" << endl;
        }
    }
}


void Foam::conformalVoronoiMesh::reorderPoints
(
    pointField& points,
    labelList& boundaryPts,
    faceList& faces,
    const label nInternalFaces
) const
{
    Info<< incrIndent << indent << "Reordering points into internal/external"
        << endl;

    labelList oldToNew(points.size(), 0);

    // Find points that are internal
    for (label fI = nInternalFaces; fI < faces.size(); ++fI)
    {
        const face& f = faces[fI];

        forAll(f, fpI)
        {
            oldToNew[f[fpI]] = 1;
        }
    }

    const label nInternalPoints = points.size() - sum(oldToNew);

    label countInternal = 0;
    label countExternal = nInternalPoints;

    forAll(points, pI)
    {
        if (oldToNew[pI] == 0)
        {
            oldToNew[pI] = countInternal++;
        }
        else
        {
            oldToNew[pI] = countExternal++;
        }
    }

    Info<< indent
        << "Number of internal points: " << countInternal << nl
        << indent << "Number of external points: " << countExternal
        << decrIndent << endl;

    inplaceReorder(oldToNew, points);
    inplaceReorder(oldToNew, boundaryPts);

    forAll(faces, fI)
    {
        face& f = faces[fI];

        forAll(f, fpI)
        {
            f[fpI] = oldToNew[f[fpI]];
        }
    }
}


void Foam::conformalVoronoiMesh::reorderProcessorPatches
(
    const word& meshName,
    const fileName& instance,
    const pointField& points,
    faceList& faces,
    const wordList& patchNames,
975
    const PtrList<dictionary>& patchDicts
976
977
978
979
980
) const
{
    Info<< incrIndent << indent << "Reordering processor patches" << endl;

    Info<< incrIndent;
981
    checkProcessorPatchesMatch(patchDicts);
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997

    // Create dummy mesh with correct proc boundaries to do sorting
    autoPtr<fvMesh> sortMeshPtr
    (
        createDummyMesh
        (
            IOobject
            (
                meshName,
                instance,
                runTime_,
                IOobject::NO_READ,
                IOobject::NO_WRITE,
                false
            ),
            patchNames,
998
            patchDicts
999
1000
        )
    );
For faster browsing, not all history is shown. View entire blame