Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
List<volumeType>& shellGapMode
) const
{
const labelList& cellLevel = meshCutter_.cellLevel();
const pointField& cellCentres = mesh_.cellCentres();
// Collect cells to test
cellMap.setSize(cellLevel.size()-nRefine);
label compactI = 0;
forAll(cellLevel, cellI)
{
if (refineCell[cellI] == -1)
{
cellMap[compactI++] = cellI;
}
}
Info<< "Selected " << returnReduce(compactI, sumOp<label>())
<< " unmarked cells out of "
<< mesh_.globalData().nTotalCells() << endl;
cellMap.setSize(compactI);
// Do test to see whether cells are inside/outside shell with
// applicable specification (minLevel <= celllevel < maxLevel)
shells_.findHigherGapLevel
(
pointField(cellCentres, cellMap),
UIndirectList<label>(cellLevel, cellMap)(),
shellGapInfo,
shellGapMode
);
// Compact out hits
labelList map(shellGapInfo.size());
compactI = 0;
forAll(shellGapInfo, i)
{
if (shellGapInfo[i][2] > 0)
{
map[compactI++] = i;
}
}
Info<< "Selected " << returnReduce(compactI, sumOp<label>())
<< " cells inside gap shells out of "
<< mesh_.globalData().nTotalCells() << endl;
map.setSize(compactI);
cellMap = UIndirectList<label>(cellMap, map)();
shellGapInfo = UIndirectList<FixedList<label, 3>>(shellGapInfo, map)();
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
shellGapMode = UIndirectList<volumeType>(shellGapMode, map)();
}
void Foam::meshRefinement::mergeGapInfo
(
const FixedList<label, 3>& shellGapInfo,
const volumeType shellGapMode,
const FixedList<label, 3>& surfGapInfo,
const volumeType surfGapMode,
FixedList<label, 3>& gapInfo,
volumeType& gapMode
) const
{
if (surfGapInfo[0] == 0)
{
gapInfo = shellGapInfo;
gapMode = shellGapMode;
}
else if (shellGapInfo[0] == 0)
{
gapInfo = surfGapInfo;
gapMode = surfGapMode;
}
else
{
// Both specify a level. Does surface level win? Or does information
// need to be merged?
//gapInfo[0] = max(surfGapInfo[0], shellGapInfo[0]);
//gapInfo[1] = min(surfGapInfo[1], shellGapInfo[1]);
//gapInfo[2] = max(surfGapInfo[2], shellGapInfo[2]);
gapInfo = surfGapInfo;
gapMode = surfGapMode;
}
}
Foam::label Foam::meshRefinement::markInternalGapRefinement
(
const scalar planarCos,
const bool spreadGapSize,
const label nAllowRefine,
labelList& refineCell,
label& nRefine,
labelList& numGapCells,
scalarField& detectedGapSize
) const
{
detectedGapSize.setSize(mesh_.nCells());
detectedGapSize = GREAT;
numGapCells.setSize(mesh_.nCells());
numGapCells = -1;
const labelList& cellLevel = meshCutter_.cellLevel();
const pointField& cellCentres = mesh_.cellCentres();
const scalar edge0Len = meshCutter_.level0EdgeLength();
const List<FixedList<label, 3>>& extendedGapLevel =
surfaces_.extendedGapLevel();
const List<volumeType>& extendedGapMode = surfaces_.extendedGapMode();
// Get the gap level for the shells
const labelList maxLevel(shells_.maxGapLevel());
label oldNRefine = nRefine;
if (max(maxLevel) > 0)
{
// Collect cells to test
labelList cellMap;
List<FixedList<label, 3>> shellGapInfo;
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
List<volumeType> shellGapMode;
selectGapCandidates
(
refineCell,
nRefine,
cellMap,
shellGapInfo,
shellGapMode
);
// Find nearest point and normal on the surfaces
List<pointIndexHit> nearInfo;
vectorField nearNormal;
labelList nearSurface;
labelList nearRegion;
{
// Now we have both the cell-level and the gap size information. Use
// this to calculate the gap size
scalarField gapSize(cellMap.size());
forAll(cellMap, i)
{
label cellI = cellMap[i];
scalar cellSize = edge0Len/pow(2.0, cellLevel[cellI]);
gapSize[i] = shellGapInfo[i][0]*cellSize;
}
surfaces_.findNearestRegion
(
identity(surfaces_.surfaces().size()),
pointField(cellCentres, cellMap),
sqr(gapSize),
nearSurface,
nearInfo,
nearRegion,
nearNormal
);
}
DynamicList<label> map(nearInfo.size());
DynamicField<point> rayStart(nearInfo.size());
DynamicField<point> rayEnd(nearInfo.size());
DynamicField<scalar> gapSize(nearInfo.size());
DynamicField<point> rayStart2(nearInfo.size());
DynamicField<point> rayEnd2(nearInfo.size());
DynamicField<scalar> gapSize2(nearInfo.size());
label nTestCells = 0;
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
forAll(nearInfo, i)
{
if (nearInfo[i].hit())
{
label globalRegionI = surfaces_.globalRegion
(
nearSurface[i],
nearRegion[i]
);
// Combine info from shell and surface
FixedList<label, 3> gapInfo;
volumeType gapMode;
mergeGapInfo
(
shellGapInfo[i],
shellGapMode[i],
extendedGapLevel[globalRegionI],
extendedGapMode[globalRegionI],
gapInfo,
gapMode
);
// Store wanted number of cells in gap
label cellI = cellMap[i];
label cLevel = cellLevel[cellI];
if (cLevel >= gapInfo[1] && cLevel < gapInfo[2])
{
numGapCells[cellI] = max(numGapCells[cellI], gapInfo[0]);
}
// Construct one or more rays to test for oppositeness
label nRays = generateRays
(
false,
nearInfo[i].hitPoint(),
nearNormal[i],
gapInfo,
gapMode,
cellCentres[cellI],
cLevel,
rayStart,
rayEnd,
gapSize,
rayStart2,
rayEnd2,
gapSize2
if (nRays > 0)
nTestCells++;
for (label j = 0; j < nRays; j++)
{
map.append(i);
}
}
}
}
Info<< "Selected " << returnReduce(nTestCells, sumOp<label>())
<< " cells for testing out of "
<< mesh_.globalData().nTotalCells() << endl;
map.shrink();
rayStart.shrink();
rayEnd.shrink();
gapSize.shrink();
rayStart2.shrink();
rayEnd2.shrink();
gapSize2.shrink();
cellMap = UIndirectList<label>(cellMap, map)();
nearNormal = UIndirectList<vector>(nearNormal, map)();
shellGapInfo.clear();
shellGapMode.clear();
nearInfo.clear();
nearSurface.clear();
nearRegion.clear();
// Do intersections in pairs
labelList surf1;
List<pointIndexHit> hit1;
vectorField normal1;
surfaces_.findNearestIntersection
(
rayStart,
rayEnd,
surf1,
hit1,
normal1
labelList surf2;
List<pointIndexHit> hit2;
vectorField normal2;
surfaces_.findNearestIntersection
(
rayStart2,
rayEnd2,
surf2,
hit2,
normal2
);
// Extract cell based gap size
forAll(surf1, i)
if (surf1[i] != -1 && surf2[i] != -1)
// Found intersections with surface. Check for
// - small gap
// - coplanar normals
label cellI = cellMap[i];
scalar d2 = magSqr(hit1[i].hitPoint()-hit2[i].hitPoint());
if
(
cellI != -1
&& (mag(normal1[i]&normal2[i]) > planarCos)
&& (d2 < Foam::sqr(gapSize[i]))
)
detectedGapSize[cellI] = min
(
detectedGapSize[cellI],
Foam::sqrt(d2)
);
}
}
}
// Spread it
if (spreadGapSize)
// Field on cells and faces
List<transportData> cellData(mesh_.nCells());
List<transportData> faceData(mesh_.nFaces());
// Start of walk
const pointField& faceCentres = mesh_.faceCentres();
DynamicList<label> frontFaces(mesh_.nFaces());
DynamicList<transportData> frontData(mesh_.nFaces());
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
label own = mesh_.faceOwner()[faceI];
label nei = mesh_.faceNeighbour()[faceI];
scalar minSize = min
(
detectedGapSize[own],
detectedGapSize[nei]
);
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
if (minSize < GREAT)
{
frontFaces.append(faceI);
frontData.append
(
transportData
(
faceCentres[faceI],
minSize,
0.0
)
);
}
}
for
(
label faceI = mesh_.nInternalFaces();
faceI < mesh_.nFaces();
faceI++
)
{
label own = mesh_.faceOwner()[faceI];
if (detectedGapSize[own] < GREAT)
{
frontFaces.append(faceI);
frontData.append
(
transportData
(
faceCentres[faceI],
detectedGapSize[own],
0.0
)
);
}
}
Info<< "Selected "
<< returnReduce(frontFaces.size(), sumOp<label>())
<< " faces for spreading gap size out of "
<< mesh_.globalData().nTotalFaces() << endl;
transportData::trackData td(surfaceIndex_);
FaceCellWave<transportData, transportData::trackData> deltaCalc
(
mesh_,
frontFaces,
frontData,
faceData,
cellData,
mesh_.globalData().nTotalCells()+1,
td
);
forAll(cellMap, i)
{
label cellI = cellMap[i];
if
(
cellI != -1
&& cellData[cellI].valid(deltaCalc.data())
&& numGapCells[cellI] != -1
)
{
// Update transported gap size
detectedGapSize[cellI] = min
(
detectedGapSize[cellI],
cellData[cellI].data()
);
}
}
}
// Use it
forAll(cellMap, i)
{
label cellI = cellMap[i];
if (cellI != -1 && numGapCells[cellI] != -1)
{
// Needed gap size
label cLevel = cellLevel[cellI];
scalar cellSize =
meshCutter_.level0EdgeLength()/pow(2.0, cLevel);
scalar neededGapSize = numGapCells[cellI]*cellSize;
if (neededGapSize > detectedGapSize[cellI])
{
if
(
!markForRefine
(
123,
nAllowRefine,
refineCell[cellI],
nRefine
)
)
{
break;
}
}
}
}
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
if
(
returnReduce(nRefine, sumOp<label>())
> returnReduce(nAllowRefine, sumOp<label>())
)
{
Info<< "Reached refinement limit." << endl;
}
}
return returnReduce(nRefine-oldNRefine, sumOp<label>());
}
Foam::label Foam::meshRefinement::markSmallFeatureRefinement
(
const scalar planarCos,
const label nAllowRefine,
const labelList& neiLevel,
const pointField& neiCc,
labelList& refineCell,
label& nRefine
) const
{
const labelList& cellLevel = meshCutter_.cellLevel();
const labelList& surfaceIndices = surfaces_.surfaces();
const List<FixedList<label, 3>>& extendedGapLevel =
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
surfaces_.extendedGapLevel();
const List<volumeType>& extendedGapMode = surfaces_.extendedGapMode();
label oldNRefine = nRefine;
// Check that we're using any gap refinement
labelList shellMaxLevel(shells_.maxGapLevel());
if (max(shellMaxLevel) == 0)
{
return 0;
}
//- Force calculation of tetBasePt
(void)mesh_.tetBasePtIs();
(void)mesh_.cellTree();
forAll(surfaceIndices, surfI)
{
label geomI = surfaceIndices[surfI];
const searchableSurface& geom = surfaces_.geometry()[geomI];
// Get the element index in a roundabout way. Problem is e.g.
// distributed surface where local indices differ from global
// ones (needed for getRegion call)
pointField ctrs;
labelList region;
vectorField normal;
{
// Representative local coordinates and bounding sphere
scalarField radiusSqr;
geom.boundingSpheres(ctrs, radiusSqr);
List<pointIndexHit> info;
geom.findNearest(ctrs, radiusSqr, info);
forAll(info, i)
{
if (!info[i].hit())
{
<< "fc:" << ctrs[i]
<< " radius:" << radiusSqr[i]
<< exit(FatalError);
}
}
geom.getRegion(info, region);
geom.getNormal(info, normal);
}
// Do test to see whether triangles are inside/outside shell with
// applicable specification (minLevel <= celllevel < maxLevel)
List<FixedList<label, 3>> shellGapInfo;
List<volumeType> shellGapMode;
shells_.findHigherGapLevel
(
ctrs,
labelList(ctrs.size(), 0),
shellGapInfo,
shellGapMode
);
DynamicList<label> map(ctrs.size());
DynamicList<label> cellMap(ctrs.size());
DynamicField<point> rayStart(ctrs.size());
DynamicField<point> rayEnd(ctrs.size());
DynamicField<scalar> gapSize(ctrs.size());
label nTestCells = 0;
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
forAll(ctrs, i)
{
if (shellGapInfo[i][2] > 0)
{
label globalRegionI = surfaces_.globalRegion(surfI, region[i]);
// Combine info from shell and surface
FixedList<label, 3> gapInfo;
volumeType gapMode;
mergeGapInfo
(
shellGapInfo[i],
shellGapMode[i],
extendedGapLevel[globalRegionI],
extendedGapMode[globalRegionI],
gapInfo,
gapMode
);
//- Option 1: use octree nearest searching inside polyMesh
//label cellI = mesh_.findCell(pt);
//- Option 2: use octree 'inside' searching inside polyMesh. Is
// much faster.
label cellI = -1;
const indexedOctree<treeDataCell>& tree = mesh_.cellTree();
if (tree.nodes().size() && tree.bb().contains(ctrs[i]))
{
cellI = tree.findInside(ctrs[i]);
}
if (cellI != -1 && refineCell[cellI] == -1)
{
// Construct one or two rays to test for oppositeness
// Note that we always want to use the surface normal
// and not the vector from cell centre to surface point
label nRays = generateRays
(
ctrs[i],
normal[i],
gapInfo,
gapMode,
cellLevel[cellI],
rayStart,
rayEnd
if (nRays > 0)
nTestCells++;
for (label j = 0; j < nRays; j++)
{
cellMap.append(cellI);
map.append(i);
}
}
}
}
}
Info<< "Selected " << returnReduce(nTestCells, sumOp<label>())
<< " cells containing triangle centres out of "
<< mesh_.globalData().nTotalCells() << endl;
map.shrink();
cellMap.shrink();
rayStart.shrink();
rayEnd.shrink();
ctrs.clear();
region.clear();
shellGapInfo.clear();
shellGapMode.clear();
normal = UIndirectList<vector>(normal, map)();
// Do intersections.
labelList surfaceHit;
vectorField surfaceNormal;
surfaces_.findNearestIntersection
(
rayStart,
rayEnd,
surfaceHit,
surfaceNormal
);
label nOldRefine = 0;
forAll(surfaceHit, i)
{
if (surfaceHit[i] != -1) // && surf2[i] != -1)
// Found intersection with surface. Check coplanar normals.
label cellI = cellMap[i];
if (mag(normal[i]&surfaceNormal[i]) > planarCos)
{
if
!markForRefine
(
surfaceHit[i],
nAllowRefine,
refineCell[cellI],
nRefine
)
{
break;
}
}
}
}
Info<< "For surface " << geom.name() << " found "
<< returnReduce(nRefine-nOldRefine, sumOp<label>())
<< " cells in small gaps" << endl;
if
(
returnReduce(nRefine, sumOp<label>())
> returnReduce(nAllowRefine, sumOp<label>())
)
{
Info<< "Reached refinement limit." << endl;
}
}
return returnReduce(nRefine-oldNRefine, sumOp<label>());
}
// ************************************************************************* //