ENH: add primitiveMesh cellBb()

- the boundBox for a given cell, using the cheapest calculation:

  - cellPoints if already available, since this will involve the
    fewest number of min/max comparisions.

  - otherwise walk the cell faces: via the cell box() method
    to avoid creating demand-driven cellPoints etc.
This commit is contained in:
Mark Olesen
2022-11-01 12:15:08 +01:00
committed by Andrew Heather
parent 27c2cdc040
commit 0ba458fdbc
12 changed files with 68 additions and 141 deletions

View File

@ -54,23 +54,20 @@ Foam::labelList Foam::meshToMeshMethod::maskCells() const
intersectBb.inflate(0.01);
const cellList& srcCells = src_.cells();
const faceList& srcFaces = src_.faces();
const pointField& srcPts = src_.points();
DynamicList<label> cells(src_.nCells());
forAll(srcCells, srcI)
for (label srcCelli = 0; srcCelli < src_.nCells(); ++srcCelli)
{
boundBox cellBb(srcCells[srcI].points(srcFaces, srcPts), false);
boundBox cellBb(src_.cellBb(srcCelli));
if (intersectBb.overlaps(cellBb))
{
cells.append(srcI);
cells.append(srcCelli);
}
}
if (debug)
{
Pout<< "participating source mesh cells: " << cells.size() << endl;
Pout<< "participating source mesh cells: " << src_.nCells() << endl;
}
return cells;
@ -87,14 +84,7 @@ bool Foam::meshToMeshMethod::intersect
tetOverlapVolume overlapEngine;
// Note: avoid demand-driven construction of cellPoints
// treeBoundBox bbTgtCell(tgt_.points(), tgt_.cellPoints()[tgtCelli]);
const UList<label>& cellFaces = tgt_.cells()[tgtCelli];
treeBoundBox bbTgtCell(tgt_.points(), tgt_.faces()[cellFaces[0]]);
for (label i = 1; i < cellFaces.size(); ++i)
{
bbTgtCell.add(tgt_.points(), tgt_.faces()[cellFaces[i]]);
}
treeBoundBox bbTgtCell(tgt_.cellBb(tgtCelli));
return overlapEngine.cellCellOverlapMinDecomp
(
@ -116,14 +106,7 @@ Foam::scalar Foam::meshToMeshMethod::interVol
{
tetOverlapVolume overlapEngine;
// Note: avoid demand-driven construction of cellPoints
// treeBoundBox bbTgtCell(tgt_.points(), tgt_.cellPoints()[tgtCelli]);
const UList<label>& cellFaces = tgt_.cells()[tgtCelli];
treeBoundBox bbTgtCell(tgt_.points(), tgt_.faces()[cellFaces[0]]);
for (label i = 1; i < cellFaces.size(); ++i)
{
bbTgtCell.add(tgt_.points(), tgt_.faces()[cellFaces[i]]);
}
treeBoundBox bbTgtCell(tgt_.cellBb(tgtCelli));
scalar vol = overlapEngine.cellCellOverlapVolumeMinDecomp
(
@ -147,14 +130,7 @@ Foam::meshToMeshMethod::interVolAndCentroid
{
tetOverlapVolume overlapEngine;
// Note: avoid demand-driven construction of cellPoints
// treeBoundBox bbTgtCell(tgt_.points(), tgt_.cellPoints()[tgtCelli]);
const UList<label>& cellFaces = tgt_.cells()[tgtCelli];
treeBoundBox bbTgtCell(tgt_.points(), tgt_.faces()[cellFaces[0]]);
for (label i = 1; i < cellFaces.size(); ++i)
{
bbTgtCell.add(tgt_.points(), tgt_.faces()[cellFaces[i]]);
}
treeBoundBox bbTgtCell(tgt_.cellBb(tgtCelli));
Tuple2<scalar, point> volAndInertia =
overlapEngine.cellCellOverlapMomentMinDecomp

View File

@ -178,12 +178,8 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap
}
// determine which cells of tgt mesh overlaps src mesh per proc
const cellList& cells = tgt.cells();
const faceList& faces = tgt.faces();
const pointField& points = tgt.points();
labelListList sendMap;
// Determine which cells of tgt mesh overlaps src mesh per proc
labelListList sendMap(Pstream::nProcs());
{
// per processor indices into all segments to send
@ -198,20 +194,11 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap
// work array - whether src processor bb overlaps the tgt cell
// bounds
boolList procBbOverlaps(Pstream::nProcs());
forAll(cells, celli)
{
const cell& c = cells[celli];
// determine bounding box of tgt cell
boundBox cellBb(boundBox::invertedBox);
forAll(c, facei)
{
const face& f = faces[c[facei]];
forAll(f, fp)
{
cellBb.add(points, f);
}
}
for (label celli = 0; celli < tgt.nCells(); ++celli)
{
// Bounding box of tgt cell
boundBox cellBb(tgt.cellBb(celli));
// find the overlapping tgt cells on each src processor
(void)calcOverlappingProcs(procBb, cellBb, procBbOverlaps);
@ -226,23 +213,22 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap
}
// convert dynamicList to labelList
sendMap.setSize(Pstream::nProcs());
forAll(sendMap, proci)
{
sendMap[proci].transfer(dynSendMap[proci]);
}
}
// debug printing
if (debug)
{
Pout<< "Of my " << cells.size()
<< " target cells I need to send to:" << nl
<< "\tproc\tcells" << endl;
forAll(sendMap, proci)
// debug printing
if (debug)
{
Pout<< '\t' << proci << '\t' << sendMap[proci].size()
<< endl;
Pout<< "Of my " << tgt.nCells()
<< " target cells I need to send to:" << nl
<< "\tproc\tcells" << endl;
forAll(sendMap, proci)
{
Pout<< '\t' << proci << '\t'
<< sendMap[proci].size() << endl;
}
}
}
@ -250,7 +236,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap
// send over how many tgt cells I need to receive from each
// processor
labelListList sendSizes(Pstream::nProcs());
sendSizes[Pstream::myProcNo()].setSize(Pstream::nProcs());
sendSizes[Pstream::myProcNo()].resize(Pstream::nProcs());
forAll(sendMap, proci)
{
sendSizes[Pstream::myProcNo()][proci] = sendMap[proci].size();

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -89,20 +89,14 @@ void Foam::cuttingSurface::calcCellCuts
);
boundBox cellBb;
for (const label celli : cellCuts)
{
cellBb.clear();
cellBb.add(pts, fvm.cellPoints(celli));
if (!cellBb.contains(nearest[celli].hitPoint()))
if (!fvm.cellBb(celli).contains(nearest[celli].point()))
{
cellCuts.unset(celli);
}
}
if (debug)
{
volScalarField cCuts

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -204,23 +204,18 @@ static bitSet simpleGeometricFilter
// A deny filter. Initially false (accept everything)
ignoreCells.resize(mesh.nCells());
bitSet pointFilter;
bitSet ignorePoints;
if (WantPointFilter)
{
// Create as accept filter. Initially false (deny everything)
pointFilter.resize(mesh.nPoints());
// Create deny filter
ignorePoints.resize(mesh.nPoints(), true);
}
boundBox cellBb;
forAll(nearest, celli)
{
const point& pt = nearest[celli].point();
const labelList& cPoints = mesh.cellPoints(celli);
cellBb.clear();
cellBb.add(mesh.points(), cPoints);
boundBox cellBb(mesh.cellBb(celli));
cellBb.inflate(boundBoxInflate);
if (!cellBb.contains(pt))
@ -229,15 +224,12 @@ static bitSet simpleGeometricFilter
}
else if (WantPointFilter)
{
// Good cell candidate, accept its points
pointFilter.set(cPoints);
// Good cell candidate, do not ignore its points
ignorePoints.unset(mesh.cellPoints(celli));
}
}
// Flip from accept to deny filter
pointFilter.flip();
return pointFilter;
return ignorePoints;
}