00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "referredCellList.H"
00028 #include "interactionLists.H"
00029 #include "polyBoundaryMeshEntries.H"
00030 #include "PstreamCombineReduceOps.H"
00031 #include "Time.H"
00032 #include "globalMeshData.H"
00033 #include "processorPolyPatch.H"
00034 #include "cyclicPolyPatch.H"
00035
00036
00037
00038 void Foam::referredCellList::buildReferredCellList
00039 (
00040 bool pointPointListBuild
00041 )
00042 {
00043 Info << nl << "Building list of referred interaction neighbours" << endl;
00044
00045 const polyMesh& mesh(il_.mesh());
00046
00047 DynamicList<referredCell> referredInteractionList;
00048
00049
00050 DynamicList<label> rCellsWRRP;
00051
00052
00053 DynamicList<label> rFacesWRRP;
00054
00055
00056 DynamicList<label> rEdgesWRRP;
00057
00058
00059 DynamicList<label> rPointsWRRP;
00060
00061 labelListList processorPatchSegmentMapping
00062 (
00063 mesh.globalData().processorPatches().size()
00064 );
00065
00066 List<vectorList> allNeighbourFaceCentres
00067 (
00068 mesh.globalData().processorPatches().size()
00069 );
00070
00071 List<vectorList> allNeighbourFaceAreas
00072 (
00073 mesh.globalData().processorPatches().size()
00074 );
00075
00076 label nUndecomposedPatches = 0;
00077
00078 if (Pstream::parRun())
00079 {
00080 dictionary patchDictionary;
00081
00082 DynamicList<word> patchNames;
00083
00084 Time undecomposedTime
00085 (
00086 Time::controlDictName,
00087 mesh.time().rootPath(),
00088 mesh.time().caseName().path()
00089 );
00090
00091 IOobject undecomposedBoundaryHeader
00092 (
00093 "boundary",
00094 undecomposedTime.constant(),
00095 polyMesh::meshSubDir,
00096 undecomposedTime,
00097 IOobject::MUST_READ,
00098 IOobject::NO_WRITE,
00099 false
00100 );
00101
00102 if (undecomposedBoundaryHeader.headerOk())
00103 {
00104 polyBoundaryMeshEntries undecomposedPatchEntries
00105 (
00106 undecomposedBoundaryHeader
00107 );
00108
00109 forAll(undecomposedPatchEntries, patchi)
00110 {
00111 patchNames.append
00112 (
00113 undecomposedPatchEntries[patchi].keyword()
00114 );
00115
00116 patchDictionary.add
00117 (
00118 undecomposedPatchEntries[patchi]
00119 );
00120 }
00121 }
00122 else
00123 {
00124 FatalErrorIn ("referredCellList.C")
00125 << nl << "unable to read undecomposed boundary file from "
00126 << "constant/polyMesh" << nl
00127 << abort(FatalError);
00128 }
00129
00130 labelIOList faceProcAddressing
00131 (
00132 IOobject
00133 (
00134 "faceProcAddressing",
00135 mesh.time().constant(),
00136 polyMesh::meshSubDir,
00137 mesh,
00138 IOobject::MUST_READ,
00139 IOobject::NO_WRITE,
00140 false
00141 )
00142 );
00143
00144 labelList procPatches(mesh.globalData().processorPatches());
00145
00146 nUndecomposedPatches = patchNames.size();
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 forAll(procPatches,pP)
00158 {
00159 const processorPolyPatch& patch = refCast<const processorPolyPatch>
00160 (
00161 mesh.boundaryMesh()[procPatches[pP]]
00162 );
00163
00164 labelList& procPatchSegMap = processorPatchSegmentMapping[pP];
00165
00166 procPatchSegMap.setSize(patch.size());
00167
00168 forAll (patch, pI)
00169 {
00170 label decomposedMeshFace = patch.start() + pI;
00171
00172 label faceProcAdd = faceProcAddressing[decomposedMeshFace];
00173
00174 label globalFace = abs(faceProcAdd)-1;
00175
00176 label minStart = -1;
00177
00178 forAll(patchNames, pN)
00179 {
00180 if (patchDictionary.found(patchNames[pN]))
00181 {
00182 const dictionary& patchDict =
00183 patchDictionary.subDict(patchNames[pN]);
00184
00185 label startFace
00186 (
00187 readLabel
00188 (
00189 patchDict.lookup("startFace")
00190 )
00191 );
00192
00193 label nFaces(readLabel(patchDict.lookup("nFaces")));
00194
00195 if (minStart < 0 || startFace < minStart)
00196 {
00197 minStart = startFace;
00198 }
00199
00200 if
00201 (
00202 globalFace >= startFace
00203 && globalFace < startFace + nFaces/2
00204 )
00205 {
00206 procPatchSegMap[pI] = pN + 1;
00207 }
00208 else if
00209 (
00210 globalFace >= startFace + nFaces/2
00211 && globalFace < startFace + nFaces
00212 )
00213 {
00214 procPatchSegMap[pI] = -(pN + 1);
00215 }
00216 }
00217 }
00218
00219 if (globalFace < minStart)
00220 {
00221 procPatchSegMap[pI] = 0;
00222 }
00223 }
00224 }
00225
00226 forAll(procPatches,pP)
00227 {
00228 const processorPolyPatch& patch = refCast<const processorPolyPatch>
00229 (
00230 mesh.boundaryMesh()[procPatches[pP]]
00231 );
00232
00233 {
00234 OPstream toNeighbProc
00235 (
00236 Pstream::blocking,
00237 patch.neighbProcNo()
00238 );
00239
00240 toNeighbProc << patch.faceCentres() << patch.faceAreas();
00241 }
00242 }
00243
00244 forAll(procPatches,pP)
00245 {
00246 const processorPolyPatch& patch = refCast<const processorPolyPatch>
00247 (
00248 mesh.boundaryMesh()[procPatches[pP]]
00249 );
00250
00251 vectorList& neighbFaceCentres = allNeighbourFaceCentres[pP];
00252
00253 neighbFaceCentres.setSize(patch.size());
00254
00255 vectorList& neighbFaceAreas = allNeighbourFaceAreas[pP];
00256
00257 neighbFaceAreas.setSize(patch.size());
00258
00259 {
00260 IPstream fromNeighbProc
00261 (
00262 Pstream::blocking,
00263 patch.neighbProcNo()
00264 );
00265
00266 fromNeighbProc >> neighbFaceCentres >> neighbFaceAreas;
00267 }
00268 }
00269
00270
00271
00272
00273
00274
00275
00276 forAll(procPatches,pP)
00277 {
00278 const processorPolyPatch& patch = refCast<const processorPolyPatch>
00279 (
00280 mesh.boundaryMesh()[procPatches[pP]]
00281 );
00282
00283 const vectorList& neighbFaceCentres = allNeighbourFaceCentres[pP];
00284
00285 const vectorList& neighbFaceAreas = allNeighbourFaceAreas[pP];
00286
00287 label nUP;
00288
00289 for
00290 (
00291 nUP = -nUndecomposedPatches;
00292 nUP <= nUndecomposedPatches;
00293 nUP++
00294 )
00295 {
00296 DynamicList<vector> refOff;
00297
00298 DynamicList<tensor> refTrans;
00299
00300 forAll (patch, faceI)
00301 {
00302 if (processorPatchSegmentMapping[pP][faceI] == nUP)
00303 {
00304 referredCell testRefCell
00305 (
00306 mesh,
00307 -1,
00308 -1,
00309 patch.faceCentres()[faceI],
00310 neighbFaceCentres[faceI],
00311 patch.faceNormals()[faceI],
00312 neighbFaceAreas[faceI]
00313 /(mag(neighbFaceAreas[faceI]) + VSMALL)
00314 );
00315
00316 refOff.append(testRefCell.offset());
00317
00318 refTrans.append(testRefCell.rotation());
00319 }
00320 }
00321
00322 refOff.shrink();
00323
00324 refTrans.shrink();
00325
00326 if (refOff.size())
00327 {
00328 if
00329 (
00330 sum(mag(refOff-refOff[0]))/refOff.size()
00331 > interactionLists::transTol
00332 || sum(mag(refTrans-refTrans[0]))/refTrans.size()
00333 > interactionLists::transTol
00334 )
00335 {
00336 FatalErrorIn ("referredCellList.C")
00337 << nl << "Face pairs on patch "
00338 << patch.name()
00339 << ", segment " << patchNames[nUP]
00340 << " do not give the same referring "
00341 << " transformations to within tolerance of "
00342 << interactionLists::transTol << nl
00343 << " Referring offsets:" << refOff << nl
00344 << " Average sum of mag difference: "
00345 << sum(mag(refOff-refOff[0]))/refOff.size() << nl
00346 << " Referring transforms:" << refTrans << nl
00347 << " Average sum of mag difference: "
00348 << sum(mag(refTrans-refTrans[0]))/refTrans.size()
00349 << nl << abort(FatalError);
00350 }
00351 }
00352 }
00353 }
00354 }
00355
00356 label cellsReferredThisIteration = 1;
00357
00358 label iterationNo = 0;
00359
00360 while (cellsReferredThisIteration)
00361 {
00362 label refIntListStartSize = referredInteractionList.size();
00363
00364 forAll (mesh.boundaryMesh(), patchI)
00365 {
00366
00367
00368
00369
00370 if (mesh.boundaryMesh()[patchI].type() == "cyclic")
00371 {
00372 const cyclicPolyPatch& patch = refCast<const cyclicPolyPatch>
00373 (
00374 mesh.boundaryMesh()[patchI]
00375 );
00376
00377 if (patch.size())
00378 {
00379 if (iterationNo == 0)
00380 {
00381
00382
00383
00384 label faceL;
00385
00386
00387 label faceM;
00388
00389
00390
00391 vectorList refOff(patch.size()/2);
00392
00393 List<tensor> refTrans(patch.size()/2);
00394
00395 for
00396 (
00397 faceL = 0, faceM = patch.size()/2;
00398 faceL < patch.size()/2;
00399 faceL++, faceM++
00400 )
00401 {
00402 referredCell testRefCell
00403 (
00404 mesh,
00405 -1,
00406 -1,
00407 patch.faceCentres()[faceL],
00408 patch.faceCentres()[faceM],
00409 patch.faceNormals()[faceL],
00410 patch.faceNormals()[faceM]
00411 );
00412
00413 refOff[faceL] = testRefCell.offset();
00414
00415 refTrans[faceL] = testRefCell.rotation();
00416 }
00417
00418 if
00419 (
00420 sum(mag(refOff - refOff[0]))/(patch.size()/2)
00421 > interactionLists::transTol
00422 || sum(mag(refTrans - refTrans[0]))/(patch.size()/2)
00423 > interactionLists::transTol
00424 )
00425 {
00426 FatalErrorIn ("referredCellList.C")
00427 << nl << "Face pairs on patch "
00428 << patch.name()
00429 << " do not give the same referring "
00430 << " transformations to within tolerance of "
00431 << interactionLists::transTol << nl
00432 << " Referring offsets:" << refOff << nl
00433 << " Average sum of mag difference: "
00434 << sum(mag(refOff-refOff[0]))/refOff.size()
00435 << nl
00436 << " Referring transforms:" << refTrans << nl
00437 << " Average sum of mag difference: "
00438 << sum(mag(refTrans-refTrans[0]))
00439 /refTrans.size()
00440 << nl << abort(FatalError);
00441 }
00442 }
00443
00444
00445
00446
00447
00448 label faceI;
00449
00450 DynamicList<label> meshFacesOnThisSegment;
00451
00452 for (faceI = 0; faceI < patch.size()/2; faceI++)
00453 {
00454
00455
00456
00457
00458 meshFacesOnThisSegment.append(faceI + patch.start());
00459 }
00460
00461 meshFacesOnThisSegment.shrink();
00462
00463 DynamicList<label> meshEdgesOnThisSegment;
00464
00465 DynamicList<label> meshPointsOnThisSegment;
00466
00467 forAll(meshFacesOnThisSegment, mFOTS)
00468 {
00469 const label segFace = meshFacesOnThisSegment[mFOTS];
00470
00471 const labelList& faceEdges = mesh.faceEdges()[segFace];
00472
00473 forAll (faceEdges, fE)
00474 {
00475 const label faceEdge(faceEdges[fE]);
00476
00477 if
00478 (
00479 findIndex
00480 (
00481 meshEdgesOnThisSegment,
00482 faceEdge
00483 ) == -1
00484 )
00485 {
00486 meshEdgesOnThisSegment.append(faceEdge);
00487 }
00488 }
00489
00490 const face& facePoints(mesh.faces()[segFace]);
00491
00492 forAll (facePoints, fP)
00493 {
00494 const label facePoint(facePoints[fP]);
00495
00496 if
00497 (
00498 findIndex
00499 (
00500 meshPointsOnThisSegment,
00501 facePoint
00502 )
00503 ==
00504 -1
00505 )
00506 {
00507 meshPointsOnThisSegment.append(facePoint);
00508 }
00509 }
00510 }
00511
00512 meshEdgesOnThisSegment.shrink();
00513
00514 meshPointsOnThisSegment.shrink();
00515
00516 if (iterationNo == 0)
00517 {
00518
00519
00520
00521
00522 labelList realCellsFoundInRange
00523 (
00524 il_.realCellsInRangeOfSegment
00525 (
00526 meshFacesOnThisSegment,
00527 meshEdgesOnThisSegment,
00528 meshPointsOnThisSegment
00529 )
00530 );
00531
00532 forAll(realCellsFoundInRange,cFIR)
00533 {
00534 const label realCell = realCellsFoundInRange[cFIR];
00535
00536 referredCell cellToRefer
00537 (
00538 mesh,
00539 Pstream::myProcNo(),
00540 realCell,
00541 patch.faceCentres()[0],
00542 patch.faceCentres()[patch.size()/2],
00543 patch.faceNormals()[0],
00544 patch.faceNormals()[patch.size()/2]
00545 );
00546
00547
00548
00549
00550
00551 bool addCellToRefer = true;
00552
00553
00554
00555 forAll(referredInteractionList, rIL)
00556 {
00557 if
00558 (
00559 cellToRefer.duplicate
00560 (
00561 referredInteractionList[rIL]
00562 )
00563 )
00564 {
00565 addCellToRefer = false;
00566
00567 break;
00568 }
00569 }
00570
00571
00572
00573
00574 if
00575 (
00576 cellToRefer.duplicate
00577 (
00578 Pstream::myProcNo(),
00579 mesh.nCells()
00580 )
00581 )
00582 {
00583 addCellToRefer = false;
00584 }
00585
00586 if (addCellToRefer)
00587 {
00588 referredInteractionList.append(cellToRefer);
00589 }
00590
00591
00592
00593
00594 if (findIndex (rCellsWRRP, realCell) == -1)
00595 {
00596 rCellsWRRP.append(realCell);
00597 }
00598 }
00599 }
00600
00601 referredInteractionList.shrink();
00602
00603 labelList referredCellsFoundInRange
00604 (
00605 il_.referredCellsInRangeOfSegment
00606 (
00607 referredInteractionList,
00608 meshFacesOnThisSegment,
00609 meshEdgesOnThisSegment,
00610 meshPointsOnThisSegment
00611 )
00612 );
00613
00614 forAll(referredCellsFoundInRange,cFIR)
00615 {
00616 referredCell& existingRefCell =
00617 referredInteractionList
00618 [
00619 referredCellsFoundInRange[cFIR]
00620 ];
00621
00622 referredCell cellToReRefer =
00623 existingRefCell.reRefer
00624 (
00625 patch.faceCentres()[0],
00626 patch.faceCentres()[patch.size()/2],
00627 patch.faceNormals()[0],
00628 patch.faceNormals()[patch.size()/2]
00629 );
00630
00631
00632
00633
00634
00635 bool addCellToReRefer = true;
00636
00637
00638
00639 forAll(referredInteractionList, rIL)
00640 {
00641 if
00642 (
00643 cellToReRefer.duplicate
00644 (
00645 referredInteractionList[rIL]
00646 )
00647 )
00648 {
00649 addCellToReRefer = false;
00650
00651 break;
00652 }
00653 }
00654
00655
00656
00657
00658 if
00659 (
00660 cellToReRefer.duplicate
00661 (
00662 Pstream::myProcNo(),
00663 mesh.nCells()
00664 )
00665 )
00666 {
00667 addCellToReRefer = false;
00668 }
00669
00670 if (addCellToReRefer)
00671 {
00672 referredInteractionList.append(cellToReRefer);
00673 }
00674 }
00675
00676
00677
00678
00679
00680 meshFacesOnThisSegment.clear();
00681
00682 for (faceI = patch.size()/2; faceI < patch.size(); faceI++)
00683 {
00684
00685
00686
00687
00688 meshFacesOnThisSegment.append(faceI + patch.start());
00689 }
00690
00691 meshFacesOnThisSegment.shrink();
00692
00693 meshEdgesOnThisSegment.clear();
00694
00695 meshPointsOnThisSegment.clear();
00696
00697 forAll(meshFacesOnThisSegment, mFOTS)
00698 {
00699 const label segFace = meshFacesOnThisSegment[mFOTS];
00700
00701 const labelList& faceEdges = mesh.faceEdges()[segFace];
00702
00703 forAll (faceEdges, fE)
00704 {
00705 const label faceEdge(faceEdges[fE]);
00706
00707 if
00708 (
00709 findIndex
00710 (
00711 meshEdgesOnThisSegment,
00712 faceEdge
00713 )
00714 ==
00715 -1
00716 )
00717 {
00718 meshEdgesOnThisSegment.append(faceEdge);
00719 }
00720 }
00721
00722 const face& facePoints(mesh.faces()[segFace]);
00723
00724 forAll (facePoints, fP)
00725 {
00726 const label facePoint(facePoints[fP]);
00727
00728 if
00729 (
00730 findIndex
00731 (
00732 meshPointsOnThisSegment,
00733 facePoint
00734 )
00735 ==
00736 -1
00737 )
00738 {
00739 meshPointsOnThisSegment.append(facePoint);
00740 }
00741 }
00742 }
00743
00744 meshEdgesOnThisSegment.shrink();
00745
00746 meshPointsOnThisSegment.shrink();
00747
00748 if (iterationNo == 0)
00749 {
00750
00751
00752
00753
00754 labelList realCellsFoundInRange
00755 (
00756 il_.realCellsInRangeOfSegment
00757 (
00758 meshFacesOnThisSegment,
00759 meshEdgesOnThisSegment,
00760 meshPointsOnThisSegment
00761 )
00762 );
00763
00764 forAll(realCellsFoundInRange,cFIR)
00765 {
00766 const label realCell = realCellsFoundInRange[cFIR];
00767
00768 referredCell cellToRefer
00769 (
00770 mesh,
00771 Pstream::myProcNo(),
00772 realCell,
00773 patch.faceCentres()[patch.size()/2],
00774 patch.faceCentres()[0],
00775 patch.faceNormals()[patch.size()/2],
00776 patch.faceNormals()[0]
00777 );
00778
00779
00780
00781
00782
00783 bool addCellToRefer = true;
00784
00785
00786
00787 forAll(referredInteractionList, rIL)
00788 {
00789 if
00790 (
00791 cellToRefer.duplicate
00792 (
00793 referredInteractionList[rIL]
00794 )
00795 )
00796 {
00797 addCellToRefer = false;
00798
00799 break;
00800 }
00801 }
00802
00803
00804
00805
00806 if
00807 (
00808 cellToRefer.duplicate
00809 (
00810 Pstream::myProcNo(),
00811 mesh.nCells()
00812 )
00813 )
00814 {
00815 addCellToRefer = false;
00816 }
00817
00818 if (addCellToRefer)
00819 {
00820 referredInteractionList.append(cellToRefer);
00821 }
00822
00823
00824
00825
00826 if (findIndex (rCellsWRRP, realCell) == -1)
00827 {
00828 rCellsWRRP.append(realCell);
00829 }
00830 }
00831 }
00832
00833 referredInteractionList.shrink();
00834
00835 referredCellsFoundInRange =
00836 il_.referredCellsInRangeOfSegment
00837 (
00838 referredInteractionList,
00839 meshFacesOnThisSegment,
00840 meshEdgesOnThisSegment,
00841 meshPointsOnThisSegment
00842 );
00843
00844 forAll(referredCellsFoundInRange,cFIR)
00845 {
00846 referredCell& existingRefCell =
00847 referredInteractionList
00848 [
00849 referredCellsFoundInRange[cFIR]
00850 ];
00851
00852 referredCell cellToReRefer =
00853 existingRefCell.reRefer
00854 (
00855 patch.faceCentres()[patch.size()/2],
00856 patch.faceCentres()[0],
00857 patch.faceNormals()[patch.size()/2],
00858 patch.faceNormals()[0]
00859 );
00860
00861
00862
00863
00864
00865 bool addCellToReRefer = true;
00866
00867
00868
00869 forAll(referredInteractionList, rIL)
00870 {
00871 if
00872 (
00873 cellToReRefer.duplicate
00874 (
00875 referredInteractionList[rIL]
00876 )
00877 )
00878 {
00879 addCellToReRefer = false;
00880
00881 break;
00882 }
00883 }
00884
00885
00886
00887
00888 if
00889 (
00890 cellToReRefer.duplicate
00891 (
00892 Pstream::myProcNo(),
00893 mesh.nCells()
00894 )
00895 )
00896 {
00897 addCellToReRefer = false;
00898 }
00899
00900 if (addCellToReRefer)
00901 {
00902 referredInteractionList.append(cellToReRefer);
00903 }
00904 }
00905 }
00906 }
00907 }
00908
00909 if (Pstream::parRun())
00910 {
00911 labelList procPatches(mesh.globalData().processorPatches());
00912
00913 forAll(procPatches,pP)
00914 {
00915 const processorPolyPatch& patch =
00916 refCast<const processorPolyPatch>
00917 (
00918 mesh.boundaryMesh()[procPatches[pP]]
00919 );
00920
00921 DynamicList<referredCell> referredCellsToTransfer;
00922
00923 const vectorList& neighbFaceCentres =
00924 allNeighbourFaceCentres[pP];
00925
00926 const vectorList& neighbFaceAreas = allNeighbourFaceAreas[pP];
00927
00928 label nUP;
00929
00930 for
00931 (
00932 nUP = -nUndecomposedPatches;
00933 nUP <= nUndecomposedPatches;
00934 nUP++
00935 )
00936 {
00937
00938
00939
00940
00941
00942
00943
00944 label faceT = -1;
00945
00946 DynamicList<label> meshFacesOnThisSegment;
00947
00948 forAll (patch, faceI)
00949 {
00950 if (processorPatchSegmentMapping[pP][faceI] == nUP)
00951 {
00952 if (faceT == -1)
00953 {
00954 faceT = faceI;
00955 }
00956
00957 meshFacesOnThisSegment.append
00958 (
00959 faceI + patch.start()
00960 );
00961 }
00962 }
00963
00964 meshFacesOnThisSegment.shrink();
00965
00966 DynamicList<label> meshEdgesOnThisSegment;
00967
00968 DynamicList<label> meshPointsOnThisSegment;
00969
00970 forAll(meshFacesOnThisSegment, mFOTS)
00971 {
00972 const label segFace = meshFacesOnThisSegment[mFOTS];
00973
00974 const labelList& faceEdges = mesh.faceEdges()[segFace];
00975
00976 forAll (faceEdges, fE)
00977 {
00978 const label faceEdge(faceEdges[fE]);
00979
00980 if
00981 (
00982 findIndex
00983 (
00984 meshEdgesOnThisSegment,
00985 faceEdge
00986 )
00987 ==
00988 -1
00989 )
00990 {
00991 meshEdgesOnThisSegment.append(faceEdge);
00992 }
00993 }
00994
00995 const face& facePoints(mesh.faces()[segFace]);
00996
00997 forAll (facePoints, fP)
00998 {
00999 const label facePoint(facePoints[fP]);
01000
01001 if
01002 (
01003 findIndex
01004 (
01005 meshPointsOnThisSegment,
01006 facePoint
01007 )
01008 ==
01009 -1
01010 )
01011 {
01012 meshPointsOnThisSegment.append(facePoint);
01013 }
01014 }
01015 }
01016
01017 meshEdgesOnThisSegment.shrink();
01018
01019 meshPointsOnThisSegment.shrink();
01020
01021 if (meshFacesOnThisSegment.size())
01022 {
01023 if (faceT == -1)
01024 {
01025 FatalErrorIn ("referredCellList.C")
01026 << nl << "faceT == -1 encountered but "
01027 << meshFacesOnThisSegment.size()
01028 << " faces found on patch segment."
01029 << abort(FatalError);
01030 }
01031
01032 if (iterationNo == 0)
01033 {
01034
01035
01036
01037
01038 labelList realCellsFoundInRange
01039 (
01040 il_.realCellsInRangeOfSegment
01041 (
01042 meshFacesOnThisSegment,
01043 meshEdgesOnThisSegment,
01044 meshPointsOnThisSegment
01045 )
01046 );
01047
01048 forAll(realCellsFoundInRange,cFIR)
01049 {
01050 const label realCell =
01051 realCellsFoundInRange[cFIR];
01052
01053 referredCell cellToRefer
01054 (
01055 mesh,
01056 Pstream::myProcNo(),
01057 realCell,
01058 patch.faceCentres()[faceT],
01059 neighbFaceCentres[faceT],
01060 patch.faceNormals()[faceT],
01061 neighbFaceAreas[faceT]
01062 /(mag(neighbFaceAreas[faceT]) + VSMALL)
01063 );
01064
01065 referredCellsToTransfer.append(cellToRefer);
01066
01067
01068
01069
01070 if (findIndex (rCellsWRRP, realCell) == -1)
01071 {
01072 rCellsWRRP.append(realCell);
01073 }
01074 }
01075 }
01076
01077 referredInteractionList.shrink();
01078
01079 labelList referredCellsFoundInRange
01080 (
01081 il_.referredCellsInRangeOfSegment
01082 (
01083 referredInteractionList,
01084 meshFacesOnThisSegment,
01085 meshEdgesOnThisSegment,
01086 meshPointsOnThisSegment
01087 )
01088 );
01089
01090 forAll(referredCellsFoundInRange,cFIR)
01091 {
01092 referredCell& existingRefCell =
01093 referredInteractionList
01094 [
01095 referredCellsFoundInRange[cFIR]
01096 ];
01097
01098 referredCell cellToReRefer =
01099 existingRefCell.reRefer
01100 (
01101 patch.faceCentres()[faceT],
01102 neighbFaceCentres[faceT],
01103 patch.faceNormals()[faceT],
01104 neighbFaceAreas[faceT]
01105 /(mag(neighbFaceAreas[faceT]) + VSMALL)
01106 );
01107
01108 referredCellsToTransfer.append(cellToReRefer);
01109 }
01110 }
01111 }
01112
01113 referredCellsToTransfer.shrink();
01114
01115
01116
01117 {
01118 OPstream toNeighbProc
01119 (
01120 Pstream::blocking,
01121 patch.neighbProcNo()
01122 );
01123
01124 toNeighbProc << referredCellsToTransfer;
01125 }
01126 }
01127
01128 forAll(procPatches,pP)
01129 {
01130 const processorPolyPatch& patch =
01131 refCast<const processorPolyPatch>
01132 (
01133 mesh.boundaryMesh()[procPatches[pP]]
01134 );
01135
01136
01137
01138 List<referredCell> referredCellsFromNeighbour(patch.size());
01139
01140 {
01141 IPstream fromNeighbProc
01142 (
01143 Pstream::blocking,
01144 patch.neighbProcNo()
01145 );
01146
01147 fromNeighbProc >> referredCellsFromNeighbour;
01148 }
01149
01150
01151
01152
01153 forAll(referredCellsFromNeighbour,rCFN)
01154 {
01155 referredCell& cellToRefer =
01156 referredCellsFromNeighbour[rCFN];
01157
01158
01159
01160
01161
01162 bool addCellToRefer = true;
01163
01164
01165
01166 forAll(referredInteractionList, rIL)
01167 {
01168 if (cellToRefer.duplicate(referredInteractionList[rIL]))
01169 {
01170 addCellToRefer = false;
01171
01172 break;
01173 }
01174 }
01175
01176
01177
01178
01179 if
01180 (
01181 cellToRefer.duplicate
01182 (
01183 Pstream::myProcNo(),
01184 mesh.nCells()
01185 )
01186 )
01187 {
01188 addCellToRefer = false;
01189 }
01190
01191 if (addCellToRefer)
01192 {
01193 referredInteractionList.append(cellToRefer);
01194 }
01195 }
01196 }
01197 }
01198
01199 if (iterationNo == 0)
01200 {
01201
01202
01203
01204
01205 rCellsWRRP.shrink();
01206
01207
01208
01209 forAll(rCellsWRRP, rCWR)
01210 {
01211 const label realCell(rCellsWRRP[rCWR]);
01212
01213 const labelList& rCFaces
01214 (
01215 mesh.cells()[realCell]
01216 );
01217
01218 forAll(rCFaces, rCF)
01219 {
01220 const label f(rCFaces[rCF]);
01221
01222 if (findIndex(rFacesWRRP,f) == -1)
01223 {
01224 rFacesWRRP.append(f);
01225 }
01226 }
01227
01228 const labelList& rCEdges
01229 (
01230 mesh.cellEdges()[realCell]
01231 );
01232
01233 forAll(rCEdges, rCE)
01234 {
01235 const label e(rCEdges[rCE]);
01236
01237 if (findIndex(rEdgesWRRP,e) == -1)
01238 {
01239 rEdgesWRRP.append(e);
01240 }
01241 }
01242
01243 const labelList& rCPoints
01244 (
01245 mesh.cellPoints()[realCell]
01246 );
01247
01248 forAll(rCPoints, rCP)
01249 {
01250 const label p(rCPoints[rCP]);
01251
01252 if (findIndex(rPointsWRRP,p) == -1)
01253 {
01254 rPointsWRRP.append(p);
01255 }
01256 }
01257 }
01258
01259 rFacesWRRP.shrink();
01260
01261 rEdgesWRRP.shrink();
01262
01263 rPointsWRRP.shrink();
01264 }
01265
01266 iterationNo++;
01267
01268 cellsReferredThisIteration =
01269 referredInteractionList.size() - refIntListStartSize;
01270
01271 reduce(cellsReferredThisIteration, sumOp<label>());
01272
01273 Info<< tab << "Cells added this iteration: "
01274 << cellsReferredThisIteration << endl;
01275 }
01276
01277 referredInteractionList.shrink();
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287 (*this).setSize
01288 (
01289 referredInteractionList.size()
01290 );
01291
01292 forAll(referredInteractionList, rIL)
01293 {
01294 (*this)[rIL] = referredInteractionList[rIL];
01295 }
01296
01297 Info<< nl << "Finding real cells in range of referred cells" << endl;
01298
01299 forAll(*this, rC)
01300 {
01301 const polyMesh& mesh(il_.mesh());
01302
01303 referredCell& refCell = (*this)[rC];
01304
01305 DynamicList<label> realCellsFoundInRange;
01306
01307 const vectorList& refCellPoints = refCell.vertexPositions();
01308
01309 forAll(rFacesWRRP, rCF)
01310 {
01311 const label f(rFacesWRRP[rCF]);
01312
01313 if (il_.testPointFaceDistance(refCellPoints,f))
01314 {
01315 const label cellO(mesh.faceOwner()[f]);
01316
01317 if (findIndex(realCellsFoundInRange, cellO) == -1)
01318 {
01319 realCellsFoundInRange.append(cellO);
01320 }
01321
01322 if (mesh.isInternalFace(f))
01323 {
01324
01325
01326 const label cellN(mesh.faceNeighbour()[f]);
01327
01328 if (findIndex(realCellsFoundInRange, cellN) == -1)
01329 {
01330 realCellsFoundInRange.append(cellN);
01331 }
01332 }
01333 }
01334 }
01335
01336 forAll(rPointsWRRP, rCP)
01337 {
01338 const label p(rPointsWRRP[rCP]);
01339
01340 if (il_.testPointFaceDistance(p,refCell))
01341 {
01342 const labelList& pCells(mesh.pointCells()[p]);
01343
01344 forAll(pCells, pC)
01345 {
01346 const label cellI(pCells[pC]);
01347
01348 if (findIndex(realCellsFoundInRange, cellI) == -1)
01349 {
01350 realCellsFoundInRange.append(cellI);
01351 }
01352 }
01353 }
01354 }
01355
01356
01357 const edgeList& refCellEdges = refCell.edges();
01358
01359 forAll(rEdgesWRRP, rCE)
01360 {
01361 const label edgeIIndex(rEdgesWRRP[rCE]);
01362
01363 const edge& eI(mesh.edges()[edgeIIndex]);
01364
01365 forAll(refCellEdges, rCE)
01366 {
01367 const edge& eJ(refCellEdges[rCE]);
01368
01369 if
01370 (
01371 il_.testEdgeEdgeDistance
01372 (
01373 eI,
01374 refCellPoints[eJ.start()],
01375 refCellPoints[eJ.end()]
01376 )
01377 )
01378 {
01379 const labelList& eICells(mesh.edgeCells()[edgeIIndex]);
01380
01381 forAll(eICells, eIC)
01382 {
01383 const label cellI(eICells[eIC]);
01384
01385 if (findIndex(realCellsFoundInRange, cellI) == -1)
01386 {
01387 realCellsFoundInRange.append(cellI);
01388 }
01389 }
01390 }
01391 }
01392 }
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425 refCell.realCells() = realCellsFoundInRange.shrink();
01426 }
01427 }
01428
01429
01430
01431
01432 Foam::referredCellList::referredCellList
01433 (
01434 interactionLists& il,
01435 bool pointPointListBuild
01436 )
01437 :
01438 List<referredCell>(),
01439 il_(il)
01440 {
01441 buildReferredCellList(pointPointListBuild);
01442 }
01443
01444
01445 Foam::referredCellList::referredCellList(interactionLists& il)
01446 :
01447 List<referredCell>(),
01448 il_(il)
01449 {
01450 Info<< "Read referredCellList from disk not implemented" << endl;
01451 }
01452
01453
01454
01455
01456 Foam::referredCellList::~referredCellList()
01457 {}
01458
01459
01460
01461
01462 void Foam::referredCellList::referMolecules
01463 (
01464 const List<DynamicList<molecule*> >& cellOccupancy
01465 )
01466 {
01467
01468
01469
01470 forAll(il_.cellSendingReferralLists(), cSRL)
01471 {
01472 const sendingReferralList& sRL
01473 (
01474 il_.cellSendingReferralLists()[cSRL]
01475 );
01476
01477 List<DynamicList<referredMolecule> > molsToReferOut(sRL.size());
01478
01479 forAll(sRL, sRLI)
01480 {
01481 List<molecule*> realMols = cellOccupancy[sRL[sRLI]];
01482
01483 forAll (realMols, rM)
01484 {
01485 molecule* mol = realMols[rM];
01486
01487 molsToReferOut[sRLI].append
01488 (
01489 referredMolecule
01490 (
01491 mol->id(),
01492 mol->position(),
01493 mol->sitePositions()
01494 )
01495 );
01496 }
01497
01498 molsToReferOut[sRLI].shrink();
01499 }
01500
01501
01502
01503 if (sRL.destinationProc() != Pstream::myProcNo())
01504 {
01505 if (Pstream::parRun())
01506 {
01507 OPstream toInteractingProc
01508 (
01509 Pstream::blocking,
01510 sRL.destinationProc()
01511 );
01512
01513 toInteractingProc << molsToReferOut;
01514 }
01515 }
01516 else
01517 {
01518
01519
01520
01521 const receivingReferralList& rRL
01522 (
01523 il_.cellReceivingReferralLists()[cSRL]
01524 );
01525
01526 forAll(rRL, rRLI)
01527 {
01528 forAll(rRL[rRLI], rC)
01529 {
01530 referredCell& refCellToRefMolsTo = (*this)[rRL[rRLI][rC]];
01531
01532 refCellToRefMolsTo.referInMols(molsToReferOut[rRLI]);
01533 }
01534 }
01535 }
01536 }
01537
01538
01539
01540
01541
01542 forAll(il_.cellReceivingReferralLists(), cRRL)
01543 {
01544 const receivingReferralList& rRL
01545 (
01546 il_.cellReceivingReferralLists()[cRRL]
01547 );
01548
01549 List<List<referredMolecule> > molsToReferIn(rRL.size());
01550
01551 if (rRL.sourceProc() != Pstream::myProcNo())
01552 {
01553 if (Pstream::parRun())
01554 {
01555 IPstream fromInteractingProc
01556 (
01557 Pstream::blocking,
01558 rRL.sourceProc()
01559 );
01560
01561 fromInteractingProc >> molsToReferIn;
01562 }
01563
01564 forAll(rRL, rRLI)
01565 {
01566 forAll(rRL[rRLI], rC)
01567 {
01568 referredCell& refCellToRefMolsTo = (*this)[rRL[rRLI][rC]];
01569
01570 refCellToRefMolsTo.referInMols(molsToReferIn[rRLI]);
01571 }
01572 }
01573 }
01574 }
01575 }
01576
01577
01578