40namespace processorLODs
54 static label time = 0;
87 for (
const label fpi :
f)
89 os <<
' ' << fpi + verti + 1;
103 const label refineIter,
104 const label nTgtObjects,
119 toProc << nObjectsOfType_ << boxes_[proci] << newToOld_[proci];
138 const label nObjects =
readLabel(fromProc);
142 if (remoteSrcBoxes.
empty())
148 labelList& procRefineFlags = refineFlags[proci];
149 procRefineFlags.
setSize(remoteSrcBoxes.
size(), FIXED);
151 if (nObjects == 0 || scalar(nTgtObjects)/scalar(nObjects) < 0.1)
155 fixedSendElems[proci].insert(
identity(nTgtObjects));
156 nElems[proci] = nTgtObjects;
165 forAll(remoteSrcBoxes, srcBoxi)
170 if (refineIter > nStartUpIter)
173 const label oldBoxi = newToOld[srcBoxi];
174 const labelList& tgtBoxElems = localProcTgtElems[oldBoxi];
176 for (
const label tgtObji : tgtBoxElems)
178 if (calcTgtBox(tgtObji).overlaps(remSrcBb))
180 selectedElems.
append(tgtObji);
187 for (label tgtObji = 0; tgtObji < nTgtObjects; ++tgtObji)
189 if (calcTgtBox(tgtObji).overlaps(remSrcBb))
191 selectedElems.
append(tgtObji);
196 nElem += selectedElems.
size();
201 || selectedElems.
size() < maxObjectsPerLeaf_
204 procRefineFlags[srcBoxi] = FIXED;
205 fixedSendElems[proci].insert(selectedElems);
209 procRefineFlags[srcBoxi] = REFINE;
210 if (refineIter >= nStartUpIter)
212 newLocalProcTgtElems[srcBoxi].
transfer(selectedElems);
217 localProcTgtElems.
transfer(newLocalProcTgtElems);
218 nElems[proci] = nElem;
226 const label refineIter,
227 const label nSrcElem,
236 if (refineIter == nStartUpIter)
239 for (
direction octant = 0; octant < 8; ++octant)
246 for (label srcElemi = 0; srcElemi < nSrcElem; ++srcElemi)
248 if (subBb.
overlaps(calcSrcBox(srcElemi)))
250 newElems.
append(srcElemi);
257 procBoxElems.
append(newElems);
258 procNewToOld.
append(boxi);
264 for (
direction octant = 0; octant < 8; ++octant)
268 for (label srcElemi = 0; srcElemi < nSrcElem; ++srcElemi)
270 if (subBb.
overlaps(calcSrcBox(srcElemi)))
292 for (
direction octant = 0; octant < 8; ++octant)
299 for (
const label srcElemi : srcAddr)
301 if (subBb.
overlaps(calcSrcBox(srcElemi)))
303 newElems.
append(srcElemi);
311 procBoxElems.
append(newElems);
312 procNewToOld.
append(boxi);
320 const label refineIter,
321 const label nSrcFaces,
329 forAll(refineFlags, proci)
334 toProc << refineFlags[proci];
342 bool refineBoxes =
false;
359 newToOld[proci].setCapacity(boxes_[proci].size());
365 if (refineFlags[boxi] == DROP)
369 else if (refineFlags[boxi] == REFINE)
371 if (refineIter > nStartUpIter)
378 boxSrcElems_[proci][boxi],
401 else if (refineFlags[boxi] == FIXED)
403 fixedBoxes[proci].append(procBoxes[boxi]);
408 <<
"Unhandled refine action " << refineFlags[boxi]
414 boxes_[proci].transfer(newProcBoxes);
415 boxSrcElems_[proci].transfer(newProcBoxElems);
416 newToOld_[proci].transfer(newProcNewToOld);
425 const label nSrcElems,
426 const label nTgtElems
440 label refinementIter = 1;
441 bool refineSrcBoxes =
true;
442 while (refineSrcBoxes && (refinementIter <= nRefineIterMax_))
478 allBoxes[proci].
append(boxes_[proci]);
480 writeBoxes(allBoxes, refinementIter);
486 Pout<<
"Local src boxes after " << refinementIter-1 <<
" iterations:"
492 label nBox = fixedBoxes[proci].
size() + boxes_[proci].size();
493 Pout<<
" proc:" << proci <<
" nBoxes:" << nBox <<
nl;
500 forAll(localTgtElems, proci)
504 sendElems[proci] =
identity(nTgtElems);
512 for (
const labelList& elems: procBoxElems)
517 sendElems[proci] = allIDs.
toc();
521 fixedSendElems.
clear();
522 localTgtElems.
clear();
526 Pout<<
"Local objects: " << nTgtElems <<
" Send map:" <<
nl
536 return createLODMap(sendElems);
551 sendSizes[localProci][proci] = sendElems[proci].
size();
560 constructMap[localProci] =
identity(sendElems[localProci].size());
562 label segmenti = constructMap[localProci].
size();
563 forAll(constructMap, proci)
565 if (proci != localProci)
568 label nRecv = sendSizes[proci][localProci];
569 constructMap[proci].
setSize(nRecv);
571 for (label& addr : constructMap[proci])
583 std::move(sendElems),
584 std::move(constructMap)
598 const label maxObjectsPerLeaf,
599 const label nObjectsOfType,
600 const label nRefineIterMax
604 srcPoints_(srcPoints),
605 tgtPoints_(tgtPoints),
607 nRefineIterMax_(nRefineIterMax),
609 boxSrcElems_(
Pstream::nProcs())
625 newProcBoxes.
append(srcBb);
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void append(const T &val)
Copy append an element to the end of this list.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void transfer(List< T > &list)
void setSize(const label n)
Alias for resize()
void append(const T &val)
Append an element at the end of the list.
void clear()
Clear the list, i.e. set size to zero.
Output to file stream, using an OSstream.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
UPstream::rangeType allProcs() const noexcept
Range of ranks indices associated with PstreamBuffers.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
void finishedSends(const bool wait=true)
Mark sends as done.
Inter-processor communications stream.
static void allGatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
void size(const label n)
Older name for setAddressableSize.
@ nonBlocking
"nonBlocking"
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void inflate(const scalar s)
Inflate box by factor*mag(span) in all dimensions.
A face is a list of labels corresponding to mesh vertices.
Class containing processor-to-processor mapping information.
int myProcNo() const noexcept
Return processor number.
Base class to generate a parallel distribution map for sending sufficient target objects to cover a d...
Creates the parallel distribution map by describing the source and target objects using box shapes.
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.
void refineBox(const label boxi, const label refineIter, const label nSrcElem, const treeBoundBox &origBox, DynamicList< treeBoundBox > &procBoxes, DynamicList< labelList > &procBoxElems, DynamicList< label > &procNewToOld) const
static const label DROP
Drop/discard.
static const label FIXED
Fixed - do not touch.
autoPtr< mapDistribute > createMap(const label nSrcElems, const label nTgtElems)
static const label nStartUpIter
Number of iterations before element indices are cached.
List< List< treeBoundBox > > boxes_
Per processor, the list of src bound boxes.
void writeBoxes(const List< DynamicList< treeBoundBox > > &fixedBoxes, const label iter) const
Helper function to write the boxes in OBJ format.
bool doRefineBoxes(const label refineIter, const label nSrcFaces, const List< labelList > &refineFlags, List< DynamicList< treeBoundBox > > &fixedBoxes)
Apply the box refinements.
static const label REFINE
Refine.
const UList< point > & srcPoints_
Reference to the source points.
autoPtr< mapDistribute > createLODMap(List< labelList > &sendElems) const
Use the current list of send elements to create the mapDistribute.
Standard boundBox with extra functionality for use in octree.
bool overlaps(const boundBox &bb) const
Overlaps other bounding box?
treeBoundBox subBbox(const direction octant) const
Sub-box of given octant. Midpoint calculated.
static const faceList faces
Face to point addressing.
tmp< pointField > points() const
Vertex coordinates. In octant coding.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
static constexpr const zero Zero
Global zero (0)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr char nl
The newline '\n' character (0x0a)
constexpr char tab
The tab '\t' character(0x09)
#define forAll(list, i)
Loop across all elements in list.