ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
BuildingsLevelsetIF Class Reference

Non-owning, GPU-copyable evaluator of the sampled buildings levelset. More...

#include <ERF_EBIFBuildings.H>

Inheritance diagram for BuildingsLevelsetIF:
Collaboration diagram for BuildingsLevelsetIF:

Public Member Functions

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. More...
 
AMREX_GPU_HOST_DEVICE amrex::Real operator() (const amrex::RealArray &p) const noexcept
 Evaluate signed distance at a point array. More...
 

Private Attributes

amrex::Box m_data_box
 Bounding box of sampled data. More...
 
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_problo
 Cached geometry data for GPU-compatible access. More...
 
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_dx
 
amrex::Array4< const amrex::Real > m_local_array
 Local array view for GPU-compatible operator() access. More...
 

Friends

class BuildingsIF
 

Detailed Description

Non-owning, GPU-copyable evaluator of the sampled buildings levelset.

BuildingsIF owns the data. Copies of this functor only copy its array view, bounds and grid spacing, so GeometryShop can capture it in device kernels.

Member Function Documentation

◆ operator()() [1/2]

AMREX_GPU_HOST_DEVICE amrex::Real BuildingsLevelsetIF::operator() ( AMREX_D_DECL(amrex::Real x, amrex::Real y, amrex::Real z)  ) const
inlinenoexcept

Evaluate signed distance at a point.

Parameters
xPhysical x-coordinate [m]
yPhysical y-coordinate [m]
zPhysical z-coordinate [m]
Returns
Signed distance value: >0 inside building, <0 in fluid, =0 at boundary.

This operator performs trilinear interpolation of the pre-sampled signed distance field. For points outside the sampled domain, it returns a negative value (fluid region).

Note: The signed distance field is computed in parallel across ranks during construction, then replicated for fast operator() access.

58  {
59  using namespace amrex;
60 
61  // fillSignedDistance samples at prob_lo + (index + 0.5) * dx.
62  // Convert physical coordinates to continuous cell-centered indices.
63  Real i_real = (x - m_problo[0]) / m_dx[0] - 0.5;
64  Real j_real = (y - m_problo[1]) / m_dx[1] - 0.5;
65  Real k_real = (z - m_problo[2]) / m_dx[2] - 0.5;
66 
67  // Get integer cell indices
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));
71 
72  // Check if point is within data bounds
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)))) {
75  // Outside sampled region - assume fluid (negative distance)
76  return -1.0;
77  }
78 
79  // Trilinear interpolation weights
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);
83 
84  // Access replicated levelset data
85  auto const& arr = m_local_array;
86 
87  // Trilinear interpolation
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);
96 
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;
101 
102  Real phi_0 = phi_00 * (1.0 - wy) + phi_10 * wy;
103  Real phi_1 = phi_01 * (1.0 - wy) + phi_11 * wy;
104 
105  Real phi = phi_0 * (1.0 - wz) + phi_1 * wz;
106 
107  // fillSignedDistance has the opposite sign to STLtools::fillFab,
108  // including with reversed normals. Match EB: positive solid, negative fluid.
109  return -phi;
110  }
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
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

Referenced by operator()().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator()() [2/2]

AMREX_GPU_HOST_DEVICE amrex::Real BuildingsLevelsetIF::operator() ( const amrex::RealArray &  p) const
inlinenoexcept

Evaluate signed distance at a point array.

Parameters
pPhysical coordinate array [x, y, z] in meters.
Returns
Signed distance value.
120  {
121  return this->operator()(AMREX_D_DECL(p[0], p[1], p[2]));
122  }
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
Here is the call graph for this function:

Friends And Related Function Documentation

◆ BuildingsIF

friend class BuildingsIF
friend

Member Data Documentation

◆ m_data_box

amrex::Box BuildingsLevelsetIF::m_data_box
private

Bounding box of sampled data.

Referenced by operator()().

◆ m_dx

amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> BuildingsLevelsetIF::m_dx
private

Referenced by operator()().

◆ m_local_array

amrex::Array4<const amrex::Real> BuildingsLevelsetIF::m_local_array
private

Local array view for GPU-compatible operator() access.

Referenced by operator()().

◆ m_problo

amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> BuildingsLevelsetIF::m_problo
private

Cached geometry data for GPU-compatible access.

Referenced by operator()().


The documentation for this class was generated from the following file: