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  Kokkos::View<double*,Kokkos::LayoutRight,Device> rc;
27  Kokkos::View<double*,Kokkos::LayoutRight,Device> zc;
28  Kokkos::View<double*,Kokkos::LayoutRight,Device> pc;
29  Kokkos::View<TricubCoeff***,Kokkos::LayoutRight,Device> acoeff_all;
30 
31  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],
32  double &f000) const;
33  static KOKKOS_INLINE_FUNCTION double interp_1d(const double (&coeff1d)[4], double dx);
34  static KOKKOS_INLINE_FUNCTION double slope_1d(const double (&coeff1d)[4], double dx);
35 
36  static KOKKOS_INLINE_FUNCTION double interp_2d(const double (&coeff2d)[4][4], double dx, double dy);
37 
38  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],
39  double &f000, double &f100, double &f010, double &f001) const;
40 
41  public:
42 
43  // Constructor from grid on r,z
44  inline Tricub(const View<double*, HostType>& r, const View<double*, HostType>& z, const View<double*, HostType>& phi, const View<double***, CLayout, HostType>& val);
45 
46  // Create a mirror with a different device type
47  template<class Device2>
48  inline Tricub<Device2> mirror() const{
50  m.nr = nr;
51  m.nz = nz;
52  m.np = np;
53  m.rmin = rmin;
54  m.dr_inv = dr_inv;
55  m.zmin = zmin;
56  m.dz_inv = dz_inv;
57  m.pmin = pmin;
58  m.dp_inv = dp_inv;
59  m.rc = my_mirror_view(rc, Device2());
60  mirror_copy(m.rc, rc);
61  m.zc = my_mirror_view(zc, Device2());
62  mirror_copy(m.zc, zc);
63  m.pc = my_mirror_view(pc, Device2());
64  mirror_copy(m.pc, pc);
65  m.acoeff_all = my_mirror_view(acoeff_all, Device2());
67 
68  return m;
69  }
70 
71  // Default constructor
72  Tricub(){}
73 
74  // Get values
75  KOKKOS_INLINE_FUNCTION void der_zero(double x, double y, double z, double &f000) const;
76 
77  // Get first derivatives
78  KOKKOS_INLINE_FUNCTION void der_one(double x, double y, double z, double &f000, double &f100, double &f010, double &f001) const;
79 };
80 
81 #include "tricub.tpp"
82 
83 #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:26
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:144
Tricub()
Definition: tricub.hpp:72
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:205
static KOKKOS_INLINE_FUNCTION double slope_1d(const double(&coeff1d)[4], double dx)
Definition: tricub.tpp:175
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:27
KOKKOS_INLINE_FUNCTION void der_zero(double x, double y, double z, double &f000) const
Definition: tricub.tpp:109
KOKKOS_INLINE_FUNCTION void der_one(double x, double y, double z, double &f000, double &f100, double &f010, double &f001) const
Definition: tricub.tpp:127
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:166
Kokkos::View< double *, Kokkos::LayoutRight, Device > pc
Array containing the phi coordinates of the grid points.
Definition: tricub.hpp:28
Kokkos::View< TricubCoeff ***, Kokkos::LayoutRight, Device > acoeff_all
The field for interpolation.
Definition: tricub.hpp:29
Definition: tricub.hpp:20
Tricub< Device2 > mirror() const
Definition: tricub.hpp:48
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:185
double dp_inv
Inverse of the cell size.
Definition: tricub.hpp:25