45Foam::label Foam::meshRefinement::markSurfaceGapRefinement
47 const scalar planarCos,
49 const label nAllowRefine,
50 const labelList& neiLevel,
51 const pointField& neiCc,
53 labelList& refineCell,
57 const labelList& cellLevel = meshCutter_.cellLevel();
58 const pointField& cellCentres = mesh_.cellCentres();
61 const labelList maxLevel(shells_.maxGapLevel());
65 if (
max(maxLevel) > 0)
73 labelList testFaces(getRefineCandidateFaces(refineCell));
95 labelList cellToCompact(mesh_.nCells(), -1);
96 labelList bFaceToCompact(mesh_.nBoundaryFaces(), -1);
98 List<FixedList<label, 3>> shellGapInfo;
99 List<volumeType> shellGapMode;
101 DynamicField<point> compactToCc(mesh_.nCells()/10);
102 DynamicList<label> compactToLevel(compactToCc.capacity());
105 label faceI = testFaces[i];
106 label own = mesh_.faceOwner()[faceI];
107 if (cellToCompact[own] == -1)
109 cellToCompact[own] = compactToCc.size();
110 compactToCc.append(cellCentres[own]);
111 compactToLevel.append(cellLevel[own]);
113 if (mesh_.isInternalFace(faceI))
115 label nei = mesh_.faceNeighbour()[faceI];
116 if (cellToCompact[nei] == -1)
118 cellToCompact[nei] = compactToCc.size();
119 compactToCc.append(cellCentres[nei]);
120 compactToLevel.append(cellLevel[nei]);
125 label bFaceI = faceI - mesh_.nInternalFaces();
126 if (bFaceToCompact[bFaceI] == -1)
128 bFaceToCompact[bFaceI] = compactToCc.size();
129 compactToCc.append(neiCc[bFaceI]);
130 compactToLevel.append(neiLevel[bFaceI]);
135 shells_.findHigherGapLevel
192 const List<FixedList<label, 3>>& extendedGapLevel =
193 surfaces_.extendedGapLevel();
194 const List<volumeType>& extendedGapMode =
195 surfaces_.extendedGapMode();
196 const boolList& extendedGapSelf = surfaces_.gapSelf();
199 List<pointIndexHit> ccHit1;
204 List<pointIndexHit> ccHit2;
208 surfaces_.findNearestIntersection
210 identity(surfaces_.surfaces().size()),
229 DynamicField<point> rayStart(2*ccSurface1.size());
230 DynamicField<point> rayEnd(2*ccSurface1.size());
231 DynamicField<scalar> gapSize(2*ccSurface1.size());
233 DynamicField<point> rayStart2(2*ccSurface1.size());
234 DynamicField<point> rayEnd2(2*ccSurface1.size());
235 DynamicField<scalar> gapSize2(2*ccSurface1.size());
237 DynamicList<label> cellMap(2*ccSurface1.size());
238 DynamicList<label> compactMap(2*ccSurface1.size());
242 label surfI = ccSurface1[i];
246 label globalRegionI =
247 surfaces_.globalRegion(surfI, ccRegion1[i]);
249 label faceI = testFaces[i];
250 const point& surfPt = ccHit1[i].hitPoint();
252 label own = mesh_.faceOwner()[faceI];
255 cellToCompact[own] != -1
256 && shellGapInfo[cellToCompact[own]][2] > 0
260 label compactI = cellToCompact[own];
261 FixedList<label, 3> gapInfo;
265 shellGapInfo[compactI],
266 shellGapMode[compactI],
267 extendedGapLevel[globalRegionI],
268 extendedGapMode[globalRegionI],
274 const point& cc = cellCentres[own];
275 label nRays = generateRays
282 surfPt+((cc-surfPt)&ccNormal1[i])*ccNormal1[i],
293 for (label j = 0; j < nRays; j++)
296 compactMap.append(i);
299 if (mesh_.isInternalFace(faceI))
301 label nei = mesh_.faceNeighbour()[faceI];
304 cellToCompact[nei] != -1
305 && shellGapInfo[cellToCompact[nei]][2] > 0
309 label compactI = cellToCompact[nei];
310 FixedList<label, 3> gapInfo;
314 shellGapInfo[compactI],
315 shellGapMode[compactI],
316 extendedGapLevel[globalRegionI],
317 extendedGapMode[globalRegionI],
323 const point& cc = cellCentres[nei];
324 label nRays = generateRays
331 surfPt+((cc-surfPt)&ccNormal1[i])*ccNormal1[i],
342 for (label j = 0; j < nRays; j++)
345 compactMap.append(i);
355 label bFaceI = faceI - mesh_.nInternalFaces();
359 bFaceToCompact[bFaceI] != -1
360 && shellGapInfo[bFaceToCompact[bFaceI]][2] > 0
364 label compactI = bFaceToCompact[bFaceI];
365 FixedList<label, 3> gapInfo;
369 shellGapInfo[compactI],
370 shellGapMode[compactI],
371 extendedGapLevel[globalRegionI],
372 extendedGapMode[globalRegionI],
378 const point& cc = neiCc[bFaceI];
379 label nRays = generateRays
386 surfPt+((cc-surfPt)&ccNormal1[i])*ccNormal1[i],
397 for (label j = 0; j < nRays; j++)
400 compactMap.append(i);
408 <<
" rays from " <<
returnReduce(testFaces.size(), sumOp<label>())
409 <<
" intersected faces" <<
endl;
426 ccNormal1 = UIndirectList<vector>(ccNormal1, compactMap)();
431 List<pointIndexHit> hit1;
433 surfaces_.findNearestIntersection
443 List<pointIndexHit> hit2;
445 surfaces_.findNearestIntersection
458 const label cellI = cellMap[i];
462 (cellI != -1 && cellToCompact[cellI] != -1)
463 ? gapShell[cellToCompact[cellI]]
467 bool selfProx =
true;
470 selfProx = shells_.gapSelf()[shelli][0];
472 if (surf1[i] != -1 && selfProx)
474 const label globalRegioni = surfaces_.globalRegion(surf1[i], 0);
475 selfProx = extendedGapSelf[globalRegioni];
482 && (surf2[i] != surf1[i] || selfProx)
489 && (
mag(normal1[i]&normal2[i]) > planarCos)
491 hit1[i].hitPoint().distSqr(hit2[i].hitPoint())
519 Info<<
"Reached refinement limit." <<
endl;
764Foam::label Foam::meshRefinement::generateRays
766 const point& nearPoint,
777 label nOldRays = start.size();
779 if (cLevel >= gapInfo[1] && cLevel < gapInfo[2] && gapInfo[0] > 0)
781 scalar cellSize = meshCutter_.level0EdgeLength()/
pow(2.0, cLevel);
784 scalar nearGap = gapInfo[0]*cellSize;
793 start.append(nearPoint+1
e-6*
n);
794 end.append(nearPoint+nearGap*
n);
798 start.append(nearPoint-1
e-6*
n);
799 end.append(nearPoint-nearGap*
n);
803 start.append(nearPoint+1
e-6*
n);
804 end.append(nearPoint+nearGap*
n);
806 start.append(nearPoint-1
e-6*
n);
807 end.append(nearPoint-nearGap*
n);
811 return start.size()-nOldRays;
815Foam::label Foam::meshRefinement::generateRays
817 const bool useSurfaceNormal,
819 const point& nearPoint,
893 label nOldRays = start.size();
895 if (cLevel >= gapInfo[1] && cLevel < gapInfo[2] && gapInfo[0] > 0)
897 scalar cellSize = meshCutter_.level0EdgeLength()/
pow(2.0, cLevel);
900 scalar nearGap = gapInfo[0]*cellSize;
904 scalar magV =
mag(v);
906 if (useSurfaceNormal || magV < 0.5*cellSize)
915 start.append(nearPoint+1
e-6*
n);
916 end.append(nearPoint+nearGap*
n);
917 gapSize.append(nearGap);
919 start2.append(nearPoint+1
e-6*
n);
920 end2.append(nearPoint-1
e-6*
n);
921 gapSize2.append(gapSize.last());
925 start.append(nearPoint-1
e-6*
n);
926 end.append(nearPoint-nearGap*
n);
927 gapSize.append(nearGap);
929 start2.append(nearPoint-1
e-6*
n);
930 end2.append(nearPoint+1
e-6*
n);
931 gapSize2.append(gapSize.last());
938 start.append(nearPoint+1
e-6*
n);
939 end.append(nearPoint+nearGap*
n);
940 gapSize.append(nearGap);
942 start2.append(nearPoint+1
e-6*
n);
943 end2.append(nearPoint-1
e-6*
n);
944 gapSize2.append(gapSize.last());
948 start.append(nearPoint-1
e-6*
n);
949 end.append(nearPoint-nearGap*
n);
950 gapSize.append(nearGap);
952 start2.append(nearPoint-1
e-6*
n);
953 end2.append(nearPoint+1
e-6*
n);
954 gapSize2.append(gapSize.last());
966 scalar
s = (v&nearNormal);
1019 vector n(v/(magV+ROOTVSMALL));
1023 scalar
s = (e2 &
n);
1041 end.append(cc+nearGap*
n);
1042 gapSize.append(nearGap);
1045 end2.append(cc-nearGap*
n);
1046 gapSize2.append(nearGap);
1050 end.append(cc+nearGap*e2);
1051 gapSize.append(nearGap);
1054 end2.append(cc-nearGap*e2);
1055 gapSize2.append(nearGap);
1059 end.append(cc+nearGap*e3);
1060 gapSize.append(nearGap);
1063 end2.append(cc-nearGap*e3);
1064 gapSize2.append(nearGap);
1069 return start.size()-nOldRays;
1073void Foam::meshRefinement::selectGapCandidates
1076 const label nRefine,
1084 const labelList& cellLevel = meshCutter_.cellLevel();
1085 const pointField& cellCentres = mesh_.cellCentres();
1088 cellMap.setSize(cellLevel.size()-nRefine);
1095 cellMap[compactI++] = cellI;
1099 <<
" unmarked cells out of "
1100 << mesh_.globalData().nTotalCells() <<
endl;
1101 cellMap.setSize(compactI);
1105 shells_.findHigherGapLevel
1121 if (shellGapInfo[i][2] > 0)
1123 map[compactI++] = i;
1128 <<
" cells inside gap shells out of "
1129 << mesh_.globalData().nTotalCells() <<
endl;
1131 map.setSize(compactI);
1139void Foam::meshRefinement::mergeGapInfo
1150 if (surfGapInfo[0] == 0)
1152 gapInfo = shellGapInfo;
1153 gapMode = shellGapMode;
1155 else if (shellGapInfo[0] == 0)
1157 gapInfo = surfGapInfo;
1158 gapMode = surfGapMode;
1168 gapInfo = surfGapInfo;
1169 gapMode = surfGapMode;
1174Foam::label Foam::meshRefinement::markInternalGapRefinement
1176 const scalar planarCos,
1177 const bool spreadGapSize,
1178 const label nAllowRefine,
1186 detectedGapSize.setSize(mesh_.nCells());
1187 detectedGapSize = GREAT;
1188 numGapCells.setSize(mesh_.nCells());
1191 const labelList& cellLevel = meshCutter_.cellLevel();
1192 const pointField& cellCentres = mesh_.cellCentres();
1193 const scalar edge0Len = meshCutter_.level0EdgeLength();
1196 surfaces_.extendedGapLevel();
1198 const boolList& extendedGapSelf = surfaces_.gapSelf();
1201 const labelList maxLevel(shells_.maxGapLevel());
1205 if (
max(maxLevel) > 0)
1234 label cellI = cellMap[i];
1235 scalar cellSize = edge0Len/
pow(2.0, cellLevel[cellI]);
1236 gapSize[i] = shellGapInfo[i][0]*cellSize;
1239 surfaces_.findNearestRegion
1241 identity(surfaces_.surfaces().size()),
1262 label nTestCells = 0;
1266 if (nearInfo[i].hit())
1268 label globalRegionI = surfaces_.globalRegion
1282 extendedGapLevel[globalRegionI],
1283 extendedGapMode[globalRegionI],
1290 label cellI = cellMap[i];
1291 label cLevel = cellLevel[cellI];
1292 if (cLevel >= gapInfo[1] && cLevel < gapInfo[2])
1294 numGapCells[cellI] =
max(numGapCells[cellI], gapInfo[0]);
1298 label nRays = generateRays
1301 nearInfo[i].hitPoint(),
1320 for (label j = 0; j < nRays; j++)
1329 <<
" cells for testing out of "
1330 << mesh_.globalData().nTotalCells() <<
endl;
1342 shellGapInfo.clear();
1343 shellGapMode.clear();
1345 nearSurface.clear();
1353 surfaces_.findNearestIntersection
1365 surfaces_.findNearestIntersection
1379 const label shelli = gapShell[map[i]];
1381 bool selfProx =
true;
1384 selfProx = shells_.gapSelf()[shelli][0];
1386 if (surf1[i] != -1 && selfProx)
1388 const label globalRegioni = surfaces_.globalRegion(surf1[i], 0);
1389 selfProx = extendedGapSelf[globalRegioni];
1396 && (surf2[i] != surf1[i] || selfProx)
1403 const label cellI = cellMap[i];
1406 hit1[i].hitPoint().distSqr(hit2[i].hitPoint());
1411 && (
mag(normal1[i]&normal2[i]) > planarCos)
1415 detectedGapSize[cellI] =
min
1417 detectedGapSize[cellI],
1440 const pointField& faceCentres = mesh_.faceCentres();
1444 for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
1446 label own = mesh_.faceOwner()[faceI];
1447 label nei = mesh_.faceNeighbour()[faceI];
1449 scalar minSize =
min
1451 detectedGapSize[own],
1452 detectedGapSize[nei]
1455 if (minSize < GREAT)
1457 frontFaces.append(faceI);
1471 label faceI = mesh_.nInternalFaces();
1472 faceI < mesh_.nFaces();
1476 label own = mesh_.faceOwner()[faceI];
1478 scalar minSize =
min
1480 detectedGapSize[own],
1481 boundaryGapSize[faceI-mesh_.nInternalFaces()]
1484 if (minSize < GREAT)
1486 frontFaces.append(faceI);
1501 <<
" faces for spreading gap size out of "
1502 << mesh_.globalData().nTotalFaces() <<
endl;
1514 mesh_.globalData().nTotalCells()+1,
1521 label cellI = cellMap[i];
1525 && cellData[cellI].valid(deltaCalc.data())
1526 && numGapCells[cellI] != -1
1530 detectedGapSize[cellI] =
min
1532 detectedGapSize[cellI],
1533 cellData[cellI].data()
1543 label cellI = cellMap[i];
1545 if (cellI != -1 && numGapCells[cellI] != -1)
1548 label cLevel = cellLevel[cellI];
1550 meshCutter_.level0EdgeLength()/
pow(2.0, cLevel);
1551 scalar neededGapSize = numGapCells[cellI]*cellSize;
1553 if (neededGapSize > detectedGapSize[cellI])
1579 Info<<
"Reached refinement limit." <<
endl;
1587Foam::label Foam::meshRefinement::markSmallFeatureRefinement
1589 const scalar planarCos,
1590 const label nAllowRefine,
1598 const labelList& cellLevel = meshCutter_.cellLevel();
1599 const labelList& surfaceIndices = surfaces_.surfaces();
1601 surfaces_.extendedGapLevel();
1603 const boolList& extendedGapSelf = surfaces_.gapSelf();
1608 labelList shellMaxLevel(shells_.maxGapLevel());
1610 if (
max(shellMaxLevel) == 0)
1616 (void)mesh_.tetBasePtIs();
1617 (void)mesh_.cellTree();
1620 forAll(surfaceIndices, surfI)
1622 label geomI = surfaceIndices[surfI];
1636 geom.boundingSpheres(ctrs, radiusSqr);
1639 geom.findNearest(ctrs, radiusSqr, info);
1647 <<
" radius:" << radiusSqr[i]
1652 geom.getRegion(info, region);
1653 geom.getNormal(info, normal);
1661 shells_.findHigherGapLevel
1679 label nTestCells = 0;
1683 if (shellGapInfo[i][2] > 0)
1685 label globalRegionI = surfaces_.globalRegion(surfI, region[i]);
1695 extendedGapLevel[globalRegionI],
1696 extendedGapMode[globalRegionI],
1709 if (
tree.nodes().size() &&
tree.bb().contains(ctrs[i]))
1711 cellI =
tree.findInside(ctrs[i]);
1720 label nRays = generateRays
1736 for (label j = 0; j < nRays; j++)
1738 cellMap.append(cellI);
1747 <<
" cells containing triangle centres out of "
1748 << mesh_.globalData().nTotalCells() <<
endl;
1756 shellGapInfo.clear();
1757 shellGapMode.clear();
1763 surfaces_.findNearestIntersection
1772 label nOldRefine = 0;
1779 const label shelli = gapShell[map[i]];
1780 bool selfProx =
true;
1783 selfProx = shells_.gapSelf()[shelli][0];
1785 if (surfI != -1 && selfProx)
1787 const label globalRegioni = surfaces_.globalRegion(surfI, 0);
1788 selfProx = extendedGapSelf[globalRegioni];
1794 && (surfaceHit[i] != surfI || selfProx)
1798 label cellI = cellMap[i];
1800 if (
mag(normal[i]&surfaceNormal[i]) > planarCos)
1819 Info<<
"For surface " << geom.name() <<
" found "
1821 <<
" cells in small gaps" <<
endl;
1829 Info<<
"Reached refinement limit." <<
endl;
1838Foam::label Foam::meshRefinement::markSurfaceFieldRefinement
1840 const label nAllowRefine,
1848 const labelList& cellLevel = meshCutter_.cellLevel();
1849 const labelList& surfaceIndices = surfaces_.surfaces();
1854 (void)mesh_.tetBasePtIs();
1855 (void)mesh_.cellTree();
1859 forAll(surfaceIndices, surfI)
1861 label geomI = surfaceIndices[surfI];
1874 geom.boundingSpheres(ctrs, radiusSqr);
1877 geom.findNearest(ctrs, radiusSqr, info);
1885 <<
" radius:" << radiusSqr[i]
1890 geom.getRegion(info, region);
1891 geom.getField(info, minLevelField);
1894 if (minLevelField.size() != geom.size())
1896 Pout<<
"** no minLevelField" <<
endl;
1901 label nOldRefine = 0;
1906 if (
tree.nodes().size() &&
tree.bb().contains(ctrs[i]))
1908 cellI =
tree.findInside(ctrs[i]);
1915 && minLevelField[i] > cellLevel[cellI]
1934 Info<<
"For surface " << geom.name() <<
" found "
1936 <<
" cells containing cached refinement field" <<
endl;
1944 Info<<
"Reached refinement limit." <<
endl;
Dynamically sized Field. Similar to DynamicList, but inheriting from a Field instead of a List.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Wave propagation of information through grid. Every iteration information goes through one layer of c...
A 1D vector of objects of type <T> with a fixed length <N>.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void clear()
Clear the list, i.e. set size to zero.
A List with indirect addressing. Like IndirectList but does not store addressing.
Non-pointer based hierarchical recursive searching.
Container with cells to refine. Refinement given as single direction.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Class used to pass additional data in.
Holds information (coordinate and distance). Walks out 0.5*distance.
An enumeration wrapper for classification of a location as being inside/outside of a volume.
@ OUTSIDE
A location outside the volume.
@ MIXED
A location that is partly inside and outside.
@ INSIDE
A location inside the volume.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
wallPoints::trackData td(isBlockedFace, regionToBlockSize)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
List< label > labelList
A List of labels.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
UIndirectList< label > labelUIndList
UIndirectList of labels.
messageStream Info
Information stream (stdout output on master, null elsewhere).
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
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...
Field< vector > vectorField
Specialisation of Field<T> for vector.
vector point
Point is a vector.
List< bool > boolList
A List of bools.
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...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Tree tree(triangles.begin(), triangles.end())
#define forAll(list, i)
Loop across all elements in list.