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 "polyBoundaryMesh.H"
00028 #include "polyMesh.H"
00029 #include "primitiveMesh.H"
00030 #include "processorPolyPatch.H"
00031 #include "stringListOps.H"
00032
00033
00034
00035 defineTypeNameAndDebug(Foam::polyBoundaryMesh, 0);
00036
00037
00038
00039
00040 Foam::labelList Foam::polyBoundaryMesh::ident(const label len)
00041 {
00042 labelList elems(len);
00043 forAll(elems, elemI)
00044 {
00045 elems[elemI] = elemI;
00046 }
00047 return elems;
00048 }
00049
00050
00051
00052
00053 Foam::polyBoundaryMesh::polyBoundaryMesh
00054 (
00055 const IOobject& io,
00056 const polyMesh& mesh
00057 )
00058 :
00059 polyPatchList(),
00060 regIOobject(io),
00061 mesh_(mesh),
00062 neighbourEdgesPtr_(NULL)
00063 {
00064 if (readOpt() == IOobject::MUST_READ)
00065 {
00066 polyPatchList& patches = *this;
00067
00068
00069 Istream& is = readStream(typeName);
00070
00071 PtrList<entry> patchEntries(is);
00072 patches.setSize(patchEntries.size());
00073
00074 forAll(patches, patchI)
00075 {
00076 patches.set
00077 (
00078 patchI,
00079 polyPatch::New
00080 (
00081 patchEntries[patchI].keyword(),
00082 patchEntries[patchI].dict(),
00083 patchI,
00084 *this
00085 )
00086 );
00087 }
00088
00089
00090 is.check
00091 (
00092 "polyBoundaryMesh::polyBoundaryMesh"
00093 "(const IOobject&, const polyMesh&)"
00094 );
00095
00096 close();
00097 }
00098 }
00099
00100
00101 Foam::polyBoundaryMesh::polyBoundaryMesh
00102 (
00103 const IOobject& io,
00104 const polyMesh& pm,
00105 const label size
00106 )
00107 :
00108 polyPatchList(size),
00109 regIOobject(io),
00110 mesh_(pm),
00111 neighbourEdgesPtr_(NULL)
00112 {}
00113
00114
00115
00116
00117 Foam::polyBoundaryMesh::~polyBoundaryMesh()
00118 {
00119 deleteDemandDrivenData(neighbourEdgesPtr_);
00120 }
00121
00122
00123 void Foam::polyBoundaryMesh::clearGeom()
00124 {
00125 forAll (*this, patchi)
00126 {
00127 operator[](patchi).clearGeom();
00128 }
00129 }
00130
00131
00132 void Foam::polyBoundaryMesh::clearAddressing()
00133 {
00134 deleteDemandDrivenData(neighbourEdgesPtr_);
00135
00136 forAll (*this, patchi)
00137 {
00138 operator[](patchi).clearAddressing();
00139 }
00140 }
00141
00142
00143
00144
00145 void Foam::polyBoundaryMesh::calcGeometry()
00146 {
00147 forAll(*this, patchi)
00148 {
00149 operator[](patchi).initGeometry();
00150 }
00151
00152 forAll(*this, patchi)
00153 {
00154 operator[](patchi).calcGeometry();
00155 }
00156 }
00157
00158
00159 const Foam::List<Foam::labelPairList>&
00160 Foam::polyBoundaryMesh::neighbourEdges() const
00161 {
00162 if (Pstream::parRun())
00163 {
00164 WarningIn("polyBoundaryMesh::neighbourEdges() const")
00165 << "Neighbour edge addressing not correct across parallel"
00166 << " boundaries." << endl;
00167 }
00168
00169 if (!neighbourEdgesPtr_)
00170 {
00171 neighbourEdgesPtr_ = new List<labelPairList>(size());
00172 List<labelPairList>& neighbourEdges = *neighbourEdgesPtr_;
00173
00174
00175 label nEdgePairs = 0;
00176 forAll(*this, patchi)
00177 {
00178 const polyPatch& pp = operator[](patchi);
00179
00180 neighbourEdges[patchi].setSize(pp.nEdges() - pp.nInternalEdges());
00181
00182 forAll(neighbourEdges[patchi], i)
00183 {
00184 labelPair& edgeInfo = neighbourEdges[patchi][i];
00185
00186 edgeInfo[0] = -1;
00187 edgeInfo[1] = -1;
00188 }
00189
00190 nEdgePairs += pp.nEdges() - pp.nInternalEdges();
00191 }
00192
00193
00194
00195 HashTable<labelPair, edge, Hash<edge> > pointsToEdge(nEdgePairs);
00196
00197 forAll(*this, patchi)
00198 {
00199 const polyPatch& pp = operator[](patchi);
00200
00201 const edgeList& edges = pp.edges();
00202
00203 for
00204 (
00205 label edgei = pp.nInternalEdges();
00206 edgei < edges.size();
00207 edgei++
00208 )
00209 {
00210
00211 const edge& e = edges[edgei];
00212
00213
00214 edge meshEdge(pp.meshPoints()[e[0]], pp.meshPoints()[e[1]]);
00215
00216 HashTable<labelPair, edge, Hash<edge> >::iterator fnd =
00217 pointsToEdge.find(meshEdge);
00218
00219 if (fnd == pointsToEdge.end())
00220 {
00221
00222
00223 pointsToEdge.insert
00224 (
00225 meshEdge,
00226 labelPair
00227 (
00228 patchi,
00229 edgei - pp.nInternalEdges()
00230 )
00231 );
00232 }
00233 else
00234 {
00235
00236 const labelPair& edgeInfo = fnd();
00237
00238 neighbourEdges[patchi][edgei - pp.nInternalEdges()] =
00239 edgeInfo;
00240
00241 neighbourEdges[edgeInfo[0]][edgeInfo[1]]
00242 = labelPair(patchi, edgei - pp.nInternalEdges());
00243
00244
00245
00246
00247 pointsToEdge.erase(meshEdge);
00248 }
00249 }
00250 }
00251
00252 if (pointsToEdge.size())
00253 {
00254 FatalErrorIn("polyBoundaryMesh::neighbourEdges() const")
00255 << "Not all boundary edges of patches match up." << nl
00256 << "Is the outside of your mesh multiply connected?"
00257 << abort(FatalError);
00258 }
00259
00260 forAll(*this, patchi)
00261 {
00262 const polyPatch& pp = operator[](patchi);
00263
00264 const labelPairList& nbrEdges = neighbourEdges[patchi];
00265
00266 forAll(nbrEdges, i)
00267 {
00268 const labelPair& edgeInfo = nbrEdges[i];
00269
00270 if (edgeInfo[0] == -1 || edgeInfo[1] == -1)
00271 {
00272 label edgeI = pp.nInternalEdges() + i;
00273 const edge& e = pp.edges()[edgeI];
00274
00275 FatalErrorIn("polyBoundaryMesh::neighbourEdges() const")
00276 << "Not all boundary edges of patches match up." << nl
00277 << "Edge " << edgeI << " on patch " << pp.name()
00278 << " end points " << pp.localPoints()[e[0]] << ' '
00279 << pp.localPoints()[e[1]] << " is not matched to an"
00280 << " edge on any other patch." << nl
00281 << "Is the outside of your mesh multiply connected?"
00282 << abort(FatalError);
00283 }
00284 }
00285 }
00286 }
00287
00288 return *neighbourEdgesPtr_;
00289 }
00290
00291
00292 Foam::wordList Foam::polyBoundaryMesh::names() const
00293 {
00294 const polyPatchList& patches = *this;
00295
00296 wordList t(patches.size());
00297
00298 forAll (patches, patchI)
00299 {
00300 t[patchI] = patches[patchI].name();
00301 }
00302
00303 return t;
00304 }
00305
00306
00307 Foam::wordList Foam::polyBoundaryMesh::types() const
00308 {
00309 const polyPatchList& patches = *this;
00310
00311 wordList t(patches.size());
00312
00313 forAll (patches, patchI)
00314 {
00315 t[patchI] = patches[patchI].type();
00316 }
00317
00318 return t;
00319 }
00320
00321
00322 Foam::wordList Foam::polyBoundaryMesh::physicalTypes() const
00323 {
00324 const polyPatchList& patches = *this;
00325
00326 wordList t(patches.size());
00327
00328 forAll (patches, patchI)
00329 {
00330 t[patchI] = patches[patchI].physicalType();
00331 }
00332
00333 return t;
00334 }
00335
00336
00337 Foam::label Foam::polyBoundaryMesh::findPatchID(const word& patchName) const
00338 {
00339 const polyPatchList& patches = *this;
00340
00341 forAll (patches, patchI)
00342 {
00343 if (patches[patchI].name() == patchName)
00344 {
00345 return patchI;
00346 }
00347 }
00348
00349
00350 if (debug)
00351 {
00352 Pout<< "label polyBoundaryMesh::findPatchID(const word& "
00353 << "patchName) const"
00354 << "Patch named " << patchName << " not found. "
00355 << "List of available patch names: " << names() << endl;
00356 }
00357
00358
00359 return -1;
00360 }
00361
00362
00363 Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const
00364 {
00365
00366
00367
00368
00369 if (faceIndex >= mesh().nFaces())
00370 {
00371 FatalErrorIn
00372 (
00373 "polyBoundaryMesh::whichPatch(const label faceIndex) const"
00374 ) << "given label greater than the number of geometric faces"
00375 << abort(FatalError);
00376 }
00377
00378 if (faceIndex < mesh().nInternalFaces())
00379 {
00380 return -1;
00381 }
00382
00383 forAll (*this, patchI)
00384 {
00385 const polyPatch& bp = operator[](patchI);
00386
00387 if
00388 (
00389 faceIndex >= bp.start()
00390 && faceIndex < bp.start() + bp.size()
00391 )
00392 {
00393 return patchI;
00394 }
00395 }
00396
00397
00398 FatalErrorIn
00399 (
00400 "label polyBoundaryMesh::whichPatch(const label faceIndex) const"
00401 ) << "Cannot find face " << faceIndex << " in any of the patches "
00402 << names() << nl
00403 << "It seems your patches are not consistent with the mesh :"
00404 << " internalFaces:" << mesh().nInternalFaces()
00405 << " total number of faces:" << mesh().nFaces()
00406 << abort(FatalError);
00407
00408 return -1;
00409 }
00410
00411
00412 Foam::labelHashSet Foam::polyBoundaryMesh::patchSet
00413 (
00414 const wordList& patchNames
00415 ) const
00416 {
00417 wordList allPatchNames = names();
00418 labelHashSet ps(size());
00419
00420 forAll(patchNames, i)
00421 {
00422
00423
00424 labelList patchIDs = findStrings(patchNames[i], allPatchNames);
00425
00426 if (patchIDs.empty())
00427 {
00428 WarningIn("polyBoundaryMesh::patchSet(const wordList&)")
00429 << "Cannot find any patch names matching " << patchNames[i]
00430 << endl;
00431 }
00432
00433 forAll(patchIDs, j)
00434 {
00435 ps.insert(patchIDs[j]);
00436 }
00437 }
00438
00439 return ps;
00440 }
00441
00442
00443 bool Foam::polyBoundaryMesh::checkParallelSync(const bool report) const
00444 {
00445 if (!Pstream::parRun())
00446 {
00447 return false;
00448 }
00449
00450
00451 const polyBoundaryMesh& bm = *this;
00452
00453 bool boundaryError = false;
00454
00455
00456 wordList names(bm.size());
00457 wordList types(bm.size());
00458
00459 label nonProcI = 0;
00460
00461 forAll (bm, patchI)
00462 {
00463 if (!isA<processorPolyPatch>(bm[patchI]))
00464 {
00465 if (nonProcI != patchI)
00466 {
00467
00468 boundaryError = true;
00469
00470 if (debug || report)
00471 {
00472 Pout<< " ***Problem with boundary patch " << patchI
00473 << " named " << bm[patchI].name()
00474 << " of type " << bm[patchI].type()
00475 << ". The patch seems to be preceeded by processor"
00476 << " patches. This is can give problems."
00477 << endl;
00478 }
00479 }
00480 else
00481 {
00482 names[nonProcI] = bm[patchI].name();
00483 types[nonProcI] = bm[patchI].type();
00484 nonProcI++;
00485 }
00486 }
00487 }
00488 names.setSize(nonProcI);
00489 types.setSize(nonProcI);
00490
00491 List<wordList> allNames(Pstream::nProcs());
00492 allNames[Pstream::myProcNo()] = names;
00493 Pstream::gatherList(allNames);
00494 Pstream::scatterList(allNames);
00495
00496 List<wordList> allTypes(Pstream::nProcs());
00497 allTypes[Pstream::myProcNo()] = types;
00498 Pstream::gatherList(allTypes);
00499 Pstream::scatterList(allTypes);
00500
00501
00502
00503 for (label procI = 1; procI < allNames.size(); procI++)
00504 {
00505 if
00506 (
00507 (allNames[procI] != allNames[0])
00508 || (allTypes[procI] != allTypes[0])
00509 )
00510 {
00511 boundaryError = true;
00512
00513 if (debug || (report && Pstream::master()))
00514 {
00515 Info<< " ***Inconsistent patches across processors, "
00516 "processor 0 has patch names:" << allNames[0]
00517 << " patch types:" << allTypes[0]
00518 << " processor " << procI << " has patch names:"
00519 << allNames[procI]
00520 << " patch types:" << allTypes[procI]
00521 << endl;
00522 }
00523 }
00524 }
00525
00526 return boundaryError;
00527 }
00528
00529
00530 bool Foam::polyBoundaryMesh::checkDefinition(const bool report) const
00531 {
00532 label nextPatchStart = mesh().nInternalFaces();
00533 const polyBoundaryMesh& bm = *this;
00534
00535 bool boundaryError = false;
00536
00537 forAll (bm, patchI)
00538 {
00539 if (bm[patchI].start() != nextPatchStart && !boundaryError)
00540 {
00541 boundaryError = true;
00542
00543 Info<< " ****Problem with boundary patch " << patchI
00544 << " named " << bm[patchI].name()
00545 << " of type " << bm[patchI].type()
00546 << ". The patch should start on face no " << nextPatchStart
00547 << " and the patch specifies " << bm[patchI].start()
00548 << "." << endl
00549 << "Possibly consecutive patches have this same problem."
00550 << " Suppressing future warnings." << endl;
00551 }
00552
00553 nextPatchStart += bm[patchI].size();
00554 }
00555
00556 reduce(boundaryError, orOp<bool>());
00557
00558 if (boundaryError)
00559 {
00560 if (debug || report)
00561 {
00562 Pout << " ***Boundary definition is in error." << endl;
00563 }
00564
00565 return true;
00566 }
00567 else
00568 {
00569 if (debug || report)
00570 {
00571 Info << " Boundary definition OK." << endl;
00572 }
00573
00574 return false;
00575 }
00576 }
00577
00578
00579 void Foam::polyBoundaryMesh::movePoints(const pointField& p)
00580 {
00581 polyPatchList& patches = *this;
00582
00583 forAll(patches, patchi)
00584 {
00585 patches[patchi].initMovePoints(p);
00586 }
00587
00588 forAll(patches, patchi)
00589 {
00590 patches[patchi].movePoints(p);
00591 }
00592 }
00593
00594
00595 void Foam::polyBoundaryMesh::updateMesh()
00596 {
00597 deleteDemandDrivenData(neighbourEdgesPtr_);
00598
00599 polyPatchList& patches = *this;
00600
00601 forAll(patches, patchi)
00602 {
00603 patches[patchi].initUpdateMesh();
00604 }
00605
00606 forAll(patches, patchi)
00607 {
00608 patches[patchi].updateMesh();
00609 }
00610 }
00611
00612
00613 void Foam::polyBoundaryMesh::reorder(const UList<label>& oldToNew)
00614 {
00615
00616 polyPatchList::reorder(oldToNew);
00617
00618
00619 polyPatchList& patches = *this;
00620
00621 forAll(patches, patchi)
00622 {
00623 patches[patchi].index() = patchi;
00624 }
00625
00626 updateMesh();
00627 }
00628
00629
00630 bool Foam::polyBoundaryMesh::writeData(Ostream& os) const
00631 {
00632 const polyPatchList& patches = *this;
00633
00634 os << patches.size() << nl << token::BEGIN_LIST << incrIndent << nl;
00635
00636 forAll(patches, patchi)
00637 {
00638 os << indent << patches[patchi].name() << nl
00639 << indent << token::BEGIN_BLOCK << nl
00640 << incrIndent << patches[patchi] << decrIndent
00641 << indent << token::END_BLOCK << endl;
00642 }
00643
00644 os << decrIndent << token::END_LIST;
00645
00646
00647 os.check("polyBoundaryMesh::writeData(Ostream& os) const");
00648
00649 return os.good();
00650 }
00651
00652
00653 bool Foam::polyBoundaryMesh::writeObject
00654 (
00655 IOstream::streamFormat fmt,
00656 IOstream::versionNumber ver,
00657 IOstream::compressionType cmp
00658 ) const
00659 {
00660 return regIOobject::writeObject(fmt, ver, IOstream::UNCOMPRESSED);
00661 }
00662
00663
00664
00665
00666 Foam::Ostream& Foam::operator<<(Ostream& os, const polyBoundaryMesh& pbm)
00667 {
00668 pbm.writeData(os);
00669 return os;
00670 }
00671
00672
00673