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 double get_analytic_dpsidr(const Equilibrium& equil, double r, double z, double phi){
22  double rp = (r - equil.axis.r)/equil.bounds.get_r_width();
23  double zp = (z - equil.axis.z)/equil.bounds.get_z_width();
24 
25  double phi_factor = 1.0 + 0.1*sin(phi);
26 
27  return 2*rp/equil.bounds.get_r_width()*phi_factor;
28 }
29 
30 double get_analytic_dpsidz(const Equilibrium& equil, double r, double z, double phi){
31  double rp = (r - equil.axis.r)/equil.bounds.get_r_width();
32  double zp = (z - equil.axis.z)/equil.bounds.get_z_width();
33 
34  double phi_factor = 1.0 + 0.1*sin(phi);
35 
36  return 2*zp/equil.bounds.get_z_width()*phi_factor;
37 }
38 
39 double get_analytic_dpsidphi(const Equilibrium& equil, double r, double z, double phi){
40  double rp = (r - equil.axis.r)/equil.bounds.get_r_width();
41  double zp = (z - equil.axis.z)/equil.bounds.get_z_width();
42 
43  return (rp*rp + zp*zp)*0.1*cos(phi);
44 }
45 
46 // Br = -dpsi/dz / r
47 double get_analytic_Br(const Equilibrium& equil, double r, double z, double phi){
48  double rp = (r - equil.axis.r)/equil.bounds.get_r_width();
49  double zp = (z - equil.axis.z)/equil.bounds.get_z_width();
50 
51  double phi_factor = 1.0 + 0.1*sin(phi);
52 
53  return -2*zp/equil.bounds.get_z_width()*phi_factor/r;
54 }
55 
56 // Bz = dpsi/dr / r
57 double get_analytic_Bz(const Equilibrium& equil, double r, double z, double phi){
58  double rp = (r - equil.axis.r)/equil.bounds.get_r_width();
59  double zp = (z - equil.axis.z)/equil.bounds.get_z_width();
60 
61  double phi_factor = 1.0 + 0.1*sin(phi);
62 
63  return 2*rp/equil.bounds.get_r_width()*phi_factor/r;
64 }
65 
66 double get_analytic_Bphi(const Equilibrium& equil, double r, double z, double phi){
67  double phi_factor = 1.0 + 0.1*cos(phi);
68  return phi_factor;
69 }
70 
71 
72 // Create a psi eq grid based off the analytic psi
73 Kokkos::View<double***, Kokkos::LayoutRight, HostType> analytic_3d_psi_grid(const Equilibrium& equil,
74  const View<double*, HostType>& r,
75  const View<double*, HostType>& z,
76  const View<double*, HostType>& phi){
77 
78  Kokkos::View<double***, Kokkos::LayoutRight, HostType> psi_grid("psi_grid",phi.size(), z.size(), r.size());
79  for (int k=0; k<phi.size(); k++){
80  for (int j=0; j<z.size(); j++){
81  for (int i=0; i<r.size(); i++){
82  psi_grid(k,j,i) = get_circular_analytic_psi3d(equil, r(i), z(j), phi(k));
83  }
84  }
85  }
86  return psi_grid;
87 }
88 
89 // Create a Br eq grid based off the analytic Br
90 Kokkos::View<double***, Kokkos::LayoutRight, HostType> analytic_3d_Br_grid(const Equilibrium& equil,
91  const View<double*, HostType>& r,
92  const View<double*, HostType>& z,
93  const View<double*, HostType>& phi){
94 
95  Kokkos::View<double***, Kokkos::LayoutRight, HostType> Br_grid("Br_grid",phi.size(), z.size(), r.size());
96  for (int k=0; k<phi.size(); k++){
97  for (int j=0; j<z.size(); j++){
98  for (int i=0; i<r.size(); i++){
99  Br_grid(k,j,i) = get_analytic_Br(equil, r(i), z(j), phi(k));
100  }
101  }
102  }
103  return Br_grid;
104 }
105 
106 // Create a Bz eq grid based off the analytic Bz
107 Kokkos::View<double***, Kokkos::LayoutRight, HostType> analytic_3d_Bz_grid(const Equilibrium& equil,
108  const View<double*, HostType>& r,
109  const View<double*, HostType>& z,
110  const View<double*, HostType>& phi){
111 
112  Kokkos::View<double***, Kokkos::LayoutRight, HostType> Bz_grid("Bz_grid",phi.size(), z.size(), r.size());
113  for (int k=0; k<phi.size(); k++){
114  for (int j=0; j<z.size(); j++){
115  for (int i=0; i<r.size(); i++){
116  Bz_grid(k,j,i) = get_analytic_Bz(equil, r(i), z(j), phi(k));
117  }
118  }
119  }
120  return Bz_grid;
121 }
122 
123 // Create a Bphi eq grid based off the analytic Bphi
124 Kokkos::View<double***, Kokkos::LayoutRight, HostType> analytic_3d_Bphi_grid(const Equilibrium& equil,
125  const View<double*, HostType>& r,
126  const View<double*, HostType>& z,
127  const View<double*, HostType>& phi){
128 
129  Kokkos::View<double***, Kokkos::LayoutRight, HostType> Bphi_grid("Bphi_grid",phi.size(), z.size(), r.size());
130  for (int k=0; k<phi.size(); k++){
131  for (int j=0; j<z.size(); j++){
132  for (int i=0; i<r.size(); i++){
133  Bphi_grid(k,j,i) = get_analytic_Bphi(equil, r(i), z(j), phi(k));
134  }
135  }
136  }
137  return Bphi_grid;
138 }
139 
140 
141 }
142 #endif
double z
Definition: grid_structs.hpp:30
RZBounds bounds
Min and max for r and z.
Definition: equil.hpp:86
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
coordinates of axis
Definition: equil.hpp:96
Definition: equil.hpp:30