enrichedPatchCutFaces.C
Go to the documentation of this file.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
00031 #include "enrichedPatch.H"
00032 #include "boolList.H"
00033 #include "DynamicList.H"
00034 #include "labelPair.H"
00035 #include "primitiveMesh.H"
00036 #include "HashSet.H"
00037
00038
00039
00040
00041 const Foam::label Foam::enrichedPatch::maxFaceSizeDebug_ = 100;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 void Foam::enrichedPatch::calcCutFaces() const
00052 {
00053 if (cutFacesPtr_ || cutFaceMasterPtr_ || cutFaceSlavePtr_)
00054 {
00055 FatalErrorIn("void enrichedPatch::calcCutFaces() const")
00056 << "Cut faces addressing already calculated."
00057 << abort(FatalError);
00058 }
00059
00060 const faceList& enFaces = enrichedFaces();
00061 const labelList& mp = meshPoints();
00062 const faceList& lf = localFaces();
00063 const pointField& lp = localPoints();
00064 const labelListList& pp = pointPoints();
00065
00066
00067
00068
00069 const Map<labelList>& masterPointFaceAddr = masterPointFaces();
00070
00071
00072 DynamicList<face> cf(2*lf.size());
00073 DynamicList<label> cfMaster(2*lf.size());
00074 DynamicList<label> cfSlave(2*lf.size());
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 HashSet<edge, Hash<edge> > edgesUsedOnce(pp.size());
00099 HashSet<edge, Hash<edge> > edgesUsedTwice
00100 (pp.size()*primitiveMesh::edgesPerPoint_);
00101
00102
00103 forAll (lf, faceI)
00104 {
00105 const face& curLocalFace = lf[faceI];
00106 const face& curGlobalFace = enFaces[faceI];
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 boolList usedFaceEdges(curLocalFace.size(), false);
00140
00141 SLList<edge> edgeSeeds;
00142
00143
00144 edgeList cfe = curLocalFace.edges();
00145 forAll (curLocalFace, edgeI)
00146 {
00147 edgeSeeds.append(cfe[edgeI]);
00148 }
00149
00150
00151 vector normal = curLocalFace.normal(lp);
00152 normal /= mag(normal);
00153
00154 while (edgeSeeds.size())
00155 {
00156
00157 const edge curEdge = edgeSeeds.removeHead();
00158
00159
00160 const label curEdgeWhich = curLocalFace.which(curEdge.start());
00161
00162
00163
00164 if
00165 (
00166 curEdgeWhich > -1
00167 && curLocalFace.nextLabel(curEdgeWhich) == curEdge.end()
00168 )
00169 {
00170
00171
00172 if (usedFaceEdges[curEdgeWhich]) continue;
00173
00174 usedFaceEdges[curEdgeWhich] = true;
00175 }
00176
00177
00178 if (edgesUsedTwice.found(curEdge)) continue;
00179
00180
00181
00182 DynamicList<label> cutFaceGlobalPoints(2*curLocalFace.size());
00183 DynamicList<label> cutFaceLocalPoints(2*curLocalFace.size());
00184
00185
00186 label prevPointLabel = curEdge.start();
00187 cutFaceGlobalPoints.append(mp[prevPointLabel]);
00188 cutFaceLocalPoints.append(prevPointLabel);
00189
00190
00191 label curPointLabel = curEdge.end();
00192 point curPoint = lp[curPointLabel];
00193 cutFaceGlobalPoints.append(mp[curPointLabel]);
00194 cutFaceLocalPoints.append(curPointLabel);
00195
00196 bool completedCutFace = false;
00197
00198 label faceSizeDebug = maxFaceSizeDebug_;
00199
00200 do
00201 {
00202
00203
00204 const labelList& nextPoints = pp[curPointLabel];
00205
00206
00207 vector ahead = curPoint - lp[prevPointLabel];
00208 ahead -= normal*(normal & ahead);
00209 ahead /= mag(ahead);
00210
00211 vector right = normal ^ ahead;
00212 right /= mag(right);
00213
00214
00215 scalar atanTurn = -GREAT;
00216 label bestAtanPoint = -1;
00217
00218 forAll (nextPoints, nextI)
00219 {
00220
00221
00222 if (nextPoints[nextI] != prevPointLabel)
00223 {
00224
00225 vector newDir = lp[nextPoints[nextI]] - curPoint;
00226
00227 newDir -= normal*(normal & newDir);
00228 scalar magNewDir = mag(newDir);
00229
00230
00231 if (magNewDir < SMALL)
00232 {
00233 FatalErrorIn
00234 (
00235 "void enrichedPatch::"
00236 "calcCutFaces() const"
00237 ) << "Zero length edge detected. Probable "
00238 << "projection error: slave patch probably "
00239 << "does not project onto master. "
00240 << "Please switch on "
00241 << "enriched patch debug for more info"
00242 << abort(FatalError);
00243 }
00244
00245 newDir /= magNewDir;
00246
00247 scalar curAtanTurn =
00248 atan2(newDir & right, newDir & ahead);
00249
00250
00251
00252 if (curAtanTurn > atanTurn)
00253 {
00254 bestAtanPoint = nextPoints[nextI];
00255 atanTurn = curAtanTurn;
00256 }
00257 }
00258 }
00259
00260
00261
00262
00263
00264
00265
00266 const label whichNextPoint = curLocalFace.which(curPointLabel);
00267
00268 if
00269 (
00270 whichNextPoint > -1
00271 && curLocalFace.nextLabel(whichNextPoint) == bestAtanPoint
00272 && usedFaceEdges[whichNextPoint]
00273 )
00274 {
00275
00276
00277
00278 completedCutFace = true;
00279 }
00280
00281
00282 if (edgesUsedTwice.found(edge(curPointLabel, bestAtanPoint)))
00283 {
00284
00285
00286 completedCutFace = true;
00287
00288 }
00289
00290 if (completedCutFace) continue;
00291
00292
00293 if (mp[bestAtanPoint] == cutFaceGlobalPoints[0])
00294 {
00295
00296
00297 completedCutFace = true;
00298
00299 if (debug)
00300 {
00301 Pout<< " local: " << cutFaceLocalPoints
00302 << " one side: " << faceI;
00303 }
00304
00305
00306 face cutFaceGlobal;
00307 cutFaceGlobal.transfer(cutFaceGlobalPoints);
00308
00309 cf.append(cutFaceGlobal);
00310
00311 face cutFaceLocal;
00312 cutFaceLocal.transfer(cutFaceLocalPoints);
00313
00314
00315
00316
00317
00318 forAll (cutFaceLocal, cutI)
00319 {
00320 const edge curCutFaceEdge
00321 (
00322 cutFaceLocal[cutI],
00323 cutFaceLocal.nextLabel(cutI)
00324 );
00325
00326
00327 HashSet<edge, Hash<edge> >::iterator euoIter =
00328 edgesUsedOnce.find(curCutFaceEdge);
00329
00330 if (euoIter == edgesUsedOnce.end())
00331 {
00332
00333 edgesUsedOnce.insert(curCutFaceEdge);
00334 }
00335 else
00336 {
00337
00338 edgesUsedOnce.erase(euoIter);
00339 edgesUsedTwice.insert(curCutFaceEdge);
00340 }
00341
00342 const label curCutFaceEdgeWhich = curLocalFace.which(curCutFaceEdge.start());
00343
00344 if
00345 (
00346 curCutFaceEdgeWhich > -1
00347 && curLocalFace.nextLabel(curCutFaceEdgeWhich) == curCutFaceEdge.end()
00348 )
00349 {
00350
00351
00352 usedFaceEdges[curCutFaceEdgeWhich] = true;
00353 }
00354 else
00355 {
00356
00357
00358 edgeSeeds.append(curCutFaceEdge.reverseEdge());
00359 }
00360 }
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382 if (faceI < slavePatch_.size())
00383 {
00384 Map<labelList>::const_iterator mpfAddrIter =
00385 masterPointFaceAddr.find(cutFaceGlobal[0]);
00386
00387 bool otherSideFound = false;
00388
00389 if (mpfAddrIter != masterPointFaceAddr.end())
00390 {
00391 bool miss = false;
00392
00393
00394 const labelList& masterFacesOfPZero = mpfAddrIter();
00395
00396 labelList hits(masterFacesOfPZero.size(), 1);
00397
00398 for
00399 (
00400 label pointI = 1;
00401 pointI < cutFaceGlobal.size();
00402 pointI++
00403 )
00404 {
00405 Map<labelList>::const_iterator
00406 mpfAddrPointIter =
00407 masterPointFaceAddr.find
00408 (
00409 cutFaceGlobal[pointI]
00410 );
00411
00412 if
00413 (
00414 mpfAddrPointIter
00415 == masterPointFaceAddr.end()
00416 )
00417 {
00418
00419 miss = true;
00420 break;
00421 }
00422
00423 const labelList& curMasterFaces =
00424 mpfAddrPointIter();
00425
00426
00427
00428 forAll (curMasterFaces, i)
00429 {
00430 forAll (masterFacesOfPZero, j)
00431 {
00432 if
00433 (
00434 curMasterFaces[i]
00435 == masterFacesOfPZero[j]
00436 )
00437 {
00438 hits[j]++;
00439 break;
00440 }
00441 }
00442 }
00443 }
00444
00445
00446 if (!miss)
00447 {
00448 forAll (hits, pointI)
00449 {
00450 if (hits[pointI] == cutFaceGlobal.size())
00451 {
00452
00453 otherSideFound = true;
00454
00455 cfMaster.append
00456 (
00457 masterFacesOfPZero[pointI]
00458 );
00459
00460 cfSlave.append(faceI);
00461
00462
00463
00464 cf[cf.size() - 1] =
00465 cf[cf.size() - 1].reverseFace();
00466
00467 if (debug)
00468 {
00469 Pout<< " other side: "
00470 << masterFacesOfPZero[pointI]
00471 << endl;
00472 }
00473 }
00474 }
00475
00476 }
00477
00478 if (!otherSideFound || miss)
00479 {
00480 if (debug)
00481 {
00482 Pout << " solo slave A" << endl;
00483 }
00484
00485 cfMaster.append(-1);
00486 cfSlave.append(faceI);
00487 }
00488 }
00489 else
00490 {
00491
00492 if (debug)
00493 {
00494 Pout << " solo slave B" << endl;
00495 }
00496
00497 cfMaster.append(-1);
00498 cfSlave.append(faceI);
00499 }
00500 }
00501 else
00502 {
00503 if (debug)
00504 {
00505 Pout << " master side" << endl;
00506 }
00507
00508 cfMaster.append(faceI - slavePatch_.size());
00509 cfSlave.append(-1);
00510 }
00511 }
00512 else
00513 {
00514
00515 prevPointLabel = curPointLabel;
00516 curPointLabel = bestAtanPoint;
00517 curPoint = lp[curPointLabel];
00518 cutFaceGlobalPoints.append(mp[curPointLabel]);
00519 cutFaceLocalPoints.append(curPointLabel);
00520
00521 if (debug || cutFaceGlobalPoints.size() > faceSizeDebug)
00522 {
00523 faceSizeDebug *= 2;
00524
00525
00526 forAll (cutFaceGlobalPoints, checkI)
00527 {
00528 for
00529 (
00530 label checkJ = checkI + 1;
00531 checkJ < cutFaceGlobalPoints.size();
00532 checkJ++
00533 )
00534 {
00535 if
00536 (
00537 cutFaceGlobalPoints[checkI]
00538 == cutFaceGlobalPoints[checkJ]
00539 )
00540 {
00541
00542 cutFaceLocalPoints.shrink();
00543
00544 face origFace;
00545 face origFaceLocal;
00546 if (faceI < slavePatch_.size())
00547 {
00548 origFace = slavePatch_[faceI];
00549 origFaceLocal =
00550 slavePatch_.localFaces()[faceI];
00551 }
00552 else
00553 {
00554 origFace =
00555 masterPatch_
00556 [faceI - slavePatch_.size()];
00557
00558 origFaceLocal =
00559 masterPatch_.localFaces()
00560 [faceI - slavePatch_.size()];
00561 }
00562
00563 FatalErrorIn
00564 (
00565 "void enrichedPatch::"
00566 "calcCutFaces() const"
00567 ) << "Duplicate point found in cut face. "
00568 << "Error in the face cutting "
00569 << "algorithm for global face "
00570 << origFace << " local face "
00571 << origFaceLocal << nl
00572 << "Slave size: " << slavePatch_.size()
00573 << " Master size: "
00574 << masterPatch_.size()
00575 << " index: " << faceI << ".\n"
00576 << "Face: " << curGlobalFace << nl
00577 << "Cut face: " << cutFaceGlobalPoints
00578 << " local: " << cutFaceLocalPoints
00579 << nl << "Points: "
00580 << face(cutFaceLocalPoints).points(lp)
00581 << abort(FatalError);
00582 }
00583 }
00584 }
00585 }
00586 }
00587 } while (!completedCutFace);
00588 }
00589
00590 if (debug)
00591 {
00592 Pout << " Finished face " << faceI << endl;
00593 }
00594
00595 }
00596
00597
00598 cutFacesPtr_ = new faceList();
00599 cutFacesPtr_->transfer(cf);
00600
00601 cutFaceMasterPtr_ = new labelList();
00602 cutFaceMasterPtr_->transfer(cfMaster);
00603
00604 cutFaceSlavePtr_ = new labelList();
00605 cutFaceSlavePtr_->transfer(cfSlave);
00606 }
00607
00608
00609 void Foam::enrichedPatch::clearCutFaces()
00610 {
00611 deleteDemandDrivenData(cutFacesPtr_);
00612 deleteDemandDrivenData(cutFaceMasterPtr_);
00613 deleteDemandDrivenData(cutFaceSlavePtr_);
00614 }
00615
00616
00617
00618
00619 const Foam::faceList& Foam::enrichedPatch::cutFaces() const
00620 {
00621 if (!cutFacesPtr_)
00622 {
00623 calcCutFaces();
00624 }
00625
00626 return *cutFacesPtr_;
00627 }
00628
00629
00630 const Foam::labelList& Foam::enrichedPatch::cutFaceMaster() const
00631 {
00632 if (!cutFaceMasterPtr_)
00633 {
00634 calcCutFaces();
00635 }
00636
00637 return *cutFaceMasterPtr_;
00638 }
00639
00640
00641 const Foam::labelList& Foam::enrichedPatch::cutFaceSlave() const
00642 {
00643 if (!cutFaceSlavePtr_)
00644 {
00645 calcCutFaces();
00646 }
00647
00648 return *cutFaceSlavePtr_;
00649 }
00650
00651
00652
Copyright © 2000-2009 OpenCFD Ltd