Skip to content

Commit

Permalink
reserve size
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Sep 8, 2024
1 parent e1d653f commit 3ab7b9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions Src/EB/AMReX_EB_STL_utils.H
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private:
Gpu::PinnedVector<Triangle>& a_tri_pts);

static void build_bvh (Triangle* begin, Triangle * end, Gpu::PinnedVector<Node>& bvh_nodes);
static void bvh_size (int ntri, std::size_t& nnodes);
};

}
Expand Down
20 changes: 20 additions & 0 deletions Src/EB/AMReX_EB_STL_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ STLtools::prepare (Gpu::PinnedVector<Triangle> a_tri_pts)
Gpu::PinnedVector<Node> bvh_nodes;
if (m_bvh_optimization) {
BL_PROFILE("STLtools::build_bvh");
std::size_t nnodes = 0;
bvh_size(int(a_tri_pts.size()), nnodes);
bvh_nodes.reserve(nnodes);
build_bvh(a_tri_pts.data(), a_tri_pts.data()+a_tri_pts.size(), bvh_nodes);
#ifdef AMREX_USE_GPU
m_bvh_nodes.resize(bvh_nodes.size());
Expand Down Expand Up @@ -600,6 +603,23 @@ STLtools::build_bvh (Triangle* begin, Triangle* end, Gpu::PinnedVector<Node>& bv
}
}

void
STLtools::bvh_size (int ntri, std::size_t& nnodes)
{
++nnodes;

if (ntri <= m_bvh_max_size) { return; } // This is a leaf node

int nsplits = std::min((ntri + (m_bvh_max_size-1)) / m_bvh_max_size, m_bvh_max_splits);
int tsize = ntri / nsplits;
int nleft = ntri - tsize*nsplits;

for (int isplit = 0; isplit < nsplits; ++isplit) {
int child_size = (isplit < nleft) ? (tsize+1) : tsize;
bvh_size(child_size, nnodes);
}
}

void
STLtools::fill (MultiFab& mf, IntVect const& nghost, Geometry const& geom,
Real outside_value, Real inside_value) const
Expand Down

0 comments on commit 3ab7b9d

Please sign in to comment.