checkGeometry.C 30.7 KB
Newer Older
1
#include "PatchTools.H"
Henry's avatar
Henry committed
2
3
4
5
6
7
8
9
10
#include "checkGeometry.H"
#include "polyMesh.H"
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
#include "EdgeMap.H"
#include "wedgePolyPatch.H"
#include "unitConversion.H"
#include "polyMeshTetDecomposition.H"
11
12
#include "surfaceWriter.H"
#include "checkTools.H"
13
14
15
#include "vtkSurfaceWriter.H"
#include "cyclicAMIPolyPatch.H"
#include "Time.H"
Henry's avatar
Henry committed
16
17
18
19
20
21
22
23
24
25
26
27
28

// Find wedge with opposite orientation. Note: does not actually check that
// it is opposite, only that it has opposite normal and same axis
Foam::label Foam::findOppositeWedge
(
    const polyMesh& mesh,
    const wedgePolyPatch& wpp
)
{
    const polyBoundaryMesh& patches = mesh.boundaryMesh();

    scalar wppCosAngle = wpp.cosAngle();

29
    forAll(patches, patchi)
Henry's avatar
Henry committed
30
31
32
    {
        if
        (
33
34
35
            patchi != wpp.index()
         && patches[patchi].size()
         && isA<wedgePolyPatch>(patches[patchi])
Henry's avatar
Henry committed
36
37
38
        )
        {
            const wedgePolyPatch& pp =
39
                refCast<const wedgePolyPatch>(patches[patchi]);
Henry's avatar
Henry committed
40
41
42
43
44
45
46
47
48
49
50

            // Calculate (cos of) angle to wpp (not pp!) centre normal
            scalar ppCosAngle = wpp.centreNormal() & pp.n();

            if
            (
                pp.size() == wpp.size()
             && mag(pp.axis() & wpp.axis()) >= (1-1e-3)
             && mag(ppCosAngle - wppCosAngle) >= 1e-3
            )
            {
51
                return patchi;
Henry's avatar
Henry committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
            }
        }
    }
    return -1;
}


bool Foam::checkWedges
(
    const polyMesh& mesh,
    const bool report,
    const Vector<label>& directions,
    labelHashSet* setPtr
)
{
    // To mark edges without calculating edge addressing
    EdgeMap<label> edgesInError;

    const pointField& p = mesh.points();
    const faceList& fcs = mesh.faces();


    const polyBoundaryMesh& patches = mesh.boundaryMesh();
75
    forAll(patches, patchi)
Henry's avatar
Henry committed
76
    {
77
        if (patches[patchi].size() && isA<wedgePolyPatch>(patches[patchi]))
Henry's avatar
Henry committed
78
79
        {
            const wedgePolyPatch& pp =
80
                refCast<const wedgePolyPatch>(patches[patchi]);
Henry's avatar
Henry committed
81
82
83
84
85
86
87
88
89
90
91

            scalar wedgeAngle = acos(pp.cosAngle());

            if (report)
            {
                Info<< "    Wedge " << pp.name() << " with angle "
                    << radToDeg(wedgeAngle) << " degrees"
                    << endl;
            }

            // Find opposite
92
            label oppositePatchi = findOppositeWedge(mesh, pp);
Henry's avatar
Henry committed
93

94
            if (oppositePatchi == -1)
Henry's avatar
Henry committed
95
96
97
98
99
100
101
102
103
104
            {
                if (report)
                {
                    Info<< " ***Cannot find opposite wedge for wedge "
                        << pp.name() << endl;
                }
                return true;
            }

            const wedgePolyPatch& opp =
105
                refCast<const wedgePolyPatch>(patches[oppositePatchi]);
Henry's avatar
Henry committed
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


            if (mag(opp.axis() & pp.axis()) < (1-1e-3))
            {
                if (report)
                {
                    Info<< " ***Wedges do not have the same axis."
                        << " Encountered " << pp.axis()
                        << " on patch " << pp.name()
                        << " which differs from " << opp.axis()
                        << " on opposite wedge patch" << opp.axis()
                        << endl;
                }
                return true;
            }



            // Mark edges on wedgePatches
            forAll(pp, i)
            {
                const face& f = pp[i];
                forAll(f, fp)
                {
                    label p0 = f[fp];
                    label p1 = f.nextLabel(fp);
                    edgesInError.insert(edge(p0, p1), -1);  // non-error value
                }
            }


            // Check that wedge patch is flat
            const point& p0 = p[pp.meshPoints()[0]];
            forAll(pp.meshPoints(), i)
            {
                const point& pt = p[pp.meshPoints()[i]];
                scalar d = mag((pt - p0) & pp.n());

Henry Weller's avatar
Henry Weller committed
144
                if (d > ROOTSMALL)
Henry's avatar
Henry committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
                {
                    if (report)
                    {
                        Info<< " ***Wedge patch " << pp.name() << " not planar."
                            << " Point " << pt << " is not in patch plane by "
                            << d << " metre."
                            << endl;
                    }
                    return true;
                }
            }
        }
    }



    // Check all non-wedge faces
    label nEdgesInError = 0;

164
    forAll(fcs, facei)
Henry's avatar
Henry committed
165
    {
166
        const face& f = fcs[facei];
Henry's avatar
Henry committed
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

        forAll(f, fp)
        {
            label p0 = f[fp];
            label p1 = f.nextLabel(fp);
            if (p0 < p1)
            {
                vector d(p[p1]-p[p0]);
                scalar magD = mag(d);

                if (magD > ROOTVSMALL)
                {
                    d /= magD;

                    // Check how many empty directions are used by the edge.
                    label nEmptyDirs = 0;
                    label nNonEmptyDirs = 0;
                    for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
                    {
                        if (mag(d[cmpt]) > 1e-6)
                        {
                            if (directions[cmpt] == 0)
                            {
                                nEmptyDirs++;
                            }
                            else
                            {
                                nNonEmptyDirs++;
                            }
                        }
                    }

                    if (nEmptyDirs == 0)
                    {
                        // Purely in ok directions.
                    }
                    else if (nEmptyDirs == 1)
                    {
                        // Ok if purely in empty directions.
                        if (nNonEmptyDirs > 0)
                        {
208
                            if (edgesInError.insert(edge(p0, p1), facei))
Henry's avatar
Henry committed
209
210
211
212
213
214
215
216
                            {
                                nEdgesInError++;
                            }
                        }
                    }
                    else if (nEmptyDirs > 1)
                    {
                        // Always an error
217
                        if (edgesInError.insert(edge(p0, p1), facei))
Henry's avatar
Henry committed
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
                        {
                            nEdgesInError++;
                        }
                    }
                }
            }
        }
    }

    label nErrorEdges = returnReduce(nEdgesInError, sumOp<label>());

    if (nErrorEdges > 0)
    {
        if (report)
        {
            Info<< " ***Number of edges not aligned with or perpendicular to "
                << "non-empty directions: " << nErrorEdges << endl;
        }

        if (setPtr)
        {
            setPtr->resize(2*nEdgesInError);
            forAllConstIter(EdgeMap<label>, edgesInError, iter)
            {
                if (iter() >= 0)
                {
                    setPtr->insert(iter.key()[0]);
                    setPtr->insert(iter.key()[1]);
                }
            }
        }

        return true;
    }
    else
    {
        if (report)
        {
            Info<< "    All edges aligned with or perpendicular to "
                << "non-empty directions." << endl;
        }
        return false;
    }
}


namespace Foam
{
    //- Default transformation behaviour for position
    class transformPositionList
    {
    public:

        //- Transform patch-based field
        void operator()
        (
            const coupledPolyPatch& cpp,
            List<pointField>& pts
        ) const
        {
            // Each element of pts is all the points in the face. Convert into
            // lists of size cpp to transform.

            List<pointField> newPts(pts.size());
282
            forAll(pts, facei)
Henry's avatar
Henry committed
283
            {
284
                newPts[facei].setSize(pts[facei].size());
Henry's avatar
Henry committed
285
286
287
288
289
290
291
292
            }

            label index = 0;
            while (true)
            {
                label n = 0;

                // Extract for every face the i'th position
Henry Weller's avatar
Henry Weller committed
293
                pointField ptsAtIndex(pts.size(), Zero);
294
                forAll(cpp, facei)
Henry's avatar
Henry committed
295
                {
296
                    const pointField& facePts = pts[facei];
Henry's avatar
Henry committed
297
298
                    if (facePts.size() > index)
                    {
299
                        ptsAtIndex[facei] = facePts[index];
Henry's avatar
Henry committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
                        n++;
                    }
                }

                if (n == 0)
                {
                    break;
                }

                // Now ptsAtIndex will have for every face either zero or
                // the position of the i'th vertex. Transform.
                cpp.transformPosition(ptsAtIndex);

                // Extract back from ptsAtIndex into newPts
314
                forAll(cpp, facei)
Henry's avatar
Henry committed
315
                {
316
                    pointField& facePts = newPts[facei];
Henry's avatar
Henry committed
317
318
                    if (facePts.size() > index)
                    {
319
                        facePts[index] = ptsAtIndex[facei];
Henry's avatar
Henry committed
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
                    }
                }

                index++;
            }

            pts.transfer(newPts);
        }
    };
}


bool Foam::checkCoupledPoints
(
    const polyMesh& mesh,
    const bool report,
    labelHashSet* setPtr
)
{
    const pointField& p = mesh.points();
    const faceList& fcs = mesh.faces();
    const polyBoundaryMesh& patches = mesh.boundaryMesh();

    // Zero'th point on coupled faces
    //pointField nbrZeroPoint(fcs.size()-mesh.nInternalFaces(), vector::max);
    List<pointField> nbrPoints(fcs.size() - mesh.nInternalFaces());

    // Exchange zero point
348
    forAll(patches, patchi)
Henry's avatar
Henry committed
349
    {
350
        if (patches[patchi].coupled())
Henry's avatar
Henry committed
351
352
353
        {
            const coupledPolyPatch& cpp = refCast<const coupledPolyPatch>
            (
354
                patches[patchi]
Henry's avatar
Henry committed
355
356
357
358
            );

            forAll(cpp, i)
            {
359
                label bFacei = cpp.start() + i - mesh.nInternalFaces();
Henry's avatar
Henry committed
360
                const face& f = cpp[i];
361
                nbrPoints[bFacei].setSize(f.size());
Henry's avatar
Henry committed
362
363
364
                forAll(f, fp)
                {
                    const point& p0 = p[f[fp]];
365
                    nbrPoints[bFacei][fp] = p0;
Henry's avatar
Henry committed
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
                }
            }
        }
    }
    syncTools::syncBoundaryFaceList
    (
        mesh,
        nbrPoints,
        eqOp<pointField>(),
        transformPositionList()
    );

    // Compare to local ones. Use same tolerance as for matching
    label nErrorFaces = 0;
    scalar avgMismatch = 0;
    label nCoupledPoints = 0;

383
    forAll(patches, patchi)
Henry's avatar
Henry committed
384
    {
385
        if (patches[patchi].coupled())
Henry's avatar
Henry committed
386
387
        {
            const coupledPolyPatch& cpp =
388
                refCast<const coupledPolyPatch>(patches[patchi]);
Henry's avatar
Henry committed
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404

            if (cpp.owner())
            {
                scalarField smallDist
                (
                    cpp.calcFaceTol
                    (
                        //cpp.matchTolerance(),
                        cpp,
                        cpp.points(),
                        cpp.faceCentres()
                    )
                );

                forAll(cpp, i)
                {
405
                    label bFacei = cpp.start() + i - mesh.nInternalFaces();
Henry's avatar
Henry committed
406
407
                    const face& f = cpp[i];

408
                    if (f.size() != nbrPoints[bFacei].size())
Henry's avatar
Henry committed
409
                    {
410
411
                        FatalErrorInFunction
                            << "Local face size : " << f.size()
Henry's avatar
Henry committed
412
                            << " does not equal neighbour face size : "
413
                            << nbrPoints[bFacei].size()
Henry's avatar
Henry committed
414
415
416
417
418
419
420
                            << abort(FatalError);
                    }

                    label fp = 0;
                    forAll(f, j)
                    {
                        const point& p0 = p[f[fp]];
421
                        scalar d = mag(p0 - nbrPoints[bFacei][j]);
Henry's avatar
Henry committed
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

                        if (d > smallDist[i])
                        {
                            if (setPtr)
                            {
                                setPtr->insert(cpp.start()+i);
                            }
                            nErrorFaces++;

                            break;
                        }

                        avgMismatch += d;
                        nCoupledPoints++;

                        fp = f.rcIndex(fp);
                    }
                }
            }
        }
    }

    reduce(nErrorFaces, sumOp<label>());
    reduce(avgMismatch, maxOp<scalar>());
    reduce(nCoupledPoints, sumOp<label>());

    if (nCoupledPoints > 0)
    {
        avgMismatch /= nCoupledPoints;
    }

    if (nErrorFaces > 0)
    {
        if (report)
        {
            Info<< "  **Error in coupled point location: "
                << nErrorFaces
                << " faces have their 0th or consecutive vertex not opposite"
                << " their coupled equivalent. Average mismatch "
                << avgMismatch << "."
                << endl;
        }

        return true;
    }
    else
    {
        if (report)
        {
            Info<< "    Coupled point location match (average "
                << avgMismatch << ") OK." << endl;
        }

        return false;
    }
}


480
481
482
483
484
485
Foam::label Foam::checkGeometry
(
    const polyMesh& mesh,
    const bool allGeometry,
    const autoPtr<surfaceWriter>& writer
)
Henry's avatar
Henry committed
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
{
    label noFailedChecks = 0;

    Info<< "\nChecking geometry..." << endl;

    // Get a small relative length from the bounding box
    const boundBox& globalBb = mesh.bounds();

    Info<< "    Overall domain bounding box "
        << globalBb.min() << " " << globalBb.max() << endl;


    // Min length
    scalar minDistSqr = magSqr(1e-6 * globalBb.span());

501
    // Geometric directions
Henry's avatar
Henry committed
502
    const Vector<label> validDirs = (mesh.geometricD() + Vector<label>::one)/2;
503
504
    Info<< "    Mesh has " << mesh.nGeometricD()
        << " geometric (non-empty/wedge) directions " << validDirs << endl;
Henry's avatar
Henry committed
505

506
    // Solution directions
Henry's avatar
Henry committed
507
    const Vector<label> solDirs = (mesh.solutionD() + Vector<label>::one)/2;
508
509
    Info<< "    Mesh has " << mesh.nSolutionD()
        << " solution (non-empty) directions " << solDirs << endl;
Henry's avatar
Henry committed
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

    if (mesh.nGeometricD() < 3)
    {
        pointSet nonAlignedPoints(mesh, "nonAlignedEdges", mesh.nPoints()/100);

        if
        (
            (
                validDirs != solDirs
             && checkWedges(mesh, true, validDirs, &nonAlignedPoints)
            )
         || (
                validDirs == solDirs
             && mesh.checkEdgeAlignment(true, validDirs, &nonAlignedPoints)
            )
        )
        {
            noFailedChecks++;
            label nNonAligned = returnReduce
            (
                nonAlignedPoints.size(),
                sumOp<label>()
            );

            if (nNonAligned > 0)
            {
                Info<< "  <<Writing " << nNonAligned
                    << " points on non-aligned edges to set "
                    << nonAlignedPoints.name() << endl;
                nonAlignedPoints.instance() = mesh.pointsInstance();
                nonAlignedPoints.write();
            }
        }
    }

    if (mesh.checkClosedBoundary(true)) noFailedChecks++;

    {
        cellSet cells(mesh, "nonClosedCells", mesh.nCells()/100+1);
        cellSet aspectCells(mesh, "highAspectRatioCells", mesh.nCells()/100+1);
        if
        (
            mesh.checkClosedCells
            (
                true,
                &cells,
                &aspectCells,
                mesh.geometricD()
            )
        )
        {
            noFailedChecks++;

            label nNonClosed = returnReduce(cells.size(), sumOp<label>());

            if (nNonClosed > 0)
            {
                Info<< "  <<Writing " << nNonClosed
                    << " non closed cells to set " << cells.name() << endl;
                cells.instance() = mesh.pointsInstance();
                cells.write();
571
572
573
574
                if (writer.valid())
                {
                    mergeAndWrite(writer(), cells);
                }
Henry's avatar
Henry committed
575
576
577
578
579
580
581
582
583
584
585
586
            }
        }

        label nHighAspect = returnReduce(aspectCells.size(), sumOp<label>());

        if (nHighAspect > 0)
        {
            Info<< "  <<Writing " << nHighAspect
                << " cells with high aspect ratio to set "
                << aspectCells.name() << endl;
            aspectCells.instance() = mesh.pointsInstance();
            aspectCells.write();
587
588
589
590
            if (writer.valid())
            {
                mergeAndWrite(writer(), aspectCells);
            }
Henry's avatar
Henry committed
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
        }
    }

    {
        faceSet faces(mesh, "zeroAreaFaces", mesh.nFaces()/100+1);
        if (mesh.checkFaceAreas(true, &faces))
        {
            noFailedChecks++;

            label nFaces = returnReduce(faces.size(), sumOp<label>());

            if (nFaces > 0)
            {
                Info<< "  <<Writing " << nFaces
                    << " zero area faces to set " << faces.name() << endl;
                faces.instance() = mesh.pointsInstance();
                faces.write();
608
609
610
611
                if (writer.valid())
                {
                    mergeAndWrite(writer(), faces);
                }
Henry's avatar
Henry committed
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
            }
        }
    }

    {
        cellSet cells(mesh, "zeroVolumeCells", mesh.nCells()/100+1);
        if (mesh.checkCellVolumes(true, &cells))
        {
            noFailedChecks++;

            label nCells = returnReduce(cells.size(), sumOp<label>());

            if (nCells > 0)
            {
                Info<< "  <<Writing " << nCells
                    << " zero volume cells to set " << cells.name() << endl;
                cells.instance() = mesh.pointsInstance();
                cells.write();
630
631
632
633
                if (writer.valid())
                {
                    mergeAndWrite(writer(), cells);
                }
Henry's avatar
Henry committed
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
            }
        }
    }

    {
        faceSet faces(mesh, "nonOrthoFaces", mesh.nFaces()/100+1);
        if (mesh.checkFaceOrthogonality(true, &faces))
        {
            noFailedChecks++;
        }

        label nFaces = returnReduce(faces.size(), sumOp<label>());

        if (nFaces > 0)
        {
            Info<< "  <<Writing " << nFaces
                << " non-orthogonal faces to set " << faces.name() << endl;
            faces.instance() = mesh.pointsInstance();
            faces.write();
653
654
655
656
            if (writer.valid())
            {
                mergeAndWrite(writer(), faces);
            }
Henry's avatar
Henry committed
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
        }
    }

    {
        faceSet faces(mesh, "wrongOrientedFaces", mesh.nFaces()/100 + 1);
        if (mesh.checkFacePyramids(true, -SMALL, &faces))
        {
            noFailedChecks++;

            label nFaces = returnReduce(faces.size(), sumOp<label>());

            if (nFaces > 0)
            {
                Info<< "  <<Writing " << nFaces
                    << " faces with incorrect orientation to set "
                    << faces.name() << endl;
                faces.instance() = mesh.pointsInstance();
                faces.write();
675
676
677
678
                if (writer.valid())
                {
                    mergeAndWrite(writer(), faces);
                }
Henry's avatar
Henry committed
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
            }
        }
    }

    {
        faceSet faces(mesh, "skewFaces", mesh.nFaces()/100+1);
        if (mesh.checkFaceSkewness(true, &faces))
        {
            noFailedChecks++;

            label nFaces = returnReduce(faces.size(), sumOp<label>());

            if (nFaces > 0)
            {
                Info<< "  <<Writing " << nFaces
                    << " skew faces to set " << faces.name() << endl;
                faces.instance() = mesh.pointsInstance();
                faces.write();
697
698
699
700
                if (writer.valid())
                {
                    mergeAndWrite(writer(), faces);
                }
Henry's avatar
Henry committed
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
            }
        }
    }

    {
        faceSet faces(mesh, "coupledFaces", mesh.nFaces()/100 + 1);
        if (checkCoupledPoints(mesh, true, &faces))
        {
            noFailedChecks++;

            label nFaces = returnReduce(faces.size(), sumOp<label>());

            if (nFaces > 0)
            {
                Info<< "  <<Writing " << nFaces
                    << " faces with incorrectly matched 0th (or consecutive)"
                    << " vertex to set "
                    << faces.name() << endl;
                faces.instance() = mesh.pointsInstance();
                faces.write();
721
722
723
724
                if (writer.valid())
                {
                    mergeAndWrite(writer(), faces);
                }
Henry's avatar
Henry committed
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
            }
        }
    }

    if (allGeometry)
    {
        faceSet faces(mesh, "lowQualityTetFaces", mesh.nFaces()/100+1);
        if
        (
            polyMeshTetDecomposition::checkFaceTets
            (
                mesh,
                polyMeshTetDecomposition::minTetQuality,
                true,
                &faces
            )
        )
        {
            noFailedChecks++;

            label nFaces = returnReduce(faces.size(), sumOp<label>());

            if (nFaces > 0)
            {
                Info<< "  <<Writing " << nFaces
                    << " faces with low quality or negative volume "
                    << "decomposition tets to set " << faces.name() << endl;
                faces.instance() = mesh.pointsInstance();
                faces.write();
754
755
756
757
                if (writer.valid())
                {
                    mergeAndWrite(writer(), faces);
                }
Henry's avatar
Henry committed
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
            }
        }
    }

    if (allGeometry)
    {
        // Note use of nPoints since don't want edge construction.
        pointSet points(mesh, "shortEdges", mesh.nPoints()/1000 + 1);
        if (mesh.checkEdgeLength(true, minDistSqr, &points))
        {
            //noFailedChecks++;

            label nPoints = returnReduce(points.size(), sumOp<label>());

            if (nPoints > 0)
            {
                Info<< "  <<Writing " << nPoints
                    << " points on short edges to set " << points.name()
                    << endl;
                points.instance() = mesh.pointsInstance();
                points.write();
            }
        }

        label nEdgeClose = returnReduce(points.size(), sumOp<label>());

        if (mesh.checkPointNearness(false, minDistSqr, &points))
        {
            //noFailedChecks++;

            label nPoints = returnReduce(points.size(), sumOp<label>());

            if (nPoints > nEdgeClose)
            {
                pointSet nearPoints(mesh, "nearPoints", points);
                Info<< "  <<Writing " << nPoints
                    << " near (closer than " << Foam::sqrt(minDistSqr)
                    << " apart) points to set " << nearPoints.name() << endl;
                nearPoints.instance() = mesh.pointsInstance();
                nearPoints.write();
            }
        }
    }

    if (allGeometry)
    {
        faceSet faces(mesh, "concaveFaces", mesh.nFaces()/100 + 1);
        if (mesh.checkFaceAngles(true, 10, &faces))
        {
            //noFailedChecks++;

            label nFaces = returnReduce(faces.size(), sumOp<label>());

            if (nFaces > 0)
            {
                Info<< "  <<Writing " << nFaces
                    << " faces with concave angles to set " << faces.name()
                    << endl;
                faces.instance() = mesh.pointsInstance();
                faces.write();
818
819
820
821
                if (writer.valid())
                {
                    mergeAndWrite(writer(), faces);
                }
Henry's avatar
Henry committed
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
            }
        }
    }

    if (allGeometry)
    {
        faceSet faces(mesh, "warpedFaces", mesh.nFaces()/100 + 1);
        if (mesh.checkFaceFlatness(true, 0.8, &faces))
        {
            //noFailedChecks++;

            label nFaces = returnReduce(faces.size(), sumOp<label>());

            if (nFaces > 0)
            {
                Info<< "  <<Writing " << nFaces
                    << " warped faces to set " << faces.name() << endl;
                faces.instance() = mesh.pointsInstance();
                faces.write();
841
842
843
844
                if (writer.valid())
                {
                    mergeAndWrite(writer(), faces);
                }
Henry's avatar
Henry committed
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
            }
        }
    }

    if (allGeometry)
    {
        cellSet cells(mesh, "underdeterminedCells", mesh.nCells()/100);
        if (mesh.checkCellDeterminant(true, &cells))
        {
            noFailedChecks++;

            label nCells = returnReduce(cells.size(), sumOp<label>());

            Info<< "  <<Writing " << nCells
                << " under-determined cells to set " << cells.name() << endl;
            cells.instance() = mesh.pointsInstance();
            cells.write();
862
863
864
865
            if (writer.valid())
            {
                mergeAndWrite(writer(), cells);
            }
Henry's avatar
Henry committed
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
        }
    }

    if (allGeometry)
    {
        cellSet cells(mesh, "concaveCells", mesh.nCells()/100);
        if (mesh.checkConcaveCells(true, &cells))
        {
            noFailedChecks++;

            label nCells = returnReduce(cells.size(), sumOp<label>());

            Info<< "  <<Writing " << nCells
                << " concave cells to set " << cells.name() << endl;
            cells.instance() = mesh.pointsInstance();
            cells.write();
882
883
884
885
            if (writer.valid())
            {
                mergeAndWrite(writer(), cells);
            }
Henry's avatar
Henry committed
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
        }
    }

    if (allGeometry)
    {
        faceSet faces(mesh, "lowWeightFaces", mesh.nFaces()/100);
        if (mesh.checkFaceWeight(true, 0.05, &faces))
        {
            noFailedChecks++;

            label nFaces = returnReduce(faces.size(), sumOp<label>());

            Info<< "  <<Writing " << nFaces
                << " faces with low interpolation weights to set "
                << faces.name() << endl;
            faces.instance() = mesh.pointsInstance();
            faces.write();
903
904
905
906
            if (writer.valid())
            {
                mergeAndWrite(writer(), faces);
            }
Henry's avatar
Henry committed
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
        }
    }

    if (allGeometry)
    {
        faceSet faces(mesh, "lowVolRatioFaces", mesh.nFaces()/100);
        if (mesh.checkVolRatio(true, 0.01, &faces))
        {
            noFailedChecks++;

            label nFaces = returnReduce(faces.size(), sumOp<label>());

            Info<< "  <<Writing " << nFaces
                << " faces with low volume ratio cells to set "
                << faces.name() << endl;
            faces.instance() = mesh.pointsInstance();
            faces.write();
924
925
926
927
            if (writer.valid())
            {
                mergeAndWrite(writer(), faces);
            }
Henry's avatar
Henry committed
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
975
976
977
978
979
980
981
982
983
984
985
986
987
988
    if (allGeometry)
    {
        const polyBoundaryMesh& pbm = mesh.boundaryMesh();

        const word tmName(mesh.time().timeName());
        const word procAndTime(Foam::name(Pstream::myProcNo()) + "_" + tmName);

        autoPtr<surfaceWriter> patchWriter;
        if (!writer.valid())
        {
            patchWriter.reset(new vtkSurfaceWriter());
        }
        const surfaceWriter& wr = (writer.valid() ? writer() : patchWriter());

        forAll(pbm, patchi)
        {
            if (isA<cyclicAMIPolyPatch>(pbm[patchi]))
            {
                const cyclicAMIPolyPatch& cpp =
                    refCast<const cyclicAMIPolyPatch>(pbm[patchi]);

                if (cpp.owner())
                {
                    Info<< "Calculating AMI weights between owner patch: "
                        << cpp.name() << " and neighbour patch: "
                        << cpp.neighbPatch().name() << endl;

                    const AMIPatchToPatchInterpolation& ami =
                        cpp.AMI();

                    {
                        // Collect geometry
                        labelList pointToGlobal;
                        labelList uniqueMeshPointLabels;
                        autoPtr<globalIndex> globalPoints;
                        autoPtr<globalIndex> globalFaces;
                        faceList mergedFaces;
                        pointField mergedPoints;
                        Foam::PatchTools::gatherAndMerge
                        (
                            mesh,
                            cpp.localFaces(),
                            cpp.meshPoints(),
                            cpp.meshPointMap(),

                            pointToGlobal,
                            uniqueMeshPointLabels,
                            globalPoints,
                            globalFaces,

                            mergedFaces,
                            mergedPoints
                        );
                        // Collect field
                        scalarField mergedWeights;
                        globalFaces().gather
                        (
                            UPstream::worldComm,
989
                            labelList(UPstream::procID(UPstream::worldComm)),
990
991
992
993
994
995
996
997
998
999
1000
                            ami.srcWeightsSum(),
                            mergedWeights
                        );

                        if (Pstream::master())
                        {
                            wr.write
                            (
                                "postProcessing",
                                "src_" + tmName,
                                mergedPoints,
For faster browsing, not all history is shown. View entire blame