From f85dbc557f5ec42bcbd9ebce75391a5351bf3265 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Tue, 1 Dec 2020 15:31:12 +0000 Subject: [PATCH] polyBoundaryMesh: Update indices in neighbour patches on reorder --- .../splitMeshRegions/splitMeshRegions.C | 26 +++++++----------- .../Identifiers/patch/patchIdentifier.H | 24 +++++------------ .../polyBoundaryMesh/polyBoundaryMesh.C | 27 ++++++++++++++++--- .../polyBoundaryMesh/polyBoundaryMesh.H | 21 ++++++++++----- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 4 +-- .../constraint/cyclic/cyclicPolyPatch.C | 17 ++++++++++++ .../constraint/cyclic/cyclicPolyPatch.H | 7 +++++ .../polyPatches/polyPatch/polyPatch.C | 13 +++++++++ .../polyPatches/polyPatch/polyPatch.H | 6 +++++ .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.C | 17 ++++++++++++ .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.H | 6 +++++ 11 files changed, 123 insertions(+), 45 deletions(-) diff --git a/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C b/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C index 0225035d14..57183aad8a 100644 --- a/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C +++ b/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C @@ -121,27 +121,19 @@ void renamePatches const labelList& patchesToRename ) { - polyBoundaryMesh& polyPatches = + polyBoundaryMesh& patches = const_cast(mesh.boundaryMesh()); + + // Create a list of all the new names + wordList newNames = patches.names(); forAll(patchesToRename, i) { - label patchi = patchesToRename[i]; - polyPatch& pp = polyPatches[patchi]; - - if (isA(pp)) - { - WarningInFunction - << "Encountered coupled patch " << pp.name() - << ". Will only rename the patch itself," - << " not any referred patches." - << " This might have to be done by hand." - << endl; - } - - pp.name() = prefix + '_' + pp.name(); + const label patchi = patchesToRename[i]; + newNames[patchi] = prefix + '_' + newNames[patchi]; } - // Recalculate any demand driven data (e.g. group to name lookup) - polyPatches.updateMesh(); + + // Apply to the patches + patches.renamePatches(newNames, true); } diff --git a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H index 763a3e9180..acaa86fade 100644 --- a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H +++ b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H @@ -57,7 +57,9 @@ Ostream& operator<<(Ostream&, const patchIdentifier&); class patchIdentifier { - // Private Data +protected: + + // Protected Data //- Name of patch word name_; @@ -66,7 +68,7 @@ class patchIdentifier label index_; //- Optional physical type - mutable word physicalType_; + word physicalType_; //- Optional groups patch belongs to wordList inGroups_; @@ -113,10 +115,10 @@ public: return name_; } - //- Return name for modification - word& name() + //- Return the index of this patch in the boundaryMesh + label index() const { - return name_; + return index_; } //- Return the optional physical type of the patch @@ -131,18 +133,6 @@ public: return physicalType_; } - //- Return the index of this patch in the boundaryMesh - label index() const - { - return index_; - } - - //- Return the index of this patch in the boundaryMesh for modification - label& index() - { - return index_; - } - //- Return the optional groups patch belongs to const wordList& inGroups() const { diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 68822e6c8d..4f82120ee7 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -1106,7 +1106,29 @@ void Foam::polyBoundaryMesh::updateMesh() } -void Foam::polyBoundaryMesh::shuffle +void Foam::polyBoundaryMesh::renamePatches +( + const wordUList& newNames, + const bool validBoundary +) +{ + polyPatchList& patches = *this; + forAll(patches, patchi) + { + if (patches.set(patchi)) + { + patches[patchi].rename(newNames); + } + } + + if (validBoundary) + { + updateMesh(); + } +} + + +void Foam::polyBoundaryMesh::reorderPatches ( const labelUList& newToOld, const bool validBoundary @@ -1117,12 +1139,11 @@ void Foam::polyBoundaryMesh::shuffle // Adapt indices polyPatchList& patches = *this; - forAll(patches, patchi) { if (patches.set(patchi)) { - patches[patchi].index() = patchi; + patches[patchi].reorder(newToOld); } } diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index cdd9f1ae97..da1429a14b 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -221,12 +221,21 @@ public: //- Correct polyBoundaryMesh after topology update void updateMesh(); - //- Reorders patches. Ordering does not have to be done in - // ascending or descending order. Reordering has to be unique. - // (is shuffle) If validBoundary calls updateMesh() - // after reordering to recalculate data (so call needs to be parallel - // sync in that case) - void shuffle(const labelUList& newToOld, const bool validBoundary); + //- Rename the patches. If validBoundary is set this calls updateMesh() + // after reordering to recalculate data (so the call needs to be + // parallel synchronised). + void renamePatches(const wordUList& newNames, const bool validBoundary); + + //- Reorders the patches. Ordering does not have to be done in + // ascending or descending order. Reordering has to be unique (is a + // shuffle). If validBoundary is set this calls updateMesh() after + // reordering to recalculate data (so the call needs to be parallel + // synchronised). + void reorderPatches + ( + const labelUList& newToOld, + const bool validBoundary + ); //- writeData member function required by regIOobject bool writeData(Ostream&) const; diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index c072936fd3..f6165ddc35 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -1037,7 +1037,7 @@ void Foam::polyMesh::reorderPatches *this ); - boundary_.shuffle(newToOld, validBoundary); + boundary_.reorderPatches(newToOld, validBoundary); // Warn mesh objects meshObject::reorderPatches(*this, newToOld, validBoundary); diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C index 8cf119f860..3632cfe079 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C @@ -117,6 +117,23 @@ void Foam::cyclicPolyPatch::updateMesh(PstreamBuffers& pBufs) } +void Foam::cyclicPolyPatch::rename(const wordList& newNames) +{ + polyPatch::rename(newNames); + nbrPatch().nbrPatchName_ = newNames[index()]; +} + + +void Foam::cyclicPolyPatch::reorder(const labelUList& newToOldIndex) +{ + polyPatch::reorder(newToOldIndex); + if (nbrPatchID_ != -1) + { + nbrPatchID_ = findIndex(newToOldIndex, nbrPatchID_); + } +} + + // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // Foam::cyclicPolyPatch::cyclicPolyPatch diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H index 732154a85d..4952d00327 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H @@ -137,6 +137,13 @@ protected: //- Update of the patch topology virtual void updateMesh(PstreamBuffers&); + //- Reset the patch name + virtual void rename(const wordList& newNames); + + //- Reset the patch index + virtual void reorder(const labelUList& newToOldIndex); + + public: //- Declare friendship with processorCyclicPolyPatch diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C index 0162fdb2d0..96110966c2 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C @@ -59,6 +59,7 @@ void Foam::polyPatch::movePoints(PstreamBuffers&, const pointField& p) primitivePatch::movePoints(p); } + void Foam::polyPatch::updateMesh(PstreamBuffers&) { primitivePatch::clearGeom(); @@ -72,6 +73,18 @@ void Foam::polyPatch::clearGeom() } +void Foam::polyPatch::rename(const wordList& newNames) +{ + name_ = newNames[index_]; +} + + +void Foam::polyPatch::reorder(const labelUList& newToOldIndex) +{ + index_ = findIndex(newToOldIndex, index_); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::polyPatch::polyPatch diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H index c7904f1775..a7e6d167a4 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H @@ -122,6 +122,12 @@ protected: //- Clear geometry virtual void clearGeom(); + //- Reset the patch name + virtual void rename(const wordList& newNames); + + //- Reset the patch index + virtual void reorder(const labelUList& newToOldIndex); + public: diff --git a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C index 570d8610fe..31fab0ff5c 100644 --- a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C +++ b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C @@ -217,6 +217,23 @@ void Foam::cyclicAMIPolyPatch::clearGeom() } +void Foam::cyclicAMIPolyPatch::rename(const wordList& newNames) +{ + polyPatch::rename(newNames); + nbrPatch().nbrPatchName_ = newNames[index()]; +} + + +void Foam::cyclicAMIPolyPatch::reorder(const labelUList& newToOldIndex) +{ + polyPatch::reorder(newToOldIndex); + if (nbrPatchID_ != -1) + { + nbrPatchID_ = findIndex(newToOldIndex, nbrPatchID_); + } +} + + // * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * // Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch diff --git a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H index 0cd542428d..e612526a02 100644 --- a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H +++ b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H @@ -119,6 +119,12 @@ protected: //- Clear geometry virtual void clearGeom(); + //- Reset the patch name + virtual void rename(const wordList& newNames); + + //- Reset the patch index + virtual void reorder(const labelUList& newToOldIndex); + public: