12 #ifndef ERF_BUILDINGS_IF_H_
13 #define ERF_BUILDINGS_IF_H_
15 #include <AMReX_EB_STL_utils.H>
16 #include <AMReX_EB2_IF_Base.H>
17 #include <AMReX_Geometry.H>
18 #include <AMReX_MultiFab.H>
19 #include <AMReX_FArrayBox.H>
20 #include <AMReX_BoxArray.H>
21 #include <AMReX_BoxList.H>
22 #include <AMReX_DistributionMapping.H>
25 #include <type_traits>
54 AMREX_GPU_HOST_DEVICE
inline
57 amrex::Real
z))
const noexcept
59 using namespace amrex;
68 int i =
static_cast<int>(std::floor(i_real));
69 int j =
static_cast<int>(std::floor(j_real));
70 int k =
static_cast<int>(std::floor(k_real));
73 if (!
m_data_box.contains(IntVect(AMREX_D_DECL(i, j, k))) ||
74 !
m_data_box.contains(IntVect(AMREX_D_DECL(i + 1, j + 1, k + 1)))) {
80 Real wx = i_real -
static_cast<Real
>(i);
81 Real wy = j_real -
static_cast<Real
>(j);
82 Real wz = k_real -
static_cast<Real
>(k);
88 Real phi_000 = arr(i, j, k);
89 Real phi_100 = arr(i + 1, j, k);
90 Real phi_010 = arr(i, j + 1, k);
91 Real phi_110 = arr(i + 1, j + 1, k);
92 Real phi_001 = arr(i, j, k + 1);
93 Real phi_101 = arr(i + 1, j, k + 1);
94 Real phi_011 = arr(i, j + 1, k + 1);
95 Real phi_111 = arr(i + 1, j + 1, k + 1);
97 Real phi_00 = phi_000 * (1.0 - wx) + phi_100 * wx;
98 Real phi_01 = phi_001 * (1.0 - wx) + phi_101 * wx;
99 Real phi_10 = phi_010 * (1.0 - wx) + phi_110 * wx;
100 Real phi_11 = phi_011 * (1.0 - wx) + phi_111 * wx;
102 Real phi_0 = phi_00 * (1.0 - wy) + phi_10 * wy;
103 Real phi_1 = phi_01 * (1.0 - wy) + phi_11 * wy;
105 Real
phi = phi_0 * (1.0 - wz) + phi_1 * wz;
118 AMREX_GPU_HOST_DEVICE
inline
131 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>
m_problo;
132 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>
m_dx;
138 static_assert(std::is_trivially_copyable_v<BuildingsLevelsetIF>,
139 "The buildings evaluator must be copyable into GPU kernels");
176 amrex::Array<amrex::Real, 3>
const& center,
178 amrex::Geometry
const& geom)
181 using namespace amrex;
185 m_stl_tools.setBVHOptimization(
true);
186 m_stl_tools.read_stl_file(stl_file, scale, center, reverse_normal);
191 Box
const& domain = geom.Domain();
192 IntVect ngrow_vec(2);
194 Box sampled_box = domain;
195 sampled_box.grow(ngrow_vec);
199 BoxArray ba(sampled_box);
201 DistributionMapping dm(ba);
205 MultiFab mf_distributed(ba, dm, 1, ngrow_vec);
210 m_stl_tools.fillSignedDistance(mf_distributed, ngrow_vec, geom);
216 int nprocs = ParallelDescriptor::NProcs();
217 Vector<Box> boxes(nprocs, sampled_box);
219 for (
const auto& bx : boxes) {
222 BoxArray ba_replicated(std::move(bl));
225 Vector<int> pmap(nprocs);
226 std::iota(pmap.begin(), pmap.end(), 0);
227 DistributionMapping dm_replicated(std::move(pmap));
230 m_levelset_mf = std::make_shared<MultiFab>(ba_replicated, dm_replicated, 1, 0);
235 IntVect dst_nghost(0);
236 m_levelset_mf->ParallelCopy(mf_distributed, 0, 0, 1, ngrow_vec, dst_nghost);
239 m_if.m_data_box = sampled_box;
242 const Real* problo_ptr = geom.ProbLo();
243 const Real* dx_ptr = geom.CellSize();
244 for (
int d = 0; d < AMREX_SPACEDIM; ++d) {
245 m_if.m_problo[d] = problo_ptr[d];
246 m_if.m_dx[d] = dx_ptr[d];
251 for (MFIter mfi(*m_levelset_mf); mfi.isValid(); ++mfi) {
252 m_if.m_local_array = (*m_levelset_mf)[mfi].const_array();
276 std::shared_ptr<
amrex::MultiFab> m_levelset_mf;
Buildings implicit function backed by STL triangle mesh.
Definition: ERF_EBIFBuildings.H:157
BuildingsLevelsetIF getIF() const &noexcept
Return the GPU-copyable evaluator for the sampled levelset.
Definition: ERF_EBIFBuildings.H:265
BuildingsIF(std::string const &stl_file, amrex::Real scale, amrex::Array< amrex::Real, 3 > const ¢er, int reverse_normal, amrex::Geometry const &geom)
Construct a buildings implicit function from an STL file.
Definition: ERF_EBIFBuildings.H:174
BuildingsLevelsetIF getIF() const &&=delete
Non-owning, GPU-copyable evaluator of the sampled buildings levelset.
Definition: ERF_EBIFBuildings.H:37
amrex::Array4< const amrex::Real > m_local_array
Local array view for GPU-compatible operator() access.
Definition: ERF_EBIFBuildings.H:135
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_problo
Cached geometry data for GPU-compatible access.
Definition: ERF_EBIFBuildings.H:131
amrex::Box m_data_box
Bounding box of sampled data.
Definition: ERF_EBIFBuildings.H:128
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_dx
Definition: ERF_EBIFBuildings.H:132
AMREX_GPU_HOST_DEVICE amrex::Real operator()(AMREX_D_DECL(amrex::Real x, amrex::Real y, amrex::Real z)) const noexcept
Evaluate signed distance at a point.
Definition: ERF_EBIFBuildings.H:55
@ p
Definition: ERF_WSM6.H:303
Definition: ERF_ConsoleIO.cpp:17
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real phi(amrex::Real d, amrex::Real z0, amrex::Real psi) noexcept
Definition: ERF_ImmersedWallCell.H:176