polyBoundaryMesh: Update indices in neighbour patches on reorder

This commit is contained in:
Will Bainbridge
2020-12-01 15:31:12 +00:00
parent 685664b3ca
commit f85dbc557f
11 changed files with 123 additions and 45 deletions

View File

@ -121,27 +121,19 @@ void renamePatches
const labelList& patchesToRename const labelList& patchesToRename
) )
{ {
polyBoundaryMesh& polyPatches = polyBoundaryMesh& patches =
const_cast<polyBoundaryMesh&>(mesh.boundaryMesh()); const_cast<polyBoundaryMesh&>(mesh.boundaryMesh());
// Create a list of all the new names
wordList newNames = patches.names();
forAll(patchesToRename, i) forAll(patchesToRename, i)
{ {
label patchi = patchesToRename[i]; const label patchi = patchesToRename[i];
polyPatch& pp = polyPatches[patchi]; newNames[patchi] = prefix + '_' + newNames[patchi];
if (isA<coupledPolyPatch>(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();
} }
// Recalculate any demand driven data (e.g. group to name lookup)
polyPatches.updateMesh(); // Apply to the patches
patches.renamePatches(newNames, true);
} }

View File

@ -57,7 +57,9 @@ Ostream& operator<<(Ostream&, const patchIdentifier&);
class patchIdentifier class patchIdentifier
{ {
// Private Data protected:
// Protected Data
//- Name of patch //- Name of patch
word name_; word name_;
@ -66,7 +68,7 @@ class patchIdentifier
label index_; label index_;
//- Optional physical type //- Optional physical type
mutable word physicalType_; word physicalType_;
//- Optional groups patch belongs to //- Optional groups patch belongs to
wordList inGroups_; wordList inGroups_;
@ -113,10 +115,10 @@ public:
return name_; return name_;
} }
//- Return name for modification //- Return the index of this patch in the boundaryMesh
word& name() label index() const
{ {
return name_; return index_;
} }
//- Return the optional physical type of the patch //- Return the optional physical type of the patch
@ -131,18 +133,6 @@ public:
return physicalType_; 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 //- Return the optional groups patch belongs to
const wordList& inGroups() const const wordList& inGroups() const
{ {

View File

@ -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 labelUList& newToOld,
const bool validBoundary const bool validBoundary
@ -1117,12 +1139,11 @@ void Foam::polyBoundaryMesh::shuffle
// Adapt indices // Adapt indices
polyPatchList& patches = *this; polyPatchList& patches = *this;
forAll(patches, patchi) forAll(patches, patchi)
{ {
if (patches.set(patchi)) if (patches.set(patchi))
{ {
patches[patchi].index() = patchi; patches[patchi].reorder(newToOld);
} }
} }

View File

@ -221,12 +221,21 @@ public:
//- Correct polyBoundaryMesh after topology update //- Correct polyBoundaryMesh after topology update
void updateMesh(); void updateMesh();
//- Reorders patches. Ordering does not have to be done in //- Rename the patches. If validBoundary is set this calls updateMesh()
// ascending or descending order. Reordering has to be unique. // after reordering to recalculate data (so the call needs to be
// (is shuffle) If validBoundary calls updateMesh() // parallel synchronised).
// after reordering to recalculate data (so call needs to be parallel void renamePatches(const wordUList& newNames, const bool validBoundary);
// sync in that case)
void shuffle(const labelUList& newToOld, 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 //- writeData member function required by regIOobject
bool writeData(Ostream&) const; bool writeData(Ostream&) const;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -1037,7 +1037,7 @@ void Foam::polyMesh::reorderPatches
*this *this
); );
boundary_.shuffle(newToOld, validBoundary); boundary_.reorderPatches(newToOld, validBoundary);
// Warn mesh objects // Warn mesh objects
meshObject::reorderPatches<polyMesh>(*this, newToOld, validBoundary); meshObject::reorderPatches<polyMesh>(*this, newToOld, validBoundary);

View File

@ -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 * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
Foam::cyclicPolyPatch::cyclicPolyPatch Foam::cyclicPolyPatch::cyclicPolyPatch

View File

@ -137,6 +137,13 @@ protected:
//- Update of the patch topology //- Update of the patch topology
virtual void updateMesh(PstreamBuffers&); 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: public:
//- Declare friendship with processorCyclicPolyPatch //- Declare friendship with processorCyclicPolyPatch

View File

@ -59,6 +59,7 @@ void Foam::polyPatch::movePoints(PstreamBuffers&, const pointField& p)
primitivePatch::movePoints(p); primitivePatch::movePoints(p);
} }
void Foam::polyPatch::updateMesh(PstreamBuffers&) void Foam::polyPatch::updateMesh(PstreamBuffers&)
{ {
primitivePatch::clearGeom(); 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::polyPatch::polyPatch Foam::polyPatch::polyPatch

View File

@ -122,6 +122,12 @@ protected:
//- Clear geometry //- Clear geometry
virtual void clearGeom(); virtual void clearGeom();
//- Reset the patch name
virtual void rename(const wordList& newNames);
//- Reset the patch index
virtual void reorder(const labelUList& newToOldIndex);
public: public:

View File

@ -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 * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * //
Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch

View File

@ -119,6 +119,12 @@ protected:
//- Clear geometry //- Clear geometry
virtual void clearGeom(); virtual void clearGeom();
//- Reset the patch name
virtual void rename(const wordList& newNames);
//- Reset the patch index
virtual void reorder(const labelUList& newToOldIndex);
public: public: