42 cyclicAMIGAMGInterface,
48 cyclicAMIGAMGInterface,
56 Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
63 const label fineLevelIndex,
64 const label coarseComm
90 const auto& fineCyclicAMIInterface =
91 refCast<const cyclicAMILduInterface>(fineInterface);
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_();
188 Pout<<
"At level:" << fineLevelIndex
189 <<
" agglomerating from ownsize:" 191 <<
" nbrSize:" << neighbourRestrictAddressing.size()
196 <<
" myRank:" << myRank <<
" agglomerated AMI:" 202 Pout<<
"From nbr:" << nbrSize <<
" to owner:" << this->
size()
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
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;
307 Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
314 GAMGInterface(index, coarseInterfaces, is),
330 const label comm =
AMI().
comm();
340 Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
344 const lduInterface& fineInterface,
350 const label coarseComm,
351 const label myProcNo,
360 faceRestrictAddresssing
368 const cyclicAMILduInterface
369 >(fineInterface).neighbPatchID()
374 refCast<const cyclicAMILduInterface>(fineInterface).owner()
378 refCast<const cyclicAMILduInterface>(fineInterface).forwardT()
382 refCast<const cyclicAMILduInterface>(fineInterface).reverseT()
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))
447 refCast<const cyclicAMIGAMGInterface>(allInterfaces[inti]);
456 firstValidAMI = inti;
459 const auto&
AMI = intf.AMI();
463 singlePatchProc = -1;
489 hasSrcCentroids =
true;
519 [](AMIType&
x,
const AMIType&
y)
521 if (
y.first() <
x.first())
532 <<
" singlePatchProc:" << singlePatchProc
533 <<
" srcHasFlip:" << srcHasFlip
534 <<
" tgtHasFlip:" << tgtHasFlip
535 <<
" requireMatch:" << requireMatch
536 <<
" reverseTarget:" << reverseTarget
537 <<
" lowWeightCorrection:" << lowWeightCorrection
538 <<
" hasSrcMagSf:" << hasSrcMagSf
539 <<
" hasSrcCentroids:" << hasSrcCentroids
540 <<
" hasTgtMagSf:" << hasTgtMagSf
558 autoPtr<mapDistribute> srcToTgtMap;
561 autoPtr<mapDistribute> tgtToSrcMap;
563 if (singlePatchProc == -1)
570 labelList localRanks(allInterfaces.size(), -1);
577 forAll(allInterfaces, inti)
579 if (allInterfaces.set(inti))
581 const auto& intf = refCast<const cyclicAMIGAMGInterface>
586 if (!intf.amiPtr_ || intf.AMI().comm() == -1)
595 DynamicList<label> oldRanks(nOldRanks);
596 forAll(allInterfaces, inti)
598 if (allInterfaces.set(inti))
600 const auto& intf = refCast<const cyclicAMIGAMGInterface>
605 if (!intf.amiPtr_ || intf.AMI().comm() == -1)
611 if (intf.myProcNo() == -1)
619 fineRank = intf.myProcNo();
622 oldRanks.append(fineRank);
623 localRanks[inti] = fineRank;
639 UPtrList<const mapDistribute> srcMaps(allInterfaces.size());
640 UPtrList<const mapDistribute> tgtMaps(allInterfaces.size());
641 forAll(allInterfaces, inti)
643 if (allInterfaces.set(inti))
645 const auto& intf = refCast<const cyclicAMIGAMGInterface>
656 const auto&
AMI = intf.AMI();
669 List<Map<label>> srcCompactMaps;
687 if (tgtAddress.size())
690 forAll(allInterfaces, inti)
692 if (allInterfaces.set(inti))
694 const auto& intf = refCast<const cyclicAMIGAMGInterface>
704 const auto&
AMI = intf.AMI();
706 const label localSize =
707 srcStartOfLocal[inti+1]
708 - srcStartOfLocal[inti];
713 auto& newSlots = tgtAddress[alli++];
714 newSlots = tgtSlots[tgti];
721 srcStartOfLocal[inti],
722 srcCompactMaps[inti],
726 for (
const label slot : newSlots)
731 || slot >= srcToTgtMap().constructSize()
751 List<Map<label>> tgtCompactMaps;
769 if (srcAddress.size())
772 forAll(allInterfaces, inti)
774 if (allInterfaces.set(inti))
776 const auto& intf = refCast<const cyclicAMIGAMGInterface>
786 const auto&
AMI = intf.AMI();
788 const label localSize =
789 tgtStartOfLocal[inti+1]
790 - tgtStartOfLocal[inti];
795 auto& newSlots = srcAddress[alli++];
796 newSlots = srcSlots[srci];
802 tgtStartOfLocal[inti],
803 tgtCompactMaps[inti],
807 for (
const label slot : newSlots)
812 || slot >= tgtToSrcMap().constructSize()
836 const auto& map = srcToTgtMap().subMap();
838 bool usesRemote =
false;
841 if (proci != myAgglom)
843 const auto& ss = srcToTgtMap().subMap()[proci];
844 const auto& sc = srcToTgtMap().constructMap()[proci];
845 const auto& ts = tgtToSrcMap().subMap()[proci];
846 const auto& tc = tgtToSrcMap().constructMap()[proci];
848 if (ss.size() || sc.size() || ts.size() || tc.size())
862 DebugPout<<
"** making fully local on new rank " 863 << myAgglom <<
" in comm:" << coarseComm <<
endl;
864 singlePatchProc = myAgglom;
874 srcAddress.setSize(nSrc);
875 tgtAddress.setSize(nTgt);
879 forAll(allInterfaces, inti)
881 if (allInterfaces.set(inti))
883 const auto& intf = refCast<const cyclicAMIGAMGInterface>
893 const auto&
AMI = intf.AMI();
896 if (srcAddress.size())
901 srcAddress[srci++] = srcA[i]+nTgt;
906 if (tgtAddress.size())
911 tgtAddress[tgti++] = tgtA[i]+nSrc;
921 srcWeights.setSize(nSrc);
924 srcMagSf.setSize(nSrc);
928 srcCentroids.setSize(nSrc);
930 tgtWeights.setSize(nTgt);
933 tgtMagSf.setSize(nTgt);
940 forAll(allInterfaces, inti)
942 if (allInterfaces.set(inti))
944 const auto& intf = refCast<const cyclicAMIGAMGInterface>
954 const auto&
AMI = intf.AMI();
959 SubList<scalarList>(srcWeights, srcA.size(), nSrc) =
965 SubList<scalar>(srcMagSf, srcA.size(), nSrc) =
972 SubList<pointList>(srcCentroids, srcA.size(), nSrc) =
980 SubList<scalarList>(tgtWeights, tgtA.size(), nTgt) =
985 SubList<scalar>(tgtMagSf, tgtA.size(), nTgt) =
1006 amiPtr_().comm(coarseComm),
1009 std::move(srcToTgtMap),
1010 std::move(tgtToSrcMap),
1011 std::move(srcAddress),
1012 std::move(srcWeights),
1013 std::move(tgtAddress),
1014 std::move(tgtWeights),
1017 amiPtr_().srcMagSf() = std::move(srcMagSf);
1018 amiPtr_().srcCentroids() = std::move(srcCentroids);
1019 amiPtr_().tgtMagSf() = std::move(tgtMagSf);
1024 const auto&
AMI = amiPtr_();
1029 Pout<<
"PROCAGGLOMERATED :" 1032 <<
" myRank:" << myRank <<
" agglomerated AMI:" 1038 Pout<<
"From nbr:" << nbrSize <<
" to owner:" << this->
size()
1048 forAll(map.subMap(), proci)
1050 Pout<<
" TGTMap: sending to rank:" << proci
1051 <<
" elements:" <<
flatOutput(map.subMap()[proci])
1054 forAll(map.constructMap(), proci)
1056 Pout<<
" TGTMap: receiving from rank:" << proci
1063 const globalIndex globalFaces(nbrSize,
AMI.
comm());
1064 Pout<<
" localNbrSize:" << nbrSize
1065 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
1066 for (label&
id : globalIDs)
1068 id = globalFaces.toGlobal(myRank,
id);
1070 map.distribute(globalIDs);
1076 Pout<<
" source face:" << facei
1079 <<
" from slots:" <<
flatOutput(addresses[facei])
1080 <<
" from global tgt faces:" 1081 << UIndirectList<label>(globalIDs, addresses[facei])
1088 Pout<<
"From owner:" << this->
size() <<
" to nbr:" << nbrSize
1098 forAll(map.subMap(), proci)
1100 Pout<<
" SRCMap: sending to rank:" << proci
1101 <<
" elements:" <<
flatOutput(map.subMap()[proci])
1104 forAll(map.constructMap(), proci)
1106 Pout<<
" SRCMap: receiving from rank:" << proci
1113 const globalIndex globalFaces(this->
size(),
AMI.
comm());
1114 Pout<<
" localSize:" << this->
size()
1115 <<
" globalSize:" << globalFaces.totalSize() <<
endl;
1116 for (label&
id : globalIDs)
1118 id = globalFaces.toGlobal(myRank,
id);
1120 map.distribute(globalIDs);
1126 Pout<<
" target face:" << facei
1129 <<
" from slots:" <<
flatOutput(addresses[facei])
1130 <<
" from global src faces:" 1131 << UIndirectList<label>(globalIDs, addresses[facei])
1135 Pout<<
"DONE PROCAGGLOMERATED" <<
endl;
1149 const cyclicAMIGAMGInterface& nbr =
1150 dynamic_cast<const cyclicAMIGAMGInterface&
>(neighbPatch());
1151 const labelUList& nbrFaceCells = nbr.faceCells();
1158 pnf[facei] = iF[nbrFaceCells[facei]];
1169 const bool hasAMI = bool(amiPtr_);
1180 AMI().writeData(
os);
1183 const label comm = AMI().comm();
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.
label comm() const noexcept
Communicator (local or otherwise) for parallel operations.
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.
T & first()
Access first element of the list, position [0].
bool requireMatch() const noexcept
Return the requireMatch flag.
Ostream & endl(Ostream &os)
Add newline and flush stream.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
static int & msgType() noexcept
Message tag of standard messages.
static void broadcast(Type &value, const int communicator=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
labelList faceRestrictAddressing_
Face restrict addressing.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
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 commWarn(const label communicator) noexcept
Alter communicator debugging setting. Warns for use of any communicator differing from specified...
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.
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.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
virtual void write(Ostream &) const
Write to stream.
List< bool > bools(const labelHashSet &locations)
Transform the on locations to a boolList, with true for each non-negative location and false for all ...
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)
bool reverseTarget() const noexcept
Access to the reverseTarget flag.
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
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...
virtual void write(Ostream &) const =0
Write to stream.
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches...
#define DebugPout
Report an information message using Foam::Pout.
static List< T > listGatherValues(const T &localValue, const int communicator=UPstream::worldComm, const int tag=UPstream::msgType())
Gather individual values into list locations.
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.
scalar lowWeightCorrection() const
Threshold weight below which interpolation is deactivated.
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&)
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.