42 cyclicAMIGAMGInterface,
48 cyclicAMIGAMGInterface,
56 Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
63 const label fineLevelIndex,
64 const label coarseComm
89 const auto& fineCyclicAMIInterface =
90 refCast<const cyclicAMILduInterface>(fineInterface);
100 localRestrictAddressing.
size()
105 for (
const label curMaster : localRestrictAddressing)
107 const auto iter = masterToCoarseFace.
cfind(curMaster);
112 dynFaceRestrictAddressing.append(iter.val());
117 const label coarseI = dynFaceCells.size();
118 dynFaceRestrictAddressing.append(coarseI);
119 dynFaceCells.append(curMaster);
120 masterToCoarseFace.insert(curMaster, coarseI);
131 if (fineCyclicAMIInterface.owner())
140 DynamicList<label> dynNbrFaceRestrictAddressing
142 neighbourRestrictAddressing.
size()
145 Map<label> masterToCoarseFace(neighbourRestrictAddressing.
size());
147 for (
const label curMaster : neighbourRestrictAddressing)
149 const auto iter = masterToCoarseFace.cfind(curMaster);
154 dynNbrFaceRestrictAddressing.
append(iter.val());
159 const label coarseI = masterToCoarseFace.size();
160 dynNbrFaceRestrictAddressing.append(coarseI);
161 masterToCoarseFace.insert(curMaster, coarseI);
165 nbrFaceRestrictAddressing.transfer(dynNbrFaceRestrictAddressing);
173 fineCyclicAMIInterface.AMI(),
175 nbrFaceRestrictAddressing
180 const auto&
AMI = amiPtr_();
187 Pout<<
"At level:" << fineLevelIndex
188 <<
" agglomerating from ownsize:" 190 <<
" nbrSize:" << neighbourRestrictAddressing.size()
195 <<
" myRank:" << myRank <<
" agglomerated AMI:" 201 Pout<<
"From nbr:" << nbrSize <<
" to owner:" << this->
size()
211 forAll(map.subMap(), proci)
213 Pout<<
" TGTMap: sending to rank:" << proci
214 <<
" elements:" <<
flatOutput(map.subMap()[proci])
217 forAll(map.constructMap(), proci)
219 Pout<<
" TGTMap: receiving from rank:" << proci
225 const globalIndex globalFaces(nbrSize,
AMI.
comm());
226 Pout<<
" localNbrSize:" << nbrSize
227 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
230 for (label&
id : globalIDs)
232 id = globalFaces.toGlobal(myRank,
id);
234 map.distribute(globalIDs);
240 Pout<<
" source face:" << facei
243 <<
" from slots:" <<
flatOutput(addresses[facei])
244 <<
" from global tgt faces:" 245 << UIndirectList<label>(globalIDs, addresses[facei])
251 Pout<<
"From owner:" << this->
size() <<
" to nbr:" << nbrSize
261 forAll(map.subMap(), proci)
263 Pout<<
" SRCMap: sending to rank:" << proci
264 <<
" elements:" <<
flatOutput(map.subMap()[proci])
267 forAll(map.constructMap(), proci)
269 Pout<<
" SRCMap: receiving from rank:" << proci
275 const globalIndex globalFaces(this->
size(),
AMI.
comm());
276 Pout<<
" localSize:" << this->
size()
277 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
279 for (label&
id : globalIDs)
281 id = globalFaces.toGlobal(myRank,
id);
283 map.distribute(globalIDs);
289 Pout<<
" target face:" << facei
292 <<
" from slots:" <<
flatOutput(addresses[facei])
293 <<
" from global src faces:" 294 << UIndirectList<label>(globalIDs, addresses[facei])
298 Pout<<
"DONE agglomerating at level:" << fineLevelIndex <<
endl;
306 Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
313 GAMGInterface(index, coarseInterfaces, is),
328 Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
332 const lduInterface& fineInterface,
338 const label coarseComm,
339 const label myProcNo,
348 faceRestrictAddresssing
356 const cyclicAMILduInterface
357 >(fineInterface).neighbPatchID()
362 refCast<const cyclicAMILduInterface>(fineInterface).owner()
366 refCast<const cyclicAMILduInterface>(fineInterface).forwardT()
370 refCast<const cyclicAMILduInterface>(fineInterface).reverseT()
373 const auto& fineCyclicAMIInterface =
374 refCast<const cyclicAMIGAMGInterface>(fineInterface);
376 if (fineCyclicAMIInterface.amiPtr_)
380 fineCyclicAMIInterface.AMI()
390 bool hasSrcMagSf =
false;
391 bool hasSrcCentroids =
false;
392 bool hasTgtMagSf =
false;
394 forAll(allInterfaces, inti)
396 if (allInterfaces.set(inti))
399 refCast<const cyclicAMIGAMGInterface>(allInterfaces[inti]);
400 const auto&
AMI = intf.AMI();
417 hasSrcCentroids =
true;
453 autoPtr<mapDistribute> srcToTgtMap;
456 autoPtr<mapDistribute> tgtToSrcMap;
458 if (fineAMI.distributed())
461 UPtrList<const mapDistribute> srcMaps(allInterfaces.size());
462 UPtrList<const mapDistribute> tgtMaps(allInterfaces.size());
463 forAll(allInterfaces, inti)
465 if (allInterfaces.set(inti))
467 const auto& intf = refCast<const cyclicAMIGAMGInterface>
471 const auto&
AMI = intf.AMI();
479 const label myAgglom =
491 const labelList& localRanks = newToOldRanks[myAgglom];
496 List<Map<label>> srcCompactMaps;
513 if (tgtAddress.size())
516 forAll(allInterfaces, inti)
518 if (allInterfaces.set(inti))
520 const auto& intf = refCast<const cyclicAMIGAMGInterface>
524 const auto&
AMI = intf.AMI();
526 const label localSize =
527 srcStartOfLocal[inti+1]
528 - srcStartOfLocal[inti];
533 auto& newSlots = tgtAddress[alli++];
534 newSlots = tgtSlots[tgti];
541 srcStartOfLocal[inti],
542 srcCompactMaps[inti],
546 for (
const label slot : newSlots)
551 || slot >= srcToTgtMap().constructSize()
571 List<Map<label>> tgtCompactMaps;
588 if (srcAddress.size())
591 forAll(allInterfaces, inti)
593 if (allInterfaces.set(inti))
595 const auto& intf = refCast<const cyclicAMIGAMGInterface>
599 const auto&
AMI = intf.AMI();
601 const label localSize =
602 tgtStartOfLocal[inti+1]
603 - tgtStartOfLocal[inti];
608 auto& newSlots = srcAddress[alli++];
609 newSlots = srcSlots[srci];
615 tgtStartOfLocal[inti],
616 tgtCompactMaps[inti],
620 for (
const label slot : newSlots)
625 || slot >= tgtToSrcMap().constructSize()
649 const auto& map = srcToTgtMap().subMap();
651 bool usesRemote =
false;
654 if (proci != myAgglom)
656 const auto& ss = srcToTgtMap().subMap()[proci];
657 const auto& sc = srcToTgtMap().constructMap()[proci];
658 const auto& ts = tgtToSrcMap().subMap()[proci];
659 const auto& tc = tgtToSrcMap().constructMap()[proci];
661 if (ss.size() || sc.size() || ts.size() || tc.size())
673 singlePatchProc = myAgglom;
683 srcAddress.setSize(nSrc);
684 tgtAddress.setSize(nTgt);
688 forAll(allInterfaces, inti)
690 if (allInterfaces.set(inti))
692 const auto& intf = refCast<const cyclicAMIGAMGInterface>
696 const auto&
AMI = intf.AMI();
699 if (srcAddress.size())
704 srcAddress[srci++] = srcA[i]+nTgt;
709 if (tgtAddress.size())
714 tgtAddress[tgti++] = tgtA[i]+nSrc;
724 srcWeights.setSize(nSrc);
727 srcMagSf.setSize(nSrc);
731 srcCentroids.setSize(nSrc);
733 tgtWeights.setSize(nTgt);
736 tgtMagSf.setSize(nTgt);
743 forAll(allInterfaces, inti)
745 if (allInterfaces.set(inti))
747 const auto& intf = refCast<const cyclicAMIGAMGInterface>
751 const auto&
AMI = intf.AMI();
756 SubList<scalarList>(srcWeights, srcA.size(), nSrc) =
762 SubList<scalar>(srcMagSf, srcA.size(), nSrc) =
769 SubList<pointList>(srcCentroids, srcA.size(), nSrc) =
777 SubList<scalarList>(tgtWeights, tgtA.size(), nTgt) =
782 SubList<scalar>(tgtMagSf, tgtA.size(), nTgt) =
798 fineAMI.requireMatch(),
799 fineAMI.reverseTarget(),
800 fineAMI.lowWeightCorrection()
803 amiPtr_().comm(coarseComm),
806 std::move(srcToTgtMap),
807 std::move(tgtToSrcMap),
808 std::move(srcAddress),
809 std::move(srcWeights),
810 std::move(tgtAddress),
811 std::move(tgtWeights),
814 amiPtr_().srcMagSf() = std::move(srcMagSf);
815 amiPtr_().srcCentroids() = std::move(srcCentroids);
816 amiPtr_().tgtMagSf() = std::move(tgtMagSf);
821 const auto&
AMI = amiPtr_();
827 Pout<<
"PROCAGGLOMERATED :" 830 <<
" myRank:" << myRank <<
" agglomerated AMI:" 836 Pout<<
"From nbr:" << nbrSize <<
" to owner:" << this->
size()
846 forAll(map.subMap(), proci)
848 Pout<<
" TGTMap: sending to rank:" << proci
849 <<
" elements:" <<
flatOutput(map.subMap()[proci])
852 forAll(map.constructMap(), proci)
854 Pout<<
" TGTMap: receiving from rank:" << proci
861 const globalIndex globalFaces(nbrSize,
AMI.
comm());
862 Pout<<
" localNbrSize:" << nbrSize
863 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
864 for (label&
id : globalIDs)
866 id = globalFaces.toGlobal(myRank,
id);
868 map.distribute(globalIDs);
874 Pout<<
" source face:" << facei
877 <<
" from slots:" <<
flatOutput(addresses[facei])
878 <<
" from global tgt faces:" 879 << UIndirectList<label>(globalIDs, addresses[facei])
885 Pout<<
"From owner:" << this->
size() <<
" to nbr:" << nbrSize
892 if (AMI.distributed())
895 forAll(map.subMap(), proci)
897 Pout<<
" SRCMap: sending to rank:" << proci
898 <<
" elements:" <<
flatOutput(map.subMap()[proci])
901 forAll(map.constructMap(), proci)
903 Pout<<
" SRCMap: receiving from rank:" << proci
910 const globalIndex globalFaces(this->
size(), AMI.comm());
911 Pout<<
" localSize:" << this->
size()
912 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
913 for (label&
id : globalIDs)
915 id = globalFaces.toGlobal(myRank,
id);
917 map.distribute(globalIDs);
923 Pout<<
" target face:" << facei
926 <<
" from slots:" <<
flatOutput(addresses[facei])
927 <<
" from global src faces:" 928 << UIndirectList<label>(globalIDs, addresses[facei])
932 Pout<<
"DONE PROCAGGLOMERATED" <<
endl;
947 const cyclicAMIGAMGInterface& nbr =
948 dynamic_cast<const cyclicAMIGAMGInterface&
>(neighbPatch());
949 const labelUList& nbrFaceCells = nbr.faceCells();
956 pnf[facei] = iF[nbrFaceCells[facei]];
967 const bool hasAMI = bool(amiPtr_);
virtual label size() const
Return size.
List< scalar > scalarList
List of scalar.
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Same as ListOps::find_if.
Field< label > labelField
Specialisation of Field<T> for label.
void size(const label n)
Older name for setAddressableSize.
const pointListList & srcCentroids() const
Return const access to source patch face centroids.
virtual const labelUList & faceCells() const =0
Return faceCell addressing.
errorManipArg< error, int > exit(error &err, const int errNo=1)
commsTypes
Communications types.
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
const scalarListList & tgtWeights() const
Return const access to target patch weights.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
void append(const T &val)
Append an element at the end of the list.
AMIInterpolation AMIPatchToPatchInterpolation
Patch-to-patch interpolation == Foam::AMIInterpolation.
virtual label index() const
const mapDistribute & srcMap() const
Source map - valid only if singlePatchProc = -1 This gets source data into a form to be consumed by t...
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
const labelListList & tgtAddress() const
Return const access to target patch addressing.
Ostream & endl(Ostream &os)
Add newline and flush stream.
label singlePatchProc() const noexcept
The processor holding all faces (both sides), or -1 if distributed.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
labelList faceRestrictAddressing_
Face restrict addressing.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
bool distributed() const noexcept
Distributed across processors (singlePatchProc == -1)
List< labelList > labelListList
List of labelList.
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
#define forAll(list, i)
Loop across all elements in list.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
An abstract base class for cyclic AMI coupled interfaces.
void setSize(const label n)
Alias for resize()
const List< scalar > & tgtMagSf() const
Return const access to target patch face areas.
labelListList invertOneToMany(const label len, const labelUList &map)
Invert one-to-many map. Unmapped elements will be size 0.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
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...
List< scalarList > scalarListList
List of scalarList.
UPtrList< const lduInterface > lduInterfacePtrsList
Store lists of lduInterface as a UPtrList.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
virtual void write(Ostream &) const
Write to stream.
const scalarListList & srcWeights() const
Return const access to source patch weights.
bool constructHasFlip() const noexcept
Does constructMap include a sign.
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
const List< scalar > & srcMagSf() const
Return const access to source patch face areas.
Abstract base class for GAMG agglomerated interfaces.
virtual const AMIPatchToPatchInterpolation & AMI() const
virtual void write(Ostream &) const =0
Write to stream.
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches...
labelList faceCells_
Face-cell addressing.
List< label > labelList
A List of labels.
const mapDistribute & tgtMap() const
Target map - valid only if singlePatchProc=-1. This gets target data into a form to be consumed by sr...
List< pointList > pointListList
List of pointList.
A class for managing temporary objects.
const labelListList & srcAddress() const
Return const access to source patch addressing.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
label comm() const
Communicator to use for parallel operations.
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...
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.