ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InterpolationUtils.H
Go to the documentation of this file.
1 #ifndef ERF_INTERPOLATION_UTILS_H
2 #define ERF_INTERPOLATION_UTILS_H
3 
4 #include <AMReX_FArrayBox.H>
5 #include <AMReX_GpuContainers.H>
6 #include <AMReX_REAL.H>
7 #include <AMReX_Array4.H>
9 
10 /**
11  * @file ERF_InterpolationUtils.H
12  * @brief Utility functions for field interpolation at particle positions
13  */
14 
15 namespace ERF {
16 namespace Interpolation {
17 
18 /**
19  * @brief Interpolate multiple field values at a particle position using CIC.
20  */
21 template <typename ParticleType>
22 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
24  const ParticleType& p,
25  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& plo,
26  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& dxi,
27  const amrex::Array4<const amrex::Real>* field_arrays,
28  amrex::ParticleReal* result_values,
29  int num_fields
30 ) {
31  for (int i = 0; i < num_fields; ++i) {
32  cic_interpolate(p, plo, dxi, field_arrays[i], &result_values[i], 1);
33  }
34 }
35 
36 /**
37  * @brief Test whether a particle's vertical CIC stencil reads past the local
38  * fab. cic_interpolate reads cell-centered data at k0+1 and k0+2 with
39  * k0 in {pk-1, pk}, so the maximum read offset is pk+2. Returns true
40  * if the stencil is out of bounds and the caller should skip the
41  * particle.
42  */
43 template <typename ParticleType, typename Array4Type>
44 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
46  const ParticleType& p,
47  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& plo,
48  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& dxi,
49  const Array4Type& zheight
50 ) noexcept
51 {
52  const int pk = int(amrex::Math::floor((p.pos(AMREX_SPACEDIM-1) - plo[AMREX_SPACEDIM-1])
53  * dxi[AMREX_SPACEDIM-1]));
54  return (pk < zheight.begin[2] || pk + 2 >= zheight.end[2]);
55 }
56 
57 } // namespace Interpolation
58 } // namespace ERF
59 
60 #endif // ERF_INTERPOLATION_UTILS_H
AMREX_GPU_DEVICE AMREX_FORCE_INLINE bool stencilOutOfBoundsZ(const ParticleType &p, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &plo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxi, const Array4Type &zheight) noexcept
Test whether a particle's vertical CIC stencil reads past the local fab. cic_interpolate reads cell-c...
Definition: ERF_InterpolationUtils.H:45
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void interpolateFields(const ParticleType &p, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &plo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxi, const amrex::Array4< const amrex::Real > *field_arrays, amrex::ParticleReal *result_values, int num_fields)
Interpolate multiple field values at a particle position using CIC.
Definition: ERF_InterpolationUtils.H:23
Definition: ERF_InterpolationUtils.H:15
@ p
Definition: ERF_WSM6.H:280