ENH: use mapDistribute linear construct order in a few places

- simplifies code by avoiding code duplication:
  * parLagrangianDistributor
  * meshToMesh (processorLOD and AABBTree methods)

BUG: inconsistent mapping when using processorLOD boxes (fixes #2932)

- internally the processorLODs createMap() method used a 'localFirst'
  layout whereas a 'linear' order is what is actually expected for the
  meshToMesh mapping. This will cause of incorrect behaviour
  if using processorLOD instead of AABBTree.
  A dormant bug since processorLOD is not currently selectable.
This commit is contained in:
Mark Olesen 2023-07-04 17:11:58 +02:00
parent 0d456a4c66
commit a1e34bb251
12 changed files with 177 additions and 162 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -144,10 +144,10 @@ Foam::parLagrangianDistributor::distributeLagrangianPositions
const label oldLpi = lpi.size();
labelListList subMap;
labelListList sendMap;
// Allocate transfer buffers
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);
// Transfer buffers
PstreamBuffers pBufs(UPstream::commsTypes::nonBlocking);
{
// List of lists of particles to be transferred for all of the
@ -173,7 +173,7 @@ Foam::parLagrangianDistributor::distributeLagrangianPositions
// Per processor the indices of the particles to send
subMap = invertOneToMany(Pstream::nProcs(), destProc);
sendMap = invertOneToMany(UPstream::nProcs(), destProc);
// Stream into send buffers
@ -282,29 +282,12 @@ Foam::parLagrangianDistributor::distributeLagrangianPositions
lpi.rename(cloudName);
}
// Until now (FEB-2023) we have always used processor ordering for the
// construct map (whereas mapDistribute has local transfers first),
// so we'll stick with that for now, but can likely just use the subMap
// directly with mapDistribute and have it determine the constructMap.
labelList recvSizes;
Pstream::exchangeSizes(subMap, recvSizes);
label constructSize = 0;
labelListList constructMap(Pstream::nProcs());
forAll(constructMap, proci)
{
const label len = recvSizes[proci];
constructMap[proci] = identity(len, constructSize);
constructSize += len;
}
// The constructMap is in linear (processor) order
return autoPtr<mapDistributeBase>::New
(
constructSize,
std::move(subMap),
std::move(constructMap)
mapDistributeBase::layoutTypes::linear,
std::move(sendMap)
);
}

View File

@ -51,28 +51,27 @@ void Foam::processorLODs::box::writeBoxes
const label iter
) const
{
static label time = 0;
static label timeIndex = 0;
OFstream os
(
"processor" + Foam::name(Pstream::myProcNo())
+ "_time" + Foam::name(time)
+ "_time" + Foam::name(timeIndex)
+ "_iter" + Foam::name(iter) + ".obj"
);
++timeIndex;
label verti = 0;
for (const int proci : Pstream::allProcs())
for (const int proci : UPstream::allProcs())
{
if (proci == Pstream::myProcNo())
if (proci == UPstream::myProcNo())
{
continue;
}
const DynamicList<treeBoundBox>& procBoxes = fixedBoxes[proci];
forAll(procBoxes, boxi)
for (const treeBoundBox& bb : fixedBoxes[proci])
{
const treeBoundBox& bb = procBoxes[boxi];
// Write the points
const pointField pts(bb.points());
meshTools::writeOBJ(os, pts);
@ -90,8 +89,6 @@ void Foam::processorLODs::box::writeBoxes
verti += pts.size();
}
}
++time;
}
@ -418,7 +415,8 @@ bool Foam::processorLODs::box::doRefineBoxes
Foam::autoPtr<Foam::mapDistribute> Foam::processorLODs::box::createMap
(
const label nSrcElems,
const label nTgtElems
const label nTgtElems,
const mapDistributeBase::layoutTypes constructLayout
)
{
// Store elements to send - will be used to build the mapDistribute
@ -528,7 +526,11 @@ Foam::autoPtr<Foam::mapDistribute> Foam::processorLODs::box::createMap
}
}
return autoPtr<mapDistribute>::New(std::move(sendElems));
return autoPtr<mapDistribute>::New
(
constructLayout,
std::move(sendElems)
);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,8 +38,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef processorLODs_box
#define processorLODs_box
#ifndef Foam_processorLODs_box
#define Foam_processorLODs_box
#include "processorLOD.H"
#include "treeBoundBox.H"
@ -62,7 +62,7 @@ class box
{
protected:
// Protected data
// Protected Data
// Flags to indicate what to do with a box
@ -112,8 +112,11 @@ protected:
) const;
virtual boundBox calcSrcBox(const label srcObji) const = 0;
virtual boundBox calcTgtBox(const label tgtObji) const = 0;
//- The local boundBox associated with given source object
virtual treeBoundBox calcSrcBox(const label srcObji) const = 0;
//- The local boundBox associated with given target object
virtual treeBoundBox calcTgtBox(const label tgtObji) const = 0;
//- Set the box refinement flags
void setRefineFlags
@ -158,10 +161,13 @@ protected:
List<DynamicList<treeBoundBox>>& fixedBoxes
);
//- Return the parallel distribution map
//- (often linear construct order)
autoPtr<mapDistribute> createMap
(
const label nSrcElems,
const label nTgtElems
const label nTgtElems,
const mapDistributeBase::layoutTypes constructLayout
);
@ -170,15 +176,18 @@ public:
//- Runtime type information
TypeName("box");
//- Construct from list of points
box
(
const UList<point>& srcPoints,
const UList<point>& tgtPoints,
const label maxObjectsPerLeaf,
const label nObjectsOfType,
const label nRefineIterMax = 100
);
// Constructors
//- Construct from list of points for source and target
box
(
const UList<point>& srcPoints,
const UList<point>& tgtPoints,
const label maxObjectsPerLeaf,
const label nObjectsOfType,
const label nRefineIterMax = 100
);
//- Destructor
virtual ~box() = default;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,12 +39,12 @@ namespace processorLODs
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::boundBox Foam::processorLODs::cellBox::calcSrcBox
Foam::treeBoundBox Foam::processorLODs::cellBox::calcSrcBox
(
const label srcObji
) const
{
boundBox bb;
treeBoundBox bb;
for (const label facei : srcCells_[srcObji])
{
@ -55,12 +55,12 @@ Foam::boundBox Foam::processorLODs::cellBox::calcSrcBox
}
Foam::boundBox Foam::processorLODs::cellBox::calcTgtBox
Foam::treeBoundBox Foam::processorLODs::cellBox::calcTgtBox
(
const label tgtObji
) const
{
boundBox bb;
treeBoundBox bb;
for (const label facei : tgtCells_[tgtObji])
{
@ -86,7 +86,7 @@ Foam::processorLODs::cellBox::cellBox
const label nRefineIterMax
)
:
faceBox
processorLODs::faceBox
(
srcFaces,
srcPoints,
@ -101,9 +101,15 @@ Foam::processorLODs::cellBox::cellBox
{}
Foam::autoPtr<Foam::mapDistribute> Foam::processorLODs::cellBox::map()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::mapDistribute>
Foam::processorLODs::cellBox::map
(
const mapDistributeBase::layoutTypes constructLayout
)
{
return createMap(srcCells_.size(), tgtCells_.size());
return createMap(srcCells_.size(), tgtCells_.size(), constructLayout);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,8 +38,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef processorLODs_cellBox
#define processorLODs_cellBox
#ifndef Foam_processorLODs_cellBox
#define Foam_processorLODs_cellBox
#include "faceBox.H"
#include "cellList.H"
@ -48,7 +48,6 @@ Description
namespace Foam
{
namespace processorLODs
{
@ -58,23 +57,27 @@ namespace processorLODs
class cellBox
:
public faceBox
public processorLODs::faceBox
{
private:
protected:
// Private data
// Protected Data
//- Reference to the source face list
//- Reference to the source cell list
const cellList& srcCells_;
//- Reference to the target face list
//- Reference to the target cell list
const cellList& tgtCells_;
// Private Member Functions
// Protected Member Functions
//- The local boundBox associated with given source object
virtual treeBoundBox calcSrcBox(const label srcObji) const;
//- The local boundBox associated with given target object
virtual treeBoundBox calcTgtBox(const label tgtObji) const;
virtual boundBox calcSrcBox(const label srcObji) const;
virtual boundBox calcTgtBox(const label tgtObji) const;
public:
@ -82,19 +85,22 @@ public:
//- Runtime type information
TypeName("box");
//- Construct from list of points
cellBox
(
const cellList& srcCells,
const faceList& srcFaces,
const UList<point>& srcPoints,
const cellList& tgtCells,
const faceList& tgtFaces,
const UList<point>& tgtPoints,
const label maxObjectsPerLeaf,
const label nObjectsOfType,
const label nRefineIterMax = 100
);
// Constructors
//- Construct from list of points/faces/cells for source and target
cellBox
(
const cellList& srcCells,
const faceList& srcFaces,
const UList<point>& srcPoints,
const cellList& tgtCells,
const faceList& tgtFaces,
const UList<point>& tgtPoints,
const label maxObjectsPerLeaf,
const label nObjectsOfType,
const label nRefineIterMax = 100
);
//- Destructor
virtual ~cellBox() = default;
@ -103,16 +109,17 @@ public:
// Member Functions
//- Return the parallel distribution map
virtual autoPtr<mapDistribute> map();
//- (usually linear construct order)
virtual autoPtr<mapDistribute> map
(
const mapDistributeBase::layoutTypes constructLayout
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace processorLODs
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,21 +38,21 @@ namespace processorLODs
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::boundBox Foam::processorLODs::faceBox::calcSrcBox
Foam::treeBoundBox Foam::processorLODs::faceBox::calcSrcBox
(
const label srcObji
) const
{
return boundBox(srcPoints_, srcFaces_[srcObji], false);
return treeBoundBox(srcPoints_, srcFaces_[srcObji]); // No reduce
}
Foam::boundBox Foam::processorLODs::faceBox::calcTgtBox
Foam::treeBoundBox Foam::processorLODs::faceBox::calcTgtBox
(
const label tgtObji
) const
{
return boundBox(tgtPoints_, tgtFaces_[tgtObji], false);
return treeBoundBox(tgtPoints_, tgtFaces_[tgtObji]); // No reduce
}
@ -69,15 +69,21 @@ Foam::processorLODs::faceBox::faceBox
const label nRefineIterMax
)
:
box(srcPoints, tgtPoints, maxObjectsPerLeaf, nObjectsOfType),
processorLODs::box(srcPoints, tgtPoints, maxObjectsPerLeaf, nObjectsOfType),
srcFaces_(srcFaces),
tgtFaces_(tgtFaces)
{}
Foam::autoPtr<Foam::mapDistribute> Foam::processorLODs::faceBox::map()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::mapDistribute>
Foam::processorLODs::faceBox::map
(
const mapDistributeBase::layoutTypes constructLayout
)
{
return createMap(srcFaces_.size(), tgtFaces_.size());
return createMap(srcFaces_.size(), tgtFaces_.size(), constructLayout);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,8 +38,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef processorLODs_faceBox
#define processorLODs_faceBox
#ifndef Foam_processorLODs_faceBox
#define Foam_processorLODs_faceBox
#include "box.H"
@ -47,7 +47,6 @@ Description
namespace Foam
{
namespace processorLODs
{
@ -57,11 +56,11 @@ namespace processorLODs
class faceBox
:
public box
public processorLODs::box
{
protected:
// Protected data
// Protected Data
//- Reference to the source face list
const faceList& srcFaces_;
@ -72,8 +71,11 @@ protected:
// Protected Member Functions
virtual boundBox calcSrcBox(const label srcObji) const;
virtual boundBox calcTgtBox(const label tgtObji) const;
//- The local boundBox associated with given source object
virtual treeBoundBox calcSrcBox(const label srcObji) const;
//- The local boundBox associated with given target object
virtual treeBoundBox calcTgtBox(const label tgtObji) const;
public:
@ -81,17 +83,20 @@ public:
//- Runtime type information
TypeName("box");
//- Construct from list of points
faceBox
(
const faceList& srcFaces,
const UList<point>& srcPoints,
const faceList& tgtFaces,
const UList<point>& tgtPoints,
const label maxObjectsPerLeaf,
const label nObjectsOfType,
const label nRefineIterMax = 100
);
// Constructors
//- Construct from list of points/faces for source and target
faceBox
(
const faceList& srcFaces,
const UList<point>& srcPoints,
const faceList& tgtFaces,
const UList<point>& tgtPoints,
const label maxObjectsPerLeaf,
const label nObjectsOfType,
const label nRefineIterMax = 100
);
//- Destructor
virtual ~faceBox() = default;
@ -100,16 +105,17 @@ public:
// Member Functions
//- Return the parallel distribution map
virtual autoPtr<mapDistribute> map();
//- (usually linear construct order)
virtual autoPtr<mapDistribute> map
(
const mapDistributeBase::layoutTypes constructLayout
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace processorLODs
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -38,7 +38,7 @@ Foam::processorLOD::processorLOD
(
const label maxObjectsPerLeaf,
const label nObjectsOfType
)
) noexcept
:
maxObjectsPerLeaf_(maxObjectsPerLeaf),
nObjectsOfType_(nObjectsOfType)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,17 +33,19 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef processorLOD_H
#define processorLOD_H
#ifndef Foam_processorLOD_H
#define Foam_processorLOD_H
#include "autoPtr.H"
#include "typeInfo.H"
#include "mapDistributeBase.H" // For layoutTypes
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class mapDistribute;
/*---------------------------------------------------------------------------*\
@ -52,16 +54,15 @@ class mapDistribute;
class processorLOD
{
protected:
// Protected data
// Protected Data
//- Maximum number of objects per leaf
label maxObjectsPerLeaf_;
//- Number of objects of this type, e.g. number of faces/cells on this
//- processor
//- Number of objects of this type.
//- e.g. number of faces/cells on this processor
label nObjectsOfType_;
@ -75,7 +76,7 @@ public:
(
const label maxObjectsPerLeaf,
const label nObjectsOfType
);
) noexcept;
//- Destructor
virtual ~processorLOD() = default;
@ -84,7 +85,12 @@ public:
// Member Functions
//- Return the parallel distribution map
virtual autoPtr<mapDistribute> map() = 0;
//- (usually linear construct order)
virtual autoPtr<mapDistribute> map
(
const mapDistributeBase::layoutTypes constructLayout
= mapDistributeBase::layoutTypes::linear
) = 0;
};

View File

@ -846,8 +846,8 @@ Foam::meshToMesh::meshToMesh
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const procMapMethod& mapMethod,
const interpolationMethod method,
const procMapMethod mapMethod,
bool interpAllPatches
)
:
@ -884,7 +884,7 @@ Foam::meshToMesh::meshToMesh
const polyMesh& tgt,
const word& methodName,
const word& AMIMethodName,
const procMapMethod& mapMethod,
const procMapMethod mapMethod,
bool interpAllPatches
)
:
@ -914,10 +914,10 @@ Foam::meshToMesh::meshToMesh
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const interpolationMethod method,
const HashTable<word>& patchMap,
const wordList& cuttingPatches,
const procMapMethod& mapMethod,
const procMapMethod mapMethod,
const bool normalise
)
:
@ -956,7 +956,7 @@ Foam::meshToMesh::meshToMesh
const word& AMIMethodName, // boundary mapping
const HashTable<word>& patchMap,
const wordList& cuttingPatches,
const procMapMethod& mapMethod,
const procMapMethod mapMethod,
const bool normalise
)
:

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -315,8 +315,8 @@ public:
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const procMapMethod& mapMethod = procMapMethod::pmAABB,
const interpolationMethod method,
const procMapMethod mapMethod = procMapMethod::pmAABB,
const bool interpAllPatches = true
);
@ -327,7 +327,7 @@ public:
const polyMesh& tgt,
const word& methodName, // internal mapping
const word& AMIMethodName, // boundary mapping
const procMapMethod& mapMethod = procMapMethod::pmAABB,
const procMapMethod mapMethod = procMapMethod::pmAABB,
const bool interpAllPatches = true
);
@ -336,10 +336,10 @@ public:
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const interpolationMethod method,
const HashTable<word>& patchMap,
const wordList& cuttingPatches,
const procMapMethod& mapMethod = procMapMethod::pmAABB,
const procMapMethod mapMethod = procMapMethod::pmAABB,
const bool normalise = true
);
@ -353,7 +353,7 @@ public:
const word& AMIMethodName, // boundary mapping
const HashTable<word>& patchMap,
const wordList& cuttingPatches,
const procMapMethod& mapMethod = procMapMethod::pmAABB,
const procMapMethod mapMethod = procMapMethod::pmAABB,
const bool normalise = true
);

View File

@ -114,6 +114,11 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap
const polyMesh& tgt
) const
{
// Uses linear construct order
const
mapDistributeBase::layoutTypes constructLayout =
mapDistributeBase::layoutTypes::linear;
switch (procMapMethod_)
{
case procMapMethod::pmLOD:
@ -139,7 +144,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap
src.nCells()
);
return boxLOD.map();
return boxLOD.map(constructLayout);
break;
}
default:
@ -232,25 +237,10 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap
}
labelList recvSizes;
Pstream::exchangeSizes(sendMap, recvSizes, UPstream::worldComm);
// Uses linear receive order
labelListList constructMap(UPstream::nProcs());
label constructSize = 0;
forAll(constructMap, proci)
{
const label len = recvSizes[proci];
constructMap[proci] = identity(len, constructSize);
constructSize += len;
}
return autoPtr<mapDistribute>::New
(
constructSize,
std::move(sendMap),
std::move(constructMap)
constructLayout,
std::move(sendMap)
);
break;
}