/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "polyBoundaryMesh.H" #include "polyMesh.H" #include "primitiveMesh.H" #include "processorPolyPatch.H" #include "stringListOps.H" #include "PstreamBuffers.H" #include "lduSchedule.H" #include "globalMeshData.H" #include "stringListOps.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(polyBoundaryMesh, 0); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::polyBoundaryMesh::polyBoundaryMesh ( const IOobject& io, const polyMesh& mesh ) : polyPatchList(), regIOobject(io), mesh_(mesh) { if ( readOpt() == IOobject::MUST_READ || readOpt() == IOobject::MUST_READ_IF_MODIFIED ) { if (readOpt() == IOobject::MUST_READ_IF_MODIFIED) { WarningInFunction << "Specified IOobject::MUST_READ_IF_MODIFIED but class" << " does not support automatic rereading." << endl; } polyPatchList& patches = *this; // Read polyPatchList Istream& is = readStream(typeName); PtrList patchEntries(is); patches.setSize(patchEntries.size()); forAll(patches, patchi) { patches.set ( patchi, polyPatch::New ( patchEntries[patchi].keyword(), patchEntries[patchi].dict(), patchi, *this ) ); } // Check state of IOstream is.check ( "polyBoundaryMesh::polyBoundaryMesh" "(const IOobject&, const polyMesh&)" ); close(); } } Foam::polyBoundaryMesh::polyBoundaryMesh ( const IOobject& io, const polyMesh& pm, const label size ) : polyPatchList(size), regIOobject(io), mesh_(pm) {} Foam::polyBoundaryMesh::polyBoundaryMesh ( const IOobject& io, const polyMesh& pm, const polyPatchList& ppl ) : polyPatchList(), regIOobject(io), mesh_(pm) { if ( (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk()) || this->readOpt() == IOobject::MUST_READ || this->readOpt() == IOobject::MUST_READ_IF_MODIFIED ) { if (readOpt() == IOobject::MUST_READ_IF_MODIFIED) { WarningInFunction << "Specified IOobject::MUST_READ_IF_MODIFIED but class" << " does not support automatic rereading." << endl; } polyPatchList& patches = *this; // Read polyPatchList Istream& is = readStream(typeName); PtrList patchEntries(is); patches.setSize(patchEntries.size()); forAll(patches, patchi) { patches.set ( patchi, polyPatch::New ( patchEntries[patchi].keyword(), patchEntries[patchi].dict(), patchi, *this ) ); } // Check state of IOstream is.check ( "polyBoundaryMesh::polyBoundaryMesh" "(const IOobject&, const polyMesh&, const polyPatchList&)" ); close(); } else { polyPatchList& patches = *this; patches.setSize(ppl.size()); forAll(patches, patchi) { patches.set(patchi, ppl[patchi].clone(*this).ptr()); } } } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::polyBoundaryMesh::~polyBoundaryMesh() {} void Foam::polyBoundaryMesh::clearGeom() { forAll(*this, patchi) { if (this->set(patchi)) { operator[](patchi).clearGeom(); } } } void Foam::polyBoundaryMesh::clearAddressing() { nbrEdgesPtr_.clear(); patchIndicesPtr_.clear(); patchFaceIndicesPtr_.clear(); groupPatchIndicesPtr_.clear(); forAll(*this, patchi) { if (this->set(patchi)) { operator[](patchi).clearAddressing(); } } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::polyBoundaryMesh::calcGeometry() { PstreamBuffers pBufs(Pstream::defaultCommsType); if ( Pstream::defaultCommsType == Pstream::commsTypes::blocking || Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking ) { forAll(*this, patchi) { operator[](patchi).initCalcGeometry(pBufs); } pBufs.finishedSends(); forAll(*this, patchi) { operator[](patchi).calcGeometry(pBufs); } } else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled) { const lduSchedule& patchSchedule = mesh().globalData().patchSchedule(); // Dummy. pBufs.finishedSends(); forAll(patchSchedule, patchEvali) { const label patchi = patchSchedule[patchEvali].patch; if (patchSchedule[patchEvali].init) { operator[](patchi).initCalcGeometry(pBufs); } else { operator[](patchi).calcGeometry(pBufs); } } } } const Foam::List& Foam::polyBoundaryMesh::nbrEdges() const { if (Pstream::parRun()) { WarningInFunction << "Neighbour edge addressing not correct across parallel" << " boundaries." << endl; } if (!nbrEdgesPtr_.valid()) { nbrEdgesPtr_.reset(new List(size())); List& nbrEdges = nbrEdgesPtr_(); // Initialise. label nEdgePairs = 0; forAll(*this, patchi) { const polyPatch& pp = operator[](patchi); nbrEdges[patchi].setSize(pp.nEdges() - pp.nInternalEdges()); forAll(nbrEdges[patchi], i) { labelPair& edgeInfo = nbrEdges[patchi][i]; edgeInfo[0] = -1; edgeInfo[1] = -1; } nEdgePairs += pp.nEdges() - pp.nInternalEdges(); } // From mesh edge (expressed as a point pair so as not to construct // point addressing) to patch + relative edge index. HashTable> pointsToEdge(nEdgePairs); forAll(*this, patchi) { const polyPatch& pp = operator[](patchi); const edgeList& edges = pp.edges(); for ( label edgei = pp.nInternalEdges(); edgei < edges.size(); edgei++ ) { // Edge in patch local points const edge& e = edges[edgei]; // Edge in mesh points. edge meshEdge(pp.meshPoints()[e[0]], pp.meshPoints()[e[1]]); HashTable>::iterator fnd = pointsToEdge.find(meshEdge); if (fnd == pointsToEdge.end()) { // First occurrence of mesh edge. Store patch and my // local index. pointsToEdge.insert ( meshEdge, labelPair ( patchi, edgei - pp.nInternalEdges() ) ); } else { // Second occurrence. Store. const labelPair& edgeInfo = fnd(); nbrEdges[patchi][edgei - pp.nInternalEdges()] = edgeInfo; nbrEdges[edgeInfo[0]][edgeInfo[1]] = labelPair(patchi, edgei - pp.nInternalEdges()); // Found all two occurrences of this edge so remove from // hash to save space. Note that this will give lots of // problems if the polyBoundaryMesh is multiply connected. pointsToEdge.erase(meshEdge); } } } if (pointsToEdge.size()) { FatalErrorInFunction << "Not all boundary edges of patches match up." << nl << "Is the outside of your mesh multiply connected?" << abort(FatalError); } forAll(*this, patchi) { const polyPatch& pp = operator[](patchi); const labelPairList& nbrEdgesp = nbrEdges[patchi]; forAll(nbrEdgesp, i) { const labelPair& edgeInfo = nbrEdgesp[i]; if (edgeInfo[0] == -1 || edgeInfo[1] == -1) { label edgeI = pp.nInternalEdges() + i; const edge& e = pp.edges()[edgeI]; FatalErrorInFunction << "Not all boundary edges of patches match up." << nl << "Edge " << edgeI << " on patch " << pp.name() << " end points " << pp.localPoints()[e[0]] << ' ' << pp.localPoints()[e[1]] << " is not matched to an" << " edge on any other patch." << nl << "Is the outside of your mesh multiply connected?" << abort(FatalError); } } } } return nbrEdgesPtr_(); } const Foam::labelList& Foam::polyBoundaryMesh::patchIndices() const { if (!patchIndicesPtr_.valid()) { patchIndicesPtr_.reset ( new labelList ( mesh_.nFaces() - mesh_.nInternalFaces() ) ); labelList& patchIndices = patchIndicesPtr_(); const polyBoundaryMesh& bm = *this; forAll(bm, patchi) { label bFacei = bm[patchi].start() - mesh_.nInternalFaces(); forAll(bm[patchi], i) { patchIndices[bFacei++] = patchi; } } } return patchIndicesPtr_(); } const Foam::labelList& Foam::polyBoundaryMesh::patchFaceIndices() const { if (!patchFaceIndicesPtr_.valid()) { patchFaceIndicesPtr_.reset ( new labelList ( mesh_.nFaces() - mesh_.nInternalFaces() ) ); labelList& patchFaceID = patchFaceIndicesPtr_(); const polyBoundaryMesh& bm = *this; forAll(bm, patchi) { label bFacei = bm[patchi].start() - mesh_.nInternalFaces(); forAll(bm[patchi], i) { patchFaceID[bFacei++] = i; } } } return patchFaceIndicesPtr_(); } const Foam::HashTable& Foam::polyBoundaryMesh::groupPatchIndices() const { if (!groupPatchIndicesPtr_.valid()) { groupPatchIndicesPtr_.reset(new HashTable(10)); HashTable& groupPatchIndices = groupPatchIndicesPtr_(); const polyBoundaryMesh& bm = *this; forAll(bm, patchi) { const wordList& groups = bm[patchi].inGroups(); forAll(groups, i) { const word& name = groups[i]; HashTable::iterator iter ( groupPatchIndices.find ( name ) ); if (iter != groupPatchIndices.end()) { iter().append(patchi); } else { groupPatchIndices.insert(name, labelList(1, patchi)); } } } // Remove patch names from patchGroups forAll(bm, patchi) { if (groupPatchIndices.erase(bm[patchi].name())) { WarningInFunction << "Removing patchGroup '" << bm[patchi].name() << "' which clashes with patch " << patchi << " of the same name." << endl; } } } return groupPatchIndicesPtr_(); } void Foam::polyBoundaryMesh::setGroup ( const word& groupName, const labelList& patchIndices ) { groupPatchIndicesPtr_.clear(); polyPatchList& patches = *this; boolList donePatch(patches.size(), false); // Add to specified patches forAll(patchIndices, i) { label patchi = patchIndices[i]; polyPatch& pp = patches[patchi]; if (!pp.inGroup(groupName)) { pp.inGroups().append(groupName); } donePatch[patchi] = true; } // Remove from other patches forAll(patches, patchi) { if (!donePatch[patchi]) { polyPatch& pp = patches[patchi]; label newI = 0; if (pp.inGroup(groupName)) { wordList& groups = pp.inGroups(); forAll(groups, i) { if (groups[i] != groupName) { groups[newI++] = groups[i]; } } groups.setSize(newI); } } } } Foam::wordList Foam::polyBoundaryMesh::toc() const { const polyPatchList& patches = *this; wordList t(patches.size()); forAll(patches, patchi) { t[patchi] = patches[patchi].name(); } return t; } Foam::wordList Foam::polyBoundaryMesh::names() const { return toc(); } Foam::wordList Foam::polyBoundaryMesh::types() const { const polyPatchList& patches = *this; wordList t(patches.size()); forAll(patches, patchi) { t[patchi] = patches[patchi].type(); } return t; } Foam::wordList Foam::polyBoundaryMesh::physicalTypes() const { const polyPatchList& patches = *this; wordList t(patches.size()); forAll(patches, patchi) { t[patchi] = patches[patchi].physicalType(); } return t; } Foam::labelList Foam::polyBoundaryMesh::findIndices ( const wordRe& key, const bool usePatchGroups ) const { DynamicList