mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Adapted for new api of searchableSurface
This commit is contained in:
@ -496,23 +496,63 @@ Foam::labelList Foam::refinementSurfaces::getClosedNamedSurfaces() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Count number of triangles per surface region
|
// // Count number of triangles per surface region
|
||||||
Foam::labelList Foam::refinementSurfaces::countRegions(const triSurface& s)
|
// Foam::labelList Foam::refinementSurfaces::countRegions(const triSurface& s)
|
||||||
{
|
// {
|
||||||
const geometricSurfacePatchList& regions = s.patches();
|
// const geometricSurfacePatchList& regions = s.patches();
|
||||||
|
//
|
||||||
|
// labelList nTris(regions.size(), 0);
|
||||||
|
//
|
||||||
|
// forAll(s, triI)
|
||||||
|
// {
|
||||||
|
// nTris[s[triI].region()]++;
|
||||||
|
// }
|
||||||
|
// return nTris;
|
||||||
|
// }
|
||||||
|
|
||||||
labelList nTris(regions.size(), 0);
|
|
||||||
|
|
||||||
forAll(s, triI)
|
// // Pre-calculate the refinement level for every element
|
||||||
{
|
// void Foam::refinementSurfaces::wantedRefinementLevel
|
||||||
nTris[s[triI].region()]++;
|
// (
|
||||||
}
|
// const shellSurfaces& shells,
|
||||||
return nTris;
|
// const label surfI,
|
||||||
}
|
// const List<pointIndexHit>& info, // Indices
|
||||||
|
// const pointField& ctrs, // Representative coordinate
|
||||||
|
// labelList& minLevelField
|
||||||
|
// ) const
|
||||||
|
// {
|
||||||
|
// const searchableSurface& geom = allGeometry_[surfaces_[surfI]];
|
||||||
|
//
|
||||||
|
// // Get per element the region
|
||||||
|
// labelList region;
|
||||||
|
// geom.getRegion(info, region);
|
||||||
|
//
|
||||||
|
// // Initialise fields to region wise minLevel
|
||||||
|
// minLevelField.setSize(ctrs.size());
|
||||||
|
// minLevelField = -1;
|
||||||
|
//
|
||||||
|
// forAll(minLevelField, i)
|
||||||
|
// {
|
||||||
|
// if (info[i].hit())
|
||||||
|
// {
|
||||||
|
// minLevelField[i] = minLevel(surfI, region[i]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Find out if triangle inside shell with higher level
|
||||||
|
// // What level does shell want to refine fc to?
|
||||||
|
// labelList shellLevel;
|
||||||
|
// shells.findHigherLevel(ctrs, minLevelField, shellLevel);
|
||||||
|
//
|
||||||
|
// forAll(minLevelField, i)
|
||||||
|
// {
|
||||||
|
// minLevelField[i] = max(minLevelField[i], shellLevel[i]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
// Precalculate the refinement level for every element of the searchable
|
// Precalculate the refinement level for every element of the searchable
|
||||||
// surface. This is currently hardcoded for triSurfaceMesh only.
|
// surface.
|
||||||
void Foam::refinementSurfaces::setMinLevelFields
|
void Foam::refinementSurfaces::setMinLevelFields
|
||||||
(
|
(
|
||||||
const shellSurfaces& shells
|
const shellSurfaces& shells
|
||||||
@ -522,58 +562,55 @@ void Foam::refinementSurfaces::setMinLevelFields
|
|||||||
{
|
{
|
||||||
const searchableSurface& geom = allGeometry_[surfaces_[surfI]];
|
const searchableSurface& geom = allGeometry_[surfaces_[surfI]];
|
||||||
|
|
||||||
if (isA<triSurfaceMesh>(geom))
|
// Precalculation only makes sense if there are different regions
|
||||||
|
// (so different refinement levels possible) and there are some
|
||||||
|
// elements. Possibly should have 'enough' elements to have fine
|
||||||
|
// enough resolution but for now just make sure we don't catch e.g.
|
||||||
|
// searchableBox (size=6)
|
||||||
|
if (geom.regions().size() > 1 && geom.globalSize() > 10)
|
||||||
{
|
{
|
||||||
const triSurfaceMesh& triMesh = refCast<const triSurfaceMesh>(geom);
|
// Representative local coordinates
|
||||||
|
const pointField ctrs = geom.coordinates();
|
||||||
|
|
||||||
autoPtr<triSurfaceLabelField> minLevelFieldPtr
|
labelList minLevelField(ctrs.size(), -1);
|
||||||
|
{
|
||||||
|
// 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)
|
||||||
|
List<pointIndexHit> info;
|
||||||
|
geom.findNearest
|
||||||
(
|
(
|
||||||
new triSurfaceLabelField
|
ctrs,
|
||||||
(
|
scalarField(ctrs.size(), sqr(GREAT)),
|
||||||
IOobject
|
info
|
||||||
(
|
|
||||||
"minLevel",
|
|
||||||
triMesh.objectRegistry::time().timeName(), // instance
|
|
||||||
"triSurface", // local
|
|
||||||
triMesh,
|
|
||||||
IOobject::NO_READ,
|
|
||||||
IOobject::AUTO_WRITE
|
|
||||||
),
|
|
||||||
triMesh,
|
|
||||||
dimless
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
triSurfaceLabelField& minLevelField = minLevelFieldPtr();
|
|
||||||
|
|
||||||
const triSurface& s = static_cast<const triSurface&>(triMesh);
|
// Get per element the region
|
||||||
|
labelList region;
|
||||||
|
geom.getRegion(info, region);
|
||||||
|
|
||||||
// Initialise fields to region wise minLevel
|
// From the region get the surface-wise refinement level
|
||||||
forAll(s, triI)
|
forAll(minLevelField, i)
|
||||||
{
|
{
|
||||||
minLevelField[triI] = minLevel(surfI, s[triI].region());
|
if (info[i].hit())
|
||||||
|
{
|
||||||
|
minLevelField[i] = minLevel(surfI, region[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out if triangle inside shell with higher level
|
// Find out if triangle inside shell with higher level
|
||||||
pointField fc(s.size());
|
|
||||||
forAll(s, triI)
|
|
||||||
{
|
|
||||||
fc[triI] = s[triI].centre(s.points());
|
|
||||||
}
|
|
||||||
// What level does shell want to refine fc to?
|
// What level does shell want to refine fc to?
|
||||||
labelList shellLevel;
|
labelList shellLevel;
|
||||||
shells.findHigherLevel(fc, minLevelField, shellLevel);
|
shells.findHigherLevel(ctrs, minLevelField, shellLevel);
|
||||||
|
|
||||||
forAll(minLevelField, triI)
|
forAll(minLevelField, i)
|
||||||
{
|
{
|
||||||
minLevelField[triI] = max
|
minLevelField[i] = max(minLevelField[i], shellLevel[i]);
|
||||||
(
|
|
||||||
minLevelField[triI],
|
|
||||||
shellLevel[triI]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store field on triMesh
|
// Store minLevelField on surface
|
||||||
minLevelFieldPtr.ptr()->store();
|
const_cast<searchableSurface&>(geom).setField(minLevelField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -601,44 +638,89 @@ void Foam::refinementSurfaces::findHigherIntersection
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (surfaces_.size() == 1)
|
||||||
|
{
|
||||||
|
// Optimisation: single segmented surface. No need to duplicate
|
||||||
|
// point storage.
|
||||||
|
|
||||||
|
label surfI = 0;
|
||||||
|
|
||||||
|
const searchableSurface& geom = allGeometry_[surfaces_[surfI]];
|
||||||
|
|
||||||
|
// Do intersection test
|
||||||
|
List<pointIndexHit> intersectionInfo(start.size());
|
||||||
|
geom.findLineAny(start, end, intersectionInfo);
|
||||||
|
|
||||||
|
// See if a cached level field available
|
||||||
|
labelList minLevelField;
|
||||||
|
geom.getField(intersectionInfo, minLevelField);
|
||||||
|
bool haveLevelField =
|
||||||
|
(
|
||||||
|
returnReduce(minLevelField.size(), sumOp<label>())
|
||||||
|
> 0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!haveLevelField && geom.regions().size() == 1)
|
||||||
|
{
|
||||||
|
minLevelField = labelList
|
||||||
|
(
|
||||||
|
intersectionInfo.size(),
|
||||||
|
minLevel(surfI, 0)
|
||||||
|
);
|
||||||
|
haveLevelField = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (haveLevelField)
|
||||||
|
{
|
||||||
|
forAll(intersectionInfo, i)
|
||||||
|
{
|
||||||
|
if
|
||||||
|
(
|
||||||
|
intersectionInfo[i].hit()
|
||||||
|
&& minLevelField[i] > currentLevel[i]
|
||||||
|
)
|
||||||
|
{
|
||||||
|
surfaces[i] = surfI; // index of surface
|
||||||
|
surfaceLevel[i] = minLevelField[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Work arrays
|
// Work arrays
|
||||||
labelList hitMap(identity(start.size()));
|
|
||||||
pointField p0(start);
|
pointField p0(start);
|
||||||
pointField p1(end);
|
pointField p1(end);
|
||||||
List<pointIndexHit> hitInfo(start.size());
|
labelList intersectionToPoint(identity(start.size()));
|
||||||
|
List<pointIndexHit> intersectionInfo(start.size());
|
||||||
|
|
||||||
forAll(surfaces_, surfI)
|
forAll(surfaces_, surfI)
|
||||||
{
|
{
|
||||||
const searchableSurface& geom = allGeometry_[surfaces_[surfI]];
|
const searchableSurface& geom = allGeometry_[surfaces_[surfI]];
|
||||||
|
|
||||||
geom.findLineAny(p0, p1, hitInfo);
|
// Do intersection test
|
||||||
|
geom.findLineAny(p0, p1, intersectionInfo);
|
||||||
|
|
||||||
|
// See if a cached level field available
|
||||||
labelList minLevelField;
|
labelList minLevelField;
|
||||||
if (isA<triSurfaceMesh>(geom))
|
geom.getField(intersectionInfo, minLevelField);
|
||||||
{
|
|
||||||
const triSurfaceMesh& triMesh = refCast<const triSurfaceMesh>(geom);
|
|
||||||
triMesh.getField
|
|
||||||
(
|
|
||||||
"minLevel",
|
|
||||||
hitInfo,
|
|
||||||
minLevelField
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Copy all hits into arguments, In-place compact misses.
|
||||||
// Copy all hits into arguments, continue with misses
|
label missI = 0;
|
||||||
label newI = 0;
|
forAll(intersectionInfo, i)
|
||||||
forAll(hitInfo, hitI)
|
|
||||||
{
|
{
|
||||||
// Get the minLevel for the point
|
// Get the minLevel for the point
|
||||||
label minLocalLevel = -1;
|
label minLocalLevel = -1;
|
||||||
|
|
||||||
if (hitInfo[hitI].hit())
|
if (intersectionInfo[i].hit())
|
||||||
{
|
{
|
||||||
// Check if minLevelField for this surface.
|
// Check if minLevelField for this surface.
|
||||||
if (minLevelField.size())
|
if (minLevelField.size())
|
||||||
{
|
{
|
||||||
minLocalLevel = minLevelField[hitI];
|
minLocalLevel = minLevelField[i];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -648,36 +730,35 @@ void Foam::refinementSurfaces::findHigherIntersection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
label pointI = hitMap[hitI];
|
|
||||||
|
label pointI = intersectionToPoint[i];
|
||||||
|
|
||||||
if (minLocalLevel > currentLevel[pointI])
|
if (minLocalLevel > currentLevel[pointI])
|
||||||
{
|
{
|
||||||
|
// Mark point for refinement
|
||||||
surfaces[pointI] = surfI;
|
surfaces[pointI] = surfI;
|
||||||
surfaceLevel[pointI] = minLocalLevel;
|
surfaceLevel[pointI] = minLocalLevel;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (hitI != newI)
|
p0[missI] = p0[pointI];
|
||||||
{
|
p1[missI] = p1[pointI];
|
||||||
hitMap[newI] = hitMap[hitI];
|
intersectionToPoint[missI] = pointI;
|
||||||
p0[newI] = p0[hitI];
|
missI++;
|
||||||
p1[newI] = p1[hitI];
|
|
||||||
}
|
|
||||||
newI++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// All done? Note that this decision should be synchronised
|
// All done? Note that this decision should be synchronised
|
||||||
if (returnReduce(newI, sumOp<label>()) == 0)
|
if (returnReduce(missI, sumOp<label>()) == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim and continue
|
// Trim misses
|
||||||
hitMap.setSize(newI);
|
p0.setSize(missI);
|
||||||
p0.setSize(newI);
|
p1.setSize(missI);
|
||||||
p1.setSize(newI);
|
intersectionToPoint.setSize(missI);
|
||||||
hitInfo.setSize(newI);
|
intersectionInfo.setSize(missI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -218,8 +218,8 @@ public:
|
|||||||
const shellSurfaces& shells
|
const shellSurfaces& shells
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Helper: count number of triangles per region
|
////- Helper: count number of triangles per region
|
||||||
static labelList countRegions(const triSurface&);
|
//static labelList countRegions(const triSurface&);
|
||||||
|
|
||||||
|
|
||||||
// Searching
|
// Searching
|
||||||
|
|||||||
Reference in New Issue
Block a user