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 "meshCutAndRemove.H"
00028 #include "polyMesh.H"
00029 #include "polyTopoChange.H"
00030 #include "polyAddFace.H"
00031 #include "polyAddPoint.H"
00032 #include "polyRemovePoint.H"
00033 #include "polyRemoveFace.H"
00034 #include "polyModifyFace.H"
00035 #include "cellCuts.H"
00036 #include "mapPolyMesh.H"
00037 #include "meshTools.H"
00038
00039
00040
00041 defineTypeNameAndDebug(Foam::meshCutAndRemove, 0);
00042
00043
00044
00045
00046 Foam::label Foam::meshCutAndRemove::firstCommon
00047 (
00048 const labelList& elems1,
00049 const labelList& elems2
00050 )
00051 {
00052 forAll(elems1, elemI)
00053 {
00054 label index1 = findIndex(elems2, elems1[elemI]);
00055
00056 if (index1 != -1)
00057 {
00058 return index1;
00059 }
00060 }
00061 return -1;
00062 }
00063
00064
00065
00066 bool Foam::meshCutAndRemove::isIn
00067 (
00068 const edge& twoCuts,
00069 const labelList& cuts
00070 )
00071 {
00072 label index = findIndex(cuts, twoCuts[0]);
00073
00074 if (index == -1)
00075 {
00076 return false;
00077 }
00078
00079 return
00080 (
00081 cuts[cuts.fcIndex(index)] == twoCuts[1]
00082 || cuts[cuts.rcIndex(index)] == twoCuts[1]
00083 );
00084 }
00085
00086
00087
00088
00089
00090 Foam::label Foam::meshCutAndRemove::findCutCell
00091 (
00092 const cellCuts& cuts,
00093 const labelList& cellLabels
00094 ) const
00095 {
00096 forAll(cellLabels, labelI)
00097 {
00098 label cellI = cellLabels[labelI];
00099
00100 if (cuts.cellLoops()[cellI].size())
00101 {
00102 return cellI;
00103 }
00104 }
00105 return -1;
00106 }
00107
00108
00109
00110
00111
00112
00113 Foam::label Foam::meshCutAndRemove::findInternalFacePoint
00114 (
00115 const labelList& pointLabels
00116 ) const
00117 {
00118 forAll(pointLabels, labelI)
00119 {
00120 label pointI = pointLabels[labelI];
00121
00122 const labelList& pFaces = mesh().pointFaces()[pointI];
00123
00124 forAll(pFaces, pFaceI)
00125 {
00126 label faceI = pFaces[pFaceI];
00127
00128 if (mesh().isInternalFace(faceI))
00129 {
00130 return pointI;
00131 }
00132 }
00133 }
00134
00135 if (pointLabels.empty())
00136 {
00137 FatalErrorIn("meshCutAndRemove::findInternalFacePoint(const labelList&)")
00138 << "Empty pointLabels" << abort(FatalError);
00139 }
00140
00141 return -1;
00142 }
00143
00144
00145
00146
00147 Foam::label Foam::meshCutAndRemove::findPatchFacePoint
00148 (
00149 const face& f,
00150 const label exposedPatchI
00151 ) const
00152 {
00153 const labelListList& pointFaces = mesh().pointFaces();
00154 const polyBoundaryMesh& patches = mesh().boundaryMesh();
00155
00156 forAll(f, fp)
00157 {
00158 label pointI = f[fp];
00159
00160 if (pointI < mesh().nPoints())
00161 {
00162 const labelList& pFaces = pointFaces[pointI];
00163
00164 forAll(pFaces, i)
00165 {
00166 if (patches.whichPatch(pFaces[i]) == exposedPatchI)
00167 {
00168 return pointI;
00169 }
00170 }
00171 }
00172 }
00173 return -1;
00174 }
00175
00176
00177
00178
00179 void Foam::meshCutAndRemove::faceCells
00180 (
00181 const cellCuts& cuts,
00182 const label exposedPatchI,
00183 const label faceI,
00184 label& own,
00185 label& nei,
00186 label& patchID
00187 ) const
00188 {
00189 const labelListList& anchorPts = cuts.cellAnchorPoints();
00190 const labelListList& cellLoops = cuts.cellLoops();
00191
00192 const face& f = mesh().faces()[faceI];
00193
00194 own = mesh().faceOwner()[faceI];
00195
00196 if (cellLoops[own].size() && firstCommon(f, anchorPts[own]) == -1)
00197 {
00198
00199 own = -1;
00200 }
00201
00202 nei = -1;
00203
00204 if (mesh().isInternalFace(faceI))
00205 {
00206 nei = mesh().faceNeighbour()[faceI];
00207
00208 if (cellLoops[nei].size() && firstCommon(f, anchorPts[nei]) == -1)
00209 {
00210 nei = -1;
00211 }
00212 }
00213
00214 patchID = mesh().boundaryMesh().whichPatch(faceI);
00215
00216 if (patchID == -1 && (own == -1 || nei == -1))
00217 {
00218
00219 patchID = exposedPatchI;
00220 }
00221 }
00222
00223
00224 void Foam::meshCutAndRemove::getZoneInfo
00225 (
00226 const label faceI,
00227 label& zoneID,
00228 bool& zoneFlip
00229 ) const
00230 {
00231 zoneID = mesh().faceZones().whichZone(faceI);
00232
00233 zoneFlip = false;
00234
00235 if (zoneID >= 0)
00236 {
00237 const faceZone& fZone = mesh().faceZones()[zoneID];
00238
00239 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00240 }
00241 }
00242
00243
00244
00245 void Foam::meshCutAndRemove::addFace
00246 (
00247 polyTopoChange& meshMod,
00248 const label faceI,
00249 const label masterPointI,
00250 const face& newFace,
00251 const label own,
00252 const label nei,
00253 const label patchID
00254 )
00255 {
00256 label zoneID;
00257 bool zoneFlip;
00258
00259 getZoneInfo(faceI, zoneID, zoneFlip);
00260
00261 if ((nei == -1) || (own != -1 && own < nei))
00262 {
00263
00264 if (debug & 2)
00265 {
00266 Pout<< "Adding face " << newFace
00267 << " with new owner:" << own
00268 << " with new neighbour:" << nei
00269 << " patchID:" << patchID
00270 << " anchor:" << masterPointI
00271 << " zoneID:" << zoneID
00272 << " zoneFlip:" << zoneFlip
00273 << endl;
00274 }
00275
00276 meshMod.setAction
00277 (
00278 polyAddFace
00279 (
00280 newFace,
00281 own,
00282 nei,
00283 masterPointI,
00284 -1,
00285 -1,
00286 false,
00287 patchID,
00288 zoneID,
00289 zoneFlip
00290 )
00291 );
00292 }
00293 else
00294 {
00295
00296 if (debug & 2)
00297 {
00298 Pout<< "Adding (reversed) face " << newFace.reverseFace()
00299 << " with new owner:" << nei
00300 << " with new neighbour:" << own
00301 << " patchID:" << patchID
00302 << " anchor:" << masterPointI
00303 << " zoneID:" << zoneID
00304 << " zoneFlip:" << zoneFlip
00305 << endl;
00306 }
00307
00308 meshMod.setAction
00309 (
00310 polyAddFace
00311 (
00312 newFace.reverseFace(),
00313 nei,
00314 own,
00315 masterPointI,
00316 -1,
00317 -1,
00318 false,
00319 patchID,
00320 zoneID,
00321 zoneFlip
00322 )
00323 );
00324 }
00325 }
00326
00327
00328
00329 void Foam::meshCutAndRemove::modFace
00330 (
00331 polyTopoChange& meshMod,
00332 const label faceI,
00333 const face& newFace,
00334 const label own,
00335 const label nei,
00336 const label patchID
00337 )
00338 {
00339 label zoneID;
00340 bool zoneFlip;
00341
00342 getZoneInfo(faceI, zoneID, zoneFlip);
00343
00344 if
00345 (
00346 (own != mesh().faceOwner()[faceI])
00347 || (
00348 mesh().isInternalFace(faceI)
00349 && (nei != mesh().faceNeighbour()[faceI])
00350 )
00351 || (newFace != mesh().faces()[faceI])
00352 )
00353 {
00354 if (debug & 2)
00355 {
00356 Pout<< "Modifying face " << faceI
00357 << " old vertices:" << mesh().faces()[faceI]
00358 << " new vertices:" << newFace
00359 << " new owner:" << own
00360 << " new neighbour:" << nei
00361 << " new patch:" << patchID
00362 << " new zoneID:" << zoneID
00363 << " new zoneFlip:" << zoneFlip
00364 << endl;
00365 }
00366
00367 if ((nei == -1) || (own != -1 && own < nei))
00368 {
00369 meshMod.setAction
00370 (
00371 polyModifyFace
00372 (
00373 newFace,
00374 faceI,
00375 own,
00376 nei,
00377 false,
00378 patchID,
00379 false,
00380 zoneID,
00381 zoneFlip
00382 )
00383 );
00384 }
00385 else
00386 {
00387 meshMod.setAction
00388 (
00389 polyModifyFace
00390 (
00391 newFace.reverseFace(),
00392 faceI,
00393 nei,
00394 own,
00395 false,
00396 patchID,
00397 false,
00398 zoneID,
00399 zoneFlip
00400 )
00401 );
00402 }
00403 }
00404 }
00405
00406
00407
00408 void Foam::meshCutAndRemove::copyFace
00409 (
00410 const face& f,
00411 const label startFp,
00412 const label endFp,
00413 face& newFace
00414 ) const
00415 {
00416 label fp = startFp;
00417
00418 label newFp = 0;
00419
00420 while (fp != endFp)
00421 {
00422 newFace[newFp++] = f[fp];
00423
00424 fp = (fp + 1) % f.size();
00425 }
00426 newFace[newFp] = f[fp];
00427 }
00428
00429
00430
00431
00432
00433
00434 void Foam::meshCutAndRemove::splitFace
00435 (
00436 const face& f,
00437 const label v0,
00438 const label v1,
00439
00440 face& f0,
00441 face& f1
00442 ) const
00443 {
00444
00445 label startFp = findIndex(f, v0);
00446
00447 if (startFp == -1)
00448 {
00449 FatalErrorIn
00450 (
00451 "meshCutAndRemove::splitFace"
00452 ", const face&, const label, const label, face&, face&)"
00453 ) << "Cannot find vertex (new numbering) " << v0
00454 << " on face " << f
00455 << abort(FatalError);
00456 }
00457
00458 label endFp = findIndex(f, v1);
00459
00460 if (endFp == -1)
00461 {
00462 FatalErrorIn
00463 (
00464 "meshCutAndRemove::splitFace("
00465 ", const face&, const label, const label, face&, face&)"
00466 ) << "Cannot find vertex (new numbering) " << v1
00467 << " on face " << f
00468 << abort(FatalError);
00469 }
00470
00471
00472 f0.setSize((endFp + 1 + f.size() - startFp) % f.size());
00473 f1.setSize(f.size() - f0.size() + 2);
00474
00475 copyFace(f, startFp, endFp, f0);
00476 copyFace(f, endFp, startFp, f1);
00477 }
00478
00479
00480
00481
00482 Foam::face Foam::meshCutAndRemove::addEdgeCutsToFace(const label faceI) const
00483 {
00484 const face& f = mesh().faces()[faceI];
00485
00486 face newFace(2 * f.size());
00487
00488 label newFp = 0;
00489
00490 forAll(f, fp)
00491 {
00492
00493 newFace[newFp++] = f[fp];
00494
00495
00496 label fp1 = f.fcIndex(fp);
00497
00498 HashTable<label, edge, Hash<edge> >::const_iterator fnd =
00499 addedPoints_.find(edge(f[fp], f[fp1]));
00500
00501 if (fnd != addedPoints_.end())
00502 {
00503
00504 newFace[newFp++] = fnd();
00505 }
00506 }
00507
00508 newFace.setSize(newFp);
00509
00510 return newFace;
00511 }
00512
00513
00514
00515
00516
00517 Foam::face Foam::meshCutAndRemove::loopToFace
00518 (
00519 const label cellI,
00520 const labelList& loop
00521 ) const
00522 {
00523 face newFace(2*loop.size());
00524
00525 label newFaceI = 0;
00526
00527 forAll(loop, fp)
00528 {
00529 label cut = loop[fp];
00530
00531 if (isEdge(cut))
00532 {
00533 label edgeI = getEdge(cut);
00534
00535 const edge& e = mesh().edges()[edgeI];
00536
00537 label vertI = addedPoints_[e];
00538
00539 newFace[newFaceI++] = vertI;
00540 }
00541 else
00542 {
00543
00544 label vertI = getVertex(cut);
00545
00546 newFace[newFaceI++] = vertI;
00547
00548 label nextCut = loop[loop.fcIndex(fp)];
00549
00550 if (!isEdge(nextCut))
00551 {
00552
00553 label nextVertI = getVertex(nextCut);
00554
00555 label edgeI = meshTools::findEdge(mesh(), vertI, nextVertI);
00556
00557 if (edgeI != -1)
00558 {
00559
00560 HashTable<label, edge, Hash<edge> >::const_iterator fnd =
00561 addedPoints_.find(mesh().edges()[edgeI]);
00562
00563 if (fnd != addedPoints_.end())
00564 {
00565 newFace[newFaceI++] = fnd();
00566 }
00567 }
00568 }
00569 }
00570 }
00571 newFace.setSize(newFaceI);
00572
00573 return newFace;
00574 }
00575
00576
00577
00578
00579
00580 Foam::meshCutAndRemove::meshCutAndRemove(const polyMesh& mesh)
00581 :
00582 edgeVertex(mesh),
00583 addedFaces_(),
00584 addedPoints_()
00585 {}
00586
00587
00588
00589
00590 void Foam::meshCutAndRemove::setRefinement
00591 (
00592 const label exposedPatchI,
00593 const cellCuts& cuts,
00594 const labelList& cutPatch,
00595 polyTopoChange& meshMod
00596 )
00597 {
00598
00599 addedFaces_.clear();
00600 addedFaces_.resize(cuts.nLoops());
00601
00602 addedPoints_.clear();
00603 addedPoints_.resize(cuts.nLoops());
00604
00605 if (cuts.nLoops() == 0)
00606 {
00607 return;
00608 }
00609
00610 const labelListList& anchorPts = cuts.cellAnchorPoints();
00611 const labelListList& cellLoops = cuts.cellLoops();
00612 const polyBoundaryMesh& patches = mesh().boundaryMesh();
00613
00614 if (exposedPatchI < 0 || exposedPatchI >= patches.size())
00615 {
00616 FatalErrorIn
00617 (
00618 "meshCutAndRemove::setRefinement("
00619 ", const label, const cellCuts&, const labelList&"
00620 ", polyTopoChange&)"
00621 ) << "Illegal exposed patch " << exposedPatchI
00622 << abort(FatalError);
00623 }
00624
00625
00626
00627
00628
00629
00630 forAll(cuts.edgeIsCut(), edgeI)
00631 {
00632 if (cuts.edgeIsCut()[edgeI])
00633 {
00634 const edge& e = mesh().edges()[edgeI];
00635
00636
00637 if (debug && findCutCell(cuts, mesh().edgeCells()[edgeI]) == -1)
00638 {
00639 FatalErrorIn
00640 (
00641 "meshCutAndRemove::setRefinement("
00642 ", const label, const cellCuts&, const labelList&"
00643 ", polyTopoChange&)"
00644 ) << "Problem: cut edge but none of the cells using it is\n"
00645 << "edge:" << edgeI << " verts:" << e
00646 << abort(FatalError);
00647 }
00648
00649
00650 label masterPointI = e.start();
00651
00652 const point& v0 = mesh().points()[e.start()];
00653 const point& v1 = mesh().points()[e.end()];
00654
00655 scalar weight = cuts.edgeWeight()[edgeI];
00656
00657 point newPt = weight*v1 + (1.0-weight)*v0;
00658
00659 label addedPointI =
00660 meshMod.setAction
00661 (
00662 polyAddPoint
00663 (
00664 newPt,
00665 masterPointI,
00666 -1,
00667 true
00668 )
00669 );
00670
00671
00672 addedPoints_.insert(e, addedPointI);
00673
00674 if (debug & 2)
00675 {
00676 Pout<< "Added point " << addedPointI
00677 << " to vertex "
00678 << masterPointI << " of edge " << edgeI
00679 << " vertices " << e << endl;
00680 }
00681 }
00682 }
00683
00684
00685
00686
00687
00688 {
00689 boolList usedPoint(mesh().nPoints(), false);
00690
00691 forAll(cellLoops, cellI)
00692 {
00693 const labelList& loop = cellLoops[cellI];
00694
00695 if (loop.size())
00696 {
00697
00698 forAll(loop, fp)
00699 {
00700 label cut = loop[fp];
00701
00702 if (!isEdge(cut))
00703 {
00704 usedPoint[getVertex(cut)] = true;
00705 }
00706 }
00707
00708 const labelList& anchors = anchorPts[cellI];
00709
00710 forAll(anchors, i)
00711 {
00712 usedPoint[anchors[i]] = true;
00713 }
00714 }
00715 else
00716 {
00717
00718 const labelList& cPoints = mesh().cellPoints()[cellI];
00719
00720 forAll(cPoints, i)
00721 {
00722 usedPoint[cPoints[i]] = true;
00723 }
00724 }
00725 }
00726
00727
00728
00729 const Map<edge>& faceSplitCut = cuts.faceSplitCut();
00730
00731 forAllConstIter(Map<edge>, faceSplitCut, iter)
00732 {
00733 const edge& fCut = iter();
00734
00735 forAll(fCut, i)
00736 {
00737 label cut = fCut[i];
00738
00739 if (!isEdge(cut))
00740 {
00741 label pointI = getVertex(cut);
00742
00743 if (!usedPoint[pointI])
00744 {
00745 FatalErrorIn
00746 (
00747 "meshCutAndRemove::setRefinement("
00748 ", const label, const cellCuts&, const labelList&"
00749 ", polyTopoChange&)"
00750 ) << "Problem: faceSplitCut not used by any loop"
00751 << " or cell anchor point"
00752 << "face:" << iter.key() << " point:" << pointI
00753 << " coord:" << mesh().points()[pointI]
00754 << abort(FatalError);
00755 }
00756 }
00757 }
00758 }
00759
00760 forAll(cuts.pointIsCut(), pointI)
00761 {
00762 if (cuts.pointIsCut()[pointI])
00763 {
00764 if (!usedPoint[pointI])
00765 {
00766 FatalErrorIn
00767 (
00768 "meshCutAndRemove::setRefinement("
00769 ", const label, const cellCuts&, const labelList&"
00770 ", polyTopoChange&)"
00771 ) << "Problem: point is marked as cut but"
00772 << " not used by any loop"
00773 << " or cell anchor point"
00774 << "point:" << pointI
00775 << " coord:" << mesh().points()[pointI]
00776 << abort(FatalError);
00777 }
00778 }
00779 }
00780
00781
00782
00783 forAll(usedPoint, pointI)
00784 {
00785 if (!usedPoint[pointI])
00786 {
00787 meshMod.setAction(polyRemovePoint(pointI));
00788
00789 if (debug & 2)
00790 {
00791 Pout<< "Removing unused point " << pointI << endl;
00792 }
00793 }
00794 }
00795 }
00796
00797
00798
00799
00800
00801
00802 forAll(cellLoops, cellI)
00803 {
00804 const labelList& loop = cellLoops[cellI];
00805
00806 if (loop.size())
00807 {
00808 if (cutPatch[cellI] < 0 || cutPatch[cellI] >= patches.size())
00809 {
00810 FatalErrorIn
00811 (
00812 "meshCutAndRemove::setRefinement("
00813 ", const label, const cellCuts&, const labelList&"
00814 ", polyTopoChange&)"
00815 ) << "Illegal patch " << cutPatch[cellI]
00816 << " provided for cut cell " << cellI
00817 << abort(FatalError);
00818 }
00819
00820
00821
00822
00823
00824 face newFace(loopToFace(cellI, loop));
00825
00826 reverse(newFace);
00827
00828
00829 label masterPointI = findPatchFacePoint(newFace, exposedPatchI);
00830
00831 label addedFaceI =
00832 meshMod.setAction
00833 (
00834 polyAddFace
00835 (
00836 newFace,
00837 cellI,
00838 -1,
00839 masterPointI,
00840 -1,
00841 -1,
00842 false,
00843 cutPatch[cellI],
00844 -1,
00845 false
00846 )
00847 );
00848
00849 addedFaces_.insert(cellI, addedFaceI);
00850
00851 if (debug & 2)
00852 {
00853 Pout<< "Added splitting face " << newFace << " index:"
00854 << addedFaceI << " from masterPoint:" << masterPointI
00855 << " to owner " << cellI << " with anchors:"
00856 << anchorPts[cellI]
00857 << " from Loop:";
00858
00859
00860 scalarField weights(loop.size());
00861 forAll(loop, i)
00862 {
00863 label cut = loop[i];
00864
00865 weights[i] =
00866 (
00867 isEdge(cut)
00868 ? cuts.edgeWeight()[getEdge(cut)]
00869 : -GREAT
00870 );
00871 }
00872 writeCuts(Pout, loop, weights);
00873 Pout<< endl;
00874 }
00875 }
00876 }
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887 boolList faceUptodate(mesh().nFaces(), false);
00888
00889 const Map<edge>& faceSplitCuts = cuts.faceSplitCut();
00890
00891 for
00892 (
00893 Map<edge>::const_iterator iter = faceSplitCuts.begin();
00894 iter != faceSplitCuts.end();
00895 ++iter
00896 )
00897 {
00898 label faceI = iter.key();
00899
00900
00901 face newFace(addEdgeCutsToFace(faceI));
00902
00903
00904 const edge& splitEdge = iter();
00905
00906 label cut0 = splitEdge[0];
00907
00908 label v0;
00909 if (isEdge(cut0))
00910 {
00911 label edgeI = getEdge(cut0);
00912 v0 = addedPoints_[mesh().edges()[edgeI]];
00913 }
00914 else
00915 {
00916 v0 = getVertex(cut0);
00917 }
00918
00919 label cut1 = splitEdge[1];
00920 label v1;
00921 if (isEdge(cut1))
00922 {
00923 label edgeI = getEdge(cut1);
00924 v1 = addedPoints_[mesh().edges()[edgeI]];
00925 }
00926 else
00927 {
00928 v1 = getVertex(cut1);
00929 }
00930
00931
00932 face f0, f1;
00933 splitFace(newFace, v0, v1, f0, f1);
00934
00935 label own = mesh().faceOwner()[faceI];
00936
00937 label nei = -1;
00938
00939 if (mesh().isInternalFace(faceI))
00940 {
00941 nei = mesh().faceNeighbour()[faceI];
00942 }
00943
00944 if (debug & 2)
00945 {
00946 Pout<< "Split face " << mesh().faces()[faceI]
00947 << " own:" << own << " nei:" << nei
00948 << " into f0:" << f0
00949 << " and f1:" << f1 << endl;
00950 }
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963 const face& f = mesh().faces()[faceI];
00964
00965 label f0Own = -1;
00966 label f1Own = -1;
00967
00968 if (cellLoops[own].empty())
00969 {
00970
00971 f0Own = own;
00972 f1Own = own;
00973 }
00974 else if (isIn(splitEdge, cellLoops[own]))
00975 {
00976
00977
00978 if (firstCommon(f0, anchorPts[own]) != -1)
00979 {
00980
00981 f0Own = own;
00982 f1Own = -1;
00983 }
00984 else
00985 {
00986 f0Own = -1;
00987 f1Own = own;
00988 }
00989 }
00990 else
00991 {
00992
00993
00994
00995 if (firstCommon(f, anchorPts[own]) != -1)
00996 {
00997
00998 f0Own = own;
00999 f1Own = own;
01000 }
01001 else
01002 {
01003
01004 f0Own = -1;
01005 f1Own = -1;
01006 }
01007 }
01008
01009
01010 label f0Nei = -1;
01011 label f1Nei = -1;
01012
01013 if (nei != -1)
01014 {
01015 if (cellLoops[nei].empty())
01016 {
01017 f0Nei = nei;
01018 f1Nei = nei;
01019 }
01020 else if (isIn(splitEdge, cellLoops[nei]))
01021 {
01022
01023
01024
01025
01026 if (firstCommon(f0, anchorPts[nei]) != -1)
01027 {
01028 f0Nei = nei;
01029 f1Nei = -1;
01030 }
01031 else
01032 {
01033 f0Nei = -1;
01034 f1Nei = nei;
01035 }
01036 }
01037 else
01038 {
01039
01040
01041
01042 if (firstCommon(f, anchorPts[nei]) != -1)
01043 {
01044 f0Nei = nei;
01045 f1Nei = nei;
01046 }
01047 else
01048 {
01049
01050 f0Nei = -1;
01051 f1Nei = -1;
01052 }
01053 }
01054 }
01055
01056
01057 if (debug & 2)
01058 {
01059 Pout<< "f0 own:" << f0Own << " nei:" << f0Nei
01060 << " f1 own:" << f1Own << " nei:" << f1Nei
01061 << endl;
01062 }
01063
01064
01065
01066
01067 label patchID = patches.whichPatch(faceI);
01068
01069 if (patchID == -1)
01070 {
01071 patchID = exposedPatchI;
01072 }
01073
01074
01075
01076
01077
01078 bool modifiedFaceI = false;
01079
01080 if (f0Own == -1)
01081 {
01082 if (f0Nei != -1)
01083 {
01084
01085 modFace(meshMod, faceI, f0, f0Own, f0Nei, patchID);
01086 modifiedFaceI = true;
01087 }
01088 }
01089 else
01090 {
01091 if (f0Nei == -1)
01092 {
01093
01094 modFace(meshMod, faceI, f0, f0Own, f0Nei, patchID);
01095 modifiedFaceI = true;
01096 }
01097 else
01098 {
01099
01100 modFace(meshMod, faceI, f0, f0Own, f0Nei, -1);
01101 modifiedFaceI = true;
01102 }
01103 }
01104
01105
01106
01107
01108 if (f1Own == -1)
01109 {
01110 if (f1Nei == -1)
01111 {
01112
01113 }
01114 else
01115 {
01116
01117 if (!modifiedFaceI)
01118 {
01119 modFace(meshMod, faceI, f1, f1Own, f1Nei, patchID);
01120 modifiedFaceI = true;
01121 }
01122 else
01123 {
01124 label masterPointI = findPatchFacePoint(f1, patchID);
01125
01126 addFace
01127 (
01128 meshMod,
01129 faceI,
01130 masterPointI,
01131 f1,
01132 f1Own,
01133 f1Nei,
01134 patchID
01135 );
01136 }
01137 }
01138 }
01139 else
01140 {
01141 if (f1Nei == -1)
01142 {
01143
01144 if (!modifiedFaceI)
01145 {
01146 modFace(meshMod, faceI, f1, f1Own, f1Nei, patchID);
01147 modifiedFaceI = true;
01148 }
01149 else
01150 {
01151 label masterPointI = findPatchFacePoint(f1, patchID);
01152
01153 addFace
01154 (
01155 meshMod,
01156 faceI,
01157 masterPointI,
01158 f1,
01159 f1Own,
01160 f1Nei,
01161 patchID
01162 );
01163 }
01164 }
01165 else
01166 {
01167
01168 if (!modifiedFaceI)
01169 {
01170 modFace(meshMod, faceI, f1, f1Own, f1Nei, -1);
01171 modifiedFaceI = true;
01172 }
01173 else
01174 {
01175 label masterPointI = findPatchFacePoint(f1, -1);
01176
01177 addFace(meshMod, faceI, masterPointI, f1, f1Own, f1Nei, -1);
01178 }
01179 }
01180 }
01181
01182 if (f0Own == -1 && f0Nei == -1 && !modifiedFaceI)
01183 {
01184 meshMod.setAction(polyRemoveFace(faceI));
01185
01186 if (debug & 2)
01187 {
01188 Pout<< "Removed face " << faceI << endl;
01189 }
01190 }
01191
01192 faceUptodate[faceI] = true;
01193 }
01194
01195
01196
01197
01198
01199
01200
01201 const boolList& edgeIsCut = cuts.edgeIsCut();
01202
01203 forAll(edgeIsCut, edgeI)
01204 {
01205 if (edgeIsCut[edgeI])
01206 {
01207 const labelList& eFaces = mesh().edgeFaces()[edgeI];
01208
01209 forAll(eFaces, i)
01210 {
01211 label faceI = eFaces[i];
01212
01213 if (!faceUptodate[faceI])
01214 {
01215
01216
01217
01218
01219
01220 label own, nei, patchID;
01221 faceCells(cuts, exposedPatchI, faceI, own, nei, patchID);
01222
01223
01224 if (own == -1 && nei == -1)
01225 {
01226 meshMod.setAction(polyRemoveFace(faceI));
01227
01228 if (debug & 2)
01229 {
01230 Pout<< "Removed face " << faceI << endl;
01231 }
01232 }
01233 else
01234 {
01235
01236 face newFace(addEdgeCutsToFace(faceI));
01237
01238 if (debug & 2)
01239 {
01240 Pout<< "Added edge cuts to face " << faceI
01241 << " f:" << mesh().faces()[faceI]
01242 << " newFace:" << newFace << endl;
01243 }
01244
01245 modFace
01246 (
01247 meshMod,
01248 faceI,
01249 newFace,
01250 own,
01251 nei,
01252 patchID
01253 );
01254 }
01255
01256 faceUptodate[faceI] = true;
01257 }
01258 }
01259 }
01260 }
01261
01262
01263
01264
01265
01266
01267
01268
01269 const faceList& faces = mesh().faces();
01270
01271 forAll(faces, faceI)
01272 {
01273 if (!faceUptodate[faceI])
01274 {
01275
01276 label own, nei, patchID;
01277 faceCells(cuts, exposedPatchI, faceI, own, nei, patchID);
01278
01279 if (own == -1 && nei == -1)
01280 {
01281 meshMod.setAction(polyRemoveFace(faceI));
01282
01283 if (debug & 2)
01284 {
01285 Pout<< "Removed face " << faceI << endl;
01286 }
01287 }
01288 else
01289 {
01290 modFace(meshMod, faceI, faces[faceI], own, nei, patchID);
01291 }
01292
01293 faceUptodate[faceI] = true;
01294 }
01295 }
01296
01297 if (debug)
01298 {
01299 Pout<< "meshCutAndRemove:" << nl
01300 << " cells split:" << cuts.nLoops() << nl
01301 << " faces added:" << addedFaces_.size() << nl
01302 << " points added on edges:" << addedPoints_.size() << nl
01303 << endl;
01304 }
01305 }
01306
01307
01308 void Foam::meshCutAndRemove::updateMesh(const mapPolyMesh& map)
01309 {
01310
01311 {
01312 Map<label> newAddedFaces(addedFaces_.size());
01313
01314 for
01315 (
01316 Map<label>::const_iterator iter = addedFaces_.begin();
01317 iter != addedFaces_.end();
01318 ++iter
01319 )
01320 {
01321 label cellI = iter.key();
01322
01323 label newCellI = map.reverseCellMap()[cellI];
01324
01325 label addedFaceI = iter();
01326
01327 label newAddedFaceI = map.reverseFaceMap()[addedFaceI];
01328
01329 if ((newCellI >= 0) && (newAddedFaceI >= 0))
01330 {
01331 if
01332 (
01333 (debug & 2)
01334 && (newCellI != cellI || newAddedFaceI != addedFaceI)
01335 )
01336 {
01337 Pout<< "meshCutAndRemove::updateMesh :"
01338 << " updating addedFace for cell " << cellI
01339 << " from " << addedFaceI
01340 << " to " << newAddedFaceI
01341 << endl;
01342 }
01343 newAddedFaces.insert(newCellI, newAddedFaceI);
01344 }
01345 }
01346
01347
01348 addedFaces_.transfer(newAddedFaces);
01349 }
01350
01351 {
01352 HashTable<label, edge, Hash<edge> > newAddedPoints(addedPoints_.size());
01353
01354 for
01355 (
01356 HashTable<label, edge, Hash<edge> >::const_iterator iter =
01357 addedPoints_.begin();
01358 iter != addedPoints_.end();
01359 ++iter
01360 )
01361 {
01362 const edge& e = iter.key();
01363
01364 label newStart = map.reversePointMap()[e.start()];
01365
01366 label newEnd = map.reversePointMap()[e.end()];
01367
01368 label addedPointI = iter();
01369
01370 label newAddedPointI = map.reversePointMap()[addedPointI];
01371
01372 if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointI >= 0))
01373 {
01374 edge newE = edge(newStart, newEnd);
01375
01376 if
01377 (
01378 (debug & 2)
01379 && (e != newE || newAddedPointI != addedPointI)
01380 )
01381 {
01382 Pout<< "meshCutAndRemove::updateMesh :"
01383 << " updating addedPoints for edge " << e
01384 << " from " << addedPointI
01385 << " to " << newAddedPointI
01386 << endl;
01387 }
01388
01389 newAddedPoints.insert(newE, newAddedPointI);
01390 }
01391 }
01392
01393
01394 addedPoints_.transfer(newAddedPoints);
01395 }
01396 }
01397
01398
01399