48 const List<label>& toProc
59 label proci = toProc[i];
70 sendMap[proci].setSize(nSend[proci]);
78 label proci = toProc[i];
80 sendMap[proci][nSend[proci]++] = i;
101 forAll(constructMap, proci)
105 label nRecv = recvSizes[proci];
107 constructMap[proci].setSize(nRecv);
109 for (
label i = 0; i < nRecv; i++)
111 constructMap[proci][i] = constructSize++;
116 return autoPtr<distributionMap>
130 void Foam::backgroundMeshDecomposition::initialRefinement()
137 mesh_.time().timeName(),
144 zeroGradientFvPatchScalarField::typeName
147 const conformationSurfaces& geometry = geometryToConformTo_;
149 decompositionMethod& decomposer = decomposerPtr_();
155 List<volumeType> volumeStatus
166 forAll(volumeStatus, celli)
172 mesh_.cells()[celli].points
179 if (geometry.overlaps(cellBb))
183 else if (geometry.inside(cellBb.midpoint()))
195 labelList refCells = selectRefinementCells
204 meshCutter_.consistentRefinement
211 forAll(newCellsToRefine, nCTRI)
213 label celli = newCellsToRefine[nCTRI];
220 icellWeights[celli] =
max 223 icellWeights[celli]/8.0
227 if (
returnReduce(newCellsToRefine.size(), sumOp<label>()) == 0)
233 polyTopoChange meshMod(mesh_);
236 meshCutter_.setRefinement(newCellsToRefine, meshMod);
239 autoPtr<polyTopoChangeMap> map = meshMod.changeMesh
249 mesh_.topoChange(map);
252 meshCutter_.topoChange(map);
257 const labelList& cellMap = map().cellMap();
259 List<volumeType> newVolumeStatus(cellMap.size());
263 label oldCelli = cellMap[newCelli];
271 newVolumeStatus[newCelli] = volumeStatus[oldCelli];
275 volumeStatus.transfer(newVolumeStatus);
278 Info<<
" Background mesh refined from " 280 <<
" to " << mesh_.globalData().nTotalCells()
281 <<
" cells." <<
endl;
285 forAll(volumeStatus, celli)
291 mesh_.cells()[celli].points
298 if (geometry.overlaps(cellBb))
302 else if (geometry.inside(cellBb.midpoint()))
314 bool removeOutsideCells =
false;
316 if (removeOutsideCells)
318 DynamicList<label> cellsToRemove;
320 forAll(volumeStatus, celli)
324 cellsToRemove.append(celli);
328 removeCells cellRemover(mesh_);
331 polyTopoChange meshMod(mesh_);
333 labelList exposedFaces = cellRemover.getExposedFaces
339 cellRemover.setRefinement
348 autoPtr<polyTopoChangeMap> map = meshMod.changeMesh
358 mesh_.topoChange(map);
361 meshCutter_.topoChange(map);
362 cellRemover.topoChange(map);
367 const labelList& cellMap = map().cellMap();
369 List<volumeType> newVolumeStatus(cellMap.size());
373 label oldCelli = cellMap[newCelli];
381 newVolumeStatus[newCelli] = volumeStatus[oldCelli];
385 volumeStatus.transfer(newVolumeStatus);
390 - mesh_.globalData().nTotalCells()
391 <<
" cells." <<
endl;
403 labelList newDecomp = decomposer.decompose
410 fvMeshDistribute distributor(mesh_);
412 autoPtr<polyDistributionMap> mapDist = distributor.distribute
417 meshCutter_.distribute(mapDist);
419 mapDist().distributeCellData(volumeStatus);
423 printMeshData(mesh_);
446 void Foam::backgroundMeshDecomposition::printMeshData
453 globalIndex globalCells(mesh.nCells());
478 Info<<
"Processor " << proci <<
" " 479 <<
"Number of cells = " << globalCells.localSize(proci)
503 bool Foam::backgroundMeshDecomposition::refineCell
507 scalar& weightEstimate
517 mesh_.cells()[celli].points
524 weightEstimate = 1.0;
628 Foam::labelList Foam::backgroundMeshDecomposition::selectRefinementCells
630 List<volumeType>& volumeStatus,
639 forAll(volumeStatus, celli)
643 if (meshCutter_.cellLevel()[celli] < minLevels_)
645 cellsToRefine.insert(celli);
661 cellsToRefine.insert(celli);
666 return cellsToRefine.toc();
670 void Foam::backgroundMeshDecomposition::buildPatchAndTree()
677 mesh_.nFaces() - mesh_.nInternalFaces(),
678 mesh_.nInternalFaces()
683 boundaryFacesPtr_.reset
687 tmpBoundaryFaces.localFaces(),
688 tmpBoundaryFaces.localPoints()
693 treeBoundBox overallBb(boundaryFacesPtr_().localPoints());
697 new indexedOctree<treeDataBPatch>
705 overallBb.extend(1e-4),
718 point bbMin(great, great, great);
719 point bbMax(-great, -great, -great);
721 forAll(allBackgroundMeshBounds_, proci)
723 bbMin =
min(bbMin, allBackgroundMeshBounds_[proci].
min());
724 bbMax =
max(bbMax, allBackgroundMeshBounds_[proci].
max());
727 globalBackgroundBounds_ = treeBoundBox(bbMin, bbMax);
734 /
"backgroundMeshDecomposition_proc_" 736 +
"_boundaryFaces.obj" 739 const faceList& faces = boundaryFacesPtr_().localFaces();
740 const List<point>& points = boundaryFacesPtr_().localPoints();
742 Map<label> foamToObj(points.size());
748 const face&
f = faces[i];
752 if (foamToObj.insert(f[fPI], vertI))
763 fStr<<
' ' << foamToObj[f[fPI]] + 1;
778 const conformationSurfaces& geometryToConformTo,
779 const dictionary& coeffsDict
783 geometryToConformTo_(geometryToConformTo),
788 "backgroundMeshDecomposition",
792 IOobject::AUTO_WRITE,
805 allBackgroundMeshBounds_(Pstream::nProcs()),
806 globalBackgroundBounds_(),
809 decompositionMethod::NewDecomposer
811 decompositionMethod::decomposeParDict(runTime)
814 spanScale_(coeffsDict.
lookup<scalar>(
"spanScale")),
817 coeffsDict.lookupOrDefault<scalar>(
"minCellSizeLimit", 0.0)
820 volRes_(coeffsDict.
lookup<
label>(
"sampleResolution")),
821 maxCellWeightCoeff_(coeffsDict.
lookup<scalar>(
"maxCellWeightCoeff"))
826 <<
"This cannot be used when not running in parallel." 830 Info<<
nl <<
"Building initial background mesh decomposition" <<
endl;
864 label nOccupiedCells = 0;
868 if (icellWeights[cI] > 1 - small)
878 scalar cellWeightLimit =
max 881 *
sum(cellWeights).value()
888 Info<<
" cellWeightLimit " << cellWeightLimit <<
endl;
890 Pout<<
" sum(cellWeights) " <<
sum(cellWeights.primitiveField())
891 <<
" max(cellWeights) " <<
max(cellWeights.primitiveField())
899 if (icellWeights[cWI] > cellWeightLimit)
901 cellsToRefine.insert(cWI);
905 if (
returnReduce(cellsToRefine.size(), sumOp<label>()) == 0)
913 meshCutter_.consistentRefinement
920 if (debug && !cellsToRefine.empty())
922 Pout<<
" cellWeights too large in " << cellsToRefine.size()
926 forAll(newCellsToRefine, nCTRI)
928 label celli = newCellsToRefine[nCTRI];
930 icellWeights[celli] /= 8.0;
934 polyTopoChange meshMod(mesh_);
937 meshCutter_.setRefinement(newCellsToRefine, meshMod);
940 autoPtr<polyTopoChangeMap> map = meshMod.changeMesh
950 mesh_.topoChange(map);
953 meshCutter_.topoChange(map);
955 Info<<
" Background mesh refined from " 957 <<
" to " << mesh_.globalData().nTotalCells()
958 <<
" cells." <<
endl;
971 printMeshData(mesh_);
973 Pout<<
" Pre distribute sum(cellWeights) " 975 <<
" max(cellWeights) " 980 labelList newDecomp = decomposerPtr_().decompose
987 Info<<
" Redistributing background mesh cells" <<
endl;
989 fvMeshDistribute distributor(mesh_);
991 autoPtr<polyDistributionMap> mapDist =
992 distributor.distribute(newDecomp);
994 meshCutter_.distribute(mapDist);
998 printMeshData(mesh_);
1000 Pout<<
" Post distribute sum(cellWeights) " 1001 <<
sum(icellWeights)
1002 <<
" max(cellWeights) " 1003 <<
max(icellWeights)
1009 cellWeights.
write();
1012 buildPatchAndTree();
1031 const List<point>& pts
1034 boolList posProc(pts.size(),
true);
1038 posProc[pI] = positionOnThisProcessor(pts[pI]);
1047 const treeBoundBox& box
1051 return !bFTreePtr_().findBox(box).empty();
1057 const point& centre,
1058 const scalar radiusSqr
1063 return bFTreePtr_().findNearest(centre, radiusSqr).hit();
1073 return bFTreePtr_().findLine(start, end);
1083 return bFTreePtr_().findLineAny(start, end);
1089 const List<point>& pts
1092 DynamicList<label> toCandidateProc;
1093 DynamicList<point> testPoints;
1097 label nTotalCandidates = 0;
1101 const point& pt = pts[pI];
1103 label nCandidates = 0;
1105 forAll(allBackgroundMeshBounds_, proci)
1109 if (allBackgroundMeshBounds_[proci].overlaps(pt,
sqr(small*100)))
1111 toCandidateProc.append(proci);
1112 testPoints.append(pt);
1118 ptBlockStart[pI] = nTotalCandidates;
1119 ptBlockSize[pI] = nCandidates;
1121 nTotalCandidates += nCandidates;
1125 label preDistributionToCandidateProcSize = toCandidateProc.size();
1127 autoPtr<distributionMap> map(buildMap(toCandidateProc));
1129 map().distribute(testPoints);
1131 List<scalar> distanceSqrToCandidate(testPoints.size(),
sqr(great));
1144 distanceSqrToCandidate[tPI] =
magSqr 1146 testPoints[tPI] - info.hitPoint()
1151 map().reverseDistribute
1153 preDistributionToCandidateProcSize,
1154 distanceSqrToCandidate
1157 labelList ptNearestProc(pts.size(), -1);
1163 SubList<scalar> ptNearestProcResults
1165 distanceSqrToCandidate,
1170 scalar nearestProcDistSqr = great;
1172 forAll(ptNearestProcResults, pPRI)
1174 if (ptNearestProcResults[pPRI] < nearestProcDistSqr)
1176 nearestProcDistSqr = ptNearestProcResults[pPRI];
1178 ptNearestProc[pI] = toCandidateProc[ptBlockStart[pI] + pPRI];
1184 Pout<< pts[pI] <<
" nearestProcDistSqr " << nearestProcDistSqr
1185 <<
" ptNearestProc[pI] " << ptNearestProc[pI] <<
endl;
1188 if (ptNearestProc[pI] < 0)
1191 <<
"The position " << pts[pI]
1192 <<
" did not find a nearest point on the background mesh." 1197 return ptNearestProc;
1205 const List<point>& starts,
1206 const List<point>& ends,
1207 bool includeOwnProcessor
1210 DynamicList<label> toCandidateProc;
1211 DynamicList<point> testStarts;
1212 DynamicList<point> testEnds;
1213 labelList segmentBlockStart(starts.size(), -1);
1214 labelList segmentBlockSize(starts.size(), -1);
1216 label nTotalCandidates = 0;
1220 const point& s = starts[sI];
1221 const point& e = ends[sI];
1226 label nCandidates = 0;
1228 forAll(allBackgroundMeshBounds_, proci)
1235 && allBackgroundMeshBounds_[proci].intersects(s, e,
p)
1238 toCandidateProc.append(proci);
1239 testStarts.append(s);
1246 segmentBlockStart[sI] = nTotalCandidates;
1247 segmentBlockSize[sI] = nCandidates;
1249 nTotalCandidates += nCandidates;
1253 label preDistributionToCandidateProcSize = toCandidateProc.size();
1255 autoPtr<distributionMap> map(buildMap(toCandidateProc));
1257 map().distribute(testStarts);
1258 map().distribute(testEnds);
1260 List<pointIndexHit> segmentIntersectsCandidate(testStarts.size());
1265 const point& s = testStarts[sI];
1266 const point& e = testEnds[sI];
1269 segmentIntersectsCandidate[sI] = bFTreePtr_().findLine(s, e);
1272 map().reverseDistribute
1274 preDistributionToCandidateProcSize,
1275 segmentIntersectsCandidate
1278 List<List<pointIndexHit>> segmentHitProcs(starts.size());
1281 DynamicList<pointIndexHit> tmpProcHits;
1285 tmpProcHits.clear();
1289 SubList<pointIndexHit> segmentProcResults
1291 segmentIntersectsCandidate,
1292 segmentBlockSize[sI],
1293 segmentBlockStart[sI]
1296 forAll(segmentProcResults, sPRI)
1298 if (segmentProcResults[sPRI].hit())
1300 tmpProcHits.append(segmentProcResults[sPRI]);
1302 tmpProcHits.last().setIndex
1304 toCandidateProc[segmentBlockStart[sI] + sPRI]
1309 segmentHitProcs[sI] = tmpProcHits;
1312 return segmentHitProcs;
1318 const point& centre,
1319 const scalar& radiusSqr
1322 forAll(allBackgroundMeshBounds_, proci)
1324 if (bFTreePtr_().findNearest(centre, radiusSqr).hit())
1336 const point& centre,
1337 const scalar radiusSqr
1342 forAll(allBackgroundMeshBounds_, proci)
1348 && allBackgroundMeshBounds_[proci].overlaps(centre, radiusSqr)
1354 toProc.append(proci);
1359 return Foam::move(toProc);
List< labelList > labelListList
A List of labelList.
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
bool positionOnThisProcessor(const point &pt) const
Is the given position inside the domain of this decomposition.
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
virtual Ostream & write(const char)=0
Write character.
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static scalar & perturbTol()
Get the perturbation tolerance.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
PointIndexHit< point > pointIndexHit
const dimensionSet dimless
labelList overlapProcessors(const point ¢re, const scalar radiusSqr) const
DimensionedField< scalar, volMesh > Internal
Type of the internal field from which this GeometricField is derived.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
autoPtr< polyDistributionMap > distribute(volScalarField &cellWeights)
Redistribute the background mesh based on a supplied weight field,.
List< bool > boolList
Bool container classes.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
treeDataPrimitivePatch< bPatch > treeDataBPatch
static void exchangeSizes(const Container &sendData, labelList &sizes, const label comm=UPstream::worldComm)
Helper: exchange sizes of sendData. sendData is the data per.
labelList processorNearestPosition(const List< point > &pts) const
What is the nearest processor to the given position?
stressControl lookup("compactNormalStress") >> compactNormalStress
bool overlapsOtherProcessors(const point ¢re, const scalar &radiusSqr) const
pointIndexHit findLine(const point &start, const point &end) const
Find nearest intersection of line between start and end, (exposing.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
List< List< pointIndexHit > > intersectsProcessors(const List< point > &starts, const List< point > &ends, bool includeOwnProcessor=false) const
Which processors are intersected by the line segment, returns all.
List< label > labelList
A List of labels.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
pointIndexHit findLineAny(const point &start, const point &end) const
Find any intersection of line between start and end, (exposing.
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
Addressing for a faceList slice.
word name(const complex &)
Return a string representation of a complex.
static autoPtr< distributionMap > buildMap(const List< label > &toProc)
Build a distributionMap for the supplied destination processor data.
static bool & parRun()
Is this a parallel run?
static label nProcs(const label communicator=0)
Number of processes in parallel run.
vector point
Point is a vector.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
prefixOSstream Pout(cout, "Pout")
PrimitivePatch< faceList, const pointField > bPatch
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
backgroundMeshDecomposition(const Time &runTime, Random &rndGen, const conformationSurfaces &geometryToConformTo, const dictionary &coeffsDict)
Construct from components in foamyHexMesh operation.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
~backgroundMeshDecomposition()
Destructor.
bool overlapsThisProcessor(const treeBoundBox &box) const
Does the given box overlap the faces of the boundary of this.