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"
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 Helper function to interpolate multiple field values at a particle position
20  *
21  * This function interpolates values from multiple field arrays at a particle's position
22  * using the cloud-in-cell (CIC) interpolation method. It supports both periodic and
23  * non-periodic z-boundaries.
24  *
25  * @tparam ParticleType The type of particle
26  * @param p The particle
27  * @param plo The domain lower bounds
28  * @param dxi The inverse of cell spacing
29  * @param field_arrays Array of field arrays to interpolate from
30  * @param result_values Output array to store interpolated values
31  * @param num_fields Number of fields to interpolate
32  * @param is_periodic_z Whether the z-boundary is periodic
33  * @param zheight Height field array (only used for non-periodic z-boundary)
34  */
35 template <typename ParticleType>
36 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
38  const ParticleType& p,
39  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& plo,
40  const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& dxi,
41  const amrex::Array4<const amrex::Real>* field_arrays,
42  amrex::ParticleReal* result_values,
43  int num_fields,
44  int is_periodic_z = 1,
45  const amrex::Array4<amrex::Real>* zheight = nullptr
46 ) {
47  // Iterate over each field and interpolate its value at the particle position
48  for (int i = 0; i < num_fields; ++i) {
49  if (is_periodic_z != 0) {
50  cic_interpolate(p, plo, dxi, field_arrays[i], &result_values[i], 1);
51  } else {
52  cic_interpolate_mapped_z(p, plo, dxi, field_arrays[i], *zheight, &result_values[i], 1);
53  }
54  }
55 }
56 
57 } // namespace Interpolation
58 } // namespace ERF
59 
60 #endif // ERF_INTERPOLATION_UTILS_H
Real * p
Definition: ERF_InitCustomPert_SquallLine.H:61
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, int is_periodic_z=1, const amrex::Array4< amrex::Real > *zheight=nullptr)
Helper function to interpolate multiple field values at a particle position.
Definition: ERF_InterpolationUtils.H:37
Definition: ERF_InterpolationUtils.H:15