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 "localPointRegion.H"
00028 #include "syncTools.H"
00029 #include "polyMesh.H"
00030 #include "mapPolyMesh.H"
00031 #include "globalIndex.H"
00032 #include "indirectPrimitivePatch.H"
00033
00034
00035
00036 namespace Foam
00037 {
00038
00039 defineTypeNameAndDebug(localPointRegion, 0);
00040
00041
00042 class minEqOpFace
00043 {
00044 public:
00045
00046 void operator()(face& x, const face& y) const
00047 {
00048 if (x.size())
00049 {
00050 label j = 0;
00051 forAll(x, i)
00052 {
00053 x[i] = min(x[i], y[j]);
00054
00055 j = y.rcIndex(j);
00056 }
00057 }
00058 };
00059 };
00060
00061
00062
00063 void transformList
00064 (
00065 const tensorField& rotTensor,
00066 UList<face>& field
00067 )
00068 {};
00069
00070 }
00071
00072
00073
00074
00075 bool Foam::localPointRegion::isDuplicate
00076 (
00077 const face& f0,
00078 const face& f1,
00079 const bool forward
00080 )
00081 {
00082 label fp1 = findIndex(f1, f0[0]);
00083
00084 if (fp1 == -1)
00085 {
00086 return false;
00087 }
00088
00089 forAll(f0, fp0)
00090 {
00091 if (f0[fp0] != f1[fp1])
00092 {
00093 return false;
00094 }
00095
00096 if (forward)
00097 {
00098 fp1 = f1.fcIndex(fp1);
00099 }
00100 else
00101 {
00102 fp1 = f1.rcIndex(fp1);
00103 }
00104 }
00105 return true;
00106 }
00107
00108
00109
00110 void Foam::localPointRegion::countPointRegions
00111 (
00112 const polyMesh& mesh,
00113 const boolList& candidatePoint,
00114 const Map<label>& candidateFace,
00115 faceList& minRegion
00116 )
00117 {
00118
00119
00120 labelList minPointRegion(mesh.nPoints(), -1);
00121
00122 meshPointMap_.resize(candidateFace.size()/100);
00123
00124 DynamicList<labelList> pointRegions(meshPointMap_.size());
00125
00126
00127 meshFaceMap_.resize(meshPointMap_.size());
00128
00129 forAllConstIter(Map<label>, candidateFace, iter)
00130 {
00131 label faceI = iter.key();
00132
00133 if (!mesh.isInternalFace(faceI))
00134 {
00135 const face& f = mesh.faces()[faceI];
00136
00137 if (minRegion[faceI].empty())
00138 {
00139 FatalErrorIn("localPointRegion::countPointRegions(..)")
00140 << "Face from candidateFace without minRegion set." << endl
00141 << "Face:" << faceI << " fc:" << mesh.faceCentres()[faceI]
00142 << " verts:" << f << abort(FatalError);
00143 }
00144
00145 forAll(f, fp)
00146 {
00147 label pointI = f[fp];
00148
00149
00150
00151
00152 if (candidatePoint[pointI])
00153 {
00154 label region = minRegion[faceI][fp];
00155
00156 if (minPointRegion[pointI] == -1)
00157 {
00158 minPointRegion[pointI] = region;
00159 }
00160 else if (minPointRegion[pointI] != region)
00161 {
00162
00163 Map<label>::iterator iter = meshPointMap_.find(pointI);
00164 if (iter != meshPointMap_.end())
00165 {
00166 labelList& regions = pointRegions[iter()];
00167 if (findIndex(regions, region) == -1)
00168 {
00169 label sz = regions.size();
00170 regions.setSize(sz+1);
00171 regions[sz] = region;
00172 }
00173 }
00174 else
00175 {
00176 label localPointI = meshPointMap_.size();
00177 meshPointMap_.insert(pointI, localPointI);
00178 labelList regions(2);
00179 regions[0] = minPointRegion[pointI];
00180 regions[1] = region;
00181 pointRegions.append(regions);
00182 }
00183
00184 label meshFaceMapI = meshFaceMap_.size();
00185 meshFaceMap_.insert(faceI, meshFaceMapI);
00186 }
00187 }
00188 }
00189 }
00190 }
00191 minPointRegion.clear();
00192
00193
00194
00195 forAllConstIter(Map<label>, candidateFace, iter)
00196 {
00197 label faceI = iter.key();
00198
00199 if (mesh.isInternalFace(faceI))
00200 {
00201 const face& f = mesh.faces()[faceI];
00202
00203 forAll(f, fp)
00204 {
00205
00206
00207 if (candidatePoint[f[fp]] && meshPointMap_.found(f[fp]))
00208 {
00209 label meshFaceMapI = meshFaceMap_.size();
00210 meshFaceMap_.insert(faceI, meshFaceMapI);
00211 }
00212 }
00213 }
00214 }
00215
00216
00217
00218 pointRegions.shrink();
00219 pointRegions_.setSize(pointRegions.size());
00220 forAll(pointRegions, i)
00221 {
00222 pointRegions_[i].transfer(pointRegions[i]);
00223 }
00224
00225
00226 faceRegions_.setSize(meshFaceMap_.size());
00227 forAllConstIter(Map<label>, meshFaceMap_, iter)
00228 {
00229 faceRegions_[iter()].labelList::transfer(minRegion[iter.key()]);
00230
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 }
00245
00246
00247
00248 }
00249
00250
00251 void Foam::localPointRegion::calcPointRegions
00252 (
00253 const polyMesh& mesh,
00254 boolList& candidatePoint
00255 )
00256 {
00257 label nBnd = mesh.nFaces()-mesh.nInternalFaces();
00258 const labelList& faceOwner = mesh.faceOwner();
00259 const labelList& faceNeighbour = mesh.faceNeighbour();
00260
00261
00262 syncTools::syncPointList
00263 (
00264 mesh,
00265 candidatePoint,
00266 orEqOp<bool>(),
00267 false,
00268 false
00269 );
00270
00271
00272
00273
00274
00275 Map<label> candidateFace(2*nBnd);
00276 label candidateFaceI = 0;
00277
00278 Map<label> candidateCell(nBnd);
00279 label candidateCellI = 0;
00280
00281 forAll(mesh.faces(), faceI)
00282 {
00283 const face& f = mesh.faces()[faceI];
00284
00285 forAll(f, fp)
00286 {
00287 if (candidatePoint[f[fp]])
00288 {
00289
00290 if (candidateFace.insert(faceI, candidateFaceI))
00291 {
00292 candidateFaceI++;
00293 }
00294
00295
00296 if (candidateCell.insert(faceOwner[faceI], candidateCellI))
00297 {
00298 candidateCellI++;
00299 }
00300
00301 if (mesh.isInternalFace(faceI))
00302 {
00303 label nei = faceNeighbour[faceI];
00304 if (candidateCell.insert(nei, candidateCellI))
00305 {
00306 candidateCellI++;
00307 }
00308 }
00309
00310 break;
00311 }
00312 }
00313 }
00314
00315
00316
00317
00318 globalIndex globalCells(mesh.nCells());
00319
00320
00321
00322
00323
00324
00325 faceList minRegion(mesh.nFaces());
00326 forAllConstIter(Map<label>, candidateFace, iter)
00327 {
00328 label faceI = iter.key();
00329 const face& f = mesh.faces()[faceI];
00330
00331 if (mesh.isInternalFace(faceI))
00332 {
00333 label globOwn = globalCells.toGlobal(faceOwner[faceI]);
00334 label globNei = globalCells.toGlobal(faceNeighbour[faceI]);
00335 minRegion[faceI].setSize(f.size(), min(globOwn, globNei));
00336 }
00337 else
00338 {
00339 label globOwn = globalCells.toGlobal(faceOwner[faceI]);
00340 minRegion[faceI].setSize(f.size(), globOwn);
00341 }
00342 }
00343
00344
00345
00346
00347
00348 while (true)
00349 {
00350
00351
00352
00353 Map<label> minPointValue(100);
00354 label nChanged = 0;
00355 forAllConstIter(Map<label>, candidateCell, iter)
00356 {
00357 minPointValue.clear();
00358
00359 label cellI = iter.key();
00360 const cell& cFaces = mesh.cells()[cellI];
00361
00362
00363 forAll(cFaces, cFaceI)
00364 {
00365 label faceI = cFaces[cFaceI];
00366
00367 if (minRegion[faceI].size())
00368 {
00369 const face& f = mesh.faces()[faceI];
00370
00371 forAll(f, fp)
00372 {
00373 label pointI = f[fp];
00374 Map<label>::iterator iter = minPointValue.find(pointI);
00375
00376 if (iter == minPointValue.end())
00377 {
00378 minPointValue.insert(pointI, minRegion[faceI][fp]);
00379 }
00380 else
00381 {
00382 label currentMin = iter();
00383 iter() = min(currentMin, minRegion[faceI][fp]);
00384 }
00385 }
00386 }
00387 }
00388
00389
00390 forAll(cFaces, cFaceI)
00391 {
00392 label faceI = cFaces[cFaceI];
00393
00394 if (minRegion[faceI].size())
00395 {
00396 const face& f = mesh.faces()[faceI];
00397
00398 forAll(f, fp)
00399 {
00400 label minVal = minPointValue[f[fp]];
00401
00402 if (minVal != minRegion[faceI][fp])
00403 {
00404 minRegion[faceI][fp] = minVal;
00405 nChanged++;
00406 }
00407 }
00408 }
00409 }
00410 }
00411
00412
00413
00414 if (returnReduce(nChanged, sumOp<label>()) == 0)
00415 {
00416 break;
00417 }
00418
00419
00420
00421
00422
00423 syncTools::syncFaceList
00424 (
00425 mesh,
00426 minRegion,
00427 minEqOpFace(),
00428 false
00429 );
00430 }
00431
00432
00433
00434 countPointRegions(mesh, candidatePoint, candidateFace, minRegion);
00435 minRegion.clear();
00436
00437
00439
00440
00441
00442
00443
00444
00445 }
00446
00447
00448
00449
00450 Foam::localPointRegion::localPointRegion(const polyMesh& mesh)
00451 :
00452
00453 meshPointMap_(0),
00454 pointRegions_(0),
00455 meshFaceMap_(0),
00456 faceRegions_(0)
00457 {
00458 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00459
00460
00461 boolList candidatePoint(mesh.nPoints(), false);
00462
00463 forAll(patches, patchI)
00464 {
00465 if (!patches[patchI].coupled())
00466 {
00467 const polyPatch& pp = patches[patchI];
00468
00469 forAll(pp.meshPoints(), i)
00470 {
00471 candidatePoint[pp.meshPoints()[i]] = true;
00472 }
00473 }
00474 }
00475
00476 calcPointRegions(mesh, candidatePoint);
00477 }
00478
00479
00480 Foam::localPointRegion::localPointRegion
00481 (
00482 const polyMesh& mesh,
00483 const labelList& candidatePoints
00484 )
00485 :
00486
00487 meshPointMap_(0),
00488 pointRegions_(0),
00489 meshFaceMap_(0),
00490 faceRegions_(0)
00491 {
00492 boolList candidatePoint(mesh.nPoints(), false);
00493
00494 forAll(candidatePoints, i)
00495 {
00496 candidatePoint[candidatePoints[i]] = true;
00497 }
00498
00499 calcPointRegions(mesh, candidatePoint);
00500 }
00501
00502
00503
00504
00505
00506
00507 Foam::labelList Foam::localPointRegion::findDuplicateFaces
00508 (
00509 const primitiveMesh& mesh,
00510 const labelList& boundaryFaces
00511 )
00512 {
00513
00514 indirectPrimitivePatch allPatch
00515 (
00516 IndirectList<face>(mesh.faces(), boundaryFaces),
00517 mesh.points()
00518 );
00519
00520 labelList duplicateFace(allPatch.size(), -1);
00521 label nDuplicateFaces = 0;
00522
00523
00524 forAll(allPatch, bFaceI)
00525 {
00526 const face& f = allPatch.localFaces()[bFaceI];
00527
00528
00529
00530 const labelList& pFaces = allPatch.pointFaces()[f[0]];
00531
00532 forAll(pFaces, i)
00533 {
00534 label otherFaceI = pFaces[i];
00535
00536 if (otherFaceI > bFaceI)
00537 {
00538 const face& otherF = allPatch.localFaces()[otherFaceI];
00539
00540 if (isDuplicate(f, otherF, true))
00541 {
00542 FatalErrorIn
00543 (
00544 "findDuplicateFaces(const primitiveMesh&"
00545 ", const labelList&)"
00546 ) << "Face:" << bFaceI + mesh.nInternalFaces()
00547 << " has local points:" << f
00548 << " which are in same order as face:"
00549 << otherFaceI + mesh.nInternalFaces()
00550 << " with local points:" << otherF
00551 << abort(FatalError);
00552 }
00553 else if (isDuplicate(f, otherF, false))
00554 {
00555 label meshFace0 = bFaceI + mesh.nInternalFaces();
00556 label meshFace1 = otherFaceI + mesh.nInternalFaces();
00557
00558 if
00559 (
00560 duplicateFace[bFaceI] != -1
00561 || duplicateFace[otherFaceI] != -1
00562 )
00563 {
00564 FatalErrorIn
00565 (
00566 "findDuplicateFaces(const primitiveMesh&"
00567 ", const labelList&)"
00568 ) << "One of two duplicate faces already marked"
00569 << " as duplicate." << nl
00570 << "This means that three or more faces share"
00571 << " the same points and this is illegal." << nl
00572 << "Face:" << meshFace0
00573 << " with local points:" << f
00574 << " which are in same order as face:"
00575 << meshFace1
00576 << " with local points:" << otherF
00577 << abort(FatalError);
00578 }
00579
00580 duplicateFace[bFaceI] = otherFaceI;
00581 duplicateFace[otherFaceI] = bFaceI;
00582 nDuplicateFaces++;
00583 }
00584 }
00585 }
00586 }
00587
00588 return duplicateFace;
00589 }
00590
00591
00592 void Foam::localPointRegion::updateMesh(const mapPolyMesh& map)
00593 {
00594 {
00595 Map<label> newMap(meshFaceMap_.size());
00596
00597 forAllConstIter(Map<label>, meshFaceMap_, iter)
00598 {
00599 label newFaceI = map.reverseFaceMap()[iter.key()];
00600
00601 if (newFaceI >= 0)
00602 {
00603 newMap.insert(newFaceI, iter());
00604 }
00605 }
00606 meshFaceMap_.transfer(newMap);
00607 }
00608 {
00609 Map<label> newMap(meshPointMap_.size());
00610
00611 forAllConstIter(Map<label>, meshPointMap_, iter)
00612 {
00613 label newPointI = map.reversePointMap()[iter.key()];
00614
00615 if (newPointI >= 0)
00616 {
00617 newMap.insert(newPointI, iter());
00618 }
00619 }
00620
00621 meshPointMap_.transfer(newMap);
00622 }
00623 }
00624
00625
00626