WarpX
LinearInterpolation.H
Go to the documentation of this file.
1 /* Copyright 2022 Luca Fedeli
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef WARPX_UTILS_ALGORITHMS_LINEAR_INTERPOLATION_H_
9 #define WARPX_UTILS_ALGORITHMS_LINEAR_INTERPOLATION_H_
10 
11 #include <AMReX_Extension.H>
12 #include <AMReX_GpuQualifiers.H>
13 
14 namespace utils::algorithms
15 {
21  template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE
22  T linear_interp(T x0, T x1, T f0, T f1, T x)
23  {
24  return ((x1-x)*f0 + (x-x0)*f1)/(x1-x0);
25  }
26 
32  template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE
33  T bilinear_interp(T x0, T x1, T y0, T y1, T f00, T f01, T f10, T f11, T x, T y)
34  {
35  const T fx0 = linear_interp(x0, x1, f00, f10, x);
36  const T fx1 = linear_interp(x0, x1, f01, f11, x);
37  return linear_interp(y0, y1, fx0, fx1, y);
38  }
39 
46  template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE
47  T trilinear_interp(T x0, T x1,T y0, T y1, T z0, T z1,
48  T f000, T f001, T f010, T f011, T f100, T f101, T f110, T f111,
49  T x, T y, T z)
50  {
51  const T fxy0 = bilinear_interp(
52  x0, x1, y0, y1, f000, f010, f100, f110, x, y);
53  const T fxy1 = bilinear_interp(
54  x0, x1, y0, y1, f001, f011, f101, f111, x, y);
55  return linear_interp(z0, z1, fxy0, fxy1, z);
56  }
57 }
58 
59 #endif //WARPX_UTILS_ALGORITHMS_LINEAR_INTERPOLATION_H_
list y1
Definition: plot_particle_path.py:131
def x
Definition: read_lab_particles.py:26
AMREX_GPU_DEVICE AMREX_FORCE_INLINE T trilinear_interp(T x0, T x1, T y0, T y1, T z0, T z1, T f000, T f001, T f010, T f011, T f100, T f101, T f110, T f111, T x, T y, T z)
Performs a trilinear interpolation.
Definition: LinearInterpolation.H:47
Definition: IsIn.H:15
def z
Definition: read_lab_particles.py:27
#define AMREX_FORCE_INLINE
#define AMREX_GPU_DEVICE
list y0
Definition: plot_particle_path.py:129
AMREX_GPU_DEVICE AMREX_FORCE_INLINE T bilinear_interp(T x0, T x1, T y0, T y1, T f00, T f01, T f10, T f11, T x, T y)
Performs a bilinear interpolation.
Definition: LinearInterpolation.H:33
list x0
Definition: plot_particle_path.py:128
list x1
Definition: plot_particle_path.py:130
AMREX_GPU_DEVICE AMREX_FORCE_INLINE T linear_interp(T x0, T x1, T f0, T f1, T x)
Performs a linear interpolation.
Definition: LinearInterpolation.H:22