40 namespace processorLODs
54 static label time = 0;
71 const DynamicList<treeBoundBox>& procBoxes = fixedBoxes[proci];
74 const treeBoundBox& bb = procBoxes[boxi];
84 for (
const label fpi :
f)
86 os <<
' ' << fpi + verti + 1;
100 const label refineIter,
101 const label nTgtObjects,
116 toProc << nObjectsOfType_ << boxes_[proci] << newToOld_[proci];
134 UIPstream fromProc(proci, pBufs);
135 const label nObjects =
readLabel(fromProc);
136 List<treeBoundBox> remoteSrcBoxes(fromProc);
137 const List<label> newToOld(fromProc);
139 if (remoteSrcBoxes.empty())
145 labelList& procRefineFlags = refineFlags[proci];
146 procRefineFlags.
setSize(remoteSrcBoxes.size(), FIXED);
148 if (nObjects == 0 || scalar(nTgtObjects)/scalar(nObjects) < 0.1)
152 fixedSendElems[proci].insert(
identity(nTgtObjects));
153 nElems[proci] = nTgtObjects;
159 List<labelList>& localProcTgtElems = localTgtElems[proci];
160 List<labelList> newLocalProcTgtElems(remoteSrcBoxes.size());
162 forAll(remoteSrcBoxes, srcBoxi)
164 const treeBoundBox& remSrcBb = remoteSrcBoxes[srcBoxi];
165 DynamicList<label> selectedElems(maxObjectsPerLeaf_);
167 if (refineIter > nStartUpIter)
170 const label oldBoxi = newToOld[srcBoxi];
171 const labelList& tgtBoxElems = localProcTgtElems[oldBoxi];
173 for (
const label tgtObji : tgtBoxElems)
175 if (calcTgtBox(tgtObji).overlaps(remSrcBb))
177 selectedElems.
append(tgtObji);
184 for (label tgtObji = 0; tgtObji < nTgtObjects; ++tgtObji)
186 if (calcTgtBox(tgtObji).overlaps(remSrcBb))
188 selectedElems.append(tgtObji);
193 nElem += selectedElems.size();
198 || selectedElems.size() < maxObjectsPerLeaf_
201 procRefineFlags[srcBoxi] = FIXED;
202 fixedSendElems[proci].insert(selectedElems);
206 procRefineFlags[srcBoxi] = REFINE;
207 if (refineIter >= nStartUpIter)
209 newLocalProcTgtElems[srcBoxi].
transfer(selectedElems);
214 localProcTgtElems.transfer(newLocalProcTgtElems);
215 nElems[proci] = nElem;
223 const label refineIter,
224 const label nSrcElem,
233 if (refineIter == nStartUpIter)
236 for (
direction octant = 0; octant < 8; ++octant)
243 for (label srcElemi = 0; srcElemi < nSrcElem; ++srcElemi)
245 if (subBb.overlaps(calcSrcBox(srcElemi)))
247 newElems.append(srcElemi);
254 procBoxElems.
append(newElems);
255 procNewToOld.
append(boxi);
261 for (
direction octant = 0; octant < 8; ++octant)
263 const treeBoundBox subBb(origBox.
subBbox(octant));
265 for (label srcElemi = 0; srcElemi < nSrcElem; ++srcElemi)
267 if (subBb.overlaps(calcSrcBox(srcElemi)))
282 const treeBoundBox& origBox,
283 DynamicList<treeBoundBox>& procBoxes,
284 DynamicList<labelList>& procBoxElems,
285 DynamicList<label>& procNewToOld
289 for (
direction octant = 0; octant < 8; ++octant)
291 const treeBoundBox subBb(origBox.subBbox(octant));
294 DynamicList<label> newElems(srcAddr.size()/2);
296 for (
const label srcElemi : srcAddr)
298 if (subBb.overlaps(calcSrcBox(srcElemi)))
300 newElems.append(srcElemi);
307 procBoxes.append(subBb);
308 procBoxElems.append(newElems);
309 procNewToOld.append(boxi);
317 const label refineIter,
318 const label nSrcFaces,
319 const List<labelList>& refineFlags,
320 List<DynamicList<treeBoundBox>>& fixedBoxes
326 forAll(refineFlags, proci)
330 UOPstream toProc(proci, pBufs);
331 toProc << refineFlags[proci];
335 pBufs.finishedSends();
339 bool refineBoxes =
false;
350 UIPstream fromProc(proci, pBufs);
353 const List<treeBoundBox>& procBoxes = boxes_[proci];
354 DynamicList<treeBoundBox> newProcBoxes(procBoxes.size());
355 DynamicList<labelList> newProcBoxElems(procBoxes.size());
356 newToOld[proci].setCapacity(boxes_[proci].size());
357 DynamicList<label>& newProcNewToOld = newToOld[proci];
362 if (refineFlags[boxi] == DROP)
366 else if (refineFlags[boxi] == REFINE)
368 if (refineIter > nStartUpIter)
375 boxSrcElems_[proci][boxi],
398 else if (refineFlags[boxi] == FIXED)
400 fixedBoxes[proci].append(procBoxes[boxi]);
405 <<
"Unhandled refine action " << refineFlags[boxi]
411 boxes_[proci].transfer(newProcBoxes);
412 boxSrcElems_[proci].transfer(newProcBoxElems);
413 newToOld_[proci].transfer(newProcNewToOld);
422 const label nSrcElems,
423 const label nTgtElems
437 label refinementIter = 1;
438 bool refineSrcBoxes =
true;
439 while (refineSrcBoxes && (refinementIter <= nRefineIterMax_))
475 allBoxes[proci].append(boxes_[proci]);
477 writeBoxes(allBoxes, refinementIter);
483 Pout<<
"Local src boxes after " << refinementIter-1 <<
" iterations:" 489 label nBox = fixedBoxes[proci].size() + boxes_[proci].size();
490 Pout<<
" proc:" << proci <<
" nBoxes:" << nBox <<
nl;
497 forAll(localTgtElems, proci)
501 sendElems[proci] =
identity(nTgtElems);
507 const List<labelList>& procBoxElems = localTgtElems[proci];
509 for (
const labelList& elems: procBoxElems)
511 allIDs.insert(elems);
514 sendElems[proci] = allIDs.toc();
518 fixedSendElems.
clear();
519 localTgtElems.clear();
523 Pout<<
"Local objects: " << nTgtElems <<
" Send map:" <<
nl 533 return createLODMap(sendElems);
548 sendSizes[localProci][proci] = sendElems[proci].
size();
557 constructMap[localProci] =
identity(sendElems[localProci].size());
559 label segmenti = constructMap[localProci].size();
560 forAll(constructMap, proci)
562 if (proci != localProci)
565 label nRecv = sendSizes[proci][localProci];
566 constructMap[proci].setSize(nRecv);
568 for (label& addr : constructMap[proci])
575 autoPtr<mapDistribute> mapPtr
580 std::move(sendElems),
581 std::move(constructMap)
595 const label maxObjectsPerLeaf,
596 const label nObjectsOfType,
597 const label nRefineIterMax
601 srcPoints_(srcPoints),
602 tgtPoints_(tgtPoints),
604 nRefineIterMax_(nRefineIterMax),
606 boxSrcElems_(
Pstream::nProcs())
622 newProcBoxes.
append(srcBb);
defineTypeNameAndDebug(box, 0)
List< labelList > labelListList
A List of labelList.
void size(const label n)
Older name for setAddressableSize.
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...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void writeBoxes(const List< DynamicList< treeBoundBox >> &fixedBoxes, const label iter) const
Helper function to write the boxes in OBJ format.
void append(const T &val)
Append an element at the end of the list.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void inflate(const scalar factor)
Expand box by factor*mag(span) in all dimensions.
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
Output to file stream, using an OSstream.
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
List< List< treeBoundBox > > boxes_
Per processor, the list of src bound boxes.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
constexpr char tab
The tab '\t' character(0x09)
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
static const faceList faces
Face to point addressing, using octant corner points.
static const label REFINE
Refine.
Base class to generate a parallel distribution map for sending sufficient target objects to cover a d...
#define forAll(list, i)
Loop across all elements in list.
bool doRefineBoxes(const label refineIter, const label nSrcFaces, const List< labelList > &refineFlags, List< DynamicList< treeBoundBox >> &fixedBoxes)
Apply the box refinements.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
static void allGatherList(List< T > &values, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Gather data, but keep individual values separate. Uses linear/tree communication. ...
autoPtr< mapDistribute > createLODMap(List< labelList > &sendElems) const
Use the current list of send elements to create the mapDistribute.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator) is 1 for serial run.
vectorField pointField
pointField is a vectorField.
void setSize(const label n)
Alias for resize()
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
void clear()
Clear the list, i.e. set size to zero.
Inter-processor communications stream.
void finishedSends(const bool wait=true)
Mark sends as done.
treeBoundBox subBbox(const direction octant) const
Sub-box of given octant. Midpoint calculated.
static const label nStartUpIter
Number of iterations before element indices are cached.
void append(const T &val)
Copy append an element to the end of this list.
box(const UList< point > &srcPoints, const UList< point > &tgtPoints, const label maxObjectsPerLeaf, const label nObjectsOfType, const label nRefineIterMax=100)
Construct from list of points.
errorManip< error > abort(error &err)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Creates the parallel distribution map by describing the source and target objects using box shapes...
Output inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void refineBox(const label boxi, const label refineIter, const label nSrcElem, const treeBoundBox &origBox, DynamicList< treeBoundBox > &procBoxes, DynamicList< labelList > &procBoxElems, DynamicList< label > &procNewToOld) const
const UList< point > & srcPoints_
Reference to the source points.
void setRefineFlags(const label refineIter, const label nTgtObjects, List< labelHashSet > &fixedSendElems, List< List< labelList >> &localTgtElems, List< labelList > &refineFlags, labelList &nElems) const
Set the box refinement flags.
Standard boundBox with extra functionality for use in octree.
"nonBlocking" : (MPI_Isend, MPI_Irecv)
static const label FIXED
Fixed - do not touch.
static const label DROP
Drop/discard.
List< label > labelList
A List of labels.
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
autoPtr< mapDistribute > createMap(const label nSrcElems, const label nTgtElems)
static constexpr const zero Zero
Global zero (0)