40 namespace processorLODs
73 for (
const treeBoundBox& bb : fixedBoxes[proci])
83 for (
const label fpi :
f)
85 os <<
' ' << fpi + verti + 1;
97 const label refineIter,
98 const label nTgtObjects,
99 List<labelHashSet>& fixedSendElems,
100 List<List<labelList>>& localTgtElems,
101 List<labelList>& refineFlags,
105 PstreamBuffers pBufs;
112 UOPstream toProc(proci, pBufs);
113 toProc << nObjectsOfType_ << boxes_[proci] << newToOld_[proci];
117 pBufs.finishedSends();
129 UIPstream fromProc(proci, pBufs);
130 const label nObjects =
readLabel(fromProc);
131 List<treeBoundBox> remoteSrcBoxes(fromProc);
132 const List<label> newToOld(fromProc);
134 if (remoteSrcBoxes.empty())
140 labelList& procRefineFlags = refineFlags[proci];
141 procRefineFlags.
setSize(remoteSrcBoxes.size(), FIXED);
143 if (nObjects == 0 || scalar(nTgtObjects)/scalar(nObjects) < 0.1)
147 fixedSendElems[proci].insert(
identity(nTgtObjects));
148 nElems[proci] = nTgtObjects;
154 List<labelList>& localProcTgtElems = localTgtElems[proci];
155 List<labelList> newLocalProcTgtElems(remoteSrcBoxes.size());
157 forAll(remoteSrcBoxes, srcBoxi)
159 const treeBoundBox& remSrcBb = remoteSrcBoxes[srcBoxi];
160 DynamicList<label> selectedElems(maxObjectsPerLeaf_);
162 if (refineIter > nStartUpIter)
165 const label oldBoxi = newToOld[srcBoxi];
166 const labelList& tgtBoxElems = localProcTgtElems[oldBoxi];
168 for (
const label tgtObji : tgtBoxElems)
170 if (calcTgtBox(tgtObji).overlaps(remSrcBb))
172 selectedElems.
append(tgtObji);
179 for (label tgtObji = 0; tgtObji < nTgtObjects; ++tgtObji)
181 if (calcTgtBox(tgtObji).overlaps(remSrcBb))
183 selectedElems.append(tgtObji);
188 nElem += selectedElems.size();
193 || selectedElems.size() < maxObjectsPerLeaf_
196 procRefineFlags[srcBoxi] = FIXED;
197 fixedSendElems[proci].insert(selectedElems);
201 procRefineFlags[srcBoxi] = REFINE;
202 if (refineIter >= nStartUpIter)
204 newLocalProcTgtElems[srcBoxi].transfer(selectedElems);
209 localProcTgtElems.transfer(newLocalProcTgtElems);
210 nElems[proci] = nElem;
218 const label refineIter,
219 const label nSrcElem,
228 if (refineIter == nStartUpIter)
231 for (
direction octant = 0; octant < 8; ++octant)
238 for (label srcElemi = 0; srcElemi < nSrcElem; ++srcElemi)
240 if (subBb.overlaps(calcSrcBox(srcElemi)))
242 newElems.append(srcElemi);
249 procBoxElems.
append(newElems);
250 procNewToOld.
append(boxi);
256 for (
direction octant = 0; octant < 8; ++octant)
258 const treeBoundBox subBb(origBox.
subBbox(octant));
260 for (label srcElemi = 0; srcElemi < nSrcElem; ++srcElemi)
262 if (subBb.overlaps(calcSrcBox(srcElemi)))
277 const treeBoundBox& origBox,
278 DynamicList<treeBoundBox>& procBoxes,
279 DynamicList<labelList>& procBoxElems,
280 DynamicList<label>& procNewToOld
284 for (
direction octant = 0; octant < 8; ++octant)
286 const treeBoundBox subBb(origBox.subBbox(octant));
289 DynamicList<label> newElems(srcAddr.size()/2);
291 for (
const label srcElemi : srcAddr)
293 if (subBb.overlaps(calcSrcBox(srcElemi)))
295 newElems.append(srcElemi);
302 procBoxes.append(subBb);
303 procBoxElems.append(newElems);
304 procNewToOld.append(boxi);
312 const label refineIter,
313 const label nSrcFaces,
314 const List<labelList>& refineFlags,
315 List<DynamicList<treeBoundBox>>& fixedBoxes
318 PstreamBuffers pBufs;
321 forAll(refineFlags, proci)
325 UOPstream toProc(proci, pBufs);
326 toProc << refineFlags[proci];
330 pBufs.finishedSends();
334 bool refineBoxes =
false;
345 UIPstream fromProc(proci, pBufs);
348 const List<treeBoundBox>& procBoxes = boxes_[proci];
349 DynamicList<treeBoundBox> newProcBoxes(procBoxes.size());
350 DynamicList<labelList> newProcBoxElems(procBoxes.size());
351 newToOld[proci].setCapacity(boxes_[proci].size());
352 DynamicList<label>& newProcNewToOld = newToOld[proci];
357 if (refineFlags[boxi] == DROP)
361 else if (refineFlags[boxi] == REFINE)
363 if (refineIter > nStartUpIter)
370 boxSrcElems_[proci][boxi],
393 else if (refineFlags[boxi] == FIXED)
395 fixedBoxes[proci].append(procBoxes[boxi]);
400 <<
"Unhandled refine action " << refineFlags[boxi]
406 boxes_[proci].transfer(newProcBoxes);
407 boxSrcElems_[proci].transfer(newProcBoxElems);
408 newToOld_[proci].transfer(newProcNewToOld);
417 const label nSrcElems,
418 const label nTgtElems,
433 label refinementIter = 1;
434 bool refineSrcBoxes =
true;
435 while (refineSrcBoxes && (refinementIter <= nRefineIterMax_))
471 allBoxes[proci].append(boxes_[proci]);
473 writeBoxes(allBoxes, refinementIter);
479 Pout<<
"Local src boxes after " << refinementIter-1 <<
" iterations:" 485 label nBox = fixedBoxes[proci].size() + boxes_[proci].size();
486 Pout<<
" proc:" << proci <<
" nBoxes:" << nBox <<
nl;
493 forAll(localTgtElems, proci)
497 sendElems[proci] =
identity(nTgtElems);
503 const List<labelList>& procBoxElems = localTgtElems[proci];
505 for (
const labelList& elems: procBoxElems)
510 sendElems[proci] = allIDs.sortedToc();
514 fixedSendElems.clear();
515 localTgtElems.clear();
519 Pout<<
"Local objects: " << nTgtElems <<
" Send map:" <<
nl 524 Pout<<
tab << proci <<
tab << sendElems[proci].size()
543 const label maxObjectsPerLeaf,
544 const label nObjectsOfType,
545 const label nRefineIterMax
549 srcPoints_(srcPoints),
550 tgtPoints_(tgtPoints),
552 nRefineIterMax_(nRefineIterMax),
554 boxSrcElems_(
Pstream::nProcs())
570 procBoxes.
front() = srcBb;
defineTypeNameAndDebug(box, 0)
void resize(const label len)
Adjust allocated size of 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 as an OSstream, normally using std::ofstream for the actual output...
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.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
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.
layoutTypes
The map layout (eg, of the constructMap)
void setSize(const label n)
Alias for resize()
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::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), works like std::iota() but returning a...
Inter-processor communications stream.
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 for source and target.
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...
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
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.
autoPtr< mapDistribute > createMap(const label nSrcElems, const label nTgtElems, const mapDistributeBase::layoutTypes constructLayout)
Return the parallel distribution map (often linear construct order)
Standard boundBox with extra functionality for use in octree.
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.
static constexpr const zero Zero
Global zero (0)