ENH: refine mapDistribute methods

- additional distribute/reverseDistribute with specified commsType.
  Improves flexibility.

- distribute with nullValue

- support move construct mapDistribute from mapDistributeBase

- refactor handling of schedules (as whichSchedule method) to
  simplify code.

- renumberMap helper for working with compact sub maps
  and renumberVisit for handling walk-ordered compaction.

COMP: make mapDistributeBase data private

- accessor methods are available - direct access is unnecessary
- mapDistribute : inherit mapDistributeBase constructors

STYLE: use List<labelPair>::null() for schedule placeholders

- clearer that they are doing nothing
This commit is contained in:
Mark Olesen
2022-05-11 21:29:13 +02:00
parent ae0ef3efed
commit 60e07d1f93
21 changed files with 1899 additions and 1048 deletions

View File

@ -663,8 +663,12 @@ $(mapPolyMesh)/mapPolyMesh.C
$(mapPolyMesh)/faceMapper/faceMapper.C $(mapPolyMesh)/faceMapper/faceMapper.C
$(mapPolyMesh)/cellMapper/cellMapper.C $(mapPolyMesh)/cellMapper/cellMapper.C
$(mapPolyMesh)/mapDistribute/mapDistribute.C $(mapPolyMesh)/mapDistribute/mapDistribute.C
$(mapPolyMesh)/mapDistribute/mapDistributeIO.C
$(mapPolyMesh)/mapDistribute/mapDistributeBase.C $(mapPolyMesh)/mapDistribute/mapDistributeBase.C
$(mapPolyMesh)/mapDistribute/mapDistributeBaseIO.C
$(mapPolyMesh)/mapDistribute/mapDistributeBaseSubset.C
$(mapPolyMesh)/mapDistribute/mapDistributePolyMesh.C $(mapPolyMesh)/mapDistribute/mapDistributePolyMesh.C
$(mapPolyMesh)/mapDistribute/mapDistributePolyMeshIO.C
$(mapPolyMesh)/mapDistribute/IOmapDistribute.C $(mapPolyMesh)/mapDistribute/IOmapDistribute.C
$(mapPolyMesh)/mapDistribute/IOmapDistributePolyMesh.C $(mapPolyMesh)/mapDistribute/IOmapDistributePolyMesh.C
$(mapPolyMesh)/mapAddedPolyMesh.C $(mapPolyMesh)/mapAddedPolyMesh.C

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -134,13 +134,13 @@ void Foam::mapDistribute::printLayout(Ostream& os) const
{ {
mapDistributeBase::printLayout(os); mapDistributeBase::printLayout(os);
forAll(transformElements_, trafoI) forAll(transformElements_, i)
{ {
if (transformElements_[trafoI].size() > 0) if (!transformElements_[i].empty())
{ {
os << "transform " << trafoI << ':' << endl os << "transform " << i << ':' << nl
<< " start : " << transformStart_[trafoI] << endl << " start : " << transformStart_[i] << nl
<< " size : " << transformElements_[trafoI].size() << endl; << " size : " << transformElements_[i].size() << endl;
} }
} }
} }
@ -148,12 +148,24 @@ void Foam::mapDistribute::printLayout(Ostream& os) const
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::mapDistribute::mapDistribute()
:
mapDistribute(UPstream::worldComm)
{}
Foam::mapDistribute::mapDistribute(const label comm) Foam::mapDistribute::mapDistribute(const label comm)
: :
mapDistributeBase(comm) mapDistributeBase(comm)
{} {}
Foam::mapDistribute::mapDistribute(mapDistributeBase&& map)
:
mapDistributeBase(std::move(map))
{}
Foam::mapDistribute::mapDistribute(const mapDistribute& map) Foam::mapDistribute::mapDistribute(const mapDistribute& map)
: :
mapDistributeBase(map), mapDistributeBase(map),
@ -170,28 +182,6 @@ Foam::mapDistribute::mapDistribute(mapDistribute&& map)
} }
Foam::mapDistribute::mapDistribute
(
const label constructSize,
labelListList&& subMap,
labelListList&& constructMap,
const bool subHasFlip,
const bool constructHasFlip,
const label comm
)
:
mapDistributeBase
(
constructSize,
std::move(subMap),
std::move(constructMap),
subHasFlip,
constructHasFlip,
comm
)
{}
Foam::mapDistribute::mapDistribute Foam::mapDistribute::mapDistribute
( (
const label constructSize, const label constructSize,
@ -218,57 +208,6 @@ Foam::mapDistribute::mapDistribute
{} {}
Foam::mapDistribute::mapDistribute
(
const labelUList& sendProcs,
const labelUList& recvProcs,
const label comm
)
:
mapDistributeBase(sendProcs, recvProcs, comm)
{}
Foam::mapDistribute::mapDistribute
(
const globalIndex& globalNumbering,
labelList& elements,
List<Map<label>>& compactMap,
const int tag,
const label comm
)
:
mapDistributeBase
(
globalNumbering,
elements,
compactMap,
tag,
comm
)
{}
Foam::mapDistribute::mapDistribute
(
const globalIndex& globalNumbering,
labelListList& cellCells,
List<Map<label>>& compactMap,
const int tag,
const label comm
)
:
mapDistributeBase
(
globalNumbering,
cellCells,
compactMap,
tag,
comm
)
{}
Foam::mapDistribute::mapDistribute Foam::mapDistribute::mapDistribute
( (
const globalIndex& globalNumbering, const globalIndex& globalNumbering,
@ -338,8 +277,8 @@ Foam::mapDistribute::mapDistribute
transformElements_.setSize(nTrafo); transformElements_.setSize(nTrafo);
forAll(transformStart_, trafoI) forAll(transformStart_, trafoI)
{ {
transformStart_[trafoI] = constructSize_; transformStart_[trafoI] = constructSize();
constructSize_ += nPerTransform[trafoI]; constructSize() += nPerTransform[trafoI];
transformElements_[trafoI].setSize(nPerTransform[trafoI]); transformElements_[trafoI].setSize(nPerTransform[trafoI]);
} }
@ -391,7 +330,7 @@ Foam::mapDistribute::mapDistribute
: :
mapDistributeBase(comm) mapDistributeBase(comm)
{ {
const label myRank = Pstream::myProcNo(comm_); const label myRank = Pstream::myProcNo(comm);
// Construct per processor compact addressing of the global elements // Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since // needed. The ones from the local processor are not included since
@ -454,8 +393,8 @@ Foam::mapDistribute::mapDistribute
transformElements_.setSize(nTrafo); transformElements_.setSize(nTrafo);
forAll(transformStart_, trafoI) forAll(transformStart_, trafoI)
{ {
transformStart_[trafoI] = constructSize_; transformStart_[trafoI] = constructSize();
constructSize_ += nPerTransform[trafoI]; constructSize() += nPerTransform[trafoI];
transformElements_[trafoI].setSize(nPerTransform[trafoI]); transformElements_[trafoI].setSize(nPerTransform[trafoI]);
} }
@ -498,24 +437,6 @@ Foam::mapDistribute::mapDistribute
} }
Foam::mapDistribute::mapDistribute
(
labelListList&& subMap,
const bool subHasFlip,
const bool constructHasFlip,
const label comm
)
:
mapDistributeBase(std::move(subMap), subHasFlip, constructHasFlip, comm)
{}
Foam::mapDistribute::mapDistribute(Istream& is)
{
is >> *this;
}
Foam::autoPtr<Foam::mapDistribute> Foam::mapDistribute::clone() const Foam::autoPtr<Foam::mapDistribute> Foam::mapDistribute::clone() const
{ {
return autoPtr<mapDistribute>::New(*this); return autoPtr<mapDistribute>::New(*this);
@ -530,11 +451,19 @@ Foam::label Foam::mapDistribute::whichTransform(const label index) const
} }
void Foam::mapDistribute::clear()
{
mapDistributeBase::clear();
transformElements_.clear();
transformStart_.clear();
}
void Foam::mapDistribute::transfer(mapDistribute& rhs) void Foam::mapDistribute::transfer(mapDistribute& rhs)
{ {
if (this == &rhs) if (this == &rhs)
{ {
// Self-assignment is a no-op return; // Self-assignment is a no-op
} }
mapDistributeBase::transfer(rhs); mapDistributeBase::transfer(rhs);
@ -568,29 +497,4 @@ void Foam::mapDistribute::operator=(mapDistribute&& rhs)
} }
// * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, mapDistribute& map)
{
is.fatalCheck(FUNCTION_NAME);
is >> static_cast<mapDistributeBase&>(map)
>> map.transformElements_ >> map.transformStart_;
return is;
}
// * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistribute& map)
{
os << static_cast<const mapDistributeBase&>(map) << token::NL
<< map.transformElements_ << token::NL
<< map.transformStart_;
return os;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -126,15 +126,15 @@ Note:
values as index+flip, similar to e.g. faceProcAddressing. The flip values as index+flip, similar to e.g. faceProcAddressing. The flip
will only be applied to fieldTypes (scalar, vector, .. triad) will only be applied to fieldTypes (scalar, vector, .. triad)
SourceFiles SourceFiles
mapDistribute.C mapDistribute.C
mapDistributeIO.C
mapDistributeTemplates.C mapDistributeTemplates.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef mapDistribute_H #ifndef Foam_mapDistribute_H
#define mapDistribute_H #define Foam_mapDistribute_H
#include "mapDistributeBase.H" #include "mapDistributeBase.H"
#include "transformList.H" #include "transformList.H"
@ -146,11 +146,8 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward Declarations
class globalIndexAndTransform; class globalIndexAndTransform;
// Forward declaration of friend functions and operators
class mapDistribute; class mapDistribute;
Istream& operator>>(Istream&, mapDistribute&); Istream& operator>>(Istream&, mapDistribute&);
@ -165,10 +162,10 @@ class mapDistribute
: :
public mapDistributeBase public mapDistributeBase
{ {
// Private data // Private Data
//- For every globalIndexAndTransform::transformPermutations //- For every globalIndexAndTransform::transformPermutations
// gives the elements that need to be transformed //- gives the elements that need to be transformed
labelListList transformElements_; labelListList transformElements_;
//- Destination in constructMap for transformed elements //- Destination in constructMap for transformed elements
@ -327,8 +324,17 @@ public:
// Constructors // Constructors
//- Construct null //- Inherit constructors
mapDistribute(const label comm = UPstream::worldComm); using mapDistributeBase::mapDistributeBase;
//- Default construct - uses worldComm
mapDistribute();
//- Default construct with specified communicator
explicit mapDistribute(const label comm);
//- Move construct from base, no transforms
explicit mapDistribute(mapDistributeBase&& map);
//- Copy construct //- Copy construct
explicit mapDistribute(const mapDistribute& map); explicit mapDistribute(const mapDistribute& map);
@ -336,14 +342,10 @@ public:
//- Move construct //- Move construct
explicit mapDistribute(mapDistribute&& map); explicit mapDistribute(mapDistribute&& map);
//- Move construct from components //- Read construct from dictionary
mapDistribute explicit mapDistribute
( (
const label constructSize, const dictionary& dict,
labelListList&& subMap,
labelListList&& constructMap,
const bool subHasFlip = false,
const bool constructHasFlip = false,
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
@ -360,44 +362,6 @@ public:
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
//- Construct from reverse addressing: per data item the send
//- processor and the receive processor.
//
// \note data are not stored per processor so cannot use printLayout.
mapDistribute
(
const labelUList& sendProcs,
const labelUList& recvProcs,
const label comm = UPstream::worldComm
);
//- Construct from list of (possibly) remote elements in globalIndex
//- numbering (or -1).
// Determines compact numbering (see above) and distribute map to
// get data into this ordering and renumbers the elements to be in
// compact numbering.
mapDistribute
(
const globalIndex&,
labelList& elements,
List<Map<label>>& compactMap,
const int tag = Pstream::msgType(),
const label comm = UPstream::worldComm
);
//- Special variant that works with the info sorted into bins
//- according to local indices.
// For example, cellCells where cellCells[localCelli] is a list of
// global cells.
mapDistribute
(
const globalIndex&,
labelListList& cellCells,
List<Map<label>>& compactMap,
const int tag = Pstream::msgType(),
const label comm = UPstream::worldComm
);
//- Construct from list of (possibly remote) untransformed elements //- Construct from list of (possibly remote) untransformed elements
//- in globalIndex numbering (or -1) and (possibly remote) //- in globalIndex numbering (or -1) and (possibly remote)
//- transformed elements in globalIndexAndTransform numbering. //- transformed elements in globalIndexAndTransform numbering.
@ -412,7 +376,7 @@ public:
const labelPairList& transformedElements, const labelPairList& transformedElements,
labelList& transformedIndices, labelList& transformedIndices,
List<Map<label>>& compactMap, List<Map<label>>& compactMap,
const int tag = Pstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
@ -425,18 +389,7 @@ public:
const List<labelPairList>& transformedElements, const List<labelPairList>& transformedElements,
labelListList& transformedIndices, labelListList& transformedIndices,
List<Map<label>>& compactMap, List<Map<label>>& compactMap,
const int tag = Pstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm
);
//- Construct from my elements to send. Assumes layout is my elements
// first followed by elements from all other processors in consecutive
// order
explicit mapDistribute
(
labelListList&& subMap,
const bool subHasFlip = false,
const bool constructHasFlip = false,
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
@ -457,13 +410,13 @@ public:
//- For every globalIndexAndTransform::transformPermutations //- For every globalIndexAndTransform::transformPermutations
// gives the elements that need to be transformed // gives the elements that need to be transformed
const labelListList& transformElements() const const labelListList& transformElements() const noexcept
{ {
return transformElements_; return transformElements_;
} }
//- Destination in constructMap for transformed elements //- Destination in constructMap for transformed elements
const labelList& transformStart() const const labelList& transformStart() const noexcept
{ {
return transformStart_; return transformStart_;
} }
@ -474,6 +427,9 @@ public:
// Other // Other
//- Reset to zero size, only retaining communicator
void clear();
//- Transfer the contents of the argument and annul the argument. //- Transfer the contents of the argument and annul the argument.
void transfer(mapDistribute& map); void transfer(mapDistribute& map);
@ -510,7 +466,7 @@ public:
void reverseDistribute void reverseDistribute
( (
const label constructSize, const label constructSize,
List<T>&, List<T>& fld,
const bool dummyTransform = true, const bool dummyTransform = true,
const int tag = UPstream::msgType() const int tag = UPstream::msgType()
) const; ) const;
@ -565,11 +521,6 @@ public:
// storage (local data first, then non-local data) // storage (local data first, then non-local data)
void printLayout(Ostream& os) const; void printLayout(Ostream& os) const;
//- Correct for topo change.
void updateMesh(const mapPolyMesh&)
{
NotImplemented;
}
// Member Operators // Member Operators
@ -580,14 +531,28 @@ public:
void operator=(mapDistribute&& rhs); void operator=(mapDistribute&& rhs);
// IOstream operators // IOstream Operators
//- Read dictionary from Istream //- Read entries from dictionary format
void readDict(const dictionary& dict);
//- Write entries in dictionary format
void writeEntries(Ostream& os) const;
//- Read plain content (not dictionary) from Istream
friend Istream& operator>>(Istream&, mapDistribute&); friend Istream& operator>>(Istream&, mapDistribute&);
//- Write dictionary to Ostream //- Write plain content (not dictionary) to Ostream
friend Ostream& operator<<(Ostream&, const mapDistribute&); friend Ostream& operator<<(Ostream&, const mapDistribute&);
// Housekeeping
//- No correction for topo change
void updateMesh(const mapPolyMesh&)
{
NotImplemented;
}
}; };

View File

@ -27,6 +27,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "mapDistributeBase.H" #include "mapDistributeBase.H"
#include "bitSet.H"
#include "commSchedule.H" #include "commSchedule.H"
#include "labelPairHashes.H" #include "labelPairHashes.H"
#include "globalIndex.H" #include "globalIndex.H"
@ -40,6 +41,146 @@ namespace Foam
} }
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
bool Foam::mapDistributeBase::hasFlipAddressing(const labelUList& map)
{
for (const label val : map)
{
if (!val)
{
// Cannot be flipped addressing if it contains zero.
return false;
}
else if (val < 0)
{
// Must be flipped addressing if it contains negatives.
return true;
}
}
return false;
}
bool Foam::mapDistributeBase::hasFlipAddressing(const labelListList& maps)
{
for (const labelList& map : maps)
{
for (const label val : map)
{
if (!val)
{
// Cannot be flipped addressing if it contains zero.
return false;
}
else if (val < 0)
{
// Must be flipped addressing if it contains negatives.
return true;
}
}
}
return false;
}
Foam::label Foam::mapDistributeBase::getMappedSize
(
const labelListList& maps,
const bool hasFlip
)
{
label maxIndex = -1;
for (const labelList& map : maps)
{
for (label index : map)
{
if (hasFlip)
{
index = mag(index)-1;
}
maxIndex = max(maxIndex, index);
}
}
return (maxIndex+1);
}
Foam::label Foam::mapDistributeBase::countUnmapped
(
const labelUList& elements,
const labelListList& maps,
const bool hasFlip
)
{
if (elements.empty())
{
return 0;
}
// Moderately efficient markup/search
bitSet unvisited(elements);
label nUnmapped = unvisited.count();
if (hasFlip)
{
for (const labelList& map : maps)
{
for (label index : map)
{
index = mag(index)-1;
if (unvisited.unset(index))
{
--nUnmapped;
if (!nUnmapped) break;
}
}
}
}
else
{
for (const labelList& map : maps)
{
for (label index : map)
{
if (unvisited.unset(index))
{
--nUnmapped;
if (!nUnmapped) break;
}
}
}
}
return nUnmapped;
}
void Foam::mapDistributeBase::checkReceivedSize
(
const label proci,
const label expectedSize,
const label receivedSize
)
{
if (receivedSize != expectedSize)
{
FatalErrorInFunction
<< "Expected from processor " << proci
<< " " << expectedSize << " but received "
<< receivedSize << " elements."
<< abort(FatalError);
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
@ -121,7 +262,6 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
// Broadcast: send comms information to all // Broadcast: send comms information to all
Pstream::broadcast(allComms, comm); Pstream::broadcast(allComms, comm);
// Determine my schedule. // Determine my schedule.
labelList mySchedule labelList mySchedule
( (
@ -134,28 +274,6 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
// Processors involved in my schedule // Processors involved in my schedule
return List<labelPair>(allComms, mySchedule); return List<labelPair>(allComms, mySchedule);
//if (debug)
//{
// Pout<< "I need to:" << endl;
// const List<labelPair>& comms = schedule();
// forAll(comms, i)
// {
// const labelPair& twoProcs = comms[i];
// label sendProc = twoProcs[0];
// label recvProc = twoProcs[1];
//
// if (recvProc == myRank)
// {
// Pout<< " receive from " << sendProc << endl;
// }
// else
// {
// Pout<< " send to " << recvProc << endl;
// }
// }
//}
} }
@ -167,29 +285,26 @@ const Foam::List<Foam::labelPair>& Foam::mapDistributeBase::schedule() const
( (
new List<labelPair> new List<labelPair>
( (
schedule(subMap_, constructMap_, Pstream::msgType(), comm_) schedule(subMap_, constructMap_, UPstream::msgType(), comm_)
) )
); );
} }
return *schedulePtr_; return *schedulePtr_;
} }
void Foam::mapDistributeBase::checkReceivedSize const Foam::List<Foam::labelPair>& Foam::mapDistributeBase::whichSchedule
( (
const label proci, const UPstream::commsTypes commsType
const label expectedSize, ) const
const label receivedSize
)
{ {
if (receivedSize != expectedSize) if (commsType == UPstream::commsTypes::scheduled)
{ {
FatalErrorInFunction return schedule();
<< "Expected from processor " << proci
<< " " << expectedSize << " but received "
<< receivedSize << " elements."
<< abort(FatalError);
} }
return List<labelPair>::null();
} }
@ -224,12 +339,9 @@ void Foam::mapDistributeBase::printLayout(Ostream& os) const
} }
} }
label localSize; label localSize(0);
if (maxIndex[myRank] == labelMin)
{ if (maxIndex[myRank] != labelMin)
localSize = 0;
}
else
{ {
localSize = maxIndex[myRank]+1; localSize = maxIndex[myRank]+1;
} }
@ -237,18 +349,21 @@ void Foam::mapDistributeBase::printLayout(Ostream& os) const
os << "Layout: (constructSize:" << constructSize_ os << "Layout: (constructSize:" << constructSize_
<< " subHasFlip:" << subHasFlip_ << " subHasFlip:" << subHasFlip_
<< " constructHasFlip:" << constructHasFlip_ << " constructHasFlip:" << constructHasFlip_
<< ")" << endl << ")" << nl
<< "local (processor " << myRank << "):" << endl << "local (processor " << myRank << "):" << nl
<< " start : 0" << endl << " start : 0" << nl
<< " size : " << localSize << endl; << " size : " << localSize << endl;
label offset = localSize; label offset = localSize;
forAll(minIndex, proci) forAll(minIndex, proci)
{ {
if (proci != myRank) if (proci != myRank && !constructMap_[proci].empty())
{ {
if (constructMap_[proci].size() > 0) label size(0);
if (maxIndex[proci] != labelMin)
{ {
size = maxIndex[proci]-minIndex[proci]+1;
if (minIndex[proci] != offset) if (minIndex[proci] != offset)
{ {
FatalErrorInFunction FatalErrorInFunction
@ -257,16 +372,15 @@ void Foam::mapDistributeBase::printLayout(Ostream& os) const
<< " minIndex:" << minIndex[proci] << " minIndex:" << minIndex[proci]
<< abort(FatalError); << abort(FatalError);
} }
}
label size = maxIndex[proci]-minIndex[proci]+1; os << "processor " << proci << ':' << nl
os << "processor " << proci << ':' << endl << " start : " << offset << nl
<< " start : " << offset << endl
<< " size : " << size << endl; << " size : " << size << endl;
offset += size; offset += size;
} }
} }
}
} }
@ -280,8 +394,6 @@ void Foam::mapDistributeBase::calcCompactAddressing
const label myRank = Pstream::myProcNo(comm_); const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_); const label nProcs = Pstream::nProcs(comm_);
compactMap.setSize(nProcs);
// Count all (non-local) elements needed. Just for presizing map. // Count all (non-local) elements needed. Just for presizing map.
labelList nNonLocal(nProcs, Zero); labelList nNonLocal(nProcs, Zero);
@ -294,6 +406,8 @@ void Foam::mapDistributeBase::calcCompactAddressing
} }
} }
compactMap.resize_nocopy(nProcs);
forAll(compactMap, proci) forAll(compactMap, proci)
{ {
compactMap[proci].clear(); compactMap[proci].clear();
@ -328,8 +442,6 @@ void Foam::mapDistributeBase::calcCompactAddressing
const label myRank = Pstream::myProcNo(comm_); const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_); const label nProcs = Pstream::nProcs(comm_);
compactMap.setSize(nProcs);
// Count all (non-local) elements needed. Just for presizing map. // Count all (non-local) elements needed. Just for presizing map.
labelList nNonLocal(nProcs, Zero); labelList nNonLocal(nProcs, Zero);
@ -345,6 +457,8 @@ void Foam::mapDistributeBase::calcCompactAddressing
} }
} }
compactMap.resize_nocopy(nProcs);
forAll(compactMap, proci) forAll(compactMap, proci)
{ {
compactMap[proci].clear(); compactMap[proci].clear();
@ -401,7 +515,6 @@ void Foam::mapDistributeBase::exchangeAddressing
} }
// Find out what to receive/send in compact addressing. // Find out what to receive/send in compact addressing.
// What I want to receive is what others have to send // What I want to receive is what others have to send
@ -430,7 +543,7 @@ void Foam::mapDistributeBase::exchangeAddressing
const label compactI = compactStart[proci] + iter.val(); const label compactI = compactStart[proci] + iter.val();
remoteElem[i] = iter.key(); remoteElem[i] = iter.key();
localElem[i] = compactI; localElem[i] = compactI;
iter() = compactI; iter.val() = compactI;
i++; i++;
} }
} }
@ -510,7 +623,7 @@ void Foam::mapDistributeBase::exchangeAddressing
const label compactI = compactStart[proci] + iter.val(); const label compactI = compactStart[proci] + iter.val();
remoteElem[i] = iter.key(); remoteElem[i] = iter.key();
localElem[i] = compactI; localElem[i] = compactI;
iter() = compactI; iter.val() = compactI;
i++; i++;
} }
} }
@ -538,17 +651,24 @@ void Foam::mapDistributeBase::exchangeAddressing
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::mapDistributeBase::mapDistributeBase()
:
mapDistributeBase(UPstream::worldComm)
{}
Foam::mapDistributeBase::mapDistributeBase(const label comm) Foam::mapDistributeBase::mapDistributeBase(const label comm)
: :
constructSize_(0), constructSize_(0),
subMap_(),
constructMap_(),
subHasFlip_(false), subHasFlip_(false),
constructHasFlip_(false), constructHasFlip_(false),
comm_(comm), comm_(comm),
schedulePtr_() schedulePtr_(nullptr)
{} {}
Foam::mapDistributeBase::mapDistributeBase(const mapDistributeBase& map) Foam::mapDistributeBase::mapDistributeBase(const mapDistributeBase& map)
: :
constructSize_(map.constructSize_), constructSize_(map.constructSize_),
@ -557,13 +677,13 @@ Foam::mapDistributeBase::mapDistributeBase(const mapDistributeBase& map)
subHasFlip_(map.subHasFlip_), subHasFlip_(map.subHasFlip_),
constructHasFlip_(map.constructHasFlip_), constructHasFlip_(map.constructHasFlip_),
comm_(map.comm_), comm_(map.comm_),
schedulePtr_() schedulePtr_(nullptr)
{} {}
Foam::mapDistributeBase::mapDistributeBase(mapDistributeBase&& map) Foam::mapDistributeBase::mapDistributeBase(mapDistributeBase&& map)
: :
mapDistributeBase() mapDistributeBase(map.comm())
{ {
transfer(map); transfer(map);
} }
@ -585,7 +705,7 @@ Foam::mapDistributeBase::mapDistributeBase
subHasFlip_(subHasFlip), subHasFlip_(subHasFlip),
constructHasFlip_(constructHasFlip), constructHasFlip_(constructHasFlip),
comm_(comm), comm_(comm),
schedulePtr_() schedulePtr_(nullptr)
{} {}
@ -597,10 +717,12 @@ Foam::mapDistributeBase::mapDistributeBase
) )
: :
constructSize_(0), constructSize_(0),
subMap_(),
constructMap_(),
subHasFlip_(false), subHasFlip_(false),
constructHasFlip_(false), constructHasFlip_(false),
comm_(comm), comm_(comm),
schedulePtr_() schedulePtr_(nullptr)
{ {
const label myRank = Pstream::myProcNo(comm_); const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_); const label nProcs = Pstream::nProcs(comm_);
@ -627,7 +749,7 @@ Foam::mapDistributeBase::mapDistributeBase
if (myRank == sendProc) if (myRank == sendProc)
{ {
// I am the sender. Count destination processor. // I am the sender.
nSend[recvProc]++; nSend[recvProc]++;
} }
if (myRank == recvProc) if (myRank == recvProc)
@ -647,6 +769,9 @@ Foam::mapDistributeBase::mapDistributeBase
nSend = 0; nSend = 0;
nRecv = 0; nRecv = 0;
// Largest entry inside constructMap
label maxRecvIndex = -1;
forAll(sendProcs, sampleI) forAll(sendProcs, sampleI)
{ {
const label sendProc = sendProcs[sampleI]; const label sendProc = sendProcs[sampleI];
@ -661,10 +786,11 @@ Foam::mapDistributeBase::mapDistributeBase
{ {
// I am the receiver. // I am the receiver.
constructMap_[sendProc][nRecv[sendProc]++] = sampleI; constructMap_[sendProc][nRecv[sendProc]++] = sampleI;
// Largest entry inside constructMap maxRecvIndex = sampleI;
constructSize_ = sampleI+1;
} }
} }
constructSize_ = maxRecvIndex+1;
} }
@ -678,10 +804,12 @@ Foam::mapDistributeBase::mapDistributeBase
) )
: :
constructSize_(0), constructSize_(0),
subMap_(),
constructMap_(),
subHasFlip_(false), subHasFlip_(false),
constructHasFlip_(false), constructHasFlip_(false),
comm_(comm), comm_(comm),
schedulePtr_() schedulePtr_(nullptr)
{ {
// Construct per processor compact addressing of the global elements // Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since // needed. The ones from the local processor are not included since
@ -739,10 +867,12 @@ Foam::mapDistributeBase::mapDistributeBase
) )
: :
constructSize_(0), constructSize_(0),
subMap_(),
constructMap_(),
subHasFlip_(false), subHasFlip_(false),
constructHasFlip_(false), constructHasFlip_(false),
comm_(comm), comm_(comm),
schedulePtr_() schedulePtr_(nullptr)
{ {
// Construct per processor compact addressing of the global elements // Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since // needed. The ones from the local processor are not included since
@ -800,10 +930,11 @@ Foam::mapDistributeBase::mapDistributeBase
: :
constructSize_(0), constructSize_(0),
subMap_(std::move(subMap)), subMap_(std::move(subMap)),
constructMap_(),
subHasFlip_(subHasFlip), subHasFlip_(subHasFlip),
constructHasFlip_(constructHasFlip), constructHasFlip_(constructHasFlip),
comm_(comm), comm_(comm),
schedulePtr_() schedulePtr_(nullptr)
{ {
const label myRank = Pstream::myProcNo(comm_); const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_); const label nProcs = Pstream::nProcs(comm_);
@ -847,13 +978,43 @@ Foam::mapDistributeBase::mapDistributeBase
} }
Foam::mapDistributeBase::mapDistributeBase(Istream& is) // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::labelList Foam::mapDistributeBase::subMapSizes() const
{ {
is >> *this; labelList sizes(subMap_.size());
forAll(subMap_, i)
{
sizes[i] = subMap_[i].size();
}
return sizes;
} }
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // Foam::labelList Foam::mapDistributeBase::constructMapSizes() const
{
labelList sizes(constructMap_.size());
forAll(constructMap_, i)
{
sizes[i] = constructMap_[i].size();
}
return sizes;
}
void Foam::mapDistributeBase::clear()
{
constructSize_ = 0;
subMap_.clear();
constructMap_.clear();
subHasFlip_ = false;
constructHasFlip_ = false;
// Leave comm_ intact
schedulePtr_.reset(nullptr);
}
void Foam::mapDistributeBase::transfer(mapDistributeBase& rhs) void Foam::mapDistributeBase::transfer(mapDistributeBase& rhs)
{ {
@ -869,7 +1030,7 @@ void Foam::mapDistributeBase::transfer(mapDistributeBase& rhs)
subHasFlip_ = rhs.subHasFlip_; subHasFlip_ = rhs.subHasFlip_;
constructHasFlip_ = rhs.constructHasFlip_; constructHasFlip_ = rhs.constructHasFlip_;
comm_ = rhs.comm_; comm_ = rhs.comm_;
schedulePtr_.clear(); schedulePtr_.reset(nullptr);
rhs.constructSize_ = 0; rhs.constructSize_ = 0;
rhs.subHasFlip_ = false; rhs.subHasFlip_ = false;
@ -1312,7 +1473,7 @@ void Foam::mapDistributeBase::operator=(const mapDistributeBase& rhs)
subHasFlip_ = rhs.subHasFlip_; subHasFlip_ = rhs.subHasFlip_;
constructHasFlip_ = rhs.constructHasFlip_; constructHasFlip_ = rhs.constructHasFlip_;
comm_ = rhs.comm_; comm_ = rhs.comm_;
schedulePtr_.clear(); schedulePtr_.reset(nullptr);
} }
@ -1326,32 +1487,4 @@ void Foam::mapDistributeBase::operator=(mapDistributeBase&& rhs)
} }
// * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, mapDistributeBase& map)
{
is.fatalCheck(FUNCTION_NAME);
is >> map.constructSize_ >> map.subMap_ >> map.constructMap_
>> map.subHasFlip_ >> map.constructHasFlip_
>> map.comm_;
return is;
}
// * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistributeBase& map)
{
os << map.constructSize_ << token::NL
<< map.subMap_ << token::NL
<< map.constructMap_ << token::NL
<< map.subHasFlip_ << token::SPACE << map.constructHasFlip_
<< token::SPACE << map.comm_ << token::NL;
return os;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2017 OpenFOAM Foundation Copyright (C) 2015-2017 OpenFOAM Foundation
Copyright (C) 2015-2016 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -66,31 +66,33 @@ Note:
SourceFiles SourceFiles
mapDistributeBase.C mapDistributeBase.C
mapDistributeBaseIO.C
mapDistributeBaseTemplates.C mapDistributeBaseTemplates.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef mapDistributeBase_H #ifndef Foam_mapDistributeBase_H
#define mapDistributeBase_H #define Foam_mapDistributeBase_H
#include "boolList.H"
#include "labelList.H" #include "labelList.H"
#include "labelPair.H" #include "labelPair.H"
#include "Pstream.H" #include "Pstream.H"
#include "boolList.H"
#include "Map.H" #include "Map.H"
#include "InfoProxy.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
class mapPolyMesh; // Forward Declarations
class bitSet;
class dictionary;
class globalIndex; class globalIndex;
class PstreamBuffers; class PstreamBuffers;
class mapPolyMesh;
// Forward declaration of friend functions and operators
class mapDistributeBase; class mapDistributeBase;
Istream& operator>>(Istream&, mapDistributeBase&); Istream& operator>>(Istream&, mapDistributeBase&);
@ -103,9 +105,7 @@ Ostream& operator<<(Ostream&, const mapDistributeBase&);
class mapDistributeBase class mapDistributeBase
{ {
protected: // Private Data
// Protected data
//- Size of reconstructed data //- Size of reconstructed data
label constructSize_; label constructSize_;
@ -129,8 +129,11 @@ protected:
mutable autoPtr<List<labelPair>> schedulePtr_; mutable autoPtr<List<labelPair>> schedulePtr_;
// Private Member Functions protected:
// Protected Member Functions
//- Fatal if expected and received size are not equal
static void checkReceivedSize static void checkReceivedSize
( (
const label proci, const label proci,
@ -138,6 +141,17 @@ protected:
const label receivedSize const label receivedSize
); );
//- Scan the maps for the max addressed index.
//
// \param maps The maps to scan
// \param hasFlip True if maps has flip addressing
// \return max-size needed for addressing (eg, constructSize)
static label getMappedSize
(
const labelListList& maps,
const bool hasFlip
);
//- Construct per processor compact addressing of the global elements //- Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since // needed. The ones from the local processor are not included since
// these are always all needed. // these are always all needed.
@ -172,6 +186,7 @@ protected:
labelList& compactStart labelList& compactStart
); );
template<class T, class CombineOp, class NegateOp> template<class T, class CombineOp, class NegateOp>
static void flipAndCombine static void flipAndCombine
( (
@ -183,15 +198,50 @@ protected:
List<T>& lhs List<T>& lhs
); );
//- Lookup a field value at specified index and return its value
//- after any flip negation operations
template<class T, class NegateOp> template<class T, class NegateOp>
static T accessAndFlip static T accessAndFlip
( (
const UList<T>& fld, const UList<T>& values,
const label index, const label index,
const bool hasFlip, const bool hasFlip,
const NegateOp& negOp const NegateOp& negOp
); );
//- Lookup field values at specified indices and return
//- after any flip negation operations
template<class T, class NegateOp>
static List<T> accessAndFlip
(
const UList<T>& values,
const labelUList& indices,
const bool hasFlip,
const NegateOp& negOp
);
private:
// Private Member Functions
//- Helper for renumbering compacted map elements and updating the
//- supplied old-to-new mapping to account for the visit order of
//- the original elements
//
// \param origElements The original elements visited (eg, meshPoints)
// \param[in,out] oldToNew The old-to-new mapping
// \param[in,out] mapElements The map to be renumbered
// \param hasFlip True if map has flip addressing
static void renumberVisitOrder
(
const labelUList& origElements,
labelList& oldToNew,
labelListList& maps,
const bool hasFlip
);
public: public:
// Declare name of the class and its debug switch // Declare name of the class and its debug switch
@ -200,8 +250,11 @@ public:
// Constructors // Constructors
//- Construct null //- Default construct (uses worldComm)
mapDistributeBase(const label comm = UPstream::worldComm); mapDistributeBase();
//- Default construct with specified communicator
explicit mapDistributeBase(const label comm);
//- Copy construct //- Copy construct
mapDistributeBase(const mapDistributeBase& map); mapDistributeBase(const mapDistributeBase& map);
@ -209,7 +262,14 @@ public:
//- Move construct //- Move construct
mapDistributeBase(mapDistributeBase&& map); mapDistributeBase(mapDistributeBase&& map);
//- Construct from components //- Read construct from dictionary
explicit mapDistributeBase
(
const dictionary& dict,
const label comm = UPstream::worldComm
);
//- Move construct from components
mapDistributeBase mapDistributeBase
( (
const label constructSize, const label constructSize,
@ -221,8 +281,9 @@ public:
); );
//- Construct from reverse addressing: per data item the send //- Construct from reverse addressing: per data item the send
// processor and the receive processor. (note: data is not stored //- processor and the receive processor.
// sorted per processor so cannot use printLayout). //
// \note data is not sorted per processor - cannot use printLayout!
mapDistributeBase mapDistributeBase
( (
const labelUList& sendProcs, const labelUList& sendProcs,
@ -231,9 +292,11 @@ public:
); );
//- Construct from list of (possibly) remote elements in globalIndex //- Construct from list of (possibly) remote elements in globalIndex
// numbering (or -1). Determines compact numbering (see above) and //- numbering (or -1).
// distribute map to get data into this ordering and renumbers the //
// elements to be in compact numbering. // Determines compact numbering (see above) and distribute map
// to get data into this ordering and renumbers the elements to
// be in compact numbering.
mapDistributeBase mapDistributeBase
( (
const globalIndex&, const globalIndex&,
@ -244,7 +307,9 @@ public:
); );
//- Special variant that works with the info sorted into bins //- Special variant that works with the info sorted into bins
// according to local indices. E.g. think cellCells where //- according to local indices.
//
// E.g. think cellCells where
// cellCells[localCellI] is a list of global cells // cellCells[localCellI] is a list of global cells
mapDistributeBase mapDistributeBase
( (
@ -255,9 +320,9 @@ public:
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
//- Construct from my elements to send. Assumes layout is my elements //- Construct from my elements to send.
// first followed by elements from all other processors in consecutive // Assumes layout is my elements first followed by elements
// order // from all other processors in consecutive order.
explicit mapDistributeBase explicit mapDistributeBase
( (
labelListList&& subMap, labelListList&& subMap,
@ -267,7 +332,40 @@ public:
); );
//- Construct from Istream //- Construct from Istream
mapDistributeBase(Istream& is); explicit mapDistributeBase(Istream& is);
// Static Functions
//- Test for flip addressing, where flips are encoded as negative
//- indices and non-flips are encoded as positive non-zero indices.
//
// Exits early on the first detected zero or negative, which
// makes this more efficient than testing min(map) \< 0.
//
// \note may return a false negative (ie, no flips detected)
// even when flip addressing is used, but the local map does not
// contain any flipped elements
static bool hasFlipAddressing(const labelUList& map);
//- Test for flip addressing, where flips are encoded as negative
//- indices and non-flips are encoded as positive non-zero indices.
//
// See notes above.
static bool hasFlipAddressing(const labelListList& maps);
//- Count the number of unmapped elements.
//
// \param elements The elements that are expected to be mapped
// \param maps The maps to scan
// \param hasFlip True if maps has flip addressing
// \return number of unmapped elements
static label countUnmapped
(
const labelUList& elements,
const labelListList& maps,
const bool hasFlip
);
// Member Functions // Member Functions
@ -275,85 +373,111 @@ public:
// Access // Access
//- Constructed data size //- Constructed data size
label constructSize() const label constructSize() const noexcept
{ {
return constructSize_; return constructSize_;
} }
//- Constructed data size //- Constructed data size
label& constructSize() label& constructSize() noexcept
{ {
return constructSize_; return constructSize_;
} }
//- From subsetted data back to original data //- From subsetted data back to original data
const labelListList& subMap() const const labelListList& subMap() const noexcept
{ {
return subMap_; return subMap_;
} }
//- From subsetted data back to original data //- From subsetted data back to original data
labelListList& subMap() labelListList& subMap() noexcept
{ {
return subMap_; return subMap_;
} }
//- From subsetted data to new reconstructed data //- From subsetted data to new reconstructed data
const labelListList& constructMap() const const labelListList& constructMap() const noexcept
{ {
return constructMap_; return constructMap_;
} }
//- From subsetted data to new reconstructed data //- From subsetted data to new reconstructed data
labelListList& constructMap() labelListList& constructMap() noexcept
{ {
return constructMap_; return constructMap_;
} }
//- Does subMap include a sign //- Does subMap include a sign
bool subHasFlip() const bool subHasFlip() const noexcept
{ {
return subHasFlip_; return subHasFlip_;
} }
//- Does subMap include a sign //- Does subMap include a sign
bool& subHasFlip() bool& subHasFlip() noexcept
{ {
return subHasFlip_; return subHasFlip_;
} }
//- Does constructMap include a sign //- Does constructMap include a sign
bool constructHasFlip() const bool constructHasFlip() const noexcept
{ {
return constructHasFlip_; return constructHasFlip_;
} }
//- Does constructMap include a sign //- Does constructMap include a sign
bool& constructHasFlip() bool& constructHasFlip() noexcept
{ {
return constructHasFlip_; return constructHasFlip_;
} }
label comm() const //- The communicator used
label comm() const noexcept
{ {
return comm_; return comm_;
} }
//- Calculate a schedule. See above. //- The number of sub-lists within the maps
label nMaps() const noexcept
{
return constructMap_.size();
}
//- The sizes of the subMap lists
labelList subMapSizes() const;
//- The sizes of the constructMap lists
labelList constructMapSizes() const;
// Schedule
//- Calculate a communication schedule. See above.
static List<labelPair> schedule static List<labelPair> schedule
( (
const labelListList& subMap, const labelListList& subMap,
const labelListList& constructMap, const labelListList& constructMap,
const int tag, const int tag, // Message tag: msgType()
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
//- Return a schedule. Demand driven. See above. //- Return a schedule. Demand driven. See above.
const List<labelPair>& schedule() const; const List<labelPair>& schedule() const;
//- Return real or dummy schedule depending on the
//- communication type
const List<labelPair>& whichSchedule
(
const UPstream::commsTypes commsType
) const;
// Other // Other
//- Reset to zero size, only retaining communicator
void clear();
//- Transfer the contents of the argument and annul the argument. //- Transfer the contents of the argument and annul the argument.
void transfer(mapDistributeBase& rhs); void transfer(mapDistributeBase& rhs);
@ -366,18 +490,35 @@ public:
const label globalElement const label globalElement
); );
//- Compact maps. Gets per field a bool whether it is used (locally) //- Helper for renumbering the (compacted) map elements
// and works out itself what this side and sender side can remove //- using the supplied old-to-new mapping.
// from maps. Only compacts non-local elements (i.e. the stuff // Only compacts the maps, does not change the local layout.
// that gets sent over), does not change the local layout //
// \param[in,out] mapElements The map to be renumbered
// \param oldToNew The old-to-new mapping
// \param hasFlip True if map has flip addressing
//
// \return max-size needed for new addressing (eg, constructSize)
static label renumberMap
(
labelListList& mapElements,
const labelUList& oldToNew,
const bool hasFlip
);
// Compaction
//- Compact all maps and layout.
// Returns compaction maps for subMap and constructMap
void compact void compact
( (
const boolList& elemIsUsed, const boolList& elemIsUsed,
const int tag = UPstream::msgType() const int tag = UPstream::msgType()
); );
//- Compact all maps and layout. Returns compaction maps for //- Compact all maps and layout.
// subMap and constructMap // Returns compaction maps for subMap and constructMap
void compact void compact
( (
const boolList& elemIsUsed, const boolList& elemIsUsed,
@ -387,8 +528,13 @@ public:
const int tag = UPstream::msgType() const int tag = UPstream::msgType()
); );
//- Distribute data. Note:schedule only used for
// Pstream::commsTypes::scheduled for now, all others just use // Distribute
//- Distribute data with specified negate operator (for flips).
//
// \note schedule currently only used for
// Pstream::commsTypes::scheduled, all others just use
// send-to-all, receive-from-all. // send-to-all, receive-from-all.
template<class T, class NegateOp> template<class T, class NegateOp>
static void distribute static void distribute
@ -400,13 +546,15 @@ public:
const bool subHasFlip, const bool subHasFlip,
const labelListList& constructMap, const labelListList& constructMap,
const bool constructHasFlip, const bool constructHasFlip,
List<T>&, List<T>& field,
const NegateOp& negOp, const NegateOp& negOp,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
//- Distribute data. If multiple processors writing to same //- Distribute data with specified combine operation
//
// If multiple processors writing to same
// position adds contributions using cop. // position adds contributions using cop.
template<class T, class CombineOp, class NegateOp> template<class T, class CombineOp, class NegateOp>
static void distribute static void distribute
@ -418,7 +566,7 @@ public:
const bool subHasFlip, const bool subHasFlip,
const labelListList& constructMap, const labelListList& constructMap,
const bool constructHasFlip, const bool constructHasFlip,
List<T>&, List<T>& field,
const T& nullValue, const T& nullValue,
const CombineOp& cop, const CombineOp& cop,
const NegateOp& negOp, const NegateOp& negOp,
@ -426,69 +574,139 @@ public:
const label comm = UPstream::worldComm const label comm = UPstream::worldComm
); );
//- Distribute data using default commsType.
//- Distribute data using default commsType
//- and the default flip/negate operator.
template<class T> template<class T>
void distribute void distribute
( (
List<T>& fld, List<T>& values,
const int tag = UPstream::msgType() const int tag = UPstream::msgType()
) const; ) const;
//- Distribute data using default commsType. //- Distribute data using default commsType
//- and the default flip/negate operator.
template<class T>
void distribute
(
DynamicList<T>& values,
const int tag = UPstream::msgType()
) const;
//- Distribute data using default commsType
//- and the specified negate operator (for flips).
template<class T, class NegateOp> template<class T, class NegateOp>
void distribute void distribute
( (
List<T>& fld, List<T>& values,
const NegateOp& negOp, const NegateOp& negOp,
const int tag = UPstream::msgType() const int tag = UPstream::msgType()
) const; ) const;
//- Distribute data using default commsType. //- Distribute data using specified commsType
template<class T> //- and the specified negate operator (for flips).
// Accepts a nullValue to initialize unmapped elements
// (ie, when the constructSize is larger than the number of
// mapped elements).
template<class T, class NegateOp>
void distribute void distribute
( (
DynamicList<T>& fld, const Pstream::commsTypes commsType,
List<T>& values,
const NegateOp& negOp,
const int tag = UPstream::msgType() const int tag = UPstream::msgType()
) const; ) const;
//- Reverse distribute data using default commsType. //- Distribute data using specified commsType
//- and the specified negate operator (for flips).
// Accepts a nullValue to initialize unmapped elements
// (ie, when the constructSize is larger than the number of
// mapped elements).
template<class T, class NegateOp>
void distribute
(
const Pstream::commsTypes commsType,
const T& nullValue,
List<T>& values,
const NegateOp& negOp,
const int tag = UPstream::msgType()
) const;
//- Reverse distribute data using default commsType
//- and the default flip/negate operator
template<class T> template<class T>
void reverseDistribute void reverseDistribute
( (
const label constructSize, const label constructSize,
List<T>&, List<T>& values,
const int tag = UPstream::msgType() const int tag = UPstream::msgType()
) const; ) const;
//- Reverse distribute data using default commsType. //- Reverse distribute data using default commsType
// Since constructSize might be larger than supplied size supply //- and the default flip/negate operator.
// a nullValue // Accepts a nullValue to initialize unmapped elements
// (ie, when the constructSize is larger than the subMap).
template<class T> template<class T>
void reverseDistribute void reverseDistribute
( (
const label constructSize, const label constructSize,
const T& nullValue, const T& nullValue,
List<T>& fld, List<T>& values,
const int tag = UPstream::msgType() const int tag = UPstream::msgType()
) const; ) const;
//- Reverse distribute data using specified commsType
//- and the default flip/negate operator
template<class T>
void reverseDistribute
(
const Pstream::commsTypes commsType,
const label constructSize,
List<T>& values,
const int tag = UPstream::msgType()
) const;
//- Reverse distribute data using specified commsType
//- and the specified flip/negate operator.
template<class T, class NegateOp>
void reverseDistribute
(
const Pstream::commsTypes commsType,
const label constructSize,
List<T>& values,
const NegateOp& negOp,
const int tag = UPstream::msgType()
) const;
//- Reverse distribute data using specified commsType
//- and the default flip/negate operator.
// Accepts a nullValue to initialize unmapped elements
// (ie, when the constructSize is larger than the subMap).
template<class T>
void reverseDistribute
(
const Pstream::commsTypes commsType,
const label constructSize,
const T& nullValue,
List<T>& values,
const int tag = UPstream::msgType()
) const;
//- Do all sends using PstreamBuffers //- Do all sends using PstreamBuffers
template<class T> template<class T>
void send(PstreamBuffers&, const List<T>&) const; void send(PstreamBuffers& pBufs, const List<T>& field) const;
//- Do all receives using PstreamBuffers //- Do all receives using PstreamBuffers
template<class T> template<class T>
void receive(PstreamBuffers&, List<T>&) const; void receive(PstreamBuffers& pBufs, List<T>& field) const;
//- Debug: print layout. Can only be used on maps with sorted //- Debug: print layout. Can only be used on maps with sorted
// storage (local data first, then non-local data) // storage (local data first, then non-local data)
void printLayout(Ostream& os) const; void printLayout(Ostream& os) const;
//- Correct for topo change.
void updateMesh(const mapPolyMesh&)
{
NotImplemented;
}
// Member Operators // Member Operators
@ -499,17 +717,43 @@ public:
void operator=(mapDistributeBase&& rhs); void operator=(mapDistributeBase&& rhs);
// IOstream operators // IOstream Operators
//- Read dictionary from Istream //- Info proxy to print summary information to a stream
InfoProxy<mapDistributeBase> info() const
{
return *this;
}
//- Read entries from dictionary format
void readDict(const dictionary& dict);
//- Write entries in dictionary format
void writeEntries(Ostream& os) const;
//- Read plain content (not dictionary) from Istream
friend Istream& operator>>(Istream&, mapDistributeBase&); friend Istream& operator>>(Istream&, mapDistributeBase&);
//- Write dictionary to Ostream //- Write plain content (not dictionary) to Ostream
friend Ostream& operator<<(Ostream&, const mapDistributeBase&); friend Ostream& operator<<(Ostream&, const mapDistributeBase&);
// Housekeeping
//- No correction for topo change
void updateMesh(const mapPolyMesh&)
{
NotImplemented;
}
}; };
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<>
Ostream& operator<<(Ostream& os, const InfoProxy<mapDistributeBase>& ip);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -0,0 +1,177 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "mapDistributeBase.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// The maps (labelListList) are not human-modifiable but if we need to
// inspect them in ASCII, it is much more convenient if each sub-list
// is flattened on a single line.
static void writeMaps(Ostream& os, const word& key, const labelListList& maps)
{
if (os.format() == IOstream::BINARY)
{
os.writeEntry(key, maps);
}
else
{
os << indent << key << nl
<< maps.size() << nl
<< token::BEGIN_LIST << nl;
// Single-line output
for (const labelList& map : maps)
{
map.writeList(os) << nl;
}
os << token::END_LIST << token::END_STATEMENT << nl;
}
}
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::mapDistributeBase::mapDistributeBase
(
const dictionary& dict,
const label comm
)
:
mapDistributeBase(comm)
{
mapDistributeBase::readDict(dict);
}
Foam::mapDistributeBase::mapDistributeBase(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::mapDistributeBase::readDict(const dictionary& dict)
{
constructSize_ = dict.get<label>("constructSize");
// The subMap
{
const dictionary& subdict = dict.subDict("subMap");
subdict.readEntry("flip", subHasFlip_);
subdict.readEntry("maps", subMap_);
}
// The constructMap
{
const dictionary& subdict = dict.subDict("constructMap");
subdict.readEntry("flip", constructHasFlip_);
subdict.readEntry("maps", constructMap_);
}
}
void Foam::mapDistributeBase::writeEntries(Ostream& os) const
{
os.writeEntry("constructSize", constructSize_);
os << nl;
os.beginBlock("subMap");
os.writeEntry("flip", subHasFlip_);
writeMaps(os, "maps", subMap_);
os.endBlock();
os << nl;
os.beginBlock("constructMap");
os.writeEntry("flip", constructHasFlip_);
writeMaps(os, "maps", constructMap_);
os.endBlock();
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, mapDistributeBase& map)
{
is.fatalCheck(FUNCTION_NAME);
is >> map.constructSize_ >> map.subMap_ >> map.constructMap_
>> map.subHasFlip_ >> map.constructHasFlip_
>> map.comm_;
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistributeBase& map)
{
os << map.constructSize_ << token::NL
<< map.subMap_ << token::NL
<< map.constructMap_ << token::NL
<< map.subHasFlip_ << token::SPACE << map.constructHasFlip_
<< token::SPACE << map.comm_ << token::NL;
return os;
}
template<>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const InfoProxy<mapDistributeBase>& ip
)
{
const auto& map = ip.t_;
// Output as compact pseudo dictionary entries
os.writeEntry("constructSize", map.constructSize());
os << indent << "local { flip " << map.subHasFlip()
<< "; sizes ";
map.subMapSizes().writeList(os) << "; }" << nl;
os << indent << "remote { flip " << map.constructHasFlip()
<< "; sizes ";
map.constructMapSizes().writeList(os) << "; }" << nl;
return os;
}
// ************************************************************************* //

View File

@ -0,0 +1,131 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "mapDistributeBase.H"
#include "bitSet.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::label Foam::mapDistributeBase::renumberMap
(
labelListList& mapElements,
const labelUList& oldToNew,
const bool hasFlip
)
{
label maxIndex = -1;
// Transcribe the map
if (hasFlip)
{
for (labelList& map : mapElements)
{
for (label& val : map)
{
// Unflip indexed value
const label index = oldToNew[mag(val)-1];
if (index >= 0) // Not certain this check is needed
{
maxIndex = max(maxIndex, index);
// Retain flip information from original
val = (val < 0 ? (-index-1) : (index+1));
}
}
}
}
else
{
for (labelList& map : mapElements)
{
for (label& val : map)
{
// Get indexed value (no flipping)
const label index = oldToNew[val];
if (index >= 0) // Not certain this check is needed
{
maxIndex = max(maxIndex, index);
val = index;
}
}
}
}
return (maxIndex+1);
}
void Foam::mapDistributeBase::renumberVisitOrder
(
const labelUList& origElements,
labelList& oldToNew,
labelListList& maps,
const bool hasFlip
)
{
// Both oldToNew and maps refer to compacted numbers in simple
// ascending order, but we want to recover the original walk order.
// CAUTION:
// The following is ill-defined (ie, really bad idea) if the original
// elements contained duplicates!
// Inverse mapping:
// Original id -> compact id -> walked id
labelList compactToWalkOrder(origElements.size(), -1);
forAll(origElements, walkIndex)
{
const label origIndex = origElements[walkIndex];
const label compactIndex = oldToNew[origIndex];
if (compactIndex >= origElements.size())
{
FatalErrorInFunction
<< "Compact index: " << compactIndex
<< " is not represented in the original ("
<< origElements.size()
<< ") elements - indicates an addressing problem" << nl
<< Foam::abort(FatalError);
}
else if (compactIndex >= 0)
{
compactToWalkOrder[compactIndex] = walkIndex;
oldToNew[origIndex] = walkIndex;
}
}
renumberMap(maps, compactToWalkOrder, hasFlip);
}
// ************************************************************************* //

View File

@ -0,0 +1,107 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "mapDistribute.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::mapDistribute::mapDistribute(const dictionary& dict, const label comm)
:
mapDistribute(comm)
{
mapDistribute::readDict(dict);
}
Foam::mapDistribute::mapDistribute(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::mapDistribute::readDict(const dictionary& dict)
{
mapDistributeBase::readDict(dict);
// Treat missing as empty
const dictionary* subdict = dict.findDict("transforms");
if (subdict)
{
subdict->readIfPresent("elements", transformElements_);
subdict->readIfPresent("starts", transformStart_);
}
else
{
transformElements_.clear();
transformStart_.clear();
}
}
void Foam::mapDistribute::writeEntries(Ostream& os) const
{
mapDistributeBase::writeEntries(os);
if (transformElements_.size())
{
os << nl;
os.beginBlock("transforms");
os.writeEntry("elements", transformElements_);
transformStart_.writeEntry("starts", os);
os.endBlock();
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, mapDistribute& map)
{
is.fatalCheck(FUNCTION_NAME);
is >> static_cast<mapDistributeBase&>(map)
>> map.transformElements_ >> map.transformStart_;
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistribute& map)
{
os << static_cast<const mapDistributeBase&>(map) << token::NL
<< map.transformElements_ << token::NL
<< map.transformStart_;
return os;
}
// ************************************************************************* //

View File

@ -62,20 +62,37 @@ void Foam::mapDistributePolyMesh::calcPatchSizes()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::mapDistributePolyMesh::mapDistributePolyMesh() Foam::mapDistributePolyMesh::mapDistributePolyMesh()
:
mapDistributePolyMesh(UPstream::worldComm)
{}
Foam::mapDistributePolyMesh::mapDistributePolyMesh(const label comm)
: :
nOldPoints_(0), nOldPoints_(0),
nOldFaces_(0), nOldFaces_(0),
nOldCells_(0), nOldCells_(0),
oldPatchSizes_(0), oldPatchSizes_(),
oldPatchStarts_(0), oldPatchStarts_(),
oldPatchNMeshPoints_(0), oldPatchNMeshPoints_(),
pointMap_(), pointMap_(comm),
faceMap_(), faceMap_(comm),
cellMap_(), cellMap_(comm),
patchMap_() patchMap_(comm)
{} {}
Foam::mapDistributePolyMesh::mapDistributePolyMesh
(
const mapDistributePolyMesh& map
)
:
mapDistributePolyMesh()
{
deepCopy(map);
}
Foam::mapDistributePolyMesh::mapDistributePolyMesh Foam::mapDistributePolyMesh::mapDistributePolyMesh
( (
mapDistributePolyMesh&& map mapDistributePolyMesh&& map
@ -87,6 +104,25 @@ Foam::mapDistributePolyMesh::mapDistributePolyMesh
} }
Foam::mapDistributePolyMesh::mapDistributePolyMesh
(
mapDistributePolyMesh& map,
bool reuse
)
:
mapDistributePolyMesh()
{
if (reuse)
{
transfer(map);
}
else
{
deepCopy(map);
}
}
Foam::mapDistributePolyMesh::mapDistributePolyMesh Foam::mapDistributePolyMesh::mapDistributePolyMesh
( (
const polyMesh& mesh, const polyMesh& mesh,
@ -117,7 +153,7 @@ Foam::mapDistributePolyMesh::mapDistributePolyMesh
nOldPoints_(nOldPoints), nOldPoints_(nOldPoints),
nOldFaces_(nOldFaces), nOldFaces_(nOldFaces),
nOldCells_(nOldCells), nOldCells_(nOldCells),
oldPatchSizes_(oldPatchStarts.size()), oldPatchSizes_(),
oldPatchStarts_(std::move(oldPatchStarts)), oldPatchStarts_(std::move(oldPatchStarts)),
oldPatchNMeshPoints_(std::move(oldPatchNMeshPoints)), oldPatchNMeshPoints_(std::move(oldPatchNMeshPoints)),
pointMap_ pointMap_
@ -170,7 +206,7 @@ Foam::mapDistributePolyMesh::mapDistributePolyMesh
nOldPoints_(nOldPoints), nOldPoints_(nOldPoints),
nOldFaces_(nOldFaces), nOldFaces_(nOldFaces),
nOldCells_(nOldCells), nOldCells_(nOldCells),
oldPatchSizes_(oldPatchStarts.size()), oldPatchSizes_(),
oldPatchStarts_(std::move(oldPatchStarts)), oldPatchStarts_(std::move(oldPatchStarts)),
oldPatchNMeshPoints_(std::move(oldPatchNMeshPoints)), oldPatchNMeshPoints_(std::move(oldPatchNMeshPoints)),
pointMap_(std::move(pointMap)), pointMap_(std::move(pointMap)),
@ -182,13 +218,43 @@ Foam::mapDistributePolyMesh::mapDistributePolyMesh
} }
Foam::mapDistributePolyMesh::mapDistributePolyMesh(Istream& is) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::mapDistributePolyMesh::clear()
{ {
is >> *this; nOldPoints_ = 0;
nOldFaces_ = 0;
nOldCells_ = 0;
oldPatchSizes_.clear();
oldPatchStarts_.clear();
oldPatchNMeshPoints_.clear();
pointMap_.clear();
faceMap_.clear();
cellMap_.clear();
patchMap_.clear();
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::mapDistributePolyMesh::deepCopy(const mapDistributePolyMesh& rhs)
{
if (this == &rhs)
{
// Self-assignment is a no-op
return;
}
nOldPoints_ = rhs.nOldPoints_;
nOldFaces_ = rhs.nOldFaces_;
nOldCells_ = rhs.nOldCells_;
oldPatchSizes_ = rhs.oldPatchSizes_;
oldPatchStarts_ = rhs.oldPatchStarts_;
oldPatchNMeshPoints_ = rhs.oldPatchNMeshPoints_;
pointMap_ = rhs.pointMap_;
faceMap_ = rhs.faceMap_;
cellMap_ = rhs.cellMap_;
patchMap_ = rhs.patchMap_;
}
void Foam::mapDistributePolyMesh::transfer(mapDistributePolyMesh& rhs) void Foam::mapDistributePolyMesh::transfer(mapDistributePolyMesh& rhs)
{ {
@ -318,45 +384,4 @@ void Foam::mapDistributePolyMesh::operator=(mapDistributePolyMesh&& rhs)
} }
// * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, mapDistributePolyMesh& map)
{
is.fatalCheck(FUNCTION_NAME);
is >> map.nOldPoints_
>> map.nOldFaces_
>> map.nOldCells_
>> map.oldPatchSizes_
>> map.oldPatchStarts_
>> map.oldPatchNMeshPoints_
>> map.pointMap_
>> map.faceMap_
>> map.cellMap_
>> map.patchMap_;
return is;
}
// * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistributePolyMesh& map)
{
os << map.nOldPoints_ << token::SPACE
<< map.nOldFaces_ << token::SPACE
<< map.nOldCells_ << token::NL
<< map.oldPatchSizes_ << token::NL
<< map.oldPatchStarts_ << token::NL
<< map.oldPatchNMeshPoints_ << token::NL
<< map.pointMap_ << token::NL
<< map.faceMap_ << token::NL
<< map.cellMap_ << token::NL
<< map.patchMap_;
return os;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -104,20 +104,34 @@ class mapDistributePolyMesh
void calcPatchSizes(); void calcPatchSizes();
//- No copy construct void deepCopy(const mapDistributePolyMesh& rhs);
mapDistributePolyMesh(const mapDistributePolyMesh&) = delete;
public: public:
// Constructors // Constructors
//- Default construct //- Default construct - uses worldComm
mapDistributePolyMesh(); mapDistributePolyMesh();
//- Default construct with specified communicator
explicit mapDistributePolyMesh(const label comm);
//- Read construct from dictionary
explicit mapDistributePolyMesh
(
const dictionary& dict,
const label comm = UPstream::worldComm
);
//- Copy construct
mapDistributePolyMesh(const mapDistributePolyMesh& map);
//- Move construct //- Move construct
mapDistributePolyMesh(mapDistributePolyMesh&& map); mapDistributePolyMesh(mapDistributePolyMesh&& map);
//- Copy/move construct
mapDistributePolyMesh(mapDistributePolyMesh& map, bool reuse);
//- Construct from components. Note that mesh has to be changed already //- Construct from components. Note that mesh has to be changed already
// since uses mesh.nPoints etc as the new size. // since uses mesh.nPoints etc as the new size.
mapDistributePolyMesh mapDistributePolyMesh
@ -233,6 +247,12 @@ public:
} }
// Edit
//- Reset to zero size, only retaining communicator(s)
void clear();
// Other // Other
//- Transfer the contents of the argument and annul the argument. //- Transfer the contents of the argument and annul the argument.
@ -276,12 +296,6 @@ public:
void distributePatchIndices(labelList& patchIDs) const; void distributePatchIndices(labelList& patchIDs) const;
//- Correct for topo change.
void updateMesh(const mapPolyMesh&)
{
NotImplemented;
}
// Member Operators // Member Operators
@ -292,16 +306,57 @@ public:
void operator=(mapDistributePolyMesh&& map); void operator=(mapDistributePolyMesh&& map);
// IOstream operators // IOstream Operators
//- Read content (not dictionary) from Istream //- Info proxy to print summary information to a stream
InfoProxy<mapDistributePolyMesh> info() const
{
return *this;
}
//- Read entries from dictionary format
void readDict(const dictionary& dict);
//- Write cellMap in dictionary format
void writeCellMapEntries(Ostream& os) const;
//- Write faceMap in dictionary format
void writeFaceMapEntries(Ostream& os) const;
//- Write pointMap entries in dictionary format
void writePointMapEntries(Ostream& os) const;
//- Write patchMap in dictionary format
void writePatchMapEntries(Ostream& os) const;
//- Write all map entries in dictionary format
void writeEntries(Ostream& os) const;
//- Read plain content (not dictionary) from Istream
friend Istream& operator>>(Istream&, mapDistributePolyMesh&); friend Istream& operator>>(Istream&, mapDistributePolyMesh&);
//- Write content (not dictionary) to Ostream //- Write plain content (not dictionary) to Ostream
friend Ostream& operator<<(Ostream&, const mapDistributePolyMesh&); friend Ostream& operator<<(Ostream&, const mapDistributePolyMesh&);
// Housekeeping
//- No correction for topo change
void updateMesh(const mapPolyMesh&)
{
NotImplemented;
}
}; };
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<>
Ostream& operator<<(Ostream& os, const InfoProxy<mapDistributePolyMesh>& ip);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -0,0 +1,211 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "mapDistributePolyMesh.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::mapDistributePolyMesh::mapDistributePolyMesh
(
const dictionary& dict,
const label comm
)
:
mapDistributePolyMesh(comm)
{
mapDistributePolyMesh::readDict(dict);
}
Foam::mapDistributePolyMesh::mapDistributePolyMesh(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::mapDistributePolyMesh::readDict(const dictionary& dict)
{
// Cell information
{
const dictionary& subdict = dict.subDict("cellMap");
subdict.readEntry("oldSize", nOldCells_);
cellMap_.readDict(subdict);
}
// Face information
{
const dictionary& subdict = dict.subDict("faceMap");
subdict.readEntry("oldSize", nOldFaces_);
faceMap_.readDict(subdict);
}
// Point information
{
const dictionary& subdict = dict.subDict("pointMap");
subdict.readEntry("oldSize", nOldPoints_);
pointMap_.readDict(subdict);
}
// Patch information
{
const dictionary& subdict = dict.subDict("patchMap");
subdict.readEntry("oldSizes", oldPatchSizes_);
subdict.readEntry("oldStarts", oldPatchStarts_);
subdict.readEntry("oldPointSizes", oldPatchNMeshPoints_);
patchMap_.readDict(subdict);
}
}
void Foam::mapDistributePolyMesh::writeCellMapEntries(Ostream& os) const
{
os.beginBlock("cellMap");
os.writeEntry("oldSize", nOldCells_);
cellMap_.writeEntries(os);
os.endBlock();
}
void Foam::mapDistributePolyMesh::writeFaceMapEntries(Ostream& os) const
{
os.beginBlock("faceMap");
os.writeEntry("oldSize", nOldFaces_);
faceMap_.writeEntries(os);
os.endBlock();
}
void Foam::mapDistributePolyMesh::writePointMapEntries(Ostream& os) const
{
os.beginBlock("pointMap");
os.writeEntry("oldSize", nOldPoints_);
pointMap_.writeEntries(os);
os.endBlock();
}
void Foam::mapDistributePolyMesh::writePatchMapEntries(Ostream& os) const
{
os.beginBlock("patchMap");
oldPatchSizes_.writeEntry("oldSizes", os);
oldPatchStarts_.writeEntry("oldStarts", os);
oldPatchNMeshPoints_.writeEntry("oldPointSizes", os);
patchMap_.writeEntries(os);
os.endBlock();
}
void Foam::mapDistributePolyMesh::writeEntries(Ostream& os) const
{
writeCellMapEntries(os);
os << nl;
writeFaceMapEntries(os);
os << nl;
writePointMapEntries(os);
os << nl;
writePatchMapEntries(os);
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, mapDistributePolyMesh& map)
{
is.fatalCheck(FUNCTION_NAME);
is >> map.nOldPoints_
>> map.nOldFaces_
>> map.nOldCells_
>> map.oldPatchSizes_
>> map.oldPatchStarts_
>> map.oldPatchNMeshPoints_
>> map.pointMap_
>> map.faceMap_
>> map.cellMap_
>> map.patchMap_;
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistributePolyMesh& map)
{
os << map.nOldPoints_ << token::SPACE
<< map.nOldFaces_ << token::SPACE
<< map.nOldCells_ << token::NL
<< map.oldPatchSizes_ << token::NL
<< map.oldPatchStarts_ << token::NL
<< map.oldPatchNMeshPoints_ << token::NL
<< map.pointMap_ << token::NL
<< map.faceMap_ << token::NL
<< map.cellMap_ << token::NL
<< map.patchMap_;
return os;
}
template<>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const InfoProxy<mapDistributePolyMesh>& ip
)
{
const auto& map = ip.t_;
os.beginBlock("cellMap");
os.writeEntry("oldSize", map.nOldCells());
os << map.cellMap().info();
os.endBlock();
os.beginBlock("faceMap");
os.writeEntry("oldSize", map.nOldFaces());
os << map.faceMap().info();
os.endBlock();
os.beginBlock("pointMap");
os.writeEntry("oldSize", map.nOldPoints());
os << map.pointMap().info();
os.endBlock();
return os;
}
// ************************************************************************* //

View File

@ -145,7 +145,6 @@ void Foam::mapDistribute::distribute
} }
//- Distribute data using default commsType.
template<class T> template<class T>
void Foam::mapDistribute::distribute void Foam::mapDistribute::distribute
( (
@ -168,11 +167,11 @@ void Foam::mapDistribute::distribute
{ {
fld.shrink(); fld.shrink();
List<T>& fldList = static_cast<List<T>&>(fld); List<T>& list = static_cast<List<T>&>(fld);
distribute(fldList, dummyTransform, tag); distribute(list, dummyTransform, tag);
fld.setCapacity(fldList.size()); fld.setCapacity(list.size());
} }
@ -224,6 +223,7 @@ void Foam::mapDistribute::distribute
{ {
// Distribute. Leave out dummy transforms since we're doing them ourselves // Distribute. Leave out dummy transforms since we're doing them ourselves
distribute(fld, false, tag); distribute(fld, false, tag);
// Do transforms // Do transforms
applyTransforms(git, fld, top); applyTransforms(git, fld, top);
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -108,8 +108,8 @@ void Foam::faMeshBoundaryHalo::reset(const faMesh& areaMesh)
return; return;
} }
const label nProcs = Pstream::nProcs(comm_); const label nProcs = UPstream::nProcs(comm());
const label myRank = Pstream::myProcNo(comm_); const label myRank = UPstream::myProcNo(comm());
const globalIndex globalFaceNum(areaMesh.mesh().nFaces()); const globalIndex globalFaceNum(areaMesh.mesh().nFaces());
@ -164,8 +164,8 @@ void Foam::faMeshBoundaryHalo::reset(const faMesh& areaMesh)
globalFaceNum, globalFaceNum,
connectivity, connectivity,
compactMap, compactMap,
Pstream::msgType(), UPstream::msgType(),
comm_ comm()
); );
// List of local mesh faces referenced. // List of local mesh faces referenced.

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -45,7 +45,7 @@ void Foam::faMeshBoundaryHalo::distributeSparse
} }
// Construct data in compact addressing // Construct data in compact addressing
List<Type> compactFld(constructSize_, Zero); List<Type> compactFld(constructSize(), Zero);
if (sparseInputLocations.empty()) if (sparseInputLocations.empty())
{ {

View File

@ -738,7 +738,7 @@ bool Foam::faceAreaWeightAMI::calculate
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
tgtPatch0.size(), tgtPatch0.size(),
extendedTgtMapPtr_->constructMap(), extendedTgtMapPtr_->constructMap(),
false, // has flip false, // has flip
@ -753,7 +753,7 @@ bool Foam::faceAreaWeightAMI::calculate
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
tgtPatch0.size(), tgtPatch0.size(),
extendedTgtMapPtr_->constructMap(), extendedTgtMapPtr_->constructMap(),
false, false,

View File

@ -458,7 +458,7 @@ bool Foam::faceAreaWeightAMI2D::calculate
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
tgtPatch0.size(), tgtPatch0.size(),
extendedTgtMapPtr_->constructMap(), extendedTgtMapPtr_->constructMap(),
false, // has flip false, // has flip
@ -473,7 +473,7 @@ bool Foam::faceAreaWeightAMI2D::calculate
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
tgtPatch0.size(), tgtPatch0.size(),
extendedTgtMapPtr_->constructMap(), extendedTgtMapPtr_->constructMap(),
false, false,

View File

@ -192,7 +192,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::nearestFaceAMI::calcDistributed
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
src.size(), src.size(),
map.constructMap(), map.constructMap(),
map.constructHasFlip(), map.constructHasFlip(),

View File

@ -1531,7 +1531,7 @@ void Foam::cellCellStencils::inverseDistance::createStencil
mapDistributeBase::distribute<point, minMagSqrEqOp<point>, flipOp> mapDistributeBase::distribute<point, minMagSqrEqOp<point>, flipOp>
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
mesh_.nCells(), mesh_.nCells(),
cellInterpolationMap().constructMap(), cellInterpolationMap().constructMap(),
false, false,

View File

@ -1452,7 +1452,7 @@ void Foam::distributedTriSurfaceMesh::surfaceSide
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
nearestInfo.size(), nearestInfo.size(),
map.constructMap(), map.constructMap(),
map.constructHasFlip(), map.constructHasFlip(),
@ -1481,7 +1481,7 @@ void Foam::distributedTriSurfaceMesh::surfaceSide
//mapDistributeBase::distribute //mapDistributeBase::distribute
//( //(
// Pstream::commsTypes::nonBlocking, // Pstream::commsTypes::nonBlocking,
// List<labelPair>(0), // List<labelPair>::null(),
// nearestInfo.size(), // nearestInfo.size(),
// map.constructMap(), // map.constructMap(),
// map.constructHasFlip(), // map.constructHasFlip(),
@ -3306,7 +3306,7 @@ void Foam::distributedTriSurfaceMesh::findNearest
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
samples.size(), samples.size(),
map1.constructMap(), map1.constructMap(),
map1.constructHasFlip(), map1.constructHasFlip(),
@ -3467,7 +3467,7 @@ void Foam::distributedTriSurfaceMesh::findNearest
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
samples.size(), samples.size(),
map2.constructMap(), map2.constructMap(),
map2.constructHasFlip(), map2.constructHasFlip(),
@ -4338,7 +4338,7 @@ void Foam::distributedTriSurfaceMesh::getVolumeType
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
samples.size(), samples.size(),
map.constructMap(), map.constructMap(),
map.constructHasFlip(), map.constructHasFlip(),
@ -4374,7 +4374,7 @@ void Foam::distributedTriSurfaceMesh::getVolumeType
//mapDistributeBase::distribute //mapDistributeBase::distribute
//( //(
// Pstream::commsTypes::nonBlocking, // Pstream::commsTypes::nonBlocking,
// List<labelPair>(0), // List<labelPair>::null(),
// samples.size(), // samples.size(),
// map.constructMap(), // map.constructMap(),
// map.constructHasFlip(), // map.constructHasFlip(),

View File

@ -550,7 +550,7 @@ void Foam::meshToMesh::calculate(const word& methodName, const bool normalise)
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
tgtRegion_.nCells(), tgtRegion_.nCells(),
map.constructMap(), map.constructMap(),
false, false,
@ -568,7 +568,7 @@ void Foam::meshToMesh::calculate(const word& methodName, const bool normalise)
mapDistributeBase::distribute mapDistributeBase::distribute
( (
Pstream::commsTypes::nonBlocking, Pstream::commsTypes::nonBlocking,
List<labelPair>(), List<labelPair>::null(),
tgtRegion_.nCells(), tgtRegion_.nCells(),
map.constructMap(), map.constructMap(),
false, false,