Skip to content

Commit

Permalink
patchkernel: optimize evaluation of vertex/pixel/voxel bounding box
Browse files Browse the repository at this point in the history
It is faster to evaluate the bounding box in PatchKernel rather than
delegate the evaluation to PABLO.
  • Loading branch information
andrea-iob committed Sep 14, 2023
1 parent 30ff08c commit bffe3c3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
52 changes: 43 additions & 9 deletions src/patchkernel/patch_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5643,17 +5643,51 @@ std::array<double, 3> PatchKernel::evalElementCentroid(const Element &element) c
*/
void PatchKernel::evalElementBoundingBox(const Element &element, std::array<double,3> *minPoint, std::array<double,3> *maxPoint) const
{
ConstProxyVector<long> elementVertexIds = element.getVertexIds();
const int nElementVertices = elementVertexIds.size();
ElementType elementType = element.getType();
switch (elementType)
{

case ElementType::VERTEX:
{
const long *elementConnect = element.getConnect();
*minPoint = getVertexCoords(elementConnect[0]);
*maxPoint = getVertexCoords(elementConnect[0]);
break;
}

case ElementType::PIXEL:
{
const long *elementConnect = element.getConnect();
*minPoint = getVertexCoords(elementConnect[0]);
*maxPoint = getVertexCoords(elementConnect[3]);
break;
}

case ElementType::VOXEL:
{
const long *elementConnect = element.getConnect();
*minPoint = getVertexCoords(elementConnect[0]);
*maxPoint = getVertexCoords(elementConnect[7]);
break;
}

*minPoint = getVertexCoords(elementVertexIds[0]);
*maxPoint = *minPoint;
for (int i = 1; i < nElementVertices; ++i) {
const std::array<double, 3> &vertexCoord = getVertexCoords(elementVertexIds[i]);
for (int d = 0; d < 3; ++d) {
(*minPoint)[d] = std::min(vertexCoord[d], (*minPoint)[d]);
(*maxPoint)[d] = std::max(vertexCoord[d], (*maxPoint)[d]);
default:
{
ConstProxyVector<long> elementVertexIds = element.getVertexIds();
const int nElementVertices = elementVertexIds.size();

*minPoint = getVertexCoords(elementVertexIds[0]);
*maxPoint = *minPoint;
for (int i = 1; i < nElementVertices; ++i) {
const std::array<double, 3> &vertexCoord = getVertexCoords(elementVertexIds[i]);
for (int d = 0; d < 3; ++d) {
(*minPoint)[d] = std::min(vertexCoord[d], (*minPoint)[d]);
(*maxPoint)[d] = std::max(vertexCoord[d], (*maxPoint)[d]);
}
}
break;
}

}
}

Expand Down
16 changes: 0 additions & 16 deletions src/voloctree/voloctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,22 +720,6 @@ std::array<double, 3> VolOctree::evalCellCentroid(long id) const
return m_tree->getCenter(octant);
}

/*!
Evaluates the bounding box of the specified cell.
\param id is the id of the cell
\param[out] minPoint is the minimum point of the bounding box
\param[out] maxPoint is the maximum point of the bounding box
*/
void VolOctree::evalCellBoundingBox(long id, std::array<double,3> *minPoint, std::array<double,3> *maxPoint) const
{
OctantInfo octantInfo = getCellOctant(id);
const Octant *octant = getOctantPointer(octantInfo);

*minPoint = m_tree->getNode(octant, 0);
*maxPoint = m_tree->getNode(octant, m_cellTypeInfo->nVertices - 1);
}

/*!
Evaluates the characteristic size of the specified cell.
Expand Down
2 changes: 0 additions & 2 deletions src/voloctree/voloctree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class VolOctree : public VolumeKernel {

void simulateCellUpdate(long id, adaption::Marker marker, std::vector<Cell> *virtualCells, PiercedVector<Vertex, long> *virtualVertices) const override;

void evalCellBoundingBox(long id, std::array<double,3> *minPoint, std::array<double,3> *maxPoint) const override;

double evalInterfaceArea(long id) const override;
std::array<double, 3> evalInterfaceNormal(long id) const override;

Expand Down

0 comments on commit bffe3c3

Please sign in to comment.