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 "starMesh.H"
00031 #include "boolList.H"
00032 #include "pointHit.H"
00033 #include "IOmanip.H"
00034 #include "boundBox.H"
00035 #include "Map.H"
00036 #include "mathematicalConstants.H"
00037
00038
00039
00040 void starMesh::createCoupleMatches()
00041 {
00042
00043
00044
00045
00046
00047
00048 const label cellMapSize = min
00049 (
00050 cellShapes_.size()/10,
00051 couples_.size()*2
00052 );
00053
00054
00055 Map<SLList<face> > cellAddedFaces(cellMapSize);
00056
00057 Map<SLList<label> > cellRemovedFaces(cellMapSize);
00058
00059
00060
00061
00062 label nLivePoints = points_.size();
00063
00064 const label infoJump = max(1000, couples_.size()/20);
00065
00066 forAll (couples_, coupleI)
00067 {
00068 if (coupleI % infoJump == 0)
00069 {
00070 Info << "Doing couple " << coupleI << ". STAR couple ID: "
00071 << couples_[coupleI].coupleID() << endl;
00072 }
00073
00074
00075 const coupledFacePair& fp = couples_[coupleI];
00076 const face& masterFace = cellFaces_[fp.masterCell()][fp.masterFace()];
00077 const face& slaveFace = cellFaces_[fp.slaveCell()][fp.slaveFace()];
00078
00079 # ifdef DEBUG_COUPLE
00080 Info<< "coupleI: " << coupleI << endl
00081 << "masterFace: " << masterFace << endl
00082 << "master points: " << masterFace.points(points_) << endl
00083 << "slaveFace: " << slaveFace << endl
00084 << "slave points: " << slaveFace.points(points_)
00085 << endl << endl;
00086 # endif
00087
00088
00089 scalar faceAreaAngle =
00090 mag
00091 (
00092 -(masterFace.normal(points_) & slaveFace.normal(points_))/
00093 (masterFace.mag(points_)*slaveFace.mag(points_) + VSMALL)
00094 );
00095
00096 if (faceAreaAngle < 0.94)
00097 {
00098 Info<< "Couple direction mismatch in the couple match "
00099 << coupleI << ". STAR couple ID: "
00100 << couples_[coupleI].coupleID() << endl
00101 << "The angle between face normals is "
00102 << Foam::acos(faceAreaAngle)/mathematicalConstant::pi*180
00103 << " deg." << endl
00104 << "master cell: " << fp.masterCell()
00105 << " STAR number: " << starCellID_[fp.masterCell()]
00106 << " type: " << cellShapes_[fp.masterCell()].model().name()
00107 << " face: " << fp.masterFace() << endl
00108 << "slave cell : " << fp.slaveCell()
00109 << " STAR number: " << starCellID_[fp.slaveCell()]
00110 << " type: " << cellShapes_[fp.slaveCell()].model().name()
00111 << " face: " << fp.slaveFace() << endl;
00112 }
00113
00114
00115 if (fp.integralMatch())
00116 {
00117
00118
00119 Map<SLList<label> >::iterator crfIter =
00120 cellRemovedFaces.find(fp.masterCell());
00121
00122 if (crfIter == cellRemovedFaces.end())
00123 {
00124 cellRemovedFaces.insert
00125 (
00126 fp.masterCell(),
00127 fp.masterFace()
00128 );
00129 }
00130 else
00131 {
00132 crfIter().append(fp.masterFace());
00133 }
00134
00135 Map<SLList<face> >::iterator cafIter =
00136 cellAddedFaces.find(fp.masterCell());
00137 if (cafIter == cellAddedFaces.end())
00138 {
00139 cellAddedFaces.insert
00140 (
00141 fp.masterCell(),
00142 SLList<face>(slaveFace.reverseFace())
00143 );
00144 }
00145 else
00146 {
00147 cafIter().append(slaveFace.reverseFace());
00148 }
00149 }
00150 else
00151 {
00152
00153
00154
00155 SLList<point> coupleFacePoints;
00156
00157
00158 edgeList masterEdges = masterFace.edges();
00159 List<SLList<label> > masterEdgePoints(masterEdges.size());
00160
00161
00162 edgeList slaveEdges = slaveFace.edges();
00163 List<SLList<label> > slaveEdgePoints(slaveEdges.size());
00164
00165
00166 vector n = masterFace.normal(points_);
00167 n /= mag(n) + VSMALL;
00168
00169
00170
00171 forAll (masterEdges, masterEdgeI)
00172 {
00173 const edge& curMasterEdge = masterEdges[masterEdgeI];
00174
00175 point P = points_[curMasterEdge.start()];
00176
00177
00178 vector d = curMasterEdge.vec(points_);
00179 d -= n*(n & d);
00180
00181 # ifdef DEBUG_COUPLE_INTERSECTION
00182 Info << "curMasterEdge: " << curMasterEdge << endl
00183 << "P: " << P << endl << "d: " << d << endl;
00184 # endif
00185
00186
00187
00188
00189 forAll (slaveEdges, slaveEdgeI)
00190 {
00191 const edge& curSlaveEdge = slaveEdges[slaveEdgeI];
00192
00193 point S = points_[curSlaveEdge.start()];
00194
00195
00196 vector e = curSlaveEdge.vec(points_);
00197 e -= n*(n & e);
00198 scalar det = -(e & (n ^ d));
00199
00200 # ifdef DEBUG_COUPLE_INTERSECTION
00201 Info << "curSlaveEdge: " << curSlaveEdge << endl
00202 << "S: " << S << endl
00203 << "e: " << e << endl;
00204 # endif
00205
00206 if (mag(det) > SMALL)
00207 {
00208
00209 scalar beta = ((S - P) & (n ^ d))/det;
00210
00211 # ifdef DEBUG_COUPLE_INTERSECTION
00212 Info << " beta: " << beta << endl;
00213 # endif
00214
00215 if (beta > -smallMergeTol_ && beta < 1 + smallMergeTol_)
00216 {
00217
00218 scalar alpha =
00219 (((S - P) & d) + beta*(d & e))/magSqr(d);
00220
00221 # ifdef DEBUG_COUPLE_INTERSECTION
00222 Info << " alpha: " << alpha << endl;
00223 # endif
00224
00225 if
00226 (
00227 alpha > -smallMergeTol_
00228 && alpha < 1 + smallMergeTol_
00229 )
00230 {
00231
00232 # ifdef DEBUG_COUPLE_INTERSECTION
00233 Info<< "intersection of non-parallel edges"
00234 << endl;
00235 # endif
00236
00237
00238
00239
00240
00241 if (alpha < smallMergeTol_)
00242 {
00243
00244 if
00245 (
00246 beta > smallMergeTol_
00247 && beta < 1 - smallMergeTol_
00248 )
00249 {
00250 slaveEdgePoints[slaveEdgeI].append
00251 (
00252 curMasterEdge.start()
00253 );
00254 }
00255 }
00256 else if (alpha > 1 - smallMergeTol_)
00257 {
00258
00259 if
00260 (
00261 beta > smallMergeTol_
00262 && beta < 1 - smallMergeTol_
00263 )
00264 {
00265 slaveEdgePoints[slaveEdgeI].append
00266 (
00267 curMasterEdge.end()
00268 );
00269 }
00270 }
00271 else if (beta < smallMergeTol_)
00272 {
00273
00274 if
00275 (
00276 alpha > smallMergeTol_
00277 && alpha < 1 - smallMergeTol_
00278 )
00279 {
00280 masterEdgePoints[masterEdgeI].append
00281 (
00282 curSlaveEdge.start()
00283 );
00284 }
00285 }
00286 else if (beta > 1 - smallMergeTol_)
00287 {
00288
00289 if
00290 (
00291 alpha > smallMergeTol_
00292 && alpha < 1 - smallMergeTol_
00293 )
00294 {
00295 masterEdgePoints[masterEdgeI].append
00296 (
00297 curSlaveEdge.end()
00298 );
00299 }
00300 }
00301 else
00302 {
00303 masterEdgePoints[masterEdgeI].append
00304 (
00305 nLivePoints + coupleFacePoints.size()
00306 );
00307
00308 slaveEdgePoints[slaveEdgeI].append
00309 (
00310 nLivePoints + coupleFacePoints.size()
00311 );
00312
00313 # ifdef DEBUG_COUPLE_INTERSECTION
00314 Info<< "regular intersection. "
00315 << "Adding point: "
00316 << coupleFacePoints.size()
00317 << " which is "
00318 << P + alpha*curMasterEdge.vec(points_)
00319 << endl;
00320 # endif
00321
00322
00323
00324
00325 coupleFacePoints.append
00326 (P + alpha*curMasterEdge.vec(points_));
00327 }
00328 }
00329 }
00330 }
00331 else
00332 {
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 vector ps = S - P;
00346
00347 bool colinear = false;
00348
00349 if (mag(ps) < SMALL)
00350 {
00351
00352 colinear = true;
00353 }
00354 else if
00355 (
00356 (ps & d)/(mag(ps)*mag(d)) > 1.0 - smallMergeTol_
00357 )
00358 {
00359
00360 colinear = true;
00361 }
00362
00363 if (colinear)
00364 {
00365 scalar alpha1 = (ps & d)/magSqr(d);
00366
00367 if
00368 (
00369 alpha1 > -smallMergeTol_
00370 && alpha1 < 1 + smallMergeTol_
00371 )
00372 {
00373 # ifdef DEBUG_COUPLE_INTERSECTION
00374 Info<< "adding irregular master "
00375 << "intersection1: "
00376 << points_[slaveEdges[slaveEdgeI].start()]
00377 << endl;
00378 # endif
00379
00380 masterEdgePoints[masterEdgeI].append
00381 (
00382 slaveEdges[slaveEdgeI].start()
00383 );
00384 }
00385
00386 scalar alpha2 = ((ps + e) & d)/magSqr(d);
00387
00388 if
00389 (
00390 alpha2 > -smallMergeTol_
00391 && alpha2 < 1 + smallMergeTol_
00392 )
00393 {
00394 # ifdef DEBUG_COUPLE_INTERSECTION
00395 Info<< "adding irregular master "
00396 << "intersection2: "
00397 << points_[slaveEdges[slaveEdgeI].end()]
00398 << endl;
00399 # endif
00400
00401 masterEdgePoints[masterEdgeI].append
00402 (
00403 slaveEdges[slaveEdgeI].end()
00404 );
00405 }
00406
00407
00408
00409
00410
00411 vector sp = P - S;
00412
00413 scalar beta1 = (sp & e)/magSqr(e);
00414
00415 # ifdef DEBUG_COUPLE_INTERSECTION
00416 Info << "P: " << P << " S: " << S << " d: " << d
00417 << " e: " << e << " sp: " << sp
00418 << " beta1: " << beta1 << endl;
00419 # endif
00420
00421 if
00422 (
00423 beta1 > -smallMergeTol_
00424 && beta1 < 1 + smallMergeTol_
00425 )
00426 {
00427 # ifdef DEBUG_COUPLE_INTERSECTION
00428 Info<< "adding irregular slave "
00429 << "intersection1: "
00430 << points_[masterEdges[masterEdgeI].start()]
00431 << endl;
00432 # endif
00433
00434 slaveEdgePoints[slaveEdgeI].append
00435 (
00436 masterEdges[masterEdgeI].start()
00437 );
00438 }
00439
00440 scalar beta2 = ((sp + d) & e)/magSqr(e);
00441
00442 if
00443 (
00444 beta2 > -smallMergeTol_
00445 && beta2 < 1 + smallMergeTol_
00446 )
00447 {
00448 # ifdef DEBUG_COUPLE_INTERSECTION
00449 Info << "adding irregular slave "
00450 << "intersection2: "
00451 << points_[masterEdges[masterEdgeI].end()]
00452 << endl;
00453 # endif
00454
00455 slaveEdgePoints[slaveEdgeI].append
00456 (
00457 masterEdges[masterEdgeI].end()
00458 );
00459 }
00460 }
00461 }
00462 }
00463 }
00464
00465 # ifdef DEBUG_COUPLE_INTERSECTION
00466 Info << "additional slave edge points: " << endl;
00467 forAll (slaveEdgePoints, edgeI)
00468 {
00469 Info << "edge: " << edgeI << ": " << slaveEdgePoints[edgeI]
00470 << endl;
00471 }
00472 # endif
00473
00474
00475 if (nLivePoints + coupleFacePoints.size() >= points_.size())
00476 {
00477
00478 Info << "Resizing points list" << endl;
00479 points_.setSize(points_.size() + couples_.size());
00480 }
00481
00482 for
00483 (
00484 SLList<point>::iterator coupleFacePointsIter =
00485 coupleFacePoints.begin();
00486 coupleFacePointsIter != coupleFacePoints.end();
00487 ++coupleFacePointsIter
00488 )
00489 {
00490 points_[nLivePoints] = coupleFacePointsIter();
00491 nLivePoints++;
00492 }
00493
00494
00495
00496
00497
00498
00499 label nAdditionalMasterPoints = 0;
00500
00501 forAll (masterEdgePoints, edgeI)
00502 {
00503 nAdditionalMasterPoints += masterEdgePoints[edgeI].size();
00504 }
00505
00506 face tmpMasterFace
00507 (
00508 masterFace.size()
00509 + nAdditionalMasterPoints
00510 );
00511 label nTmpMasterLabels = 0;
00512
00513 # ifdef DEBUG_COUPLE_INTERSECTION
00514 Info << "masterFace: " << masterFace << endl
00515 << "nAdditionalMasterPoints: " << nAdditionalMasterPoints
00516 << endl;
00517 # endif
00518
00519 forAll (masterEdges, masterEdgeI)
00520 {
00521
00522 tmpMasterFace[nTmpMasterLabels] =
00523 masterEdges[masterEdgeI].start();
00524 nTmpMasterLabels++;
00525
00526
00527 const SLList<label>& curMEdgePoints =
00528 masterEdgePoints[masterEdgeI];
00529
00530
00531 boolList usedMasterPoint(curMEdgePoints.size(), false);
00532
00533 vector edgeVector = masterEdges[masterEdgeI].vec(points_);
00534
00535 # ifdef DEBUG_FACE_ORDERING
00536 Info<< "edgeVector: " << edgeVector << endl
00537 << "curMEdgePoints.size(): " << curMEdgePoints.size()
00538 << endl;
00539 # endif
00540
00541
00542 edgeVector /= magSqr(edgeVector);
00543
00544 point edgeStartPoint =
00545 points_[masterEdges[masterEdgeI].start()];
00546
00547
00548 for(;;)
00549 {
00550 label nextPointLabel = -1;
00551 label usedI = -1;
00552 scalar minAlpha = GREAT;
00553
00554 label i = 0;
00555
00556 for
00557 (
00558 SLList<label>::const_iterator curMEdgePointsIter =
00559 curMEdgePoints.begin();
00560 curMEdgePointsIter != curMEdgePoints.end();
00561 ++curMEdgePointsIter
00562 )
00563 {
00564 if (!usedMasterPoint[i])
00565 {
00566 scalar alpha =
00567 edgeVector
00568 & (
00569 points_[curMEdgePointsIter()]
00570 - edgeStartPoint
00571 );
00572
00573 # ifdef DEBUG_FACE_ORDERING
00574 Info<< " edgeStartPoint: " << edgeStartPoint
00575 << " edgeEndPoint: "
00576 << points_[masterEdges[masterEdgeI].end()]
00577 << " other point: "
00578 << points_[curMEdgePointsIter()]
00579 << " alpha: " << alpha << endl;
00580 # endif
00581
00582 if (alpha < minAlpha)
00583 {
00584 minAlpha = alpha;
00585 usedI = i;
00586 nextPointLabel = curMEdgePointsIter();
00587 }
00588 }
00589
00590 # ifdef DEBUG_FACE_ORDERING
00591 Info << "nextPointLabel: " << nextPointLabel << endl;
00592 # endif
00593
00594 i++;
00595 }
00596
00597 if (nextPointLabel > -1)
00598 {
00599 # ifdef DEBUG_FACE_ORDERING
00600 Info<< "added nextPointLabel: " << nextPointLabel
00601 << " nTmpMasterLabels: " << nTmpMasterLabels
00602 << " to place " << nTmpMasterLabels << endl;
00603 # endif
00604
00605 usedMasterPoint[usedI] = true;
00606
00607 tmpMasterFace[nTmpMasterLabels] =
00608 nextPointLabel;
00609 nTmpMasterLabels++;
00610 }
00611 else
00612 {
00613 break;
00614 }
00615 }
00616 }
00617
00618
00619 tmpMasterFace.setSize(nTmpMasterLabels);
00620
00621 # ifdef DEBUG_FACE_ORDERING
00622 Info << "tmpMasterFace: " << tmpMasterFace << endl;
00623 # endif
00624
00625
00626 face newMasterFace(labelList(tmpMasterFace.size(), labelMax));
00627
00628
00629
00630
00631
00632 newMasterFace[0] = tmpMasterFace[0];
00633 label nMaster = 0;
00634
00635 edgeList mstEdgesToCollapse = tmpMasterFace.edges();
00636
00637 scalar masterTol =
00638 cpMergePointTol_*boundBox(tmpMasterFace.points(points_)).mag();
00639
00640 forAll (mstEdgesToCollapse, edgeI)
00641 {
00642 # ifdef DEBUG_FACE_ORDERING
00643 Info<< "edgeI: " << edgeI << " curEdge: "
00644 << mstEdgesToCollapse[edgeI] << endl
00645 << "master edge " << edgeI << ", "
00646 << mstEdgesToCollapse[edgeI].mag(points_) << endl;
00647 # endif
00648
00649
00650 if (mstEdgesToCollapse[edgeI].mag(points_) < masterTol)
00651 {
00652 newMasterFace[nMaster] =
00653 min
00654 (
00655 newMasterFace[nMaster],
00656 mstEdgesToCollapse[edgeI].end()
00657 );
00658
00659 # ifdef DEBUG_FACE_ORDERING
00660 Info << "Collapsed: nMaster: " << nMaster
00661 << " label: " << newMasterFace[nMaster] << endl;
00662 # endif
00663
00664 }
00665 else
00666 {
00667 nMaster++;
00668
00669 if (edgeI < mstEdgesToCollapse.size() - 1)
00670 {
00671
00672 # ifdef DEBUG_FACE_ORDERING
00673 Info<< "Added: nMaster: " << nMaster
00674 << " label: " << mstEdgesToCollapse[edgeI].end()
00675 << endl;
00676 # endif
00677
00678 newMasterFace[nMaster] =
00679 mstEdgesToCollapse[edgeI].end();
00680 }
00681 }
00682 }
00683
00684 newMasterFace.setSize(nMaster);
00685
00686 # ifdef DEBUG_COUPLE
00687 Info<< "newMasterFace: " << newMasterFace << endl
00688 << "points: " << newMasterFace.points(points_) << endl;
00689 # endif
00690
00691
00692
00693
00694 label nAdditionalSlavePoints = 0;
00695
00696 forAll (slaveEdgePoints, edgeI)
00697 {
00698 nAdditionalSlavePoints += slaveEdgePoints[edgeI].size();
00699 }
00700
00701 face tmpSlaveFace
00702 (
00703 slaveFace.size()
00704 + nAdditionalSlavePoints
00705 );
00706 label nTmpSlaveLabels = 0;
00707
00708 # ifdef DEBUG_COUPLE_INTERSECTION
00709 Info<< "slaveFace: " << slaveFace << endl
00710 << "nAdditionalSlavePoints: " << nAdditionalSlavePoints << endl;
00711 # endif
00712
00713 forAll (slaveEdges, slaveEdgeI)
00714 {
00715
00716 tmpSlaveFace[nTmpSlaveLabels] =
00717 slaveEdges[slaveEdgeI].start();
00718 nTmpSlaveLabels++;
00719
00720
00721 const SLList<label>& curSEdgePoints =
00722 slaveEdgePoints[slaveEdgeI];
00723
00724
00725 boolList usedSlavePoint(curSEdgePoints.size(), false);
00726
00727 vector edgeVector = slaveEdges[slaveEdgeI].vec(points_);
00728
00729 # ifdef DEBUG_FACE_ORDERING
00730 Info << "curSEdgePoints.size(): "
00731 << curSEdgePoints.size() << endl
00732 << "edgeVector: " << edgeVector << endl;
00733 # endif
00734
00735
00736 edgeVector /= magSqr(edgeVector);
00737
00738 point edgeStartPoint =
00739 points_[slaveEdges[slaveEdgeI].start()];
00740
00741
00742 for(;;)
00743 {
00744 label nextPointLabel = -1;
00745 label usedI = -1;
00746 scalar minAlpha = GREAT;
00747
00748 label i = 0;
00749
00750 for
00751 (
00752 SLList<label>::const_iterator curSEdgePointsIter =
00753 curSEdgePoints.begin();
00754 curSEdgePointsIter != curSEdgePoints.end();
00755 ++curSEdgePointsIter
00756 )
00757 {
00758 if (!usedSlavePoint[i])
00759 {
00760 scalar alpha =
00761 edgeVector
00762 & (
00763 points_[curSEdgePointsIter()]
00764 - edgeStartPoint
00765 );
00766
00767 # ifdef DEBUG_FACE_ORDERING
00768 Info<< " edgeStartPoint: " << edgeStartPoint
00769 << " edgeEndPoint: "
00770 << points_[slaveEdges[slaveEdgeI].end()]
00771 << " other point: "
00772 << points_[curSEdgePointsIter()]
00773 << " alpha: " << alpha << endl;
00774 # endif
00775
00776 if (alpha < minAlpha)
00777 {
00778 minAlpha = alpha;
00779 usedI = i;
00780 nextPointLabel = curSEdgePointsIter();
00781 }
00782 }
00783
00784 # ifdef DEBUG_FACE_ORDERING
00785 Info << "nextPointLabel: " << nextPointLabel << endl;
00786 # endif
00787
00788 i++;
00789 }
00790
00791 if (nextPointLabel > -1)
00792 {
00793 # ifdef DEBUG_FACE_ORDERING
00794 Info<< "added nextPointLabel: " << nextPointLabel
00795 << " nTmpSlaveLabels: " << nTmpSlaveLabels
00796 << " to place " << nTmpSlaveLabels << endl;
00797 # endif
00798
00799 usedSlavePoint[usedI] = true;
00800
00801 tmpSlaveFace[nTmpSlaveLabels] =
00802 nextPointLabel;
00803 nTmpSlaveLabels++;
00804 }
00805 else
00806 {
00807 break;
00808 }
00809 }
00810 }
00811
00812
00813 tmpSlaveFace.setSize(nTmpSlaveLabels);
00814
00815 # ifdef DEBUG_FACE_ORDERING
00816 Info << "tmpSlaveFace: " << tmpSlaveFace << endl;
00817 # endif
00818
00819
00820 face newSlaveFace(labelList(tmpSlaveFace.size(), labelMax));
00821
00822
00823
00824
00825
00826 newSlaveFace[0] = tmpSlaveFace[0];
00827 label nSlave = 0;
00828
00829 edgeList slvEdgesToCollapse = tmpSlaveFace.edges();
00830
00831 scalar slaveTol =
00832 cpMergePointTol_*boundBox(tmpSlaveFace.points(points_)).mag();
00833
00834 forAll(slvEdgesToCollapse, edgeI)
00835 {
00836 # ifdef DEBUG_FACE_ORDERING
00837 Info << "slave edge length: " << edgeI << ", "
00838 << slvEdgesToCollapse[edgeI].mag(points_)<< endl;
00839 # endif
00840
00841
00842 if (slvEdgesToCollapse[edgeI].mag(points_) < slaveTol)
00843 {
00844 newSlaveFace[nSlave] =
00845 min
00846 (
00847 newSlaveFace[nSlave],
00848 slvEdgesToCollapse[edgeI].end()
00849 );
00850 }
00851 else
00852 {
00853 nSlave++;
00854 if (edgeI < slvEdgesToCollapse.size() - 1)
00855 {
00856
00857 newSlaveFace[nSlave] = slvEdgesToCollapse[edgeI].end();
00858 }
00859 }
00860 }
00861
00862 newSlaveFace.setSize(nSlave);
00863
00864 # ifdef DEBUG_COUPLE
00865 Info<< "newSlaveFace: " << newSlaveFace << endl
00866 << "points: " << newSlaveFace.points(points_) << endl << endl;
00867 # endif
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879 edgeList newMasterEdges = newMasterFace.edges();
00880 edgeList newSlaveEdges = newSlaveFace.edges();
00881
00882 # ifdef DEBUG_RIGHT_HAND_WALK
00883 Info << "newMasterEdges: " << newMasterEdges << endl
00884 << "newSlaveEdges: " << newSlaveEdges << endl;
00885 # endif
00886
00887 edge startEdge;
00888
00889
00890
00891
00892
00893 label startEdgeFound = 0;
00894
00895 vector masterProjDir = -newMasterFace.normal(points_);
00896
00897 forAll (newSlaveEdges, edgeI)
00898 {
00899
00900
00901
00902
00903 point pointStart = points_[newSlaveEdges[edgeI].start()];
00904
00905 point pointEnd = points_[newSlaveEdges[edgeI].end()];
00906
00907 if
00908 (
00909 newMasterFace.ray
00910 (
00911 pointStart,
00912 masterProjDir,
00913 points_,
00914 intersection::FULL_RAY
00915 ).hit()
00916 && newMasterFace.ray
00917 (
00918 pointEnd,
00919 masterProjDir,
00920 points_,
00921 intersection::FULL_RAY
00922 ).hit()
00923 )
00924 {
00925 startEdge = newSlaveEdges[edgeI];
00926 startEdgeFound = 2;
00927
00928 # ifdef DEBUG_RIGHT_HAND_WALK
00929 Info << "slave edge found" << endl;
00930 # endif
00931
00932 break;
00933 }
00934 }
00935
00936 if (startEdgeFound == 0)
00937 {
00938 vector slaveProjDir = -newSlaveFace.normal(points_);
00939
00940 forAll (newMasterEdges, edgeI)
00941 {
00942
00943
00944
00945
00946 point pointStart = points_[newMasterEdges[edgeI].start()];
00947
00948 point pointEnd = points_[newMasterEdges[edgeI].end()];
00949
00950 if
00951 (
00952 newSlaveFace.ray
00953 (
00954 pointStart,
00955 slaveProjDir,
00956 points_,
00957 intersection::FULL_RAY
00958 ).hit()
00959 && newSlaveFace.ray
00960 (
00961 pointEnd,
00962 slaveProjDir,
00963 points_,
00964 intersection::FULL_RAY
00965 ).hit()
00966 )
00967 {
00968 startEdge = newMasterEdges[edgeI];
00969 startEdgeFound = 1;
00970
00971 # ifdef DEBUG_RIGHT_HAND_WALK
00972 Info << "master edge found" << endl;
00973 # endif
00974
00975 break;
00976 }
00977 }
00978 }
00979
00980
00981 face intersectedFace
00982 (
00983 labelList(newMasterFace.size() + newSlaveFace.size(), -1)
00984 );
00985
00986 if (startEdgeFound > 0)
00987 {
00988 # ifdef DEBUG_RIGHT_HAND_WALK
00989 Info << "start edge: " << startEdge << endl;
00990 # endif
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003 vector planeNormal = newMasterFace.normal(points_);
01004 planeNormal /= mag(planeNormal) + VSMALL;
01005
01006 # ifdef DEBUG_RIGHT_HAND_WALK
01007 Info << "planeNormal: " << planeNormal << endl;
01008 # endif
01009
01010
01011
01012
01013
01014
01015
01016
01017 vector faceCentre;
01018
01019 if (startEdgeFound == 1)
01020 {
01021 faceCentre = newMasterFace.centre(points_);
01022 }
01023 else
01024 {
01025 faceCentre = newSlaveFace.centre(points_);
01026 }
01027
01028 scalar tripleProduct =
01029 (
01030 (faceCentre - points_[startEdge.start()])
01031 ^ startEdge.vec(points_)
01032 ) & planeNormal;
01033
01034 if (tripleProduct < 0)
01035 {
01036 # ifdef DEBUG_RIGHT_HAND_WALK
01037 Info << "Turning edge for right-hand turn rule" << endl;
01038 # endif
01039 startEdge = startEdge.reverseEdge();
01040 }
01041
01042
01043 intersectedFace[0] = startEdge.start();
01044 intersectedFace[1] = startEdge.end();
01045 label nIntFacePoints = 2;
01046
01047 edge curEdge = startEdge;
01048
01049 bool completedFace = false;
01050
01051 do
01052 {
01053 SLList<edge> edgesToConsider;
01054
01055
01056 forAll (newMasterEdges, edgeI)
01057 {
01058 const edge& cme = newMasterEdges[edgeI];
01059
01060 if (cme != curEdge)
01061 {
01062 if (cme.start() == curEdge.end())
01063 {
01064 edgesToConsider.append(cme);
01065 }
01066 else if (cme.end() == curEdge.end())
01067 {
01068 edgesToConsider.append(cme.reverseEdge());
01069 }
01070
01071 }
01072 }
01073
01074
01075 forAll (newSlaveEdges, edgeI)
01076 {
01077 const edge& cse = newSlaveEdges[edgeI];
01078
01079 if (cse != curEdge)
01080 {
01081 if (cse.start() == curEdge.end())
01082 {
01083 edgesToConsider.append(cse);
01084 }
01085 else if (cse.end() == curEdge.end())
01086 {
01087 edgesToConsider.append(cse.reverseEdge());
01088 }
01089
01090 }
01091 }
01092
01093 # ifdef DEBUG_RIGHT_HAND_WALK
01094 Info<< "number of edges to consider: "
01095 << edgesToConsider.size() << endl
01096 << "edges to consider: " << edgesToConsider << endl;
01097 # endif
01098
01099 if (edgesToConsider.empty())
01100 {
01101 FatalErrorIn("void starMesh::createCoupleMatches()")
01102 << setprecision(12)
01103 << "void starMesh::createCoupleMatches() : "
01104 << endl << "error in face intersection: "
01105 << "no edges to consider for closing the loop"
01106 << coupleI << ". STAR couple ID: "
01107 << couples_[coupleI].coupleID() << endl
01108 << "Cut Master Face: " << newMasterFace << endl
01109 << "points: " << newMasterFace.points(points_)
01110 << endl
01111 << "Cut Slave Face: " << newSlaveFace << endl
01112 << "points: " << newSlaveFace.points(points_)
01113 << endl << "intersected face: "
01114 << intersectedFace
01115 << abort(FatalError);
01116 }
01117
01118
01119 vector ahead = curEdge.vec(points_);
01120 ahead -= planeNormal*(planeNormal & ahead);
01121 ahead /= mag(ahead) + VSMALL;
01122
01123
01124 vector right = ahead ^ planeNormal;
01125 right /= mag(right) + VSMALL;
01126
01127
01128 edge nextEdge = edgesToConsider.first();
01129 vector nextEdgeVec = nextEdge.vec(points_);
01130 nextEdgeVec -= planeNormal*(planeNormal & nextEdgeVec);
01131 nextEdgeVec /= mag(nextEdgeVec) + VSMALL;
01132
01133 scalar rightTurn = nextEdgeVec & right;
01134 scalar goStraight = nextEdgeVec & ahead;
01135
01136 # ifdef DEBUG_RIGHT_HAND_WALK
01137 Info<< "rightTurn: " << rightTurn
01138 << " goStraight: " << goStraight << endl;
01139 # endif
01140
01141 for
01142 (
01143 SLList<edge>::iterator etcIter =
01144 edgesToConsider.begin();
01145 etcIter != edgesToConsider.end();
01146 ++etcIter
01147 )
01148 {
01149
01150 vector newDir = etcIter().vec(points_);
01151 newDir -= planeNormal*(planeNormal & newDir);
01152 newDir /= mag(newDir) + VSMALL;
01153
01154 scalar curRightTurn = newDir & right;
01155 scalar curGoStraight = newDir & ahead;
01156
01157 # ifdef DEBUG_RIGHT_HAND_WALK
01158 Info << "curRightTurn: " << curRightTurn
01159 << " curGoStraight: " << curGoStraight << endl;
01160 # endif
01161
01162 if (rightTurn < 0)
01163 {
01164 if (curRightTurn < 0)
01165 {
01166
01167 if (curGoStraight > goStraight)
01168 {
01169 # ifdef DEBUG_RIGHT_HAND_WALK
01170 Info << "a" << endl;
01171 # endif
01172
01173
01174 nextEdge = etcIter();
01175 rightTurn = curRightTurn;
01176 goStraight = curGoStraight;
01177 }
01178 }
01179 else
01180 {
01181 # ifdef DEBUG_RIGHT_HAND_WALK
01182 Info << "b" << endl;
01183 # endif
01184
01185
01186 nextEdge = etcIter();
01187 rightTurn = curRightTurn;
01188 goStraight = curGoStraight;
01189 }
01190 }
01191 else
01192 {
01193
01194 if (curRightTurn >= 0)
01195 {
01196
01197 if (curGoStraight < goStraight)
01198 {
01199 # ifdef DEBUG_RIGHT_HAND_WALK
01200 Info << "c" << endl;
01201 # endif
01202
01203
01204 nextEdge = etcIter();
01205 rightTurn = curRightTurn;
01206 goStraight = curGoStraight;
01207 }
01208 }
01209 }
01210 }
01211
01212
01213 if (nextEdge.end() == intersectedFace[0])
01214 {
01215
01216 completedFace = true;
01217 }
01218 else
01219 {
01220
01221 if (nIntFacePoints >= intersectedFace.size())
01222 {
01223 FatalErrorIn("void starMesh::createCoupleMatches()")
01224 << setprecision(12)
01225 << "void starMesh::createCoupleMatches() : "
01226 << endl << "error in intersected face: "
01227 << "lost thread for intersection of couple "
01228 << coupleI << ". STAR couple ID: "
01229 << couples_[coupleI].coupleID() << endl
01230 << "Cut Master Face: " << newMasterFace << endl
01231 << "points: " << newMasterFace.points(points_)
01232 << endl
01233 << "Cut Slave Face: " << newSlaveFace << endl
01234 << "points: " << newSlaveFace.points(points_)
01235 << endl << "intersected face: "
01236 << intersectedFace
01237 << abort(FatalError);
01238 }
01239
01240
01241 intersectedFace[nIntFacePoints] = nextEdge.end();
01242 nIntFacePoints++;
01243
01244
01245 curEdge = nextEdge;
01246
01247 # ifdef DEBUG_RIGHT_HAND_WALK
01248 Info<< "inserted point " << nextEdge.end() << endl
01249 << "curEdge: " << curEdge << endl;
01250 # endif
01251 }
01252 }
01253 while (!completedFace);
01254
01255
01256 intersectedFace.setSize(nIntFacePoints);
01257
01258 # ifdef DEBUG_COUPLE
01259 Info << "intersectedFace: " << intersectedFace << endl;
01260 # endif
01261
01262
01263 forAll (intersectedFace, checkI)
01264 {
01265 for
01266 (
01267 label checkJ = checkI + 1;
01268 checkJ < intersectedFace.size();
01269 checkJ++
01270 )
01271 {
01272 if (intersectedFace[checkI] == intersectedFace[checkJ])
01273 {
01274 FatalErrorIn("void starMesh::createCoupleMatches()")
01275 << setprecision(12)
01276 << "void starMesh::createCoupleMatches() : "
01277 << endl << "error in intersected face: "
01278 << "duplicate point in intersected face "
01279 << "for couple no " << coupleI
01280 << ". STAR couple ID: "
01281 << couples_[coupleI].coupleID() << endl
01282 << "Duplicate point label: "
01283 << intersectedFace[checkI] << endl
01284 << "Cut Master Face: " << newMasterFace << endl
01285 << "points: " << newMasterFace.points(points_)
01286 << endl
01287 << "Cut Slave Face: " << newSlaveFace << endl
01288 << "points: " << newSlaveFace.points(points_)
01289 << endl << "intersected face: "
01290 << intersectedFace
01291 << abort(FatalError);
01292 }
01293 }
01294 }
01295 }
01296 else
01297 {
01298 FatalErrorIn("void starMesh::createCoupleMatches()")
01299 << setprecision(12)
01300 << "void starMesh::createCoupleMatches() : " << endl
01301 << "could not find start edge for intersection of couple "
01302 << coupleI << ". STAR couple ID: "
01303 << couples_[coupleI].coupleID() << endl
01304 << "Cut Master Face: " << newMasterFace << endl
01305 << "points: " << newMasterFace.points(points_) << endl
01306 << "Cut Slave Face: " << newSlaveFace << endl
01307 << "points: " << newSlaveFace.points(points_)
01308 << abort(FatalError);
01309 }
01310
01311
01312
01313 vector pointProjectionNormal = -masterFace.normal(points_);
01314
01315 forAll (intersectedFace, intPointI)
01316 {
01317 # ifdef DEBUG_COUPLE_PROJECTION
01318 Info << "Proj: old point: "
01319 << points_[intersectedFace[intPointI]] << endl;
01320 # endif
01321
01322 pointHit projHit =
01323 masterFace.ray
01324 (
01325 points_[intersectedFace[intPointI]],
01326 pointProjectionNormal,
01327 points_,
01328 intersection::FULL_RAY
01329 );
01330
01331 if (projHit.hit())
01332 {
01333 points_[intersectedFace[intPointI]] =
01334 projHit.hitPoint();
01335
01336 # ifdef DEBUG_COUPLE_PROJECTION
01337 Info<< " new point: "
01338 << points_[intersectedFace[intPointI]] << endl;
01339 # endif
01340 }
01341 }
01342
01343
01344 if
01345 (
01346 (
01347 masterFace.normal(points_)
01348 & intersectedFace.normal(points_)
01349 ) < VSMALL
01350 )
01351 {
01352 intersectedFace = intersectedFace.reverseFace();
01353 }
01354
01355
01356
01357
01358 Map<SLList<label> >::iterator crfMasterIter =
01359 cellRemovedFaces.find(fp.masterCell());
01360
01361 if (crfMasterIter == cellRemovedFaces.end())
01362 {
01363 cellRemovedFaces.insert
01364 (
01365 fp.masterCell(),
01366 fp.masterFace()
01367 );
01368 }
01369 else
01370 {
01371 crfMasterIter().append(fp.masterFace());
01372 }
01373
01374 Map<SLList<label> >::iterator crfSlaveIter =
01375 cellRemovedFaces.find(fp.slaveCell());
01376
01377 if (crfSlaveIter == cellRemovedFaces.end())
01378 {
01379 cellRemovedFaces.insert
01380 (
01381 fp.slaveCell(),
01382 fp.slaveFace()
01383 );
01384 }
01385 else
01386 {
01387 crfSlaveIter().append(fp.slaveFace());
01388 }
01389
01390 Map<SLList<face> >::iterator cafMasterIter =
01391 cellAddedFaces.find(fp.masterCell());
01392 if (cafMasterIter == cellAddedFaces.end())
01393 {
01394 cellAddedFaces.insert
01395 (
01396 fp.masterCell(),
01397 SLList<face>(intersectedFace)
01398 );
01399 }
01400 else
01401 {
01402 cafMasterIter().append(intersectedFace);
01403 }
01404
01405 Map<SLList<face> >::iterator cafSlaveIter =
01406 cellAddedFaces.find(fp.slaveCell());
01407 if (cafSlaveIter == cellAddedFaces.end())
01408 {
01409 cellAddedFaces.insert
01410 (
01411 fp.slaveCell(),
01412 SLList<face>(intersectedFace.reverseFace())
01413 );
01414 }
01415 else
01416 {
01417 cafSlaveIter().append(intersectedFace.reverseFace());
01418 }
01419 }
01420 }
01421
01422 if (couples_.size())
01423 {
01424
01425 const labelList crfToc = cellRemovedFaces.toc();
01426
01427 forAll (crfToc, cellI)
01428 {
01429 const label curCell = crfToc[cellI];
01430
01431 const SLList<label>& curRemovedFaces = cellRemovedFaces[curCell];
01432
01433 for
01434 (
01435 SLList<label>::const_iterator curRemovedFacesIter =
01436 curRemovedFaces.begin();
01437 curRemovedFacesIter != curRemovedFaces.end();
01438 ++curRemovedFacesIter
01439 )
01440 {
01441 cellFaces_[curCell][curRemovedFacesIter()].setSize(0);
01442 }
01443
01444 if (curRemovedFaces.size())
01445 {
01446
01447 cellShapes_[curCell] = cellShape(*unknownPtr_, labelList(0));
01448 }
01449 }
01450
01451 const labelList cafToc = cellAddedFaces.toc();
01452
01453
01454 forAll (cafToc, cellI)
01455 {
01456 const label curCell = cafToc[cellI];
01457
01458 const SLList<face>& curAddedFaces = cellAddedFaces[curCell];
01459
01460 faceList oldFaces = cellFaces_[curCell];
01461
01462 faceList& newFaces = cellFaces_[curCell];
01463
01464 newFaces.setSize(oldFaces.size() + curAddedFaces.size());
01465 label nNewFaces = 0;
01466
01467
01468 forAll (oldFaces, faceI)
01469 {
01470 if (oldFaces[faceI].size())
01471 {
01472 newFaces[nNewFaces] = oldFaces[faceI];
01473 nNewFaces++;
01474 }
01475 }
01476
01477
01478 for
01479 (
01480 SLList<face>::const_iterator curAddedFacesIter =
01481 curAddedFaces.begin();
01482 curAddedFacesIter != curAddedFaces.end();
01483 ++curAddedFacesIter
01484 )
01485 {
01486 newFaces[nNewFaces] = curAddedFacesIter();
01487 nNewFaces++;
01488 }
01489
01490
01491 newFaces.setSize(nNewFaces);
01492
01493 if (curAddedFaces.size())
01494 {
01495
01496 cellShapes_[curCell] = cellShape(*unknownPtr_, labelList(0));
01497 }
01498 }
01499
01500
01501 points_.setSize(nLivePoints);
01502
01503
01504 Info << "Finished doing couples" << endl;
01505 }
01506 }
01507
01508
01509