XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bicub.hpp
Go to the documentation of this file.
1 #ifndef BICUB_HPP
2 #define BICUB_HPP
3 #include "space_settings.hpp"
4 #include "simd.hpp"
5 #include "my_mirror_view.hpp"
6 
7 // The dimensions of this were (0:ndeg, 0:ndeg) - hardcoded to (4,4) here
8 struct BicubCoeff {
9  double coeff[4][4];
10 };
11 
12 // Bicubic spline class
13 template<class Device>
14 class Bicub {
15  // This line enables private access between the host and device implementations of this class
16  // i.e. Makes the copy from host to device more straightforward
17  template<class Device2> friend class Bicub;
18 
19  // bicub variables
20  int nr, nz;
21  double rmin, zmin;
22  double dr_inv, dz_inv;
23  Kokkos::View<double*,Kokkos::LayoutRight,Device> rc;
24  Kokkos::View<double*,Kokkos::LayoutRight,Device> zc;
25  Kokkos::View<BicubCoeff**,Kokkos::LayoutRight,Device> acoeff_all;
26 
27  // Compute value
28  KOKKOS_INLINE_FUNCTION void eval_bicub_0(double x, double y, double xc, double yc, const double (&acoeff)[4][4],
29  double &f00) const;
30 
31  // Compute first derivatives
32  KOKKOS_INLINE_FUNCTION void eval_bicub_1(double x, double y, double xc, double yc, const double (&acoeff)[4][4],
33  double &f00, double &f10, double &f01) const;
34 
35  // Compute first and second derivatives
36  KOKKOS_INLINE_FUNCTION void eval_bicub_2(double x, double y, double xc, double yc, const double (&acoeff)[4][4],
37  double &f00, double &f10, double &f01,
38  double &f11, double &f20, double &f02) const;
39 
40  public:
41 
42  // Constructor
43  Bicub(double *rc_in, double *zc_in, BicubCoeff *acoeff_in, int nr_in, int nz_in,
44  double rmin_in, double zmin_in, double dr_inv_in, double dz_inv_in);
45 
46  // Constructor from grid on r,z
47  inline Bicub(const View<double*, HostType>& r, const View<double*, HostType>& z, const View<double**, CLayout, HostType>& val);
48 
49  // Create a mirror with a different device type
50  template<class Device2>
51  inline Bicub<Device2> mirror() const{
53  m.nr = nr;
54  m.nz = nz;
55  m.rmin = rmin;
56  m.dr_inv = dr_inv;
57  m.zmin = zmin;
58  m.dz_inv = dz_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.acoeff_all = my_mirror_view(acoeff_all, Device2());
65 
66  return m;
67  }
68 
69  // Default constructor
70  Bicub(){}
71 
72  // Get values
73  KOKKOS_INLINE_FUNCTION void der_zero(double x, double y, double &f00) const;
74 
75  // Get first derivatives
76  KOKKOS_INLINE_FUNCTION void der_one(double x, double y, double &f00, double &f10, double &f01) const;
77 
78  // Get first and second derivatives
79  KOKKOS_INLINE_FUNCTION void der_all(double x, double y, double &f00, double &f10, double &f01,
80  double &f11, double &f20, double &f02) const;
81 };
82 
83 #include "bicub.tpp"
84 
85 #endif
double zmin
First r and z point.
Definition: bicub.hpp:21
void mirror_copy(T1 &view_dest, const T2 &view_src)
Definition: my_mirror_view.hpp:122
KOKKOS_INLINE_FUNCTION void der_zero(double x, double y, double &f00) const
Definition: bicub.tpp:111
KOKKOS_INLINE_FUNCTION void der_all(double x, double y, double &f00, double &f10, double &f01, double &f11, double &f20, double &f02) const
Definition: bicub.tpp:144
Definition: bicub.hpp:8
KOKKOS_INLINE_FUNCTION void eval_bicub_0(double x, double y, double xc, double yc, const double(&acoeff)[4][4], double &f00) const
Definition: bicub.tpp:161
Kokkos::View< double *, Kokkos::LayoutRight, Device > rc
Array containing the r coordinates of the grid points.
Definition: bicub.hpp:23
Bicub()
Definition: bicub.hpp:70
int nz
Number of points in r and z directions.
Definition: bicub.hpp:20
KOKKOS_INLINE_FUNCTION void eval_bicub_1(double x, double y, double xc, double yc, const double(&acoeff)[4][4], double &f00, double &f10, double &f01) const
Definition: bicub.tpp:192
Kokkos::View< double *, Kokkos::LayoutRight, Device > zc
Array containing the z coordinates of the grid points.
Definition: bicub.hpp:24
Bicub< Device2 > mirror() const
Definition: bicub.hpp:51
Definition: bicub.hpp:14
double coeff[4][4]
Definition: bicub.hpp:9
double dr_inv
Definition: bicub.hpp:22
KOKKOS_INLINE_FUNCTION void eval_bicub_2(double x, double y, double xc, double yc, const double(&acoeff)[4][4], double &f00, double &f10, double &f01, double &f11, double &f20, double &f02) const
Definition: bicub.tpp:248
double rmin
Definition: bicub.hpp:21
View< T *, CLayout, Device > my_mirror_view(const View< T *, CLayout, Device > &view, Device nd)
Definition: my_mirror_view.hpp:14
int nr
Definition: bicub.hpp:20
double dz_inv
Inverse of the cell size.
Definition: bicub.hpp:22
KOKKOS_INLINE_FUNCTION void der_one(double x, double y, double &f00, double &f10, double &f01) const
Definition: bicub.tpp:126
Kokkos::View< BicubCoeff **, Kokkos::LayoutRight, Device > acoeff_all
The field for interpolation.
Definition: bicub.hpp:25