11 #ifndef ERF_BUILDINGS_IF_H_
12 #define ERF_BUILDINGS_IF_H_
14 #include <AMReX_EB_STL_utils.H>
15 #include <AMReX_Geometry.H>
16 #include <AMReX_MultiFab.H>
17 #include <AMReX_FArrayBox.H>
18 #include <AMReX_BoxArray.H>
19 #include <AMReX_BoxList.H>
20 #include <AMReX_DistributionMapping.H>
61 amrex::Array<amrex::Real, 3>
const& center,
63 amrex::Geometry
const& geom)
66 using namespace amrex;
71 m_stl_tools.read_stl_file(stl_file, scale, center, reverse_normal);
76 Box
const& domain = geom.Domain();
79 Box sampled_box = domain;
80 sampled_box.grow(ngrow_vec);
84 BoxArray ba(sampled_box);
86 DistributionMapping dm(ba);
90 MultiFab mf_distributed(ba, dm, 1, ngrow_vec);
95 m_stl_tools.fillSignedDistance(mf_distributed, ngrow_vec, geom);
101 int nprocs = ParallelDescriptor::NProcs();
102 Vector<Box> boxes(nprocs, sampled_box);
104 for (
const auto& bx : boxes) {
107 BoxArray ba_replicated(std::move(bl));
110 Vector<int> pmap(nprocs);
111 std::iota(pmap.begin(), pmap.end(), 0);
112 DistributionMapping dm_replicated(std::move(pmap));
115 m_levelset_mf = std::make_shared<MultiFab>(ba_replicated, dm_replicated, 1, 0);
120 IntVect dst_nghost(0);
121 m_levelset_mf->ParallelCopy(mf_distributed, 0, 0, 1, ngrow_vec, dst_nghost);
127 const Real* problo_ptr = geom.ProbLo();
128 const Real* dx_ptr = geom.CellSize();
129 for (
int d = 0; d < AMREX_SPACEDIM; ++d) {
157 AMREX_GPU_HOST_DEVICE
inline
162 using namespace amrex;
170 int i =
static_cast<int>(std::floor(i_real));
171 int j =
static_cast<int>(std::floor(j_real));
172 int k =
static_cast<int>(std::floor(k_real));
175 if (!
m_data_box.contains(IntVect(AMREX_D_DECL(i, j, k))) ||
176 !
m_data_box.contains(IntVect(AMREX_D_DECL(i + 1, j + 1, k + 1)))) {
182 Real wx = i_real -
static_cast<Real>(i);
183 Real wy = j_real -
static_cast<Real>(j);
184 Real wz = k_real -
static_cast<Real>(k);
190 Real phi_000 = arr(i, j, k);
191 Real phi_100 = arr(i + 1, j, k);
192 Real phi_010 = arr(i, j + 1, k);
193 Real phi_110 = arr(i + 1, j + 1, k);
194 Real phi_001 = arr(i, j, k + 1);
195 Real phi_101 = arr(i + 1, j, k + 1);
196 Real phi_011 = arr(i, j + 1, k + 1);
197 Real phi_111 = arr(i + 1, j + 1, k + 1);
199 Real phi_00 = phi_000 * (1.0 - wx) + phi_100 * wx;
200 Real phi_01 = phi_001 * (1.0 - wx) + phi_101 * wx;
201 Real phi_10 = phi_010 * (1.0 - wx) + phi_110 * wx;
202 Real phi_11 = phi_011 * (1.0 - wx) + phi_111 * wx;
204 Real phi_0 = phi_00 * (1.0 - wy) + phi_10 * wy;
205 Real phi_1 = phi_01 * (1.0 - wy) + phi_11 * wy;
207 Real phi = phi_0 * (1.0 - wz) + phi_1 * wz;
218 AMREX_GPU_HOST_DEVICE
inline
238 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>
m_problo;
239 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>
m_dx;
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Buildings implicit function backed by STL triangle mesh.
Definition: ERF_EBIFBuildings.H:42
AMREX_GPU_HOST_DEVICE amrex::Real operator()(const amrex::RealArray &p) const noexcept
Evaluate signed distance at a point array.
Definition: ERF_EBIFBuildings.H:219
amrex::Box m_data_box
Bounding box of sampled data.
Definition: ERF_EBIFBuildings.H:235
amrex::Array4< const amrex::Real > m_local_array
Local array view for GPU-compatible operator() access.
Definition: ERF_EBIFBuildings.H:242
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_problo
Cached geometry data for GPU-compatible access.
Definition: ERF_EBIFBuildings.H:238
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:59
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_dx
Definition: ERF_EBIFBuildings.H:239
amrex::STLtools m_stl_tools
STL tools object (for loading and processing STL files)
Definition: ERF_EBIFBuildings.H:229
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:158
amrex::Geometry m_geom
Domain geometry (for coordinate transformations)
Definition: ERF_EBIFBuildings.H:226
std::shared_ptr< amrex::MultiFab > m_levelset_mf
Pre-sampled signed distance field (distributed MultiFab for parallel computation)
Definition: ERF_EBIFBuildings.H:232
@ p
Definition: ERF_WSM6.H:280
Definition: ERF_ConsoleIO.cpp:15