PointEdgeWave.C 23.5 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
6
7
8
9
10
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    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.
15
16
17
18
19
20
21

    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
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
23
24
25
26

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

#include "PointEdgeWave.H"
27
#include "polyMesh.H"
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "processorPolyPatch.H"
#include "cyclicPolyPatch.H"
#include "OPstream.H"
#include "IPstream.H"
#include "PstreamCombineReduceOps.H"
#include "debug.H"
#include "typeInfo.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

template <class Type>
Foam::scalar Foam::PointEdgeWave<Type>::propagationTol_ = 0.01;


// Offset labelList. Used for transferring from one cyclic half to the other.
template <class Type>
void Foam::PointEdgeWave<Type>::offset(const label val, labelList& elems)
{
    forAll(elems, i)
    {
        elems[i] += val;
    }
}


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

55
// Gets point-point correspondence. Is
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// - list of halfA points (in cyclic patch points)
// - list of halfB points (can overlap with A!)
// - for every patchPoint its corresponding point
// Handle leaving domain. Implementation referred to Type
template <class Type>
void Foam::PointEdgeWave<Type>::leaveDomain
(
    const polyPatch& meshPatch,
    const primitivePatch& patch,
    const labelList& patchPointLabels,
    List<Type>& pointInfo
) const
{
    const labelList& meshPoints = patch.meshPoints();
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    forAll(patchPointLabels, i)
    {
        label patchPointI = patchPointLabels[i];

        const point& pt = patch.points()[meshPoints[patchPointI]];

        pointInfo[i].leaveDomain(meshPatch, patchPointI, pt);
    }
}


// Handle entering domain. Implementation referred to Type
template <class Type>
void Foam::PointEdgeWave<Type>::enterDomain
(
    const polyPatch& meshPatch,
    const primitivePatch& patch,
    const labelList& patchPointLabels,
    List<Type>& pointInfo
) const
{
    const labelList& meshPoints = patch.meshPoints();
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
    forAll(patchPointLabels, i)
    {
        label patchPointI = patchPointLabels[i];

        const point& pt = patch.points()[meshPoints[patchPointI]];

        pointInfo[i].enterDomain(meshPatch, patchPointI, pt);
    }
}


// Transform. Implementation referred to Type
template <class Type>
void Foam::PointEdgeWave<Type>::transform
(
    const tensorField& rotTensor,
    List<Type>& pointInfo
) const
{
    if (rotTensor.size() == 1)
    {
        const tensor& T = rotTensor[0];

        forAll(pointInfo, i)
        {
            pointInfo[i].transform(T);
        }
    }
    else
    {
        FatalErrorIn
        (
            "PointEdgeWave<Type>::transform(const tensorField&, List<Type>&)"
        )   << "Parallel cyclics not supported" << abort(FatalError);
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
        forAll(pointInfo, i)
        {
            pointInfo[i].transform(rotTensor[i]);
        }
    }
}


// Update info for pointI, at position pt, with information from
// neighbouring edge.
// Updates:
//      - changedPoint_, changedPoints_, nChangedPoints_,
//      - statistics: nEvals_, nUnvisitedPoints_
template <class Type>
bool Foam::PointEdgeWave<Type>::updatePoint
(
    const label pointI,
    const label neighbourEdgeI,
    const Type& neighbourInfo,
    const scalar tol,
    Type& pointInfo
)
{
    nEvals_++;

    bool wasValid = pointInfo.valid();

    bool propagate =
        pointInfo.updatePoint
        (
159
            mesh_,
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
            pointI,
            neighbourEdgeI,
            neighbourInfo,
            tol
        );

    if (propagate)
    {
        if (!changedPoint_[pointI])
        {
            changedPoint_[pointI] = true;
            changedPoints_[nChangedPoints_++] = pointI;
        }
    }

    if (!wasValid && pointInfo.valid())
    {
        --nUnvisitedPoints_;
    }

    return propagate;
}


// Update info for pointI, at position pt, with information from
// same point.
// Updates:
//      - changedPoint_, changedPoints_, nChangedPoints_,
//      - statistics: nEvals_, nUnvisitedPoints_
template <class Type>
bool Foam::PointEdgeWave<Type>::updatePoint
(
    const label pointI,
    const Type& neighbourInfo,
    const scalar tol,
    Type& pointInfo
)
{
    nEvals_++;

    bool wasValid = pointInfo.valid();

    bool propagate =
        pointInfo.updatePoint
        (
205
            mesh_,
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
            pointI,
            neighbourInfo,
            tol
        );

    if (propagate)
    {
        if (!changedPoint_[pointI])
        {
            changedPoint_[pointI] = true;
            changedPoints_[nChangedPoints_++] = pointI;
        }
    }

    if (!wasValid && pointInfo.valid())
    {
        --nUnvisitedPoints_;
    }

    return propagate;
}


// Update info for edgeI, at position pt, with information from
// neighbouring point.
// Updates:
//      - changedEdge_, changedEdges_, nChangedEdges_,
//      - statistics: nEvals_, nUnvisitedEdge_
template <class Type>
bool Foam::PointEdgeWave<Type>::updateEdge
(
    const label edgeI,
    const label neighbourPointI,
    const Type& neighbourInfo,
    const scalar tol,
    Type& edgeInfo
)
{
    nEvals_++;

    bool wasValid = edgeInfo.valid();

    bool propagate =
        edgeInfo.updateEdge
        (
251
            mesh_,
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
            edgeI,
            neighbourPointI,
            neighbourInfo,
            tol
        );

    if (propagate)
    {
        if (!changedEdge_[edgeI])
        {
            changedEdge_[edgeI] = true;
            changedEdges_[nChangedEdges_++] = edgeI;
        }
    }

    if (!wasValid && edgeInfo.valid())
    {
        --nUnvisitedEdges_;
    }

    return propagate;
}


// Check if patches of given type name are present
template <class Type>
template <class PatchType>
Foam::label Foam::PointEdgeWave<Type>::countPatchType() const
{
    label nPatches = 0;

283
    forAll(mesh_.boundaryMesh(), patchI)
284
    {
285
        if (isA<PatchType>(mesh_.boundaryMesh()[patchI]))
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
        {
            nPatches++;
        }
    }
    return nPatches;
}


// Collect changed patch points
template <class Type>
void Foam::PointEdgeWave<Type>::getChangedPatchPoints
(
    const primitivePatch& patch,

    DynamicList<Type>& patchInfo,
    DynamicList<label>& patchPoints,
    DynamicList<label>& owner,
    DynamicList<label>& ownerIndex
) const
{
    const labelList& meshPoints = patch.meshPoints();
    const faceList& localFaces = patch.localFaces();
    const labelListList& pointFaces = patch.pointFaces();

    forAll(meshPoints, patchPointI)
    {
        label meshPointI = meshPoints[patchPointI];

        if (changedPoint_[meshPointI])
        {
            patchInfo.append(allPointInfo_[meshPointI]);
            patchPoints.append(patchPointI);

            label patchFaceI = pointFaces[patchPointI][0];

            const face& f = localFaces[patchFaceI];

            label index = findIndex(f, patchPointI);

            owner.append(patchFaceI);
            ownerIndex.append(index);
        }
    }

    patchInfo.shrink();
    patchPoints.shrink();
    owner.shrink();
    ownerIndex.shrink();
}


// Update overall for changed patch points
template <class Type>
void Foam::PointEdgeWave<Type>::updateFromPatchInfo
(
    const polyPatch& meshPatch,
    const primitivePatch& patch,
    const labelList& owner,
    const labelList& ownerIndex,
    List<Type>& patchInfo
)
{
    const faceList& localFaces = patch.localFaces();
    const labelList& meshPoints = patch.meshPoints();

    // Get patch and mesh points.
    labelList changedPatchPoints(patchInfo.size());
    labelList changedMeshPoints(patchInfo.size());

    forAll(owner, i)
    {
        label faceI = owner[i];

        const face& f = localFaces[faceI];

        label index = (f.size() - ownerIndex[i]) % f.size();

        changedPatchPoints[i] = f[index];
        changedMeshPoints[i] = meshPoints[f[index]];
    }

    // Adapt for entering domain
    enterDomain(meshPatch, patch, changedPatchPoints, patchInfo);

    // Merge received info
    forAll(patchInfo, i)
    {
        updatePoint
        (
            changedMeshPoints[i],
            patchInfo[i],
            propagationTol_,
            allPointInfo_[changedMeshPoints[i]]
        );
    }
}



// Transfer all the information to/from neighbouring processors
template <class Type>
void Foam::PointEdgeWave<Type>::handleProcPatches()
{
mattijs's avatar
mattijs committed
389
390
    // 1. Send all point info on processor patches. Send as
    // face label + offset in face.
391

392
    forAll(mesh_.boundaryMesh(), patchI)
mattijs's avatar
mattijs committed
393
    {
394
        const polyPatch& patch = mesh_.boundaryMesh()[patchI];
395

mattijs's avatar
mattijs committed
396
397
398
        if (isA<processorPolyPatch>(patch))
        {
            // Get all changed points in relative addressing
399

mattijs's avatar
mattijs committed
400
401
402
403
            DynamicList<Type> patchInfo(patch.nPoints());
            DynamicList<label> patchPoints(patch.nPoints());
            DynamicList<label> owner(patch.nPoints());
            DynamicList<label> ownerIndex(patch.nPoints());
404

mattijs's avatar
mattijs committed
405
406
407
408
409
410
411
412
            getChangedPatchPoints
            (
                patch,
                patchInfo,
                patchPoints,
                owner,
                ownerIndex
            );
413

mattijs's avatar
mattijs committed
414
415
            // Adapt for leaving domain
            leaveDomain(patch, patch, patchPoints, patchInfo);
416

mattijs's avatar
mattijs committed
417
418
            const processorPolyPatch& procPatch =
                refCast<const processorPolyPatch>(patch);
419

mattijs's avatar
mattijs committed
420
421
422
423
424
425
            if (debug)
            {
                Pout<< "Processor patch " << patchI << ' ' << patch.name()
                    << " communicating with " << procPatch.neighbProcNo()
                    << "  Sending:" << patchInfo.size() << endl;
            }
426

mattijs's avatar
mattijs committed
427
428
            {
                OPstream toNeighbour
429
                (
mattijs's avatar
mattijs committed
430
431
432
                    Pstream::blocking,
                    procPatch.neighbProcNo()
                );
433

mattijs's avatar
mattijs committed
434
                toNeighbour << owner << ownerIndex << patchInfo;
435
436
            }
        }
mattijs's avatar
mattijs committed
437
    }
438
439


mattijs's avatar
mattijs committed
440
441
442
    //
    // 2. Receive all point info on processor patches.
    //
443

444
    forAll(mesh_.boundaryMesh(), patchI)
mattijs's avatar
mattijs committed
445
    {
446
        const polyPatch& patch = mesh_.boundaryMesh()[patchI];
mattijs's avatar
mattijs committed
447
448

        if (isA<processorPolyPatch>(patch))
449
        {
mattijs's avatar
mattijs committed
450
451
            const processorPolyPatch& procPatch =
                refCast<const processorPolyPatch>(patch);
452

mattijs's avatar
mattijs committed
453
454
455
            List<Type> patchInfo;
            labelList owner;
            labelList ownerIndex;
456
            {
mattijs's avatar
mattijs committed
457
                IPstream fromNeighbour
458
                (
mattijs's avatar
mattijs committed
459
460
                    Pstream::blocking,
                    procPatch.neighbProcNo()
461
                );
mattijs's avatar
mattijs committed
462
463

                fromNeighbour >> owner >> ownerIndex >> patchInfo;
464
            }
mattijs's avatar
mattijs committed
465
466
467
468
469
470

            if (debug)
            {
                Pout<< "Processor patch " << patchI << ' ' << patch.name()
                    << " communicating with " << procPatch.neighbProcNo()
                    << "  Received:" << patchInfo.size() << endl;
471
            }
mattijs's avatar
mattijs committed
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

            // Apply transform to received data for non-parallel planes
            if (!procPatch.parallel())
            {
                transform(procPatch.reverseT(), patchInfo);
            }

            updateFromPatchInfo
            (
                patch,
                patch,
                owner,
                ownerIndex,
                patchInfo
            );
487
        }
mattijs's avatar
mattijs committed
488
    }
489
490
491



mattijs's avatar
mattijs committed
492
493
494
495
    //
    // 3. Handle all shared points
    //    (Note:irrespective if changed or not for now)
    //
496

497
    const globalMeshData& pd = mesh_.globalData();
498

mattijs's avatar
mattijs committed
499
    List<Type> sharedData(pd.nGlobalPoints());
500

mattijs's avatar
mattijs committed
501
502
503
    forAll(pd.sharedPointLabels(), i)
    {
        label meshPointI = pd.sharedPointLabels()[i];
504

mattijs's avatar
mattijs committed
505
506
507
        // Fill my entries in the shared points
        sharedData[pd.sharedPointAddr()[i]] = allPointInfo_[meshPointI];
    }
508

mattijs's avatar
mattijs committed
509
510
511
    // Combine on master. Reduce operator has to handle a list and call
    // Type.updatePoint for all elements
    combineReduce(sharedData, listUpdateOp<Type>());
512

mattijs's avatar
mattijs committed
513
514
515
    forAll(pd.sharedPointLabels(), i)
    {
        label meshPointI = pd.sharedPointLabels()[i];
516

mattijs's avatar
mattijs committed
517
518
519
520
521
522
523
524
        // Retrieve my entries from the shared points
        updatePoint
        (
            meshPointI,
            sharedData[pd.sharedPointAddr()[i]],
            propagationTol_,
            allPointInfo_[meshPointI]
        );
525
526
527
528
529
530
531
532
533
534
    }
}


template <class Type>
void Foam::PointEdgeWave<Type>::handleCyclicPatches()
{
    // 1. Send all point info on cyclic patches. Send as
    // face label + offset in face.

535
    forAll(mesh_.boundaryMesh(), patchI)
536
    {
537
        const polyPatch& patch = mesh_.boundaryMesh()[patchI];
538
539
540

        if (isA<cyclicPolyPatch>(patch))
        {
541
542
            const cyclicPolyPatch& cycPatch =
                refCast<const cyclicPolyPatch>(patch);
543

544
            const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch();
545

546
547
548
549
            DynamicList<Type> nbrInfo(nbrPatch.nPoints());
            DynamicList<label> nbrPoints(nbrPatch.nPoints());
            DynamicList<label> nbrOwner(nbrPatch.nPoints());
            DynamicList<label> nbrIndex(nbrPatch.nPoints());
550
551
552

            getChangedPatchPoints
            (
553
554
555
556
557
                nbrPatch,
                nbrInfo,
                nbrPoints,
                nbrOwner,
                nbrIndex
558
559
            );

560
561
            // nbr : adapt for leaving domain
            leaveDomain(nbrPatch, nbrPatch, nbrPoints, nbrInfo);
562
563
564
565
566
567

            // Apply rotation for non-parallel planes

            if (!cycPatch.parallel())
            {
                // received data from half1
568
                transform(cycPatch.forwardT(), nbrInfo);
569
570
571
572
            }

            if (debug)
            {
573
                Pout<< "Cyclic patch " << patchI << ' ' << patch.name()
574
                    << "  Changed : " << nbrInfo.size()
575
576
577
578
579
580
                    << endl;
            }

            // Half1: update with data from halfB
            updateFromPatchInfo
            (
581
582
583
584
585
                cycPatch,
                cycPatch,
                nbrOwner,
                nbrIndex,
                nbrInfo
586
587
588
589
590
591
592
593
594
595
596
597
598
            );

            if (debug)
            {
                //checkCyclic(patch);
            }
        }
    }
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

599
// Iterate, propagating changedPointsInfo across mesh, until no change (or
600
601
602
603
// maxIter reached). Initial point values specified.
template <class Type>
Foam::PointEdgeWave<Type>::PointEdgeWave
(
604
    const polyMesh& mesh,
605
606
607
608
609
610
611
612
613
    const labelList& changedPoints,
    const List<Type>& changedPointsInfo,

    List<Type>& allPointInfo,
    List<Type>& allEdgeInfo,

    const label maxIter
)
:
614
    mesh_(mesh),
615
616
    allPointInfo_(allPointInfo),
    allEdgeInfo_(allEdgeInfo),
617
618
    changedPoint_(mesh_.nPoints(), false),
    changedPoints_(mesh_.nPoints()),
619
    nChangedPoints_(0),
620
621
    changedEdge_(mesh_.nEdges(), false),
    changedEdges_(mesh_.nEdges()),
622
623
624
    nChangedEdges_(0),
    nCyclicPatches_(countPatchType<cyclicPolyPatch>()),
    nEvals_(0),
625
626
    nUnvisitedPoints_(mesh_.nPoints()),
    nUnvisitedEdges_(mesh_.nEdges())
627
{
628
    if (allPointInfo_.size() != mesh_.nPoints())
629
630
631
632
    {
        FatalErrorIn
        (
            "PointEdgeWave<Type>::PointEdgeWave"
633
            "(const polyMesh&, const labelList&, const List<Type>,"
634
635
636
637
            " List<Type>&, List<Type>&, const label maxIter)"
        )   << "size of pointInfo work array is not equal to the number"
            << " of points in the mesh" << endl
            << "    pointInfo   :" << allPointInfo_.size() << endl
638
            << "    mesh.nPoints:" << mesh_.nPoints()
639
640
            << exit(FatalError);
    }
641
    if (allEdgeInfo_.size() != mesh_.nEdges())
642
643
644
645
    {
        FatalErrorIn
        (
            "PointEdgeWave<Type>::PointEdgeWave"
646
            "(const polyMesh&, const labelList&, const List<Type>,"
647
648
649
650
            " List<Type>&, List<Type>&, const label maxIter)"
        )   << "size of edgeInfo work array is not equal to the number"
            << " of edges in the mesh" << endl
            << "    edgeInfo   :" << allEdgeInfo_.size() << endl
651
            << "    mesh.nEdges:" << mesh_.nEdges()
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
            << exit(FatalError);
    }


    // Set from initial changed points data
    setPointInfo(changedPoints, changedPointsInfo);

    if (debug)
    {
        Pout<< "Seed points               : " << nChangedPoints_ << endl;
    }

    // Iterate until nothing changes
    label iter = iterate(maxIter);

    if ((maxIter > 0) && (iter >= maxIter))
    {
        FatalErrorIn
        (
            "PointEdgeWave<Type>::PointEdgeWave"
672
            "(const polyMesh&, const labelList&, const List<Type>,"
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
            " List<Type>&, List<Type>&, const label maxIter)"
        )   << "Maximum number of iterations reached. Increase maxIter." << endl
            << "    maxIter:" << maxIter << endl
            << "    nChangedPoints:" << nChangedPoints_ << endl
            << "    nChangedEdges:" << nChangedEdges_ << endl
            << exit(FatalError);
    }
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

template <class Type>
Foam::PointEdgeWave<Type>::~PointEdgeWave()
{}


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


template <class Type>
Foam::label Foam::PointEdgeWave<Type>::getUnsetPoints() const
{
    return nUnvisitedPoints_;
}


template <class Type>
Foam::label Foam::PointEdgeWave<Type>::getUnsetEdges() const
{
    return nUnvisitedEdges_;
}


// Copy point information into member data
template <class Type>
void Foam::PointEdgeWave<Type>::setPointInfo
(
    const labelList& changedPoints,
    const List<Type>& changedPointsInfo
)
{
    forAll(changedPoints, changedPointI)
    {
        label pointI = changedPoints[changedPointI];

        bool wasValid = allPointInfo_[pointI].valid();

        // Copy info for pointI
        allPointInfo_[pointI] = changedPointsInfo[changedPointI];

        // Maintain count of unset points
        if (!wasValid && allPointInfo_[pointI].valid())
        {
            --nUnvisitedPoints_;
        }

        // Mark pointI as changed, both on list and on point itself.

        if (!changedPoint_[pointI])
        {
            changedPoint_[pointI] = true;
            changedPoints_[nChangedPoints_++] = pointI;
        }
    }
}


// Propagate information from edge to point. Return number of points changed.
template <class Type>
Foam::label Foam::PointEdgeWave<Type>::edgeToPoint()
{
    for
    (
        label changedEdgeI = 0;
        changedEdgeI < nChangedEdges_;
        changedEdgeI++
    )
    {
        label edgeI = changedEdges_[changedEdgeI];

        if (!changedEdge_[edgeI])
        {
            FatalErrorIn("PointEdgeWave<Type>::edgeToPoint()")
                << "edge " << edgeI
                << " not marked as having been changed" << nl
                << "This might be caused by multiple occurences of the same"
                << " seed point." << abort(FatalError);
        }


        const Type& neighbourWallInfo = allEdgeInfo_[edgeI];

        // Evaluate all connected points (= edge endpoints)
767
        const edge& e = mesh_.edges()[edgeI];
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

        forAll(e, eI)
        {
            Type& currentWallInfo = allPointInfo_[e[eI]];

            if (currentWallInfo != neighbourWallInfo)
            {
                updatePoint
                (
                    e[eI],
                    edgeI,
                    neighbourWallInfo,
                    propagationTol_,
                    currentWallInfo
                );
            }
        }

        // Reset status of edge
        changedEdge_[edgeI] = false;
    }

    // Handled all changed edges by now
    nChangedEdges_ = 0;

    if (nCyclicPatches_ > 0)
    {
        // Transfer changed points across cyclic halves
        handleCyclicPatches();
    }
mattijs's avatar
mattijs committed
798
    if (Pstream::parRun())
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
    {
        // Transfer changed points from neighbouring processors.
        handleProcPatches();
    }

    if (debug)
    {
        Pout<< "Changed points            : " << nChangedPoints_ << endl;
    }

    // Sum nChangedPoints over all procs
    label totNChanged = nChangedPoints_;

    reduce(totNChanged, sumOp<label>());

    return totNChanged;
}


// Propagate information from point to edge. Return number of edges changed.
template <class Type>
Foam::label Foam::PointEdgeWave<Type>::pointToEdge()
{
822
    const labelListList& pointEdges = mesh_.pointEdges();
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895

    for
    (
        label changedPointI = 0;
        changedPointI < nChangedPoints_;
        changedPointI++
    )
    {
        label pointI = changedPoints_[changedPointI];

        if (!changedPoint_[pointI])
        {
            FatalErrorIn("PointEdgeWave<Type>::pointToEdge()")
                << "Point " << pointI
                << " not marked as having been changed" << nl
                << "This might be caused by multiple occurences of the same"
                << " seed point." << abort(FatalError);
        }

        const Type& neighbourWallInfo = allPointInfo_[pointI];

        // Evaluate all connected edges

        const labelList& edgeLabels = pointEdges[pointI];
        forAll(edgeLabels, edgeLabelI)
        {
            label edgeI = edgeLabels[edgeLabelI];

            Type& currentWallInfo = allEdgeInfo_[edgeI];

            if (currentWallInfo != neighbourWallInfo)
            {
                updateEdge
                (
                    edgeI,
                    pointI,
                    neighbourWallInfo,
                    propagationTol_,
                    currentWallInfo
                );
            }
        }

        // Reset status of point
        changedPoint_[pointI] = false;
    }

    // Handled all changed points by now
    nChangedPoints_ = 0;

    if (debug)
    {
        Pout<< "Changed edges             : " << nChangedEdges_ << endl;
    }

    // Sum nChangedPoints over all procs
    label totNChanged = nChangedEdges_;

    reduce(totNChanged, sumOp<label>());

    return totNChanged;
}


// Iterate
template <class Type>
Foam::label Foam::PointEdgeWave<Type>::iterate(const label maxIter)
{
    if (nCyclicPatches_ > 0)
    {
        // Transfer changed points across cyclic halves
        handleCyclicPatches();
    }
mattijs's avatar
mattijs committed
896
    if (Pstream::parRun())
897
898
899
900
901
902
903
904
905
    {
        // Transfer changed points from neighbouring processors.
        handleProcPatches();
    }

    nEvals_ = 0;

    label iter = 0;

906
    while (iter < maxIter)
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
    {
        if (debug)
        {
            Pout<< "Iteration " << iter << endl;
        }

        label nEdges = pointToEdge();

        if (debug)
        {
            Pout<< "Total changed edges       : " << nEdges << endl;
        }

        if (nEdges == 0)
        {
            break;
        }

        label nPoints = edgeToPoint();

        if (debug)
        {
            Pout<< "Total changed points      : " << nPoints << endl;

            Pout<< "Total evaluations         : " << nEvals_ << endl;

            Pout<< "Remaining unvisited points: " << nUnvisitedPoints_ << endl;

            Pout<< "Remaining unvisited edges : " << nUnvisitedEdges_ << endl;

            Pout<< endl;
        }

        if (nPoints == 0)
        {
            break;
        }

        iter++;
    }

    return iter;
}

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