56Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
63 const label fineLevelIndex,
64 const label coarseComm
90 const auto& fineCyclicAMIInterface =
101 localRestrictAddressing.
size()
106 for (
const label curMaster : localRestrictAddressing)
108 const auto iter = masterToCoarseFace.cfind(curMaster);
113 dynFaceRestrictAddressing.append(iter.val());
118 const label coarseI = dynFaceCells.size();
119 dynFaceRestrictAddressing.append(coarseI);
120 dynFaceCells.append(curMaster);
121 masterToCoarseFace.insert(curMaster, coarseI);
132 if (fineCyclicAMIInterface.owner())
141 DynamicList<label> dynNbrFaceRestrictAddressing
143 neighbourRestrictAddressing.
size()
146 Map<label> masterToCoarseFace(neighbourRestrictAddressing.
size());
148 for (
const label curMaster : neighbourRestrictAddressing)
150 const auto iter = masterToCoarseFace.cfind(curMaster);
155 dynNbrFaceRestrictAddressing.append(iter.val());
160 const label coarseI = masterToCoarseFace.size();
161 dynNbrFaceRestrictAddressing.append(coarseI);
162 masterToCoarseFace.insert(curMaster, coarseI);
166 nbrFaceRestrictAddressing.transfer(dynNbrFaceRestrictAddressing);
174 fineCyclicAMIInterface.AMI(),
176 nbrFaceRestrictAddressing
181 const auto&
AMI = amiPtr_();
183 if (debug & 2 &&
AMI.comm() != -1)
188 Pout<<
"At level:" << fineLevelIndex
189 <<
" agglomerating from ownsize:"
191 <<
" nbrSize:" << neighbourRestrictAddressing.size()
192 <<
" down to ownsize:" <<
AMI.srcAddress().size()
193 <<
" nbrsize:" <<
AMI.tgtAddress().size()
194 <<
" Patch:" <<
index <<
" comm:" <<
AMI.comm()
196 <<
" myRank:" << myRank <<
" agglomerated AMI:"
199 const label nbrSize =
AMI.tgtAddress().size();
202 Pout<<
"From nbr:" << nbrSize <<
" to owner:" << this->
size()
205 const auto& addresses =
AMI.srcAddress();
206 const auto& weights =
AMI.srcWeights();
209 if (
AMI.distributed() &&
AMI.comm() != -1)
211 const auto& map =
AMI.tgtMap();
212 forAll(map.subMap(), proci)
214 Pout<<
" TGTMap: sending to rank:" << proci
215 <<
" elements:" <<
flatOutput(map.subMap()[proci])
218 forAll(map.constructMap(), proci)
220 Pout<<
" TGTMap: receiving from rank:" << proci
226 const globalIndex globalFaces(nbrSize,
AMI.comm());
227 Pout<<
" localNbrSize:" << nbrSize
228 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
231 for (label&
id : globalIDs)
233 id = globalFaces.toGlobal(myRank,
id);
235 map.distribute(globalIDs);
241 Pout<<
" source face:" << facei
244 <<
" from slots:" <<
flatOutput(addresses[facei])
245 <<
" from global tgt faces:"
246 << UIndirectList<label>(globalIDs, addresses[facei])
252 Pout<<
"From owner:" << this->
size() <<
" to nbr:" << nbrSize
255 const auto& addresses =
AMI.tgtAddress();
256 const auto& weights =
AMI.tgtWeights();
259 if (
AMI.distributed() &&
AMI.comm() != -1)
261 const auto& map =
AMI.srcMap();
262 forAll(map.subMap(), proci)
264 Pout<<
" SRCMap: sending to rank:" << proci
265 <<
" elements:" <<
flatOutput(map.subMap()[proci])
268 forAll(map.constructMap(), proci)
270 Pout<<
" SRCMap: receiving from rank:" << proci
276 const globalIndex globalFaces(this->
size(),
AMI.comm());
277 Pout<<
" localSize:" << this->
size()
278 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
280 for (label&
id : globalIDs)
282 id = globalFaces.toGlobal(myRank,
id);
284 map.distribute(globalIDs);
290 Pout<<
" target face:" << facei
293 <<
" from slots:" <<
flatOutput(addresses[facei])
294 <<
" from global src faces:"
295 << UIndirectList<label>(globalIDs, addresses[facei])
299 Pout<<
"DONE agglomerating at level:" << fineLevelIndex <<
endl;
307Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
330 const label comm =
AMI().
comm();
340Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
350 const label coarseComm,
351 const label myProcNo,
360 faceRestrictAddresssing
369 >(fineInterface).neighbPatchID()
415 FixedList<bool, 4>&
bools = globalInfo.second().first().first();
418 label& firstValidAMI = globalInfo.
first();
419 bool& requireMatch =
bools[0];
420 bool& reverseTarget =
bools[1];
421 bool& srcHasFlip =
bools[2];
422 bool& tgtHasFlip =
bools[3];
423 scalar& lowWeightCorrection = globalInfo.second().first().second();
424 label& singlePatchProc = globalInfo.second().second();
428 requireMatch =
false;
429 reverseTarget =
false;
432 lowWeightCorrection = -1;
433 singlePatchProc = -1;
436 bool hasSrcMagSf =
false;
437 bool hasSrcCentroids =
false;
438 bool hasTgtMagSf =
false;
442 forAll(allInterfaces, inti)
444 if (allInterfaces.set(inti))
456 firstValidAMI = inti;
459 const auto&
AMI = intf.AMI();
467 if (!
AMI.distributed())
469 singlePatchProc =
AMI.singlePatchProc();
471 else if (
AMI.comm() != -1)
473 singlePatchProc = -1;
475 srcHasFlip ||
AMI.srcMap().constructHasFlip();
477 tgtHasFlip ||
AMI.tgtMap().constructHasFlip();
479 requireMatch =
AMI.requireMatch();
480 reverseTarget =
AMI.reverseTarget();
481 lowWeightCorrection =
AMI.lowWeightCorrection();
483 nSrc +=
AMI.srcAddress().size();
484 nTgt +=
AMI.tgtAddress().size();
486 if (
AMI.srcMagSf().size())
489 if (
AMI.srcMagSf().size() !=
AMI.srcAddress().size())
492 <<
"srcMagSf size:" <<
AMI.srcMagSf().size()
493 <<
"srcAddress size:" <<
AMI.srcAddress().size()
497 if (
AMI.srcCentroids().size())
499 hasSrcCentroids =
true;
500 if (
AMI.srcCentroids().size() !=
AMI.srcAddress().size())
503 <<
"srcCentroids size:" <<
AMI.srcCentroids().size()
504 <<
"srcAddress size:" <<
AMI.srcAddress().size()
508 if (
AMI.tgtMagSf().size())
511 if (
AMI.tgtMagSf().size() !=
AMI.tgtAddress().size())
514 <<
"tgtMagSf size:" <<
AMI.tgtMagSf().size()
515 <<
"tgtAddress size:" <<
AMI.tgtAddress().size()
529 [](AMIType&
x,
const AMIType&
y)
531 if (
y.first() <
x.first())
542 <<
" singlePatchProc:" << singlePatchProc
543 <<
" srcHasFlip:" << srcHasFlip
544 <<
" tgtHasFlip:" << tgtHasFlip
545 <<
" requireMatch:" << requireMatch
546 <<
" reverseTarget:" << reverseTarget
547 <<
" lowWeightCorrection:" << lowWeightCorrection
548 <<
" hasSrcMagSf:" << hasSrcMagSf
549 <<
" hasSrcCentroids:" << hasSrcCentroids
550 <<
" hasTgtMagSf:" << hasTgtMagSf
568 autoPtr<mapDistribute> srcToTgtMap;
571 autoPtr<mapDistribute> tgtToSrcMap;
573 if (singlePatchProc == -1)
580 labelList localRanks(allInterfaces.size(), -1);
587 forAll(allInterfaces, inti)
589 if (allInterfaces.set(inti))
596 if (!intf.amiPtr_ || intf.AMI().comm() == -1)
605 DynamicList<label> oldRanks(nOldRanks);
606 forAll(allInterfaces, inti)
608 if (allInterfaces.set(inti))
615 if (!intf.amiPtr_ || intf.AMI().comm() == -1)
621 if (intf.myProcNo() == -1)
629 fineRank = intf.myProcNo();
632 oldRanks.append(fineRank);
633 localRanks[inti] = fineRank;
649 UPtrList<const mapDistribute> srcMaps(allInterfaces.size());
650 UPtrList<const mapDistribute> tgtMaps(allInterfaces.size());
651 forAll(allInterfaces, inti)
653 if (allInterfaces.set(inti))
666 const auto&
AMI = intf.AMI();
668 if (
AMI.comm() != -1)
670 srcMaps.set(inti, &
AMI.srcMap());
671 tgtMaps.set(inti, &
AMI.tgtMap());
679 List<Map<label>> srcCompactMaps;
697 if (tgtAddress.size())
700 forAll(allInterfaces, inti)
702 if (allInterfaces.set(inti))
714 const auto&
AMI = intf.AMI();
715 const auto& tgtSlots =
AMI.tgtAddress();
716 const label localSize =
717 srcStartOfLocal[inti+1]
718 - srcStartOfLocal[inti];
723 auto& newSlots = tgtAddress[alli++];
724 newSlots = tgtSlots[tgti];
731 srcStartOfLocal[inti],
732 srcCompactMaps[inti],
736 for (
const label slot : newSlots)
741 || slot >= srcToTgtMap().constructSize()
761 List<Map<label>> tgtCompactMaps;
779 if (srcAddress.size())
782 forAll(allInterfaces, inti)
784 if (allInterfaces.set(inti))
796 const auto&
AMI = intf.AMI();
797 const auto& srcSlots =
AMI.srcAddress();
798 const label localSize =
799 tgtStartOfLocal[inti+1]
800 - tgtStartOfLocal[inti];
805 auto& newSlots = srcAddress[alli++];
806 newSlots = srcSlots[srci];
812 tgtStartOfLocal[inti],
813 tgtCompactMaps[inti],
817 for (
const label slot : newSlots)
822 || slot >= tgtToSrcMap().constructSize()
846 const auto& map = srcToTgtMap().subMap();
848 bool usesRemote =
false;
851 if (proci != myAgglom)
853 const auto& ss = srcToTgtMap().subMap()[proci];
854 const auto& sc = srcToTgtMap().constructMap()[proci];
855 const auto& ts = tgtToSrcMap().subMap()[proci];
856 const auto& tc = tgtToSrcMap().constructMap()[proci];
858 if (ss.size() || sc.size() || ts.size() || tc.size())
872 DebugPout<<
"** making fully local on new rank "
873 << myAgglom <<
" in comm:" << coarseComm <<
endl;
874 singlePatchProc = myAgglom;
884 srcAddress.setSize(nSrc);
885 tgtAddress.setSize(nTgt);
889 forAll(allInterfaces, inti)
891 if (allInterfaces.set(inti))
903 const auto&
AMI = intf.AMI();
905 const auto& srcA =
AMI.srcAddress();
906 if (srcAddress.size())
911 srcAddress[srci++] = srcA[i]+nTgt;
915 const auto& tgtA =
AMI.tgtAddress();
916 if (tgtAddress.size())
921 tgtAddress[tgti++] = tgtA[i]+nSrc;
931 srcWeights.setSize(nSrc);
934 srcMagSf.setSize(nSrc);
938 srcCentroids.setSize(nSrc);
940 tgtWeights.setSize(nTgt);
943 tgtMagSf.setSize(nTgt);
950 forAll(allInterfaces, inti)
952 if (allInterfaces.set(inti))
964 const auto&
AMI = intf.AMI();
966 const auto& srcA =
AMI.srcAddress();
969 SubList<scalarList>(srcWeights, srcA.size(), nSrc) =
975 SubList<scalar>(srcMagSf, srcA.size(), nSrc) =
982 SubList<pointList>(srcCentroids, srcA.size(), nSrc) =
987 const auto& tgtA =
AMI.tgtAddress();
990 SubList<scalarList>(tgtWeights, tgtA.size(), nTgt) =
995 SubList<scalar>(tgtMagSf, tgtA.size(), nTgt) =
1000 nSrc += srcA.size();
1001 nTgt += tgtA.size();
1016 amiPtr_().comm(coarseComm),
1019 std::move(srcToTgtMap),
1020 std::move(tgtToSrcMap),
1021 std::move(srcAddress),
1022 std::move(srcWeights),
1023 std::move(tgtAddress),
1024 std::move(tgtWeights),
1027 amiPtr_().srcMagSf() = std::move(srcMagSf);
1028 amiPtr_().srcCentroids() = std::move(srcCentroids);
1029 amiPtr_().tgtMagSf() = std::move(tgtMagSf);
1034 const auto&
AMI = amiPtr_();
1039 Pout<<
"PROCAGGLOMERATED :"
1040 <<
" Patch:" <<
index <<
" comm:" <<
AMI.comm()
1042 <<
" myRank:" << myRank <<
" agglomerated AMI:"
1045 const label nbrSize =
AMI.tgtAddress().size();
1048 Pout<<
"From nbr:" << nbrSize <<
" to owner:" << this->
size()
1051 const auto& addresses =
AMI.srcAddress();
1052 const auto& weights =
AMI.srcWeights();
1055 if (
AMI.distributed() &&
AMI.comm() != -1)
1057 const auto& map =
AMI.tgtMap();
1058 forAll(map.subMap(), proci)
1060 Pout<<
" TGTMap: sending to rank:" << proci
1061 <<
" elements:" <<
flatOutput(map.subMap()[proci])
1064 forAll(map.constructMap(), proci)
1066 Pout<<
" TGTMap: receiving from rank:" << proci
1073 const globalIndex globalFaces(nbrSize,
AMI.comm());
1074 Pout<<
" localNbrSize:" << nbrSize
1075 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
1076 for (label&
id : globalIDs)
1078 id = globalFaces.toGlobal(myRank,
id);
1080 map.distribute(globalIDs);
1086 Pout<<
" source face:" << facei
1089 <<
" from slots:" <<
flatOutput(addresses[facei])
1090 <<
" from global tgt faces:"
1091 << UIndirectList<label>(globalIDs, addresses[facei])
1098 Pout<<
"From owner:" << this->
size() <<
" to nbr:" << nbrSize
1101 const auto& addresses =
AMI.tgtAddress();
1102 const auto& weights =
AMI.tgtWeights();
1105 if (
AMI.distributed() &&
AMI.comm() != -1)
1107 const auto& map =
AMI.srcMap();
1108 forAll(map.subMap(), proci)
1110 Pout<<
" SRCMap: sending to rank:" << proci
1111 <<
" elements:" <<
flatOutput(map.subMap()[proci])
1114 forAll(map.constructMap(), proci)
1116 Pout<<
" SRCMap: receiving from rank:" << proci
1123 const globalIndex globalFaces(this->
size(),
AMI.comm());
1124 Pout<<
" localSize:" << this->
size()
1125 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
1126 for (label&
id : globalIDs)
1128 id = globalFaces.toGlobal(myRank,
id);
1130 map.distribute(globalIDs);
1136 Pout<<
" target face:" << facei
1139 <<
" from slots:" <<
flatOutput(addresses[facei])
1140 <<
" from global src faces:"
1141 << UIndirectList<label>(globalIDs, addresses[facei])
1145 Pout<<
"DONE PROCAGGLOMERATED" <<
endl;
1159 const cyclicAMIGAMGInterface& nbr =
1160 dynamic_cast<const cyclicAMIGAMGInterface&
>(neighbPatch());
1161 const labelUList& nbrFaceCells = nbr.faceCells();
1168 pnf[facei] = iF[nbrFaceCells[facei]];
1179 const bool hasAMI = bool(amiPtr_);
1190 AMI().writeData(
os);
1193 const label comm = AMI().comm();
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
label comm() const noexcept
Communicator (local or otherwise) for parallel operations.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void append(const T &val)
Copy append an element to the end of this list.
A 1D vector of objects of type <T> with a fixed length <N>.
Abstract base class for GAMG agglomerated interfaces.
virtual label size() const
Return size.
labelList faceRestrictAddressing_
Face restrict addressing.
virtual label index() const
virtual const lduInterfacePtrsList & coarseInterfaces() const
virtual const labelUList & faceCells() const
Return faceCell addressing.
labelList faceCells_
Face-cell addressing.
GAMGInterface(const GAMGInterface &)=delete
No copy construct.
virtual void write(Ostream &) const =0
Write to stream.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
label size() const noexcept
The number of elements in table.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
void setSize(label n)
Alias for resize().
A HashTable to objects of type <T> with a label key.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
static void combineReduce(T &value, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors.
static List< T > listGatherValues(const T &localValue, const int communicator=UPstream::worldComm, const int tag=UPstream::msgType())
Gather individual values into list locations.
A non-owning sub-view of a List (allocated or unallocated storage).
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
A List with indirect addressing. Like IndirectList but does not store addressing.
T & first()
Access first element of the list, position [0].
void size(const label n)
Older name for setAddressableSize.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
commsTypes
Communications types.
static int & msgType() noexcept
Message tag of standard messages.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
static label commWarn(const label communicator) noexcept
Alter communicator debugging setting. Warns for use of any communicator differing from specified....
@ broadcast
broadcast [MPI]
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
label size() const noexcept
The number of entries in the list.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void clear() noexcept
Same as reset(nullptr).
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
GAMG agglomerated cyclic AMI interface.
virtual void write(Ostream &) const
Write to stream.
virtual bool owner() const
virtual const tensorField & reverseT() const
Return neighbour-cell transformation tensor.
virtual label neighbPatchID() const
Cyclic interface functions.
virtual const AMIPatchToPatchInterpolation & AMI() const
virtual label myProcNo() const
-1 or old local rank
virtual const cyclicAMIGAMGInterface & neighbPatch() const
Return processor number.
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
virtual const tensorField & forwardT() const
Return face transformation tensor.
An abstract base class for cyclic AMI coupled interfaces.
cyclicAMILduInterface() noexcept=default
Default construct.
Smooth ATC in cells next to a set of patches supplied by type.
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
label totalSize() const noexcept
The total addressed size, which corresponds to the end offset and also the sum of all localSizes.
label toGlobal(const label proci, const label i) const
From local to global on proci.
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
virtual const labelUList & faceCells() const =0
Return faceCell addressing.
static label renumberMap(labelListList &mapElements, const labelUList &oldToNew, const bool hasFlip)
Helper for renumbering the (compacted) map elements using the supplied old-to-new mapping.
Class containing processor-to-processor mapping information.
A class for managing temporary objects.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
#define DebugPout
Report an information message using Foam::Pout.
List< bool > bools(const labelHashSet &locations)
Transform the on locations to a boolList, with true for each non-negative location and false for all ...
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Same as ListOps::find_if.
Namespace for handling debugging switches.
List< scalarList > scalarListList
List of scalarList.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
UPtrList< const lduInterface > lduInterfacePtrsList
Store lists of lduInterface as a UPtrList.
Ostream & endl(Ostream &os)
Add newline and flush stream.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
AMIInterpolation AMIPatchToPatchInterpolation
Patch-to-patch interpolation == Foam::AMIInterpolation.
Field< label > labelField
Specialisation of Field<T> for label.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
UList< label > labelUList
A UList of labels.
List< scalar > scalarList
List of scalar.
List< pointList > pointListList
List of pointList.
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&).
#define forAll(list, i)
Loop across all elements in list.