XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tricub.hpp
Go to the documentation of this file.
1 #ifndef TRICUB_HPP
2 #define TRICUB_HPP
3 #include "space_settings.hpp"
4 #include "simd.hpp"
5 #include "my_mirror_view.hpp"
6 
7 struct TricubCoeff {
8  double coeff[4][4][4];
9 };
10 
11 // Tricubic spline class
12 template<class Device>
13 class Tricub {
14  // This line enables private access between the host and device implementations of this class
15  // i.e. Makes the copy from host to device more straightforward
16  template<class Device2> friend class Tricub;
17 
18  // enums to read indices more easily
19  enum{ J0 = 0, J1 = 1, J2 = 2, J3 = 3 };
20  enum{ K0 = 0, K1 = 1, K2 = 2, K3 = 3 };
21 
22  // bicub variables
23  int nr, nz, np;
24  double rmin, zmin, pmin;
25  double dr_inv, dz_inv, dp_inv;
26  double dp; // Needed for modulo
27  Kokkos::View<double*,Kokkos::LayoutRight,Device> rc;
28  Kokkos::View<double*,Kokkos::LayoutRight,Device> zc;
29  Kokkos::View<double*,Kokkos::LayoutRight,Device> pc;
30  Kokkos::View<TricubCoeff***,Kokkos::LayoutRight,Device> acoeff_all;
31 
32  KOKKOS_INLINE_FUNCTION void eval_tricub_0(double x, double y, double z, double xc, double yc, double zc, const double (&acoeff)[4][4][4],
33  double &f000) const;
34  static KOKKOS_INLINE_FUNCTION double interp_1d(const double (&coeff1d)[4], double dx);
35  static KOKKOS_INLINE_FUNCTION double slope_1d(const double (&coeff1d)[4], double dx);
36 
37  static KOKKOS_INLINE_FUNCTION double interp_2d(const double (&coeff2d)[4][4], double dx, double dy);
38 
39  KOKKOS_INLINE_FUNCTION void eval_tricub_1(double x, double y, double z, double xc, double yc, double zc, const double (&acoeff)[4][4][4],
40  double &f000, double &f100, double &f010, double &f001) const;
41 
42  public:
43 
44  // Constructor from grid on r,z
45  Tricub(const View<double*, HostType>& r, const View<double*, HostType>& z, const View<double*, HostType>& phi, const View<double***, CLayout, HostType>& val, bool keep_positive=false);
46 
47  // Create a mirror with a different device type
48  template<class Device2>
49  inline Tricub<Device2> mirror() const{
51  m.nr = nr;
52  m.nz = nz;
53  m.np = np;
54  m.rmin = rmin;
55  m.dr_inv = dr_inv;
56  m.zmin = zmin;
57  m.dz_inv = dz_inv;
58  m.pmin = pmin;
59  m.dp_inv = dp_inv;
60  m.dp = dp;
61  m.rc = my_mirror_view(rc, Device2());
62  mirror_copy(m.rc, rc);
63  m.zc = my_mirror_view(zc, Device2());
64  mirror_copy(m.zc, zc);
65  m.pc = my_mirror_view(pc, Device2());
66  mirror_copy(m.pc, pc);
67  m.acoeff_all = my_mirror_view(acoeff_all, Device2());
69 
70  return m;
71  }
72 
73  // Default constructor
74  Tricub(){}
75 
76  // Get values
77  KOKKOS_INLINE_FUNCTION void der_zero(double x, double y, double z, double &f000) const;
78 
79  // Get first derivatives
80  KOKKOS_INLINE_FUNCTION void der_one(double x, double y, double z, double &f000, double &f100, double &f010, double &f001) const;
81 };
82 
83 #include "tricub.tpp"
84 
85 #endif
Definition: tricub.hpp:13
double rmin
Definition: tricub.hpp:24
void mirror_copy(T1 &view_dest, const T2 &view_src)
Definition: my_mirror_view.hpp:122
Kokkos::View< double *, Kokkos::LayoutRight, Device > rc
Array containing the r coordinates of the grid points.
Definition: tricub.hpp:27
double coeff[4][4][4]
Definition: tricub.hpp:8
Definition: tricub.hpp:19
KOKKOS_INLINE_FUNCTION void eval_tricub_0(double x, double y, double z, double xc, double yc, double zc, const double(&acoeff)[4][4][4], double &f000) const
Definition: tricub.tpp:66
Tricub()
Definition: tricub.hpp:74
double pmin
First r and z point.
Definition: tricub.hpp:24
KOKKOS_INLINE_FUNCTION void eval_tricub_1(double x, double y, double z, double xc, double yc, double zc, const double(&acoeff)[4][4][4], double &f000, double &f100, double &f010, double &f001) const
Definition: tricub.tpp:127
static KOKKOS_INLINE_FUNCTION double slope_1d(const double(&coeff1d)[4], double dx)
Definition: tricub.tpp:97
double zmin
Definition: tricub.hpp:24
Kokkos::View< double *, Kokkos::LayoutRight, Device > zc
Array containing the z coordinates of the grid points.
Definition: tricub.hpp:28
KOKKOS_INLINE_FUNCTION void der_zero(double x, double y, double z, double &f000) const
Definition: tricub.tpp:27
KOKKOS_INLINE_FUNCTION void der_one(double x, double y, double z, double &f000, double &f100, double &f010, double &f001) const
Definition: tricub.tpp:47
Definition: tricub.hpp:19
int nz
Definition: tricub.hpp:23
Definition: tricub.hpp:20
static KOKKOS_INLINE_FUNCTION double interp_1d(const double(&coeff1d)[4], double dx)
Definition: tricub.tpp:88
double dp
Definition: tricub.hpp:26
Kokkos::View< double *, Kokkos::LayoutRight, Device > pc
Array containing the phi coordinates of the grid points.
Definition: tricub.hpp:29
Kokkos::View< TricubCoeff ***, Kokkos::LayoutRight, Device > acoeff_all
The field for interpolation.
Definition: tricub.hpp:30
Definition: tricub.hpp:20
Tricub< Device2 > mirror() const
Definition: tricub.hpp:49
Definition: tricub.hpp:20
View< T *, CLayout, Device > my_mirror_view(const View< T *, CLayout, Device > &view, Device nd)
Definition: my_mirror_view.hpp:14
Definition: tricub.hpp:7
Definition: tricub.hpp:19
double dr_inv
Definition: tricub.hpp:25
double dz_inv
Definition: tricub.hpp:25
Definition: tricub.hpp:19
int np
Number of points in r and z directions.
Definition: tricub.hpp:23
Definition: tricub.hpp:20
int nr
Definition: tricub.hpp:23
static KOKKOS_INLINE_FUNCTION double interp_2d(const double(&coeff2d)[4][4], double dx, double dy)
Definition: tricub.tpp:107
double dp_inv
Inverse of the cell size.
Definition: tricub.hpp:25