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);
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)
507 allIDs.insert(elems);
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())
560 forAll(boxes_, proci)
562 List<treeBoundBox>& procBoxes = boxes_[proci];
566 treeBoundBox srcBb(srcPoints_);
570 procBoxes.front() = 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 > sortedToc() const
The table of contents (the keys) in sorted 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)
Transfer the contents of the argument List into this list and annul the argument list.
void append(const T &val)
Append an element at the end of the list.
void setSize(label n)
Alias for resize().
void clear()
Clear the list, i.e. set size to zero.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
label recvDataCount(const label proci) const
Number of unconsumed receive bytes for the specified processor. Must call finishedSends() or other fi...
void finishedSends(const bool wait=true)
Mark the send phase as being finished.
Inter-processor communications stream.
Input inter-processor communications stream using MPI send/recv etc. - operating on external buffer.
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 List is empty (ie, size() is zero).
void size(const label n)
Older name for setAddressableSize.
Output inter-processor communications stream using MPI send/recv etc. - operating on external buffer.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
A face is a list of labels corresponding to mesh vertices.
layoutTypes
The map layout (eg, of the constructMap).
Base class to generate a parallel distribution map for sending sufficient target objects to cover a d...
label maxObjectsPerLeaf_
Maximum number of objects per leaf.
processorLOD(const label maxObjectsPerLeaf, const label nObjectsOfType) noexcept
Construct from components.
label nObjectsOfType_
Number of objects of this type. e.g. number of faces/cells on this processor.
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.
label nRefineIterMax_
Maximum number of refinement iterations.
List< labelList > newToOld_
Addressing per proc of new to old bound boxes.
void refineBox(const label boxi, const label refineIter, const label nSrcElem, const treeBoundBox &origBox, DynamicList< treeBoundBox > &procBoxes, DynamicList< labelList > &procBoxElems, DynamicList< label > &procNewToOld) const
virtual treeBoundBox calcSrcBox(const label srcObji) const =0
The local boundBox associated with given source object.
static const label DROP
Drop/discard.
static const label FIXED
Fixed - do not touch.
static const label nStartUpIter
Number of iterations before element indices are cached.
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.
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.
autoPtr< mapDistribute > createMap(const label nSrcElems, const label nTgtElems, const mapDistributeBase::layoutTypes constructLayout)
Return the parallel distribution map (often linear construct order).
static const label REFINE
Refine.
const UList< point > & tgtPoints_
Reference to the target points.
virtual treeBoundBox calcTgtBox(const label tgtObji) const =0
The local boundBox associated with given target object.
const UList< point > & srcPoints_
Reference to the source points.
List< List< labelList > > boxSrcElems_
Indices of elements in the src boxes.
Standard boundBox with extra functionality for use in octree.
static const faceList faces
Face to point addressing, using octant corner points.
bool overlaps(const boundBox &bb) const
Overlaps with other bounding box, sphere etc?
treeBoundBox subBbox(const direction octant) const
Sub-box of given octant. Midpoint calculated.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
Namespace for handling debugging switches.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
List< label > labelList
A List of labels.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Ostream & endl(Ostream &os)
Add newline and flush stream.
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...
errorManip< error > abort(error &err)
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
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.