mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: PatchTools::gatherAndMerge with recovery of the globalIndex
- support globalIndex for points/faces as an output parameter, which allows reuse in subsequent field merge operations. - make pointMergeMap an optional parameter. This information is not always required. Eg, if only using gatherAndMerge to combine faces but without any point fields. ENH: make globalIndex() noexcept, add globalIndex::clear() method
This commit is contained in:
committed by
Andrew Heather
parent
70208a7399
commit
799d247142
@ -727,14 +727,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
pointField mergedPoints;
|
pointField mergedPoints;
|
||||||
faceList mergedFaces;
|
faceList mergedFaces;
|
||||||
labelList pointMergeMap;
|
|
||||||
PatchTools::gatherAndMerge
|
PatchTools::gatherAndMerge
|
||||||
(
|
(
|
||||||
tolDim,
|
tolDim,
|
||||||
primitivePatch(SubList<face>(isoFaces), isoPoints),
|
primitivePatch(SubList<face>(isoFaces), isoPoints),
|
||||||
mergedPoints,
|
mergedPoints,
|
||||||
mergedFaces,
|
mergedFaces
|
||||||
pointMergeMap
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Pstream::master())
|
if (Pstream::master())
|
||||||
|
|||||||
@ -221,9 +221,14 @@ public:
|
|||||||
//
|
//
|
||||||
// \param[in] mergeDist Geometric merge tolerance for Foam::mergePoints
|
// \param[in] mergeDist Geometric merge tolerance for Foam::mergePoints
|
||||||
// \param[in] pp The patch to merge
|
// \param[in] pp The patch to merge
|
||||||
// \param[out] mergedPoints
|
// \param[out] mergedPoints merged points (master only, empty elsewhere)
|
||||||
// \param[out] mergedFaces
|
// \param[out] mergedFaces merged faces (master only, empty elsewhere)
|
||||||
// \param[out] pointMergeMap
|
// \param[out] pointAddr Points globalIndex gather addressing
|
||||||
|
// (master only, empty elsewhere)
|
||||||
|
// \param[out] faceAddr Faces globalIndex gather addressing
|
||||||
|
// (master only, empty elsewhere)
|
||||||
|
// \param[out] pointMergeMap An old-to-new mapping from original
|
||||||
|
// point index to the index into merged points.
|
||||||
// \param[in] useLocal gather/merge patch localFaces/localPoints
|
// \param[in] useLocal gather/merge patch localFaces/localPoints
|
||||||
// instead of faces/points
|
// instead of faces/points
|
||||||
//
|
//
|
||||||
@ -243,19 +248,54 @@ public:
|
|||||||
<
|
<
|
||||||
typename PrimitivePatch<FaceList, PointField>::face_type
|
typename PrimitivePatch<FaceList, PointField>::face_type
|
||||||
>& mergedFaces,
|
>& mergedFaces,
|
||||||
labelList& pointMergeMap,
|
globalIndex& pointAddr,
|
||||||
|
globalIndex& faceAddr,
|
||||||
|
labelList& pointMergeMap = const_cast<labelList&>(labelList::null()),
|
||||||
|
const bool useLocal = false
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Gather points and faces onto master and merge into single patch.
|
||||||
|
// Note: Normally uses faces/points (not localFaces/localPoints)
|
||||||
|
//
|
||||||
|
// \param[in] mergeDist Geometric merge tolerance for Foam::mergePoints
|
||||||
|
// \param[in] pp The patch to merge
|
||||||
|
// \param[out] mergedPoints merged points (master only, empty elsewhere)
|
||||||
|
// \param[out] mergedFaces merged faces (master only, empty elsewhere)
|
||||||
|
// \param[out] pointMergeMap An old-to-new mapping from original
|
||||||
|
// point index to the index into merged points.
|
||||||
|
// \param[in] useLocal gather/merge patch localFaces/localPoints
|
||||||
|
// instead of faces/points
|
||||||
|
//
|
||||||
|
// \note
|
||||||
|
// - OpenFOAM-v2112 and earlier: geometric merge on all patch points.
|
||||||
|
// - OpenFOAM-v2206 and later: geometric merge on patch boundary points.
|
||||||
|
template<class FaceList, class PointField>
|
||||||
|
static void gatherAndMerge
|
||||||
|
(
|
||||||
|
const scalar mergeDist,
|
||||||
|
const PrimitivePatch<FaceList, PointField>& pp,
|
||||||
|
Field
|
||||||
|
<
|
||||||
|
typename PrimitivePatch<FaceList, PointField>::point_type
|
||||||
|
>& mergedPoints,
|
||||||
|
List
|
||||||
|
<
|
||||||
|
typename PrimitivePatch<FaceList, PointField>::face_type
|
||||||
|
>& mergedFaces,
|
||||||
|
labelList& pointMergeMap = const_cast<labelList&>(labelList::null()),
|
||||||
const bool useLocal = false
|
const bool useLocal = false
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Gather (mesh!) points and faces onto master and merge collocated
|
//- Gather (mesh!) points and faces onto master and merge collocated
|
||||||
// points into a single patch. Uses coupled point mesh
|
// points into a single patch. Uses coupled point mesh
|
||||||
// structure so does not need tolerances.
|
// structure so does not need tolerances.
|
||||||
// On master and slave returns:
|
// On master and sub-ranks returns:
|
||||||
// - pointToGlobal : for every local point index the global point index
|
// - pointToGlobal : for every local point index the global point index
|
||||||
// - uniqueMeshPointLabels : my local mesh points
|
// - uniqueMeshPointLabels : my local mesh points
|
||||||
// - globalPoints : global numbering for the global points
|
// - globalPoints : global numbering for the global points
|
||||||
// - globalFaces : global numbering for the faces
|
// - globalFaces : global numbering for the faces
|
||||||
// On master only:
|
// .
|
||||||
|
// On master only returns:
|
||||||
// - mergedFaces : the merged faces
|
// - mergedFaces : the merged faces
|
||||||
// - mergedPoints : the merged points
|
// - mergedPoints : the merged points
|
||||||
template<class FaceList>
|
template<class FaceList>
|
||||||
|
|||||||
@ -46,17 +46,19 @@ void Foam::PatchTools::gatherAndMerge
|
|||||||
<
|
<
|
||||||
typename PrimitivePatch<FaceList, PointField>::face_type
|
typename PrimitivePatch<FaceList, PointField>::face_type
|
||||||
>& mergedFaces,
|
>& mergedFaces,
|
||||||
|
globalIndex& pointAddr,
|
||||||
|
globalIndex& faceAddr,
|
||||||
labelList& pointMergeMap,
|
labelList& pointMergeMap,
|
||||||
const bool useLocal
|
const bool useLocal
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
typedef typename PrimitivePatch<FaceList,PointField>::face_type FaceType;
|
typedef typename PrimitivePatch<FaceList, PointField>::face_type FaceType;
|
||||||
|
|
||||||
// Faces from all ranks
|
// Faces from all ranks
|
||||||
const globalIndex faceAddr(pp.size(), globalIndex::gatherOnly{});
|
faceAddr = globalIndex(pp.size(), globalIndex::gatherOnly{});
|
||||||
|
|
||||||
// Points from all ranks
|
// Points from all ranks
|
||||||
const globalIndex pointAddr
|
pointAddr = globalIndex
|
||||||
(
|
(
|
||||||
(useLocal ? pp.localPoints().size() : pp.points().size()),
|
(useLocal ? pp.localPoints().size() : pp.points().size()),
|
||||||
globalIndex::gatherOnly{}
|
globalIndex::gatherOnly{}
|
||||||
@ -152,6 +154,40 @@ void Foam::PatchTools::gatherAndMerge
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class FaceList, class PointField>
|
||||||
|
void Foam::PatchTools::gatherAndMerge
|
||||||
|
(
|
||||||
|
const scalar mergeDist,
|
||||||
|
const PrimitivePatch<FaceList, PointField>& pp,
|
||||||
|
Field
|
||||||
|
<
|
||||||
|
typename PrimitivePatch<FaceList, PointField>::point_type
|
||||||
|
>& mergedPoints,
|
||||||
|
List
|
||||||
|
<
|
||||||
|
typename PrimitivePatch<FaceList, PointField>::face_type
|
||||||
|
>& mergedFaces,
|
||||||
|
labelList& pointMergeMap,
|
||||||
|
const bool useLocal
|
||||||
|
)
|
||||||
|
{
|
||||||
|
globalIndex pointAddr;
|
||||||
|
globalIndex faceAddr;
|
||||||
|
|
||||||
|
PatchTools::gatherAndMerge<FaceList, PointField>
|
||||||
|
(
|
||||||
|
mergeDist,
|
||||||
|
pp,
|
||||||
|
mergedPoints,
|
||||||
|
mergedFaces,
|
||||||
|
pointAddr,
|
||||||
|
faceAddr,
|
||||||
|
pointMergeMap,
|
||||||
|
useLocal
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class FaceList>
|
template<class FaceList>
|
||||||
void Foam::PatchTools::gatherAndMerge
|
void Foam::PatchTools::gatherAndMerge
|
||||||
(
|
(
|
||||||
|
|||||||
@ -108,8 +108,8 @@ public:
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Default construct
|
//- Default construct (empty)
|
||||||
globalIndex() = default;
|
globalIndex() noexcept = default;
|
||||||
|
|
||||||
//- Copy construct from a list of offsets.
|
//- Copy construct from a list of offsets.
|
||||||
//- No communication required
|
//- No communication required
|
||||||
@ -184,9 +184,15 @@ public:
|
|||||||
//- Global max of localSizes
|
//- Global max of localSizes
|
||||||
inline label maxSize() const;
|
inline label maxSize() const;
|
||||||
|
|
||||||
|
|
||||||
|
// Access
|
||||||
|
|
||||||
//- Const-access to the offsets
|
//- Const-access to the offsets
|
||||||
inline const labelList& offsets() const noexcept;
|
inline const labelList& offsets() const noexcept;
|
||||||
|
|
||||||
|
//- Write-access to the offsets, for changing after construction
|
||||||
|
inline labelList& offsets() noexcept;
|
||||||
|
|
||||||
|
|
||||||
// Dimensions
|
// Dimensions
|
||||||
|
|
||||||
@ -202,8 +208,8 @@ public:
|
|||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
|
|
||||||
//- Write-access to the offsets, for changing after construction
|
//- Reset to be empty (no offsets)
|
||||||
inline labelList& offsets() noexcept;
|
inline void clear();
|
||||||
|
|
||||||
//- Reset from local size, using gather/broadcast
|
//- Reset from local size, using gather/broadcast
|
||||||
//- with default/specified communicator if parallel.
|
//- with default/specified communicator if parallel.
|
||||||
|
|||||||
@ -176,6 +176,12 @@ inline Foam::labelList& Foam::globalIndex::offsets() noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void Foam::globalIndex::clear()
|
||||||
|
{
|
||||||
|
offsets_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::labelUList Foam::globalIndex::localStarts() const
|
inline const Foam::labelUList Foam::globalIndex::localStarts() const
|
||||||
{
|
{
|
||||||
const label len = (offsets_.size() - 1);
|
const label len = (offsets_.size() - 1);
|
||||||
|
|||||||
@ -418,15 +418,12 @@ combineSurfaceGeometry
|
|||||||
// Dimension as fraction of surface
|
// Dimension as fraction of surface
|
||||||
const scalar mergeDim = 1e-10*boundBox(s.points(), true).mag();
|
const scalar mergeDim = 1e-10*boundBox(s.points(), true).mag();
|
||||||
|
|
||||||
labelList pointsMap;
|
Foam::PatchTools::gatherAndMerge
|
||||||
|
|
||||||
PatchTools::gatherAndMerge
|
|
||||||
(
|
(
|
||||||
mergeDim,
|
mergeDim,
|
||||||
primitivePatch(SubList<face>(s.faces()), s.points()),
|
primitivePatch(SubList<face>(s.faces()), s.points()),
|
||||||
points,
|
points,
|
||||||
faces,
|
faces
|
||||||
pointsMap
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -444,15 +441,12 @@ combineSurfaceGeometry
|
|||||||
// Dimension as fraction of mesh bounding box
|
// Dimension as fraction of mesh bounding box
|
||||||
const scalar mergeDim = 1e-10*mesh_.bounds().mag();
|
const scalar mergeDim = 1e-10*mesh_.bounds().mag();
|
||||||
|
|
||||||
labelList pointsMap;
|
Foam::PatchTools::gatherAndMerge
|
||||||
|
|
||||||
PatchTools::gatherAndMerge
|
|
||||||
(
|
(
|
||||||
mergeDim,
|
mergeDim,
|
||||||
primitivePatch(SubList<face>(s.faces()), s.points()),
|
primitivePatch(SubList<face>(s.faces()), s.points()),
|
||||||
points,
|
points,
|
||||||
faces,
|
faces
|
||||||
pointsMap
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -206,14 +206,12 @@ void Foam::cyclicPeriodicAMIPolyPatch::writeOBJ
|
|||||||
// Collect faces and points
|
// Collect faces and points
|
||||||
pointField allPoints;
|
pointField allPoints;
|
||||||
faceList allFaces;
|
faceList allFaces;
|
||||||
labelList pointMergeMap;
|
|
||||||
PatchTools::gatherAndMerge
|
PatchTools::gatherAndMerge
|
||||||
(
|
(
|
||||||
-1.0, // do not merge points
|
-1.0, // do not merge points
|
||||||
p,
|
p,
|
||||||
allPoints,
|
allPoints,
|
||||||
allFaces,
|
allFaces
|
||||||
pointMergeMap
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Pstream::master())
|
if (Pstream::master())
|
||||||
|
|||||||
Reference in New Issue
Block a user