36 template<
class ParticleType>
39 Info<<
"Building InteractionLists with interaction distance "
40 << maxDistance_ <<
endl;
42 const vector interactionVec = maxDistance_*vector::one;
44 treeBoundBox procBb(treeBoundBox(mesh_.points()));
46 treeBoundBox extendedProcBb
48 procBb.min() - interactionVec,
49 procBb.max() + interactionVec
54 allExtendedProcBbs[Pstream::myProcNo()] = extendedProcBb;
56 Pstream::gatherList(allExtendedProcBbs);
58 Pstream::scatterList(allExtendedProcBbs);
64 findExtendedProcBbsInRange
68 mesh_.globalData().globalTransforms(),
69 extendedProcBbsInRange,
70 extendedProcBbsTransformIndex,
71 extendedProcBbsOrigProc
78 cellBbs[celli] = treeBoundBox
80 mesh_.cells()[celli].points
88 const globalIndexAndTransform& globalTransforms =
89 mesh_.globalData().globalTransforms();
94 PackedBoolList cellInRangeOfCoupledPatch(mesh_.nCells(),
false);
98 DynamicList<labelPair> cellIAndTToExchange;
100 DynamicList<treeBoundBox> cellBbsToExchange;
102 DynamicList<label> procToDistributeCellTo;
104 forAll(extendedProcBbsInRange, ePBIRI)
106 const treeBoundBox& otherExtendedProcBb =
107 extendedProcBbsInRange[ePBIRI];
109 label transformIndex = extendedProcBbsTransformIndex[ePBIRI];
111 label origProc = extendedProcBbsOrigProc[ePBIRI];
115 const treeBoundBox& cellBb = cellBbs[celli];
117 if (cellBb.overlaps(otherExtendedProcBb))
122 cellInRangeOfCoupledPatch[celli] =
true;
124 cellIAndTToExchange.append
126 globalTransforms.encode(celli, transformIndex)
129 cellBbsToExchange.append(cellBb);
131 procToDistributeCellTo.append(origProc);
136 buildMap(cellMapPtr_, procToDistributeCellTo);
139 label preDistributionCellMapSize = procToDistributeCellTo.size();
141 cellMap().distribute(cellBbsToExchange);
143 cellMap().distribute(cellIAndTToExchange);
147 DynamicList<label> coupledPatchRangeCells;
149 forAll(cellInRangeOfCoupledPatch, celli)
151 if (cellInRangeOfCoupledPatch[celli])
153 coupledPatchRangeCells.append(celli);
157 treeBoundBox procBbRndExt
159 treeBoundBox(mesh_.points()).extend(1
e-4)
162 indexedOctree<treeDataCell> coupledPatchRangeTree
164 treeDataCell(
true, mesh_, coupledPatchRangeCells),
171 ril_.setSize(cellBbsToExchange.size());
175 boolList cellBbRequiredByAnyCell(cellBbsToExchange.size(),
false);
177 Info<<
" Building referred interaction lists" <<
endl;
179 forAll(cellBbsToExchange, bbI)
181 const labelPair& ciat = cellIAndTToExchange[bbI];
183 const transformer&
transform = globalTransforms.transform
185 globalTransforms.transformIndex(ciat)
188 treeBoundBox tempTransformedBb
190 transform.invTransformPosition(cellBbsToExchange[bbI].points())()
193 treeBoundBox extendedBb
195 tempTransformedBb.min() - interactionVec,
196 tempTransformedBb.max() + interactionVec
202 coupledPatchRangeTree.findBox(extendedBb)
205 if (!interactingElems.empty())
207 cellBbRequiredByAnyCell[bbI] =
true;
210 ril_[bbI].setSize(interactingElems.size(), -1);
212 forAll(interactingElems, i)
214 label elemI = interactingElems[i];
220 label c = coupledPatchRangeTree.shapes().cellLabels()[elemI];
243 cellBbsToExchange.setSize(0);
245 cellMap().reverseDistribute
247 preDistributionCellMapSize,
248 cellBbRequiredByAnyCell
251 cellMap().reverseDistribute
253 preDistributionCellMapSize,
260 preDistributionCellMapSize = -1;
267 inplaceSubset(cellBbRequiredByAnyCell, procToDistributeCellTo);
269 preDistributionCellMapSize = procToDistributeCellTo.size();
272 buildMap(cellMapPtr_, procToDistributeCellTo);
275 cellIndexAndTransformToDistribute_.transfer(cellIAndTToExchange);
279 rilInverse_.setSize(mesh_.nCells());
287 const labelList& realCells = ril_[refCelli];
293 forAll(realCells, realCelli)
295 rilInverseTemp[realCells[realCelli]].append(refCelli);
299 forAll(rilInverse_, celli)
301 rilInverse_[celli].transfer(rilInverseTemp[celli]);
308 mesh_.boundary().checkParallelSync(
true);
311 DynamicList<label> localWallFaces;
315 const polyPatch& patch = mesh_.boundary()[
patchi];
317 if (isA<wallPolyPatch>(patch))
319 localWallFaces.append(
identityMap(patch.start(), patch.size()));
327 wallFaceBbs[i] = treeBoundBox
329 mesh_.faces()[localWallFaces[i]].points(mesh_.points())
334 DynamicList<labelPair> wallFaceIAndTToExchange;
336 DynamicList<treeBoundBox> wallFaceBbsToExchange;
338 DynamicList<label> procToDistributeWallFaceTo;
340 forAll(extendedProcBbsInRange, ePBIRI)
342 const treeBoundBox& otherExtendedProcBb =
343 extendedProcBbsInRange[ePBIRI];
345 label transformIndex = extendedProcBbsTransformIndex[ePBIRI];
347 label origProc = extendedProcBbsOrigProc[ePBIRI];
351 const treeBoundBox& wallFaceBb = wallFaceBbs[i];
353 if (wallFaceBb.overlaps(otherExtendedProcBb))
358 label wallFacei = localWallFaces[i];
360 wallFaceIAndTToExchange.append
362 globalTransforms.encode(wallFacei, transformIndex)
365 wallFaceBbsToExchange.append(wallFaceBb);
367 procToDistributeWallFaceTo.append(origProc);
372 buildMap(wallFaceMapPtr_, procToDistributeWallFaceTo);
375 label preDistributionWallFaceMapSize = procToDistributeWallFaceTo.size();
377 wallFaceMap().distribute(wallFaceBbsToExchange);
379 wallFaceMap().distribute(wallFaceIAndTToExchange);
381 indexedOctree<treeDataCell> allCellsTree
383 treeDataCell(
true, mesh_),
390 rwfil_.setSize(wallFaceBbsToExchange.size());
394 boolList wallFaceBbRequiredByAnyCell(wallFaceBbsToExchange.size(),
false);
396 forAll(wallFaceBbsToExchange, bbI)
398 const labelPair& wfiat = wallFaceIAndTToExchange[bbI];
400 const transformer&
transform = globalTransforms.transform
402 globalTransforms.transformIndex(wfiat)
405 treeBoundBox tempTransformedBb
409 wallFaceBbsToExchange[bbI].points()
413 treeBoundBox extendedBb
415 tempTransformedBb.min() - interactionVec,
416 tempTransformedBb.max() + interactionVec
422 coupledPatchRangeTree.findBox(extendedBb)
425 if (!interactingElems.empty())
427 wallFaceBbRequiredByAnyCell[bbI] =
true;
430 rwfil_[bbI].setSize(interactingElems.size(), -1);
432 forAll(interactingElems, i)
434 label elemI = interactingElems[i];
440 label c = coupledPatchRangeTree.shapes().cellLabels()[elemI];
463 wallFaceBbsToExchange.setSize(0);
465 wallFaceMap().reverseDistribute
467 preDistributionWallFaceMapSize,
468 wallFaceBbRequiredByAnyCell
471 wallFaceMap().reverseDistribute
473 preDistributionWallFaceMapSize,
474 wallFaceIAndTToExchange
480 preDistributionWallFaceMapSize = -1;
485 inplaceSubset(wallFaceBbRequiredByAnyCell, wallFaceIAndTToExchange);
487 inplaceSubset(wallFaceBbRequiredByAnyCell, procToDistributeWallFaceTo);
489 preDistributionWallFaceMapSize = procToDistributeWallFaceTo.size();
492 buildMap(wallFaceMapPtr_, procToDistributeWallFaceTo);
495 wallFaceIndexAndTransformToDistribute_.transfer(wallFaceIAndTToExchange);
499 rwfilInverse_.setSize(mesh_.nCells());
505 forAll(rwfil_, refWallFacei)
507 const labelList& realCells = rwfil_[refWallFacei];
513 forAll(realCells, realCelli)
515 rwfilInverseTemp[realCells[realCelli]].append(refWallFacei);
519 forAll(rwfilInverse_, celli)
521 rwfilInverse_[celli].transfer(rwfilInverseTemp[celli]);
525 referredWallFaces_.setSize(wallFaceIndexAndTransformToDistribute_.size());
527 forAll(referredWallFaces_, rWFI)
529 const labelPair& wfiat = wallFaceIndexAndTransformToDistribute_[rWFI];
531 label wallFaceIndex = globalTransforms.index(wfiat);
533 const transformer&
transform = globalTransforms.transform
535 globalTransforms.transformIndex(wfiat)
538 const face&
f = mesh_.faces()[wallFaceIndex];
542 wallFaceIndex - mesh_.nInternalFaces()
545 referredWallFaces_[rWFI] = referredWallFace
548 transform.invTransformPosition(
f.points(mesh_.points())),
553 wallFaceMap().distribute(referredWallFaces_);
557 writeReferredWallFaces();
562 Info<<
" Building direct interaction lists" <<
endl;
564 indexedOctree<treeDataFace> wallFacesTree
566 treeDataFace(
true, mesh_, localWallFaces),
573 dil_.setSize(mesh_.nCells());
575 dwfil_.setSize(mesh_.nCells());
579 const treeBoundBox& cellBb = cellBbs[celli];
581 treeBoundBox extendedBb
583 cellBb.min() - interactionVec,
584 cellBb.max() + interactionVec
588 labelList interactingElems(allCellsTree.findBox(extendedBb));
591 DynamicList<label> cellDIL(interactingElems.size());
593 forAll(interactingElems, i)
595 label elemI = interactingElems[i];
597 label c = allCellsTree.shapes().cellLabels()[elemI];
611 dil_[celli].transfer(cellDIL);
614 interactingElems = wallFacesTree.findBox(extendedBb);
616 dwfil_[celli].setSize(interactingElems.size(), -1);
618 forAll(interactingElems, i)
620 label elemI = interactingElems[i];
622 label f = wallFacesTree.shapes().faceLabels()[elemI];
624 dwfil_[celli][i] =
f;
630 template<
class ParticleType>
633 const treeBoundBox& procBb,
635 const globalIndexAndTransform& globalTransforms,
641 extendedProcBbsInRange.setSize(0);
642 extendedProcBbsTransformIndex.setSize(0);
643 extendedProcBbsOrigProc.setSize(0);
645 DynamicList<treeBoundBox> tmpExtendedProcBbsInRange;
646 DynamicList<label> tmpExtendedProcBbsTransformIndex;
647 DynamicList<label> tmpExtendedProcBbsOrigProc;
649 label nTrans = globalTransforms.nIndependentTransforms();
651 forAll(allExtendedProcBbs, proci)
655 if (nTrans == 0 && proci != Pstream::myProcNo())
657 treeBoundBox extendedReferredProcBb = allExtendedProcBbs[proci];
659 if (procBb.overlaps(extendedReferredProcBb))
661 tmpExtendedProcBbsInRange.append(extendedReferredProcBb);
665 tmpExtendedProcBbsTransformIndex.append(0);
667 tmpExtendedProcBbsOrigProc.append(proci);
670 else if (nTrans == 3)
672 label& i = permutationIndices[0];
673 label& j = permutationIndices[1];
674 label&
k = permutationIndices[2];
676 for (i = -1; i <= 1; i++)
678 for (j = -1; j <= 1; j++)
680 for (
k = -1;
k <= 1;
k++)
687 && proci == Pstream::myProcNo()
695 label transI = globalTransforms.encodeTransformIndex
701 globalTransforms.transform(transI);
703 treeBoundBox extendedReferredProcBb
707 allExtendedProcBbs[proci].points()
711 if (procBb.overlaps(extendedReferredProcBb))
713 tmpExtendedProcBbsInRange.append
715 extendedReferredProcBb
718 tmpExtendedProcBbsTransformIndex.append(transI);
720 tmpExtendedProcBbsOrigProc.append(proci);
726 else if (nTrans == 2)
728 label& i = permutationIndices[0];
729 label& j = permutationIndices[1];
731 for (i = -1; i <= 1; i++)
733 for (j = -1; j <= 1; j++)
735 if (i == 0 && j == 0 && proci == Pstream::myProcNo())
742 label transI = globalTransforms.encodeTransformIndex
748 globalTransforms.transform(transI);
750 treeBoundBox extendedReferredProcBb
754 allExtendedProcBbs[proci].points()
758 if (procBb.overlaps(extendedReferredProcBb))
760 tmpExtendedProcBbsInRange.append
762 extendedReferredProcBb
765 tmpExtendedProcBbsTransformIndex.append(transI);
767 tmpExtendedProcBbsOrigProc.append(proci);
772 else if (nTrans == 1)
774 label& i = permutationIndices[0];
776 for (i = -1; i <= 1; i++)
778 if (i == 0 && proci == Pstream::myProcNo())
785 label transI = globalTransforms.encodeTransformIndex
791 globalTransforms.transform(transI);
793 treeBoundBox extendedReferredProcBb
797 allExtendedProcBbs[proci].points()
801 if (procBb.overlaps(extendedReferredProcBb))
803 tmpExtendedProcBbsInRange.append
805 extendedReferredProcBb
808 tmpExtendedProcBbsTransformIndex.append(transI);
810 tmpExtendedProcBbsOrigProc.append(proci);
816 extendedProcBbsInRange = move(tmpExtendedProcBbsInRange);
817 extendedProcBbsTransformIndex = move(tmpExtendedProcBbsTransformIndex);
818 extendedProcBbsOrigProc = move(tmpExtendedProcBbsOrigProc);
822 template<
class ParticleType>
825 autoPtr<distributionMap>& mapPtr,
837 label proci = toProc[i];
847 sendMap[proci].setSize(nSend[proci]);
855 label proci = toProc[i];
857 sendMap[proci][nSend[proci]++] = i;
862 Pstream::exchangeSizes(sendMap, recvSizes);
873 sendMap[Pstream::myProcNo()].size()
876 label constructSize = constructMap[Pstream::myProcNo()].size();
878 forAll(constructMap, proci)
880 if (proci != Pstream::myProcNo())
882 label nRecv = recvSizes[proci];
884 constructMap[proci].setSize(nRecv);
886 for (
label i = 0; i < nRecv; i++)
888 constructMap[proci][i] = constructSize++;
905 template<
class ParticleType>
911 const globalIndexAndTransform& globalTransforms =
912 mesh_.globalData().globalTransforms();
914 referredParticles_.setSize(cellIndexAndTransformToDistribute_.size());
918 forAll(referredParticles_, i)
920 referredParticles_[i].clear();
926 forAll(cellIndexAndTransformToDistribute_, i)
928 const labelPair ciat = cellIndexAndTransformToDistribute_[i];
930 label cellIndex = globalTransforms.index(ciat);
934 IDLList<ParticleType>& particlesToRefer = referredParticles_[i];
938 const ParticleType& particle = *realParticles[rM];
940 particlesToRefer.append(particle.clone().ptr());
942 prepareParticleToBeReferred(particlesToRefer.last(), ciat);
948 template<
class ParticleType>
951 ParticleType* particle,
955 const globalIndexAndTransform& globalTransforms =
956 mesh_.globalData().globalTransforms();
958 const transformer&
transform = globalTransforms.transform
960 globalTransforms.transformIndex(ciat)
963 particle->prepareForInteractionListReferral(mesh_,
transform);
967 template<
class ParticleType>
972 forAll(referredParticles_, refCelli)
974 const IDLList<ParticleType>& refCell =
975 referredParticles_[refCelli];
981 static_cast<ParticleType*
>(iter().
clone().ptr())
989 template<
class ParticleType>
992 const globalIndexAndTransform& globalTransforms =
993 mesh_.globalData().globalTransforms();
995 referredWallData_.setSize
997 wallFaceIndexAndTransformToDistribute_.size()
1002 forAll(referredWallData_, rWVI)
1004 const labelPair& wfiat = wallFaceIndexAndTransformToDistribute_[rWVI];
1006 label wallFaceIndex = globalTransforms.index(wfiat);
1008 const transformer&
transform = globalTransforms.transform
1010 globalTransforms.transformIndex(wfiat)
1015 wallFaceIndex - mesh_.nInternalFaces()
1020 - mesh_.boundary()[
patchi].start();
1024 referredWallData_[rWVI] =
U.boundaryField()[
patchi][patchFacei];
1028 referredWallData_[rWVI] =
1029 transform.invTransform(referredWallData_[rWVI]);
1035 template<
class ParticleType>
1038 if (referredWallFaces_.empty())
1043 fileName objDir = mesh_.time().timePath()/lagrangian::cloud::prefix;
1047 fileName objFileName =
"referredWallFaces.obj";
1049 OFstream str(objDir/objFileName);
1052 << mesh_.time().name()/lagrangian::cloud::prefix/objFileName
1057 forAll(referredWallFaces_, rWFI)
1059 const referredWallFace& rwf = referredWallFaces_[rWFI];
1070 str<<
' ' << fPtI +
offset;
1082 template<
class ParticleType>
1086 cloud_(mesh_,
"nullptr_Cloud",
IDLList<ParticleType>()),
1095 cellIndexAndTransformToDistribute_(),
1096 wallFaceIndexAndTransformToDistribute_(),
1097 referredWallFaces_(),
1098 UName_(
"unknown_U"),
1099 referredWallData_(),
1100 referredParticles_()
1104 template<
class ParticleType>
1114 cloud_(mesh_,
"referredParticleCloud",
IDLList<ParticleType>()),
1115 writeCloud_(writeCloud),
1118 maxDistance_(maxDistance),
1123 cellIndexAndTransformToDistribute_(),
1124 wallFaceIndexAndTransformToDistribute_(),
1125 referredWallFaces_(),
1127 referredWallData_(),
1128 referredParticles_()
1130 buildInteractionLists();
1136 template<
class ParticleType>
1143 template<
class ParticleType>
1150 if (mesh_.changing())
1153 <<
"Mesh changing, rebuilding InteractionLists form scratch."
1156 buildInteractionLists();
1159 prepareWallDataToRefer();
1165 const labelList& subMap = cellMap().subMap()[domain];
1177 forAll(subMappedParticles, i)
1179 toDomain << subMappedParticles[i];
1187 wallFaceMap().send(pBufs, referredWallData_);
1191 template<
class ParticleType>
1195 const label startOfRequests
1200 referredParticles_.setSize(cellMap().constructSize());
1204 const labelList& constructMap = cellMap().constructMap()[domain];
1206 if (constructMap.
size())
1212 referredParticles_[constructMap[i]] =
1218 forAll(referredParticles_, refCelli)
1223 iter().correctAfterInteractionListReferral
1231 fillReferredParticleCloud();
1233 wallFaceMap().receive(pBufs, referredWallData_);
#define forAll(list, i)
Loop across all elements in list.
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
const List< DynamicList< molecule * > > & cellOccupancy
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Template class for intrusive linked lists.
Builds direct interaction list, specifying which local (real) cells are potentially in range of each ...
InteractionLists(const polyMesh &mesh)
Construct null from mesh.
void sendReferredData(const List< DynamicList< ParticleType * >> &cellOccupancy, PstreamBuffers &pBufs)
Prepare and send referred particles and wall data,.
void receiveReferredData(PstreamBuffers &pBufs, const label startReq=0)
Receive referred data.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void size(const label)
Override size to be inconsistent with allocated storage.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Input inter-processor communications stream operating on external buffer.
A List with indirect addressing.
Output inter-processor communications stream operating on external buffer.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
Motion of the mesh specified as a list of pointMeshMovers.
Mesh consisting of general polyhedral cells.
A class for handling words, derived from string.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionedScalar e
Elementary charge.
const dimensionedScalar c
Speed of light in a vacuum.
Pair< label > labelPair
Label pair.
VolField< vector > volVectorField
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void transform(GeometricField< Type, GeoMesh > &rtf, const GeometricField< tensor, GeoMesh > &trf, const GeometricField< Type, GeoMesh > &tf)
void inplaceSubset(const UList< T > &select, const T &value, ListType &)
Inplace extract elements of List when select is a certain value.
List< bool > boolList
Bool container classes.
Vector< scalar > vector
A scalar version of the templated Vector.
List< labelList > labelListList
A List of labelList.
List< treeBoundBox > treeBoundBoxList
List of bounding boxes.
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
void offset(label &lst, const label o)