XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
magnetic_field.hpp
Go to the documentation of this file.
1 #ifndef MAGNETIC_FIELD_HPP
2 #define MAGNETIC_FIELD_HPP
3 #include "equil.hpp"
4 #include "bicub.hpp"
5 #include "cub_interp.hpp"
6 
7 // Magnetic field class
8 template<class Device>
9 class MagneticField {
10 
11  KOKKOS_INLINE_FUNCTION void derivs(const double (&x)[2],double phi,double (&dx)[2]) const;
12 
13  public:
14 
15  // Field variables
16  double bt_sign;
17  double bp_sign;
18  int ff_step;
19  int ff_order;
20  double bd_min_r;
21  double bd_max_r;
22  double bd_min_z;
23  double bd_max_z;
24 
25  double inpsi;
26  double outpsi;
27 
28 
29  // Structures inside B-field
33 
34  MagneticField(double bt_sign_in, double bp_sign_in, int ff_step_in, int ff_order_in, double bd_min_r_in, double bd_max_r_in, double bd_min_z_in, double bd_max_z_in, double inpsi_in, double outpsi_in,
35  // Bicub:
36  double *rc_in, double *zc_in, BicubCoeff *acoeff_in, int nr_in, int nz_in, double rmin_in, double zmin_in, double dr_inv_in, double dz_inv_in,
37  // Interp:
38  OneDCoeff *one_d_cub_acoef_in, int ncoeff_in, double max_psi_in, double min_psi_in, double one_d_cub_dpsi_inv_in,
39  // Equil:
40  double eq_min_r, double eq_max_r, double eq_min_z, double eq_max_z,
41  double eq_x_psi, double epsil_psi, double eq_x_r, double eq_x_slope, double eq_x_z,
42  double eq_x2_r, double eq_x2_slope, double eq_x2_z, double eq_x2_psi, double eq_axis_r,
43  double eq_axis_z, int eq_mpsi);
44 
45  // Constructor for analytic test field
47  : inpsi(0.0),
48  outpsi(2.0),
49 
50  bt_sign(-1),
51  bp_sign(1),
52 
53  bd_min_r(0.5),
54  bd_max_r(2.5),
55  bd_min_z(-1.0),
56  bd_max_z(1.0),
57  equil(psi_opt)
58  {}
59 
60  // Default constructor
62 
63  KOKKOS_INLINE_FUNCTION void get_psi(const Simd<double>& r_in,const Simd<double>& z_in,Simd<double>& psi_out) const;
64 
65  KOKKOS_INLINE_FUNCTION double I_value(double psi_in,int rgn3) const;
66 
67  KOKKOS_INLINE_FUNCTION double I_deriv(double psi_in,int rgn3) const;
68 
69  // Get complete B-field info
70  KOKKOS_INLINE_FUNCTION void field(const Simd<double>& fld_r, const Simd<double>& fld_z,
71  SimdVector &bvec, SimdVector (&jacb)[3], Simd<double>& psivec, SimdVector2D &gradpsi, SimdVector &tdb, Simd<bool>& rz_outside) const;
72 
73  KOKKOS_INLINE_FUNCTION void bvec_interpol(double r,double z,double phi,double &br,double &bz,double &bphi) const;
74 
75  KOKKOS_INLINE_FUNCTION void bmag_interpol(const Simd<double>& r, const Simd<double>& z, const Simd<double>& phi,Simd<double>& bmag) const;
76 
77  KOKKOS_INLINE_FUNCTION void follow_field(const SimdVector2D &x_org,const Simd<double>& phi_org, const Simd<double>& phi_dest,SimdVector2D &x_dest) const;
78 };
79 
80 #include "magnetic_field.tpp"
81 #endif
double inpsi
Boundary condition used in a few spots.
Definition: magnetic_field.hpp:25
MagneticField(PsiOption psi_opt)
Definition: magnetic_field.hpp:46
double bd_max_z
Maximum z (of what exactly?)
Definition: magnetic_field.hpp:23
CubInterp< Device > I_interp
The object for interpolating I (for deriving toroidal magnetic field)
Definition: magnetic_field.hpp:31
KOKKOS_INLINE_FUNCTION void bvec_interpol(double r, double z, double phi, double &br, double &bz, double &bphi) const
Definition: magnetic_field.tpp:150
Definition: globals.hpp:59
PsiOption
Definition: equil.hpp:7
KOKKOS_INLINE_FUNCTION void follow_field(const SimdVector2D &x_org, const Simd< double > &phi_org, const Simd< double > &phi_dest, SimdVector2D &x_dest) const
Definition: magnetic_field.tpp:204
KOKKOS_INLINE_FUNCTION void get_psi(const Simd< double > &r_in, const Simd< double > &z_in, Simd< double > &psi_out) const
Definition: magnetic_field.tpp:37
int ff_order
Order of RK scheme used for field following. Can be 1, 2, or 4.
Definition: magnetic_field.hpp:19
KOKKOS_INLINE_FUNCTION void field(const Simd< double > &fld_r, const Simd< double > &fld_z, SimdVector &bvec, SimdVector(&jacb)[3], Simd< double > &psivec, SimdVector2D &gradpsi, SimdVector &tdb, Simd< bool > &rz_outside) const
Definition: magnetic_field.tpp:78
Definition: bicub.hpp:7
Definition: magnetic_field.hpp:9
KOKKOS_INLINE_FUNCTION double I_deriv(double psi_in, int rgn3) const
Definition: magnetic_field.tpp:63
Definition: cub_interp.hpp:11
MagneticField()
Definition: magnetic_field.hpp:61
KOKKOS_INLINE_FUNCTION double I_value(double psi_in, int rgn3) const
Definition: magnetic_field.tpp:52
double bd_min_r
Minimum r (of what exactly?)
Definition: magnetic_field.hpp:20
double outpsi
Boundary condition used in a few spots.
Definition: magnetic_field.hpp:26
double bd_min_z
Minimum z (of what exactly?)
Definition: magnetic_field.hpp:22
double bt_sign
Whether toroidal field is reversed?
Definition: magnetic_field.hpp:16
Definition: bicub.hpp:13
double bp_sign
Whether poloidal field is reversed?
Definition: magnetic_field.hpp:17
Definition: cub_interp.hpp:6
Equilibrium< Device > equil
The object containing information about the magnetic equilibrium.
Definition: magnetic_field.hpp:32
Definition: globals.hpp:54
Bicub< Device > psi_bicub
The object for interpolating psi (magnetic flux surfaces)
Definition: magnetic_field.hpp:30
int ff_step
Number of steps taken when projecting the particle location onto the midplane.
Definition: magnetic_field.hpp:18
KOKKOS_INLINE_FUNCTION void derivs(const double(&x)[2], double phi, double(&dx)[2]) const
Definition: magnetic_field.tpp:318
Definition: equil.hpp:14
KOKKOS_INLINE_FUNCTION void bmag_interpol(const Simd< double > &r, const Simd< double > &z, const Simd< double > &phi, Simd< double > &bmag) const
Definition: magnetic_field.tpp:187
double bd_max_r
Maximum r (of what exactly?)
Definition: magnetic_field.hpp:21