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
00028
00029
00030 #include "meshDualiser.H"
00031 #include "meshTools.H"
00032 #include "polyMesh.H"
00033 #include "polyTopoChange.H"
00034 #include "mapPolyMesh.H"
00035 #include "edgeFaceCirculator.H"
00036 #include "mergePoints.H"
00037 #include "OFstream.H"
00038
00039
00040
00041 defineTypeNameAndDebug(Foam::meshDualiser, 0);
00042
00043
00044
00045
00046 void Foam::meshDualiser::checkPolyTopoChange(const polyTopoChange& meshMod)
00047 {
00048
00049 pointField points(meshMod.points().size());
00050 forAll(meshMod.points(), i)
00051 {
00052 points[i] = meshMod.points()[i];
00053 }
00054
00055 labelList oldToNew;
00056 pointField newPoints;
00057 bool hasMerged = mergePoints
00058 (
00059 points,
00060 1E-6,
00061 false,
00062 oldToNew,
00063 newPoints
00064 );
00065
00066 if (hasMerged)
00067 {
00068 labelListList newToOld(invertOneToMany(newPoints.size(), oldToNew));
00069
00070 forAll(newToOld, newI)
00071 {
00072 if (newToOld[newI].size() != 1)
00073 {
00074 FatalErrorIn
00075 (
00076 "meshDualiser::checkPolyTopoChange(const polyTopoChange&)"
00077 ) << "duplicate verts:" << newToOld[newI]
00078 << " coords:"
00079 << UIndirectList<point>(points, newToOld[newI])()
00080 << abort(FatalError);
00081 }
00082 }
00083 }
00084 }
00085
00086
00087
00088 void Foam::meshDualiser::dumpPolyTopoChange
00089 (
00090 const polyTopoChange& meshMod,
00091 const fileName& prefix
00092 )
00093 {
00094 OFstream str1(prefix + "Faces.obj");
00095 OFstream str2(prefix + "Edges.obj");
00096
00097 Info<< "Dumping current polyTopoChange. Faces to " << str1.name()
00098 << " , points and edges to " << str2.name() << endl;
00099
00100 const DynamicList<point>& points = meshMod.points();
00101
00102 forAll(points, pointI)
00103 {
00104 meshTools::writeOBJ(str1, points[pointI]);
00105 meshTools::writeOBJ(str2, points[pointI]);
00106 }
00107
00108 const DynamicList<face>& faces = meshMod.faces();
00109
00110 forAll(faces, faceI)
00111 {
00112 const face& f = faces[faceI];
00113
00114 str1<< 'f';
00115 forAll(f, fp)
00116 {
00117 str1<< ' ' << f[fp]+1;
00118 }
00119 str1<< nl;
00120
00121 str2<< 'l';
00122 forAll(f, fp)
00123 {
00124 str2<< ' ' << f[fp]+1;
00125 }
00126 str2<< ' ' << f[0]+1 << nl;
00127 }
00128 }
00129
00130
00131
00132
00133 Foam::label Foam::meshDualiser::findDualCell
00134 (
00135 const label cellI,
00136 const label pointI
00137 ) const
00138 {
00139 const labelList& dualCells = pointToDualCells_[pointI];
00140
00141 if (dualCells.size() == 1)
00142 {
00143 return dualCells[0];
00144 }
00145 else
00146 {
00147 label index = findIndex(mesh_.pointCells()[pointI], cellI);
00148
00149 return dualCells[index];
00150 }
00151 }
00152
00153
00154
00155
00156 void Foam::meshDualiser::generateDualBoundaryEdges
00157 (
00158 const PackedBoolList& isBoundaryEdge,
00159 const label pointI,
00160 polyTopoChange& meshMod
00161 )
00162 {
00163 const labelList& pEdges = mesh_.pointEdges()[pointI];
00164
00165 forAll(pEdges, pEdgeI)
00166 {
00167 label edgeI = pEdges[pEdgeI];
00168
00169 if (edgeToDualPoint_[edgeI] == -1 && isBoundaryEdge.get(edgeI) == 1)
00170 {
00171 const edge& e = mesh_.edges()[edgeI];
00172
00173 edgeToDualPoint_[edgeI] = meshMod.addPoint
00174 (
00175 e.centre(mesh_.points()),
00176 pointI,
00177 -1,
00178 true
00179 );
00180 }
00181 }
00182 }
00183
00184
00185
00186
00187 bool Foam::meshDualiser::sameDualCell
00188 (
00189 const label faceI,
00190 const label pointI
00191 ) const
00192 {
00193 if (!mesh_.isInternalFace(faceI))
00194 {
00195 FatalErrorIn("sameDualCell(const label, const label)")
00196 << "face:" << faceI << " is not internal face."
00197 << abort(FatalError);
00198 }
00199
00200 label own = mesh_.faceOwner()[faceI];
00201 label nei = mesh_.faceNeighbour()[faceI];
00202
00203 return findDualCell(own, pointI) == findDualCell(nei, pointI);
00204 }
00205
00206
00207 Foam::label Foam::meshDualiser::addInternalFace
00208 (
00209 const label masterPointI,
00210 const label masterEdgeI,
00211 const label masterFaceI,
00212
00213 const bool edgeOrder,
00214 const label dualCell0,
00215 const label dualCell1,
00216 const DynamicList<label>& verts,
00217 polyTopoChange& meshMod
00218 ) const
00219 {
00220 face newFace(verts);
00221
00222 if (edgeOrder != (dualCell0 < dualCell1))
00223 {
00224 reverse(newFace);
00225 }
00226
00227 if (debug)
00228 {
00229 pointField facePoints(meshMod.points(), newFace);
00230
00231 labelList oldToNew;
00232 pointField newPoints;
00233 bool hasMerged = mergePoints
00234 (
00235 facePoints,
00236 1E-6,
00237 false,
00238 oldToNew,
00239 newPoints
00240 );
00241
00242 if (hasMerged)
00243 {
00244 FatalErrorIn("addInternalFace(..)")
00245 << "verts:" << verts << " newFace:" << newFace
00246 << " face points:" << facePoints
00247 << abort(FatalError);
00248 }
00249 }
00250
00251
00252 label zoneID = -1;
00253 bool zoneFlip = false;
00254 if (masterFaceI != -1)
00255 {
00256 zoneID = mesh_.faceZones().whichZone(masterFaceI);
00257
00258 if (zoneID != -1)
00259 {
00260 const faceZone& fZone = mesh_.faceZones()[zoneID];
00261
00262 zoneFlip = fZone.flipMap()[fZone.whichFace(masterFaceI)];
00263 }
00264 }
00265
00266 label dualFaceI;
00267
00268 if (dualCell0 < dualCell1)
00269 {
00270 dualFaceI = meshMod.addFace
00271 (
00272 newFace,
00273 dualCell0,
00274 dualCell1,
00275 masterPointI,
00276 masterEdgeI,
00277 masterFaceI,
00278 false,
00279 -1,
00280 zoneID,
00281 zoneFlip
00282 );
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 }
00295 else
00296 {
00297 dualFaceI = meshMod.addFace
00298 (
00299 newFace,
00300 dualCell1,
00301 dualCell0,
00302 masterPointI,
00303 masterEdgeI,
00304 masterFaceI,
00305 false,
00306 -1,
00307 zoneID,
00308 zoneFlip
00309 );
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 }
00322 return dualFaceI;
00323 }
00324
00325
00326 Foam::label Foam::meshDualiser::addBoundaryFace
00327 (
00328 const label masterPointI,
00329 const label masterEdgeI,
00330 const label masterFaceI,
00331
00332 const label dualCellI,
00333 const label patchI,
00334 const DynamicList<label>& verts,
00335 polyTopoChange& meshMod
00336 ) const
00337 {
00338 face newFace(verts);
00339
00340 label zoneID = -1;
00341 bool zoneFlip = false;
00342 if (masterFaceI != -1)
00343 {
00344 zoneID = mesh_.faceZones().whichZone(masterFaceI);
00345
00346 if (zoneID != -1)
00347 {
00348 const faceZone& fZone = mesh_.faceZones()[zoneID];
00349
00350 zoneFlip = fZone.flipMap()[fZone.whichFace(masterFaceI)];
00351 }
00352 }
00353
00354 label dualFaceI = meshMod.addFace
00355 (
00356 newFace,
00357 dualCellI,
00358 -1,
00359 masterPointI,
00360 masterEdgeI,
00361 masterFaceI,
00362 false,
00363 patchI,
00364 zoneID,
00365 zoneFlip
00366 );
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 return dualFaceI;
00378 }
00379
00380
00381
00382
00383
00384
00385 void Foam::meshDualiser::createFacesAroundEdge
00386 (
00387 const bool splitFace,
00388 const PackedBoolList& isBoundaryEdge,
00389 const label edgeI,
00390 const label startFaceI,
00391 polyTopoChange& meshMod,
00392 boolList& doneEFaces
00393 ) const
00394 {
00395 const edge& e = mesh_.edges()[edgeI];
00396 const labelList& eFaces = mesh_.edgeFaces()[edgeI];
00397
00398 label fp = edgeFaceCirculator::getMinIndex
00399 (
00400 mesh_.faces()[startFaceI],
00401 e[0],
00402 e[1]
00403 );
00404
00405 edgeFaceCirculator ie
00406 (
00407 mesh_,
00408 startFaceI,
00409 true,
00410 fp,
00411 isBoundaryEdge.get(edgeI) == 1
00412 );
00413 ie.setCanonical();
00414
00415 bool edgeOrder = ie.sameOrder(e[0], e[1]);
00416 label startFaceLabel = ie.faceLabel();
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 DynamicList<label> verts(100);
00428
00429 if (edgeToDualPoint_[edgeI] != -1)
00430 {
00431 verts.append(edgeToDualPoint_[edgeI]);
00432 }
00433 if (faceToDualPoint_[ie.faceLabel()] != -1)
00434 {
00435 doneEFaces[findIndex(eFaces, ie.faceLabel())] = true;
00436 verts.append(faceToDualPoint_[ie.faceLabel()]);
00437 }
00438 if (cellToDualPoint_[ie.cellLabel()] != -1)
00439 {
00440 verts.append(cellToDualPoint_[ie.cellLabel()]);
00441 }
00442
00443 label currentDualCell0 = findDualCell(ie.cellLabel(), e[0]);
00444 label currentDualCell1 = findDualCell(ie.cellLabel(), e[1]);
00445
00446 ++ie;
00447
00448 while (true)
00449 {
00450 label faceI = ie.faceLabel();
00451
00452
00453 doneEFaces[findIndex(eFaces, faceI)] = true;
00454
00455 if (faceToDualPoint_[faceI] != -1)
00456 {
00457 verts.append(faceToDualPoint_[faceI]);
00458 }
00459
00460 label cellI = ie.cellLabel();
00461
00462 if (cellI == -1)
00463 {
00464
00465
00466 break;
00467 }
00468
00469
00470 label dualCell0 = findDualCell(cellI, e[0]);
00471 label dualCell1 = findDualCell(cellI, e[1]);
00472
00473
00474
00475 if
00476 (
00477 splitFace
00478 || (
00479 dualCell0 != currentDualCell0
00480 || dualCell1 != currentDualCell1
00481 )
00482 )
00483 {
00484
00485 addInternalFace
00486 (
00487 -1,
00488 edgeI,
00489 -1,
00490 edgeOrder,
00491 currentDualCell0,
00492 currentDualCell1,
00493 verts.shrink(),
00494 meshMod
00495 );
00496
00497
00498 currentDualCell0 = dualCell0;
00499 currentDualCell1 = dualCell1;
00500
00501 verts.clear();
00502 if (edgeToDualPoint_[edgeI] != -1)
00503 {
00504 verts.append(edgeToDualPoint_[edgeI]);
00505 }
00506 if (faceToDualPoint_[faceI] != -1)
00507 {
00508 verts.append(faceToDualPoint_[faceI]);
00509 }
00510 }
00511
00512 if (cellToDualPoint_[cellI] != -1)
00513 {
00514 verts.append(cellToDualPoint_[cellI]);
00515 }
00516
00517 ++ie;
00518
00519 if (ie == ie.end())
00520 {
00521
00522
00523 if (isBoundaryEdge.get(edgeI) == 0)
00524 {
00525 label startDual = faceToDualPoint_[startFaceLabel];
00526
00527 if (startDual != -1 && findIndex(verts, startDual) == -1)
00528 {
00529 verts.append(startDual);
00530 }
00531 }
00532 break;
00533 }
00534 }
00535
00536 verts.shrink();
00537 addInternalFace
00538 (
00539 -1,
00540 edgeI,
00541 -1,
00542 edgeOrder,
00543 currentDualCell0,
00544 currentDualCell1,
00545 verts,
00546 meshMod
00547 );
00548 }
00549
00550
00551
00552
00553
00554 void Foam::meshDualiser::createFaceFromInternalFace
00555 (
00556 const label faceI,
00557 label& fp,
00558 polyTopoChange& meshMod
00559 ) const
00560 {
00561 const face& f = mesh_.faces()[faceI];
00562 const labelList& fEdges = mesh_.faceEdges()[faceI];
00563 label own = mesh_.faceOwner()[faceI];
00564 label nei = mesh_.faceNeighbour()[faceI];
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575 DynamicList<label> verts(100);
00576
00577 verts.append(faceToDualPoint_[faceI]);
00578 verts.append(edgeToDualPoint_[fEdges[fp]]);
00579
00580
00581 fp = f.fcIndex(fp);
00582
00583
00584 label currentDualCell0 = findDualCell(own, f[fp]);
00585 label currentDualCell1 = findDualCell(nei, f[fp]);
00586
00587 forAll(f, i)
00588 {
00589
00590 if (pointToDualPoint_[f[fp]] != -1)
00591 {
00592 verts.append(pointToDualPoint_[f[fp]]);
00593 }
00594
00595
00596 label edgeI = fEdges[fp];
00597
00598 if (edgeToDualPoint_[edgeI] != -1)
00599 {
00600 verts.append(edgeToDualPoint_[edgeI]);
00601 }
00602
00603
00604 label nextFp = f.fcIndex(fp);
00605
00606
00607 label dualCell0 = findDualCell(own, f[nextFp]);
00608 label dualCell1 = findDualCell(nei, f[nextFp]);
00609
00610 if (dualCell0 != currentDualCell0 || dualCell1 != currentDualCell1)
00611 {
00612
00613 if (edgeToDualPoint_[edgeI] == -1)
00614 {
00615 FatalErrorIn("createFacesFromInternalFace(..)")
00616 << "face:" << faceI << " verts:" << f
00617 << " points:" << UIndirectList<point>(mesh_.points(), f)()
00618 << " no feature edge between " << f[fp]
00619 << " and " << f[nextFp] << " although have different"
00620 << " dual cells." << endl
00621 << "point " << f[fp] << " has dual cells "
00622 << currentDualCell0 << " and " << currentDualCell1
00623 << " ; point "<< f[nextFp] << " has dual cells "
00624 << dualCell0 << " and " << dualCell1
00625 << abort(FatalError);
00626 }
00627
00628
00629
00630 verts.shrink();
00631 addInternalFace
00632 (
00633 -1,
00634 -1,
00635 faceI,
00636 true,
00637 currentDualCell0,
00638 currentDualCell1,
00639 verts,
00640 meshMod
00641 );
00642 break;
00643 }
00644
00645 fp = nextFp;
00646 }
00647 }
00648
00649
00650
00651
00652 void Foam::meshDualiser::createFacesAroundBoundaryPoint
00653 (
00654 const label patchI,
00655 const label patchPointI,
00656 const label startFaceI,
00657 polyTopoChange& meshMod,
00658 boolList& donePFaces
00659 ) const
00660 {
00661 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00662 const polyPatch& pp = patches[patchI];
00663 const labelList& pFaces = pp.pointFaces()[patchPointI];
00664 const labelList& own = mesh_.faceOwner();
00665
00666 label pointI = pp.meshPoints()[patchPointI];
00667
00668 if (pointToDualPoint_[pointI] == -1)
00669 {
00670
00671
00672
00673
00674 label faceI = startFaceI;
00675
00676 DynamicList<label> verts(4);
00677
00678 while (true)
00679 {
00680 label index = findIndex(pFaces, faceI-pp.start());
00681
00682
00683 if (donePFaces[index])
00684 {
00685 break;
00686 }
00687 donePFaces[index] = true;
00688
00689
00690 verts.append(faceToDualPoint_[faceI]);
00691
00692 label dualCellI = findDualCell(own[faceI], pointI);
00693
00694
00695 const face& f = mesh_.faces()[faceI];
00696 label fp = findIndex(f, pointI);
00697 label prevFp = f.rcIndex(fp);
00698 label edgeI = mesh_.faceEdges()[faceI][prevFp];
00699
00700 if (edgeToDualPoint_[edgeI] != -1)
00701 {
00702 verts.append(edgeToDualPoint_[edgeI]);
00703 }
00704
00705
00706 edgeFaceCirculator circ
00707 (
00708 mesh_,
00709 faceI,
00710 true,
00711 prevFp,
00712 true
00713 );
00714
00715 do
00716 {
00717 ++circ;
00718 }
00719 while (mesh_.isInternalFace(circ.faceLabel()));
00720
00721
00722 faceI = circ.faceLabel();
00723
00724 if (faceI < pp.start() || faceI >= pp.start()+pp.size())
00725 {
00726 FatalErrorIn
00727 (
00728 "meshDualiser::createFacesAroundBoundaryPoint(..)"
00729 ) << "Walked from face on patch:" << patchI
00730 << " to face:" << faceI
00731 << " fc:" << mesh_.faceCentres()[faceI]
00732 << " on patch:" << patches.whichPatch(faceI)
00733 << abort(FatalError);
00734 }
00735
00736
00737 if (dualCellI != findDualCell(own[faceI], pointI))
00738 {
00739 FatalErrorIn
00740 (
00741 "meshDualiser::createFacesAroundBoundaryPoint(..)"
00742 ) << "Different dual cells but no feature edge"
00743 << " inbetween point:" << pointI
00744 << " coord:" << mesh_.points()[pointI]
00745 << abort(FatalError);
00746 }
00747 }
00748
00749 verts.shrink();
00750
00751 label dualCellI = findDualCell(own[faceI], pointI);
00752
00753
00754
00755
00756
00757 addBoundaryFace
00758 (
00759
00760 -1,
00761 -1,
00762 faceI,
00763 dualCellI,
00764 patchI,
00765 verts,
00766 meshMod
00767 );
00768 }
00769 else
00770 {
00771 label faceI = startFaceI;
00772
00773
00774 DynamicList<label> verts(mesh_.faces()[faceI].size());
00775
00776
00777 verts.append(pointToDualPoint_[pointI]);
00778
00779
00780 const labelList& fEdges = mesh_.faceEdges()[faceI];
00781 label nextEdgeI = fEdges[findIndex(mesh_.faces()[faceI], pointI)];
00782 if (edgeToDualPoint_[nextEdgeI] != -1)
00783 {
00784 verts.append(edgeToDualPoint_[nextEdgeI]);
00785 }
00786
00787 do
00788 {
00789 label index = findIndex(pFaces, faceI-pp.start());
00790
00791
00792 if (donePFaces[index])
00793 {
00794 break;
00795 }
00796 donePFaces[index] = true;
00797
00798
00799 verts.append(faceToDualPoint_[faceI]);
00800
00801
00802 const labelList& fEdges = mesh_.faceEdges()[faceI];
00803 const face& f = mesh_.faces()[faceI];
00804 label prevFp = f.rcIndex(findIndex(f, pointI));
00805 label edgeI = fEdges[prevFp];
00806
00807 if (edgeToDualPoint_[edgeI] != -1)
00808 {
00809
00810
00811 verts.append(edgeToDualPoint_[edgeI]);
00812 addBoundaryFace
00813 (
00814 -1,
00815 -1,
00816 faceI,
00817 findDualCell(own[faceI], pointI),
00818 patchI,
00819 verts.shrink(),
00820 meshMod
00821 );
00822 verts.clear();
00823
00824 verts.append(pointToDualPoint_[pointI]);
00825 verts.append(edgeToDualPoint_[edgeI]);
00826 }
00827
00828
00829 edgeFaceCirculator circ
00830 (
00831 mesh_,
00832 faceI,
00833 true,
00834 prevFp,
00835 true
00836 );
00837
00838 do
00839 {
00840 ++circ;
00841 }
00842 while (mesh_.isInternalFace(circ.faceLabel()));
00843
00844
00845 faceI = circ.faceLabel();
00846 }
00847 while
00848 (
00849 faceI != startFaceI
00850 && faceI >= pp.start()
00851 && faceI < pp.start()+pp.size()
00852 );
00853
00854 if (verts.size() > 2)
00855 {
00856
00857 addBoundaryFace
00858 (
00859 -1,
00860 -1,
00861 startFaceI,
00862 findDualCell(own[faceI], pointI),
00863 patchI,
00864 verts.shrink(),
00865 meshMod
00866 );
00867 }
00868 }
00869 }
00870
00871
00872
00873
00874 Foam::meshDualiser::meshDualiser(const polyMesh& mesh)
00875 :
00876 mesh_(mesh),
00877 pointToDualCells_(mesh_.nPoints()),
00878 pointToDualPoint_(mesh_.nPoints(), -1),
00879 cellToDualPoint_(mesh_.nCells()),
00880 faceToDualPoint_(mesh_.nFaces(), -1),
00881 edgeToDualPoint_(mesh_.nEdges(), -1)
00882 {}
00883
00884
00885
00886
00887
00888
00889
00890 void Foam::meshDualiser::setRefinement
00891 (
00892 const bool splitFace,
00893 const labelList& featureFaces,
00894 const labelList& featureEdges,
00895 const labelList& singleCellFeaturePoints,
00896 const labelList& multiCellFeaturePoints,
00897 polyTopoChange& meshMod
00898 )
00899 {
00900 const labelList& own = mesh_.faceOwner();
00901 const labelList& nei = mesh_.faceNeighbour();
00902 const vectorField& cellCentres = mesh_.cellCentres();
00903
00904
00905
00906
00907 PackedBoolList isBoundaryEdge(mesh_.nEdges());
00908 for (label faceI = mesh_.nInternalFaces(); faceI < mesh_.nFaces(); faceI++)
00909 {
00910 const labelList& fEdges = mesh_.faceEdges()[faceI];
00911
00912 forAll(fEdges, i)
00913 {
00914 isBoundaryEdge.set(fEdges[i], 1);
00915 }
00916 }
00917
00918
00919 if (splitFace)
00920 {
00921
00922
00923
00924
00925
00926
00927
00928 boolList featureFaceSet(mesh_.nFaces(), false);
00929 forAll(featureFaces, i)
00930 {
00931 featureFaceSet[featureFaces[i]] = true;
00932 }
00933 label faceI = findIndex(featureFaceSet, false);
00934
00935 if (faceI != -1)
00936 {
00937 FatalErrorIn
00938 (
00939 "meshDualiser::setRefinement"
00940 "(const labelList&, const labelList&, const labelList&"
00941 ", const labelList, polyTopoChange&)"
00942 ) << "In split-face-mode (splitFace=true) but not all faces"
00943 << " marked as feature faces." << endl
00944 << "First conflicting face:" << faceI
00945 << " centre:" << mesh_.faceCentres()[faceI]
00946 << abort(FatalError);
00947 }
00948
00949 boolList featureEdgeSet(mesh_.nEdges(), false);
00950 forAll(featureEdges, i)
00951 {
00952 featureEdgeSet[featureEdges[i]] = true;
00953 }
00954 label edgeI = findIndex(featureEdgeSet, false);
00955
00956 if (edgeI != -1)
00957 {
00958 const edge& e = mesh_.edges()[edgeI];
00959 FatalErrorIn
00960 (
00961 "meshDualiser::setRefinement"
00962 "(const labelList&, const labelList&, const labelList&"
00963 ", const labelList, polyTopoChange&)"
00964 ) << "In split-face-mode (splitFace=true) but not all edges"
00965 << " marked as feature edges." << endl
00966 << "First conflicting edge:" << edgeI
00967 << " verts:" << e
00968 << " coords:" << mesh_.points()[e[0]] << mesh_.points()[e[1]]
00969 << abort(FatalError);
00970 }
00971 }
00972 else
00973 {
00974
00975
00976 boolList featureFaceSet(mesh_.nFaces(), false);
00977 forAll(featureFaces, i)
00978 {
00979 featureFaceSet[featureFaces[i]] = true;
00980 }
00981 for
00982 (
00983 label faceI = mesh_.nInternalFaces();
00984 faceI < mesh_.nFaces();
00985 faceI++
00986 )
00987 {
00988 if (!featureFaceSet[faceI])
00989 {
00990 FatalErrorIn
00991 (
00992 "meshDualiser::setRefinement"
00993 "(const labelList&, const labelList&, const labelList&"
00994 ", const labelList, polyTopoChange&)"
00995 ) << "Not all boundary faces marked as feature faces."
00996 << endl
00997 << "First conflicting face:" << faceI
00998 << " centre:" << mesh_.faceCentres()[faceI]
00999 << abort(FatalError);
01000 }
01001 }
01002 }
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028 autoPtr<OFstream> dualCcStr;
01029 if (debug)
01030 {
01031 dualCcStr.reset(new OFstream("dualCc.obj"));
01032 Pout<< "Dumping centres of dual cells to " << dualCcStr().name()
01033 << endl;
01034 }
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047 forAll(singleCellFeaturePoints, i)
01048 {
01049 label pointI = singleCellFeaturePoints[i];
01050
01051 pointToDualPoint_[pointI] = meshMod.addPoint
01052 (
01053 mesh_.points()[pointI],
01054 pointI,
01055 mesh_.pointZones().whichZone(pointI),
01056 true
01057 );
01058
01059
01060 pointToDualCells_[pointI].setSize(1);
01061 pointToDualCells_[pointI][0] = meshMod.addCell
01062 (
01063 pointI,
01064 -1,
01065 -1,
01066 -1,
01067 -1
01068 );
01069 if (dualCcStr.valid())
01070 {
01071 meshTools::writeOBJ(dualCcStr(), mesh_.points()[pointI]);
01072 }
01073 }
01074
01075
01076 forAll(multiCellFeaturePoints, i)
01077 {
01078 label pointI = multiCellFeaturePoints[i];
01079
01080 if (pointToDualCells_[pointI].size() > 0)
01081 {
01082 FatalErrorIn
01083 (
01084 "meshDualiser::setRefinement"
01085 "(const labelList&, const labelList&, const labelList&"
01086 ", const labelList, polyTopoChange&)"
01087 ) << "Point " << pointI << " at:" << mesh_.points()[pointI]
01088 << " is both in singleCellFeaturePoints"
01089 << " and multiCellFeaturePoints."
01090 << abort(FatalError);
01091 }
01092
01093 pointToDualPoint_[pointI] = meshMod.addPoint
01094 (
01095 mesh_.points()[pointI],
01096 pointI,
01097 mesh_.pointZones().whichZone(pointI),
01098 true
01099 );
01100
01101
01102
01103 const labelList& pCells = mesh_.pointCells()[pointI];
01104
01105 pointToDualCells_[pointI].setSize(pCells.size());
01106
01107 forAll(pCells, pCellI)
01108 {
01109 pointToDualCells_[pointI][pCellI] = meshMod.addCell
01110 (
01111 pointI,
01112 -1,
01113 -1,
01114 -1,
01115 mesh_.cellZones().whichZone(pCells[pCellI])
01116 );
01117 if (dualCcStr.valid())
01118 {
01119 meshTools::writeOBJ
01120 (
01121 dualCcStr(),
01122 0.5*(mesh_.points()[pointI]+cellCentres[pCells[pCellI]])
01123 );
01124 }
01125 }
01126 }
01127
01128 forAll(mesh_.points(), pointI)
01129 {
01130 if (pointToDualCells_[pointI].empty())
01131 {
01132 pointToDualCells_[pointI].setSize(1);
01133 pointToDualCells_[pointI][0] = meshMod.addCell
01134 (
01135 pointI,
01136 -1,
01137 -1,
01138 -1,
01139 -1
01140 );
01141
01142 if (dualCcStr.valid())
01143 {
01144 meshTools::writeOBJ(dualCcStr(), mesh_.points()[pointI]);
01145 }
01146 }
01147 }
01148
01149
01150
01151
01152
01153 forAll(cellToDualPoint_, cellI)
01154 {
01155 cellToDualPoint_[cellI] = meshMod.addPoint
01156 (
01157 cellCentres[cellI],
01158 mesh_.faces()[mesh_.cells()[cellI][0]][0],
01159 -1,
01160 true
01161 );
01162 }
01163
01164
01165
01166 forAll(featureFaces, i)
01167 {
01168 label faceI = featureFaces[i];
01169
01170 faceToDualPoint_[faceI] = meshMod.addPoint
01171 (
01172 mesh_.faceCentres()[faceI],
01173 mesh_.faces()[faceI][0],
01174 -1,
01175 true
01176 );
01177 }
01178
01179
01180
01181 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
01182 {
01183 if (faceToDualPoint_[faceI] == -1)
01184 {
01185 const face& f = mesh_.faces()[faceI];
01186
01187 forAll(f, fp)
01188 {
01189 label ownDualCell = findDualCell(own[faceI], f[fp]);
01190 label neiDualCell = findDualCell(nei[faceI], f[fp]);
01191
01192 if (ownDualCell != neiDualCell)
01193 {
01194 faceToDualPoint_[faceI] = meshMod.addPoint
01195 (
01196 mesh_.faceCentres()[faceI],
01197 f[fp],
01198 -1,
01199 true
01200 );
01201
01202 break;
01203 }
01204 }
01205 }
01206 }
01207
01208
01209
01210 forAll(featureEdges, i)
01211 {
01212 label edgeI = featureEdges[i];
01213
01214 const edge& e = mesh_.edges()[edgeI];
01215
01216 edgeToDualPoint_[edgeI] = meshMod.addPoint
01217 (
01218 e.centre(mesh_.points()),
01219 e[0],
01220 -1,
01221 true
01222 );
01223 }
01224
01225
01226
01227
01228
01229 const labelListList& edgeCells = mesh_.edgeCells();
01230
01231 forAll(edgeCells, edgeI)
01232 {
01233 if (edgeToDualPoint_[edgeI] == -1)
01234 {
01235 const edge& e = mesh_.edges()[edgeI];
01236
01237
01238
01239
01240 const labelList& eCells = mesh_.edgeCells()[edgeI];
01241
01242 label dualE0 = findDualCell(eCells[0], e[0]);
01243 label dualE1 = findDualCell(eCells[0], e[1]);
01244
01245 for (label i = 1; i < eCells.size(); i++)
01246 {
01247 label newDualE0 = findDualCell(eCells[i], e[0]);
01248
01249 if (dualE0 != newDualE0)
01250 {
01251 edgeToDualPoint_[edgeI] = meshMod.addPoint
01252 (
01253 e.centre(mesh_.points()),
01254 e[0],
01255 mesh_.pointZones().whichZone(e[0]),
01256 true
01257 );
01258
01259 break;
01260 }
01261
01262 label newDualE1 = findDualCell(eCells[i], e[1]);
01263
01264 if (dualE1 != newDualE1)
01265 {
01266 edgeToDualPoint_[edgeI] = meshMod.addPoint
01267 (
01268 e.centre(mesh_.points()),
01269 e[1],
01270 mesh_.pointZones().whichZone(e[1]),
01271 true
01272 );
01273
01274 break;
01275 }
01276 }
01277 }
01278 }
01279
01280
01281
01282 forAll(singleCellFeaturePoints, i)
01283 {
01284 generateDualBoundaryEdges
01285 (
01286 isBoundaryEdge,
01287 singleCellFeaturePoints[i],
01288 meshMod
01289 );
01290 }
01291 forAll(multiCellFeaturePoints, i)
01292 {
01293 generateDualBoundaryEdges
01294 (
01295 isBoundaryEdge,
01296 multiCellFeaturePoints[i],
01297 meshMod
01298 );
01299 }
01300
01301
01302
01303 if (debug)
01304 {
01305 dumpPolyTopoChange(meshMod, "generatedPoints_");
01306 checkPolyTopoChange(meshMod);
01307 }
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320 const edgeList& edges = mesh_.edges();
01321
01322 forAll(edges, edgeI)
01323 {
01324 const labelList& eFaces = mesh_.edgeFaces()[edgeI];
01325
01326 boolList doneEFaces(eFaces.size(), false);
01327
01328 forAll(eFaces, i)
01329 {
01330 if (!doneEFaces[i])
01331 {
01332
01333
01334
01335
01336 label startFaceI = eFaces[i];
01337
01338
01339
01340
01341
01342
01343
01344
01345 createFacesAroundEdge
01346 (
01347 splitFace,
01348 isBoundaryEdge,
01349 edgeI,
01350 startFaceI,
01351 meshMod,
01352 doneEFaces
01353 );
01354 }
01355 }
01356 }
01357
01358 if (debug)
01359 {
01360 dumpPolyTopoChange(meshMod, "generatedFacesFromEdges_");
01361 }
01362
01363
01364
01365
01366
01367
01368
01369 forAll(faceToDualPoint_, faceI)
01370 {
01371 if (faceToDualPoint_[faceI] != -1 && mesh_.isInternalFace(faceI))
01372 {
01373 const face& f = mesh_.faces()[faceI];
01374 const labelList& fEdges = mesh_.faceEdges()[faceI];
01375
01376
01377 label fp = 0;
01378
01379 do
01380 {
01381
01382
01383 bool foundStart = false;
01384
01385 do
01386 {
01387 if
01388 (
01389 edgeToDualPoint_[fEdges[fp]] != -1
01390 && !sameDualCell(faceI, f.nextLabel(fp))
01391 )
01392 {
01393 foundStart = true;
01394 break;
01395 }
01396 fp = f.fcIndex(fp);
01397 }
01398 while (fp != 0);
01399
01400 if (!foundStart)
01401 {
01402 break;
01403 }
01404
01405
01406 createFaceFromInternalFace
01407 (
01408 faceI,
01409 fp,
01410 meshMod
01411 );
01412 }
01413 while(fp != 0);
01414 }
01415 }
01416
01417 if (debug)
01418 {
01419 dumpPolyTopoChange(meshMod, "generatedFacesFromFeatFaces_");
01420 }
01421
01422
01423
01424
01425 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
01426
01427 forAll(patches, patchI)
01428 {
01429 const polyPatch& pp = patches[patchI];
01430
01431 const labelListList& pointFaces = pp.pointFaces();
01432
01433 forAll(pointFaces, patchPointI)
01434 {
01435 const labelList& pFaces = pointFaces[patchPointI];
01436
01437 boolList donePFaces(pFaces.size(), false);
01438
01439 forAll(pFaces, i)
01440 {
01441 if (!donePFaces[i])
01442 {
01443
01444 label startFaceI = pp.start()+pFaces[i];
01445
01446
01447
01448
01449
01450
01451
01452
01453 createFacesAroundBoundaryPoint
01454 (
01455 patchI,
01456 patchPointI,
01457 startFaceI,
01458 meshMod,
01459 donePFaces
01460 );
01461 }
01462 }
01463 }
01464 }
01465
01466 if (debug)
01467 {
01468 dumpPolyTopoChange(meshMod, "generatedFacesFromBndFaces_");
01469 }
01470 }
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483