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