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 21, 2023
1 parent 30ff08c commit 7c4fe82
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
65 changes: 57 additions & 8 deletions src/patchkernel/patch_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5643,17 +5643,66 @@ 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 = *minPoint;
break;
}

case ElementType::PIXEL:
{
const long *elementConnect = element.getConnect();

const std::array<double, 3> &vertexCoord_0 = getVertexCoords(elementConnect[0]);
const std::array<double, 3> &vertexCoord_3 = getVertexCoords(elementConnect[3]);

for (int d = 0; d < 3; ++d) {
(*minPoint)[d] = std::min(vertexCoord_0[d], vertexCoord_3[d]);
(*maxPoint)[d] = std::max(vertexCoord_0[d], vertexCoord_3[d]);
}

break;
}

case ElementType::VOXEL:
{
const long *elementConnect = element.getConnect();

const std::array<double, 3> &vertexCoord_0 = getVertexCoords(elementConnect[0]);
const std::array<double, 3> &vertexCoord_7 = getVertexCoords(elementConnect[7]);

*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]);
(*minPoint)[d] = std::min(vertexCoord_0[d], vertexCoord_7[d]);
(*maxPoint)[d] = std::max(vertexCoord_0[d], vertexCoord_7[d]);
}

break;
}

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 7c4fe82

Please sign in to comment.