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 "faceZone.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 #include "faceZoneMesh.H"
00033 #include "polyMesh.H"
00034 #include "primitiveMesh.H"
00035 #include "demandDrivenData.H"
00036 #include "mapPolyMesh.H"
00037 #include "syncTools.H"
00038
00039
00040
00041 namespace Foam
00042 {
00043 defineTypeNameAndDebug(faceZone, 0);
00044 defineRunTimeSelectionTable(faceZone, dictionary);
00045 addToRunTimeSelectionTable(faceZone, faceZone, dictionary);
00046 }
00047
00048
00049
00050 void Foam::faceZone::calcFaceZonePatch() const
00051 {
00052 if (debug)
00053 {
00054 Info<< "void faceZone::calcFaceZonePatch() const : "
00055 << "Calculating primitive patch"
00056 << endl;
00057 }
00058
00059 if (patchPtr_)
00060 {
00061 FatalErrorIn
00062 (
00063 "void faceZone::calcFaceZonePatch() const"
00064 ) << "primitive face zone patch already calculated"
00065 << abort(FatalError);
00066 }
00067
00068 patchPtr_ =
00069 new primitiveFacePatch
00070 (
00071 faceList(size()),
00072 zoneMesh().mesh().points()
00073 );
00074
00075 primitiveFacePatch& patch = *patchPtr_;
00076
00077 const faceList& f = zoneMesh().mesh().faces();
00078
00079 const labelList& addr = *this;
00080 const boolList& flip = flipMap();
00081
00082 forAll (addr, faceI)
00083 {
00084 if (flip[faceI])
00085 {
00086 patch[faceI] = f[addr[faceI]].reverseFace();
00087 }
00088 else
00089 {
00090 patch[faceI] = f[addr[faceI]];
00091 }
00092 }
00093
00094 if (debug)
00095 {
00096 Info<< "void faceZone::calcFaceZonePatch() const : "
00097 << "Finished calculating primitive patch"
00098 << endl;
00099 }
00100 }
00101
00102
00103 const Foam::Map<Foam::label>& Foam::faceZone::faceLookupMap() const
00104 {
00105 if (!faceLookupMapPtr_)
00106 {
00107 calcFaceLookupMap();
00108 }
00109
00110 return *faceLookupMapPtr_;
00111 }
00112
00113
00114 void Foam::faceZone::calcFaceLookupMap() const
00115 {
00116 if (debug)
00117 {
00118 Info<< "void faceZone::calcFaceLookupMap() const : "
00119 << "Calculating face lookup map"
00120 << endl;
00121 }
00122
00123 if (faceLookupMapPtr_)
00124 {
00125 FatalErrorIn
00126 (
00127 "void faceZone::calcFaceLookupMap() const"
00128 ) << "face lookup map already calculated"
00129 << abort(FatalError);
00130 }
00131
00132 const labelList& addr = *this;
00133
00134 faceLookupMapPtr_ = new Map<label>(2*addr.size());
00135 Map<label>& flm = *faceLookupMapPtr_;
00136
00137 forAll (addr, faceI)
00138 {
00139 flm.insert(addr[faceI], faceI);
00140 }
00141
00142 if (debug)
00143 {
00144 Info<< "void faceZone::calcFaceLookupMap() const : "
00145 << "Finished calculating face lookup map"
00146 << endl;
00147 }
00148 }
00149
00150
00151 void Foam::faceZone::calcCellLayers() const
00152 {
00153 if (debug)
00154 {
00155 Info<< "void Foam::faceZone::calcCellLayers() const : "
00156 << "calculating master cells"
00157 << endl;
00158 }
00159
00160
00161
00162 if (masterCellsPtr_ || slaveCellsPtr_)
00163 {
00164 FatalErrorIn("void faceZone::calcCellLayers() const")
00165 << "cell layers already calculated"
00166 << abort(FatalError);
00167 }
00168 else
00169 {
00170
00171
00172
00173 const labelList& own = zoneMesh().mesh().faceOwner();
00174 const labelList& nei = zoneMesh().mesh().faceNeighbour();
00175
00176 const labelList& mf = *this;
00177
00178 const boolList& faceFlip = flipMap();
00179
00180 masterCellsPtr_ = new labelList(mf.size());
00181 labelList& mc = *masterCellsPtr_;
00182
00183 slaveCellsPtr_ = new labelList(mf.size());
00184 labelList& sc = *slaveCellsPtr_;
00185
00186 forAll (mf, faceI)
00187 {
00188 if (!faceFlip[faceI])
00189 {
00190
00191 mc[faceI] = nei[mf[faceI]];
00192 sc[faceI] = own[mf[faceI]];
00193 }
00194 else
00195 {
00196 mc[faceI] = own[mf[faceI]];
00197 sc[faceI] = nei[mf[faceI]];
00198 }
00199 }
00200
00201
00202 }
00203 }
00204
00205
00206 void Foam::faceZone::checkAddressing() const
00207 {
00208 if (size() != flipMap_.size())
00209 {
00210 FatalErrorIn("void Foam::faceZone::checkAddressing() const")
00211 << "Different sizes of the addressing and flipMap arrays. "
00212 << "Size of addressing: " << size()
00213 << " size of flip map: " << flipMap_.size()
00214 << abort(FatalError);
00215 }
00216 }
00217
00218
00219
00220
00221
00222 Foam::faceZone::faceZone
00223 (
00224 const word& name,
00225 const labelList& addr,
00226 const boolList& fm,
00227 const label index,
00228 const faceZoneMesh& zm
00229 )
00230 :
00231 labelList(addr),
00232 name_(name),
00233 flipMap_(fm),
00234 index_(index),
00235 zoneMesh_(zm),
00236 patchPtr_(NULL),
00237 masterCellsPtr_(NULL),
00238 slaveCellsPtr_(NULL),
00239 mePtr_(NULL),
00240 faceLookupMapPtr_(NULL)
00241 {
00242 checkAddressing();
00243 }
00244
00245
00246 Foam::faceZone::faceZone
00247 (
00248 const word& name,
00249 const Xfer<labelList>& addr,
00250 const Xfer<boolList>& fm,
00251 const label index,
00252 const faceZoneMesh& zm
00253 )
00254 :
00255 labelList(addr),
00256 name_(name),
00257 flipMap_(fm),
00258 index_(index),
00259 zoneMesh_(zm),
00260 patchPtr_(NULL),
00261 masterCellsPtr_(NULL),
00262 slaveCellsPtr_(NULL),
00263 mePtr_(NULL),
00264 faceLookupMapPtr_(NULL)
00265 {
00266 checkAddressing();
00267 }
00268
00269
00270
00271 Foam::faceZone::faceZone
00272 (
00273 const word& name,
00274 const dictionary& dict,
00275 const label index,
00276 const faceZoneMesh& zm
00277 )
00278 :
00279 labelList(dict.lookup("faceLabels")),
00280 name_(name),
00281 flipMap_(dict.lookup("flipMap")),
00282 index_(index),
00283 zoneMesh_(zm),
00284 patchPtr_(NULL),
00285 masterCellsPtr_(NULL),
00286 slaveCellsPtr_(NULL),
00287 mePtr_(NULL),
00288 faceLookupMapPtr_(NULL)
00289 {
00290 checkAddressing();
00291 }
00292
00293
00294
00295
00296 Foam::faceZone::faceZone
00297 (
00298 const faceZone& fz,
00299 const labelList& addr,
00300 const boolList& fm,
00301 const label index,
00302 const faceZoneMesh& zm
00303 )
00304 :
00305 labelList(addr),
00306 name_(fz.name()),
00307 flipMap_(fm),
00308 index_(index),
00309 zoneMesh_(zm),
00310 patchPtr_(NULL),
00311 masterCellsPtr_(NULL),
00312 slaveCellsPtr_(NULL),
00313 mePtr_(NULL),
00314 faceLookupMapPtr_(NULL)
00315 {
00316 checkAddressing();
00317 }
00318
00319
00320 Foam::faceZone::faceZone
00321 (
00322 const faceZone& fz,
00323 const Xfer<labelList>& addr,
00324 const Xfer<boolList>& fm,
00325 const label index,
00326 const faceZoneMesh& zm
00327 )
00328 :
00329 labelList(addr),
00330 name_(fz.name()),
00331 flipMap_(fm),
00332 index_(index),
00333 zoneMesh_(zm),
00334 patchPtr_(NULL),
00335 masterCellsPtr_(NULL),
00336 slaveCellsPtr_(NULL),
00337 mePtr_(NULL),
00338 faceLookupMapPtr_(NULL)
00339 {
00340 checkAddressing();
00341 }
00342
00343
00344
00345
00346 Foam::faceZone::~faceZone()
00347 {
00348 clearAddressing();
00349 }
00350
00351
00352
00353
00354 Foam::label Foam::faceZone::whichFace(const label globalFaceID) const
00355 {
00356 const Map<label>& flm = faceLookupMap();
00357
00358 Map<label>::const_iterator flmIter = flm.find(globalFaceID);
00359
00360 if (flmIter == flm.end())
00361 {
00362 return -1;
00363 }
00364 else
00365 {
00366 return flmIter();
00367 }
00368 }
00369
00370
00371 const Foam::faceZoneMesh& Foam::faceZone::zoneMesh() const
00372 {
00373 return zoneMesh_;
00374 }
00375
00376
00377 const Foam::primitiveFacePatch& Foam::faceZone::operator()() const
00378 {
00379 if (!patchPtr_)
00380 {
00381 calcFaceZonePatch();
00382 }
00383
00384 return *patchPtr_;
00385 }
00386
00387
00388 const Foam::labelList& Foam::faceZone::masterCells() const
00389 {
00390 if (!masterCellsPtr_)
00391 {
00392 calcCellLayers();
00393 }
00394
00395 return *masterCellsPtr_;
00396 }
00397
00398
00399 const Foam::labelList& Foam::faceZone::slaveCells() const
00400 {
00401 if (!slaveCellsPtr_)
00402 {
00403 calcCellLayers();
00404 }
00405
00406 return *slaveCellsPtr_;
00407 }
00408
00409
00410 const Foam::labelList& Foam::faceZone::meshEdges() const
00411 {
00412 if (!mePtr_)
00413 {
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436 mePtr_ =
00437 new labelList
00438 (
00439 operator()().meshEdges
00440 (
00441 zoneMesh().mesh().edges(),
00442 zoneMesh().mesh().pointEdges()
00443 )
00444 );
00445 }
00446
00447 return *mePtr_;
00448 }
00449
00450
00451 void Foam::faceZone::clearAddressing()
00452 {
00453 deleteDemandDrivenData(patchPtr_);
00454
00455 deleteDemandDrivenData(masterCellsPtr_);
00456 deleteDemandDrivenData(slaveCellsPtr_);
00457
00458 deleteDemandDrivenData(mePtr_);
00459 deleteDemandDrivenData(faceLookupMapPtr_);
00460 }
00461
00462
00463 void Foam::faceZone::resetAddressing
00464 (
00465 const labelList& addr,
00466 const boolList& flipMap
00467 )
00468 {
00469 clearAddressing();
00470 labelList::operator=(addr);
00471 flipMap_ = flipMap;
00472 }
00473
00474
00475 void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
00476 {
00477 clearAddressing();
00478
00479 labelList newAddressing(size());
00480 boolList newFlipMap(flipMap_.size());
00481 label nFaces = 0;
00482
00483 const labelList& faceMap = mpm.reverseFaceMap();
00484
00485 forAll(*this, i)
00486 {
00487 label faceI = operator[](i);
00488
00489 if (faceMap[faceI] >= 0)
00490 {
00491 newAddressing[nFaces] = faceMap[faceI];
00492 newFlipMap[nFaces] = flipMap_[i];
00493 nFaces++;
00494 }
00495 }
00496
00497 newAddressing.setSize(nFaces);
00498 newFlipMap.setSize(nFaces);
00499
00500 transfer(newAddressing);
00501 flipMap_.transfer(newFlipMap);
00502 }
00503
00504
00505 bool Foam::faceZone::checkDefinition(const bool report) const
00506 {
00507 const labelList& addr = *this;
00508
00509 bool boundaryError = false;
00510
00511 forAll(addr, i)
00512 {
00513 if (addr[i] < 0 || addr[i] >= zoneMesh().mesh().faces().size())
00514 {
00515 boundaryError = true;
00516
00517 if (report)
00518 {
00519 SeriousErrorIn
00520 (
00521 "bool faceZone::checkDefinition("
00522 "const bool report) const"
00523 ) << "Zone " << name()
00524 << " contains invalid face label " << addr[i] << nl
00525 << "Valid face labels are 0.."
00526 << zoneMesh().mesh().faces().size()-1 << endl;
00527 }
00528 }
00529 }
00530 return boundaryError;
00531 }
00532
00533
00534 bool Foam::faceZone::checkParallelSync(const bool report) const
00535 {
00536 const polyMesh& mesh = zoneMesh().mesh();
00537 const polyBoundaryMesh& bm = mesh.boundaryMesh();
00538
00539 bool boundaryError = false;
00540
00541
00542
00543
00544
00545 {
00546 boolList neiZoneFace(mesh.nFaces()-mesh.nInternalFaces(), false);
00547 boolList neiZoneFlip(mesh.nFaces()-mesh.nInternalFaces(), false);
00548 forAll(*this, i)
00549 {
00550 label faceI = operator[](i);
00551
00552 if (!mesh.isInternalFace(faceI))
00553 {
00554 neiZoneFace[faceI-mesh.nInternalFaces()] = true;
00555 neiZoneFlip[faceI-mesh.nInternalFaces()] = flipMap()[i];
00556 }
00557 }
00558 boolList myZoneFace(neiZoneFace);
00559 syncTools::swapBoundaryFaceList(mesh, neiZoneFace, false);
00560 boolList myZoneFlip(neiZoneFlip);
00561 syncTools::swapBoundaryFaceList(mesh, neiZoneFlip, false);
00562
00563 forAll(*this, i)
00564 {
00565 label faceI = operator[](i);
00566
00567 label patchI = bm.whichPatch(faceI);
00568
00569 if (patchI != -1 && bm[patchI].coupled())
00570 {
00571 label bFaceI = faceI-mesh.nInternalFaces();
00572
00573
00574 if (myZoneFace[bFaceI] != neiZoneFace[bFaceI])
00575 {
00576 boundaryError = true;
00577
00578 if (report)
00579 {
00580 Pout<< " ***Problem with faceZone " << index()
00581 << " named " << name()
00582 << ". Face " << faceI
00583 << " on coupled patch "
00584 << bm[patchI].name()
00585 << " is not consistent with its coupled neighbour."
00586 << endl;
00587 }
00588 }
00589
00590
00591 if (myZoneFlip[bFaceI] == neiZoneFlip[bFaceI])
00592 {
00593 boundaryError = true;
00594
00595 if (report)
00596 {
00597 Pout<< " ***Problem with faceZone " << index()
00598 << " named " << name()
00599 << ". Face " << faceI
00600 << " on coupled patch "
00601 << bm[patchI].name()
00602 << " does not have consistent flipMap"
00603 << " across coupled faces."
00604 << endl;
00605 }
00606 }
00607 }
00608 }
00609 }
00610
00611 return returnReduce(boundaryError, orOp<bool>());
00612 }
00613
00614
00615 void Foam::faceZone::movePoints(const pointField& p)
00616 {
00617 if (patchPtr_)
00618 {
00619 patchPtr_->movePoints(p);
00620 }
00621 }
00622
00623 void Foam::faceZone::write(Ostream& os) const
00624 {
00625 os << nl << name()
00626 << nl << static_cast<const labelList&>(*this)
00627 << nl << flipMap();
00628 }
00629
00630
00631 void Foam::faceZone::writeDict(Ostream& os) const
00632 {
00633 os << nl << name() << nl << token::BEGIN_BLOCK << nl
00634 << " type " << type() << token::END_STATEMENT << nl;
00635
00636 writeEntry("faceLabels", os);
00637 flipMap().writeEntry("flipMap", os);
00638
00639 os << token::END_BLOCK << endl;
00640 }
00641
00642
00643
00644
00645 Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& p)
00646 {
00647 p.write(os);
00648 os.check("Ostream& operator<<(Ostream& f, const faceZone& p");
00649 return os;
00650 }
00651
00652
00653