XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
analytic_3dmag.hpp
Go to the documentation of this file.
1 #ifndef ANALYTIC_3D_MAG_HPP
2 #define ANALYTIC_3D_MAG_HPP
3 
4 #include "globals.hpp"
5 #include "equil.hpp"
6 
7 // Provides setup and get psi for an analytic example of psi
8 // get_analytic_psi() will be replaced with bicubic interp eventually
9 
10 namespace{
11 
12 double get_circular_analytic_psi3d(const Equilibrium& equil, double r, double z, double phi){
13  double rp = (r - equil.axis.r)/equil.bounds.get_r_width();
14  double zp = (z - equil.axis.z)/equil.bounds.get_z_width();
15 
16  double phi_factor = 1.0 + 0.1*sin(phi);
17 
18  return (rp*rp + zp*zp)*phi_factor;
19 }
20 
21 // Br = -dpsi/dz / r
22 double get_analytic_Br(const Equilibrium& equil, double r, double z, double phi){
23  double rp = (r - equil.axis.r)/equil.bounds.get_r_width();
24  double zp = (z - equil.axis.z)/equil.bounds.get_z_width();
25 
26  double phi_factor = 1.0 + 0.1*sin(phi);
27 
28  return -2*zp/equil.bounds.get_z_width()*phi_factor/r;
29 }
30 
31 // Bz = dpsi/dr / r
32 double get_analytic_Bz(const Equilibrium& equil, double r, double z, double phi){
33  double rp = (r - equil.axis.r)/equil.bounds.get_r_width();
34  double zp = (z - equil.axis.z)/equil.bounds.get_z_width();
35 
36  double phi_factor = 1.0 + 0.1*sin(phi);
37 
38  return 2*rp/equil.bounds.get_r_width()*phi_factor/r;
39 }
40 
41 double get_analytic_Bphi(const Equilibrium& equil, double r, double z, double phi){
42  double phi_factor = 1.0 + 0.1*cos(phi);
43  return phi_factor;
44 }
45 
46 
47 // Create a psi eq grid based off the analytic psi
48 Kokkos::View<double***, Kokkos::LayoutRight, HostType> analytic_3d_psi_grid(const Equilibrium& equil,
49  const View<double*, HostType>& r,
50  const View<double*, HostType>& z,
51  const View<double*, HostType>& phi){
52 
53  Kokkos::View<double***, Kokkos::LayoutRight, HostType> psi_grid("psi_grid",phi.size(), z.size(), r.size());
54  for (int k=0; k<phi.size(); k++){
55  for (int j=0; j<z.size(); j++){
56  for (int i=0; i<r.size(); i++){
57  psi_grid(k,j,i) = get_circular_analytic_psi3d(equil, r(i), z(j), phi(k));
58  }
59  }
60  }
61  return psi_grid;
62 }
63 
64 // Create a Br eq grid based off the analytic Br
65 Kokkos::View<double***, Kokkos::LayoutRight, HostType> analytic_3d_Br_grid(const Equilibrium& equil,
66  const View<double*, HostType>& r,
67  const View<double*, HostType>& z,
68  const View<double*, HostType>& phi){
69 
70  Kokkos::View<double***, Kokkos::LayoutRight, HostType> Br_grid("Br_grid",phi.size(), z.size(), r.size());
71  for (int k=0; k<phi.size(); k++){
72  for (int j=0; j<z.size(); j++){
73  for (int i=0; i<r.size(); i++){
74  Br_grid(k,j,i) = get_analytic_Br(equil, r(i), z(j), phi(k));
75  }
76  }
77  }
78  return Br_grid;
79 }
80 
81 // Create a Bz eq grid based off the analytic Bz
82 Kokkos::View<double***, Kokkos::LayoutRight, HostType> analytic_3d_Bz_grid(const Equilibrium& equil,
83  const View<double*, HostType>& r,
84  const View<double*, HostType>& z,
85  const View<double*, HostType>& phi){
86 
87  Kokkos::View<double***, Kokkos::LayoutRight, HostType> Bz_grid("Bz_grid",phi.size(), z.size(), r.size());
88  for (int k=0; k<phi.size(); k++){
89  for (int j=0; j<z.size(); j++){
90  for (int i=0; i<r.size(); i++){
91  Bz_grid(k,j,i) = get_analytic_Bz(equil, r(i), z(j), phi(k));
92  }
93  }
94  }
95  return Bz_grid;
96 }
97 
98 // Create a Bphi eq grid based off the analytic Bphi
99 Kokkos::View<double***, Kokkos::LayoutRight, HostType> analytic_3d_Bphi_grid(const Equilibrium& equil,
100  const View<double*, HostType>& r,
101  const View<double*, HostType>& z,
102  const View<double*, HostType>& phi){
103 
104  Kokkos::View<double***, Kokkos::LayoutRight, HostType> Bphi_grid("Bphi_grid",phi.size(), z.size(), r.size());
105  for (int k=0; k<phi.size(); k++){
106  for (int j=0; j<z.size(); j++){
107  for (int i=0; i<r.size(); i++){
108  Bphi_grid(k,j,i) = get_analytic_Bphi(equil, r(i), z(j), phi(k));
109  }
110  }
111  }
112  return Bphi_grid;
113 }
114 
115 
116 }
117 #endif
double z
Definition: grid_structs.hpp:30
RZBounds bounds
Min and max for r and z.
Definition: equil.hpp:80
double r
Definition: grid_structs.hpp:29
KOKKOS_INLINE_FUNCTION double get_z_width() const
Definition: rz_bounds.hpp:28
KOKKOS_INLINE_FUNCTION double get_r_width() const
Definition: rz_bounds.hpp:24
RZPair axis
Definition: equil.hpp:90
Definition: equil.hpp:29