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];
132 UIPstream fromProc(proci, pBufs);
133 const label nObjects =
readLabel(fromProc);
134 List<treeBoundBox> remoteSrcBoxes(fromProc);
135 const List<label> newToOld(fromProc);
137 if (remoteSrcBoxes.empty())
143 labelList& procRefineFlags = refineFlags[proci];
144 procRefineFlags.
setSize(remoteSrcBoxes.size(), FIXED);
146 if (nObjects == 0 || scalar(nTgtObjects)/scalar(nObjects) < 0.1)
150 fixedSendElems[proci].insert(
identity(nTgtObjects));
151 nElems[proci] = nTgtObjects;
157 List<labelList>& localProcTgtElems = localTgtElems[proci];
158 List<labelList> newLocalProcTgtElems(remoteSrcBoxes.size());
160 forAll(remoteSrcBoxes, srcBoxi)
162 const treeBoundBox& remSrcBb = remoteSrcBoxes[srcBoxi];
163 DynamicList<label> selectedElems(maxObjectsPerLeaf_);
165 if (refineIter > nStartUpIter)
168 const label oldBoxi = newToOld[srcBoxi];
169 const labelList& tgtBoxElems = localProcTgtElems[oldBoxi];
171 for (
const label tgtObji : tgtBoxElems)
173 if (calcTgtBox(tgtObji).overlaps(remSrcBb))
175 selectedElems.
append(tgtObji);
182 for (label tgtObji = 0; tgtObji < nTgtObjects; ++tgtObji)
184 if (calcTgtBox(tgtObji).overlaps(remSrcBb))
186 selectedElems.append(tgtObji);
191 nElem += selectedElems.size();
196 || selectedElems.size() < maxObjectsPerLeaf_
199 procRefineFlags[srcBoxi] = FIXED;
200 fixedSendElems[proci].insert(selectedElems);
204 procRefineFlags[srcBoxi] = REFINE;
205 if (refineIter >= nStartUpIter)
207 newLocalProcTgtElems[srcBoxi].
transfer(selectedElems);
212 localProcTgtElems.transfer(newLocalProcTgtElems);
213 nElems[proci] = nElem;
221 const label refineIter,
222 const label nSrcElem,
231 if (refineIter == nStartUpIter)
234 for (
direction octant = 0; octant < 8; ++octant)
241 for (label srcElemi = 0; srcElemi < nSrcElem; ++srcElemi)
243 if (subBb.overlaps(calcSrcBox(srcElemi)))
245 newElems.append(srcElemi);
252 procBoxElems.
append(newElems);
253 procNewToOld.
append(boxi);
259 for (
direction octant = 0; octant < 8; ++octant)
261 const treeBoundBox subBb(origBox.
subBbox(octant));
263 for (label srcElemi = 0; srcElemi < nSrcElem; ++srcElemi)
265 if (subBb.overlaps(calcSrcBox(srcElemi)))
280 const treeBoundBox& origBox,
281 DynamicList<treeBoundBox>& procBoxes,
282 DynamicList<labelList>& procBoxElems,
283 DynamicList<label>& procNewToOld
287 for (
direction octant = 0; octant < 8; ++octant)
289 const treeBoundBox subBb(origBox.subBbox(octant));
292 DynamicList<label> newElems(srcAddr.size()/2);
294 for (
const label srcElemi : srcAddr)
296 if (subBb.overlaps(calcSrcBox(srcElemi)))
298 newElems.append(srcElemi);
305 procBoxes.append(subBb);
306 procBoxElems.append(newElems);
307 procNewToOld.append(boxi);
315 const label refineIter,
316 const label nSrcFaces,
317 const List<labelList>& refineFlags,
318 List<DynamicList<treeBoundBox>>& fixedBoxes
324 forAll(refineFlags, proci)
328 UOPstream toProc(proci, pBufs);
329 toProc << refineFlags[proci];
333 pBufs.finishedSends();
337 bool refineBoxes =
false;
348 UIPstream fromProc(proci, pBufs);
351 const List<treeBoundBox>& procBoxes = boxes_[proci];
352 DynamicList<treeBoundBox> newProcBoxes(procBoxes.size());
353 DynamicList<labelList> newProcBoxElems(procBoxes.size());
354 newToOld[proci].setCapacity(boxes_[proci].size());
355 DynamicList<label>& newProcNewToOld = newToOld[proci];
360 if (refineFlags[boxi] == DROP)
364 else if (refineFlags[boxi] == REFINE)
366 if (refineIter > nStartUpIter)
373 boxSrcElems_[proci][boxi],
396 else if (refineFlags[boxi] == FIXED)
398 fixedBoxes[proci].append(procBoxes[boxi]);
403 <<
"Unhandled refine action " << refineFlags[boxi]
409 boxes_[proci].transfer(newProcBoxes);
410 boxSrcElems_[proci].transfer(newProcBoxElems);
411 newToOld_[proci].transfer(newProcNewToOld);
420 const label nSrcElems,
421 const label nTgtElems
435 label refinementIter = 1;
436 bool refineSrcBoxes =
true;
437 while (refineSrcBoxes && (refinementIter <= nRefineIterMax_))
473 allBoxes[proci].append(boxes_[proci]);
475 writeBoxes(allBoxes, refinementIter);
481 Pout<<
"Local src boxes after " << refinementIter-1 <<
" iterations:" 487 label nBox = fixedBoxes[proci].size() + boxes_[proci].size();
488 Pout<<
" proc:" << proci <<
" nBoxes:" << nBox <<
nl;
495 forAll(localTgtElems, proci)
499 sendElems[proci] =
identity(nTgtElems);
505 const List<labelList>& procBoxElems = localTgtElems[proci];
507 for (
const labelList& elems: procBoxElems)
509 allIDs.insert(elems);
512 sendElems[proci] = allIDs.sortedToc();
516 fixedSendElems.
clear();
517 localTgtElems.clear();
521 Pout<<
"Local objects: " << nTgtElems <<
" Send map:" <<
nl 526 Pout<<
tab << proci <<
tab << sendElems[proci].size()
541 const label maxObjectsPerLeaf,
542 const label nObjectsOfType,
543 const label nRefineIterMax
547 srcPoints_(srcPoints),
548 tgtPoints_(tgtPoints),
550 nRefineIterMax_(nRefineIterMax),
552 boxSrcElems_(
Pstream::nProcs())
568 procBoxes.
front() = srcBb;
defineTypeNameAndDebug(box, 0)
void resize(const label len)
Adjust allocated size of list.
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...
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)
T & front()
Access first element of the list, position [0].
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)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
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 label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It 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...
label recvDataCount(const label proci) const
Number of unconsumed receive bytes for the specified processor. Must call finishedSends() or other fi...
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.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
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)