XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
electric_field.hpp
Go to the documentation of this file.
1 #ifndef ELECTRIC_FIELD_HPP
2 #define ELECTRIC_FIELD_HPP
3 #include "space_settings.hpp"
4 #include "grid.hpp"
5 #include "linear_weights.hpp"
6 #include "local_fields.hpp"
7 
8 //Struct used for E_phi_ff, dAs_phi_ff, dAh_phi_ff, As_phi_ff, Ah_phi_ff. 3 vector components, 2 contributing planes
10  double V[3][2];
11 };
12 
13 // Same as VectorFieldPlanes, but the dimensions are reversed. Should remove this when possible - ALS
15  double V[2][3];
16 };
17 
18 //Struct used for E00_ff. 2 vector components, 2 contributing planes
20  double V[2][2];
21 };
22 
23 //Struct used for ddpotdt_phi, As_phi_ff, Ah_phi_ff, Ah_cv for EM. 2 contributing planes
25  double S[2];
26 };
27 
28 // Struct used for E_rho. 2 vector components (r,z) --> can be combined to ScalarFieldPlanes
29 struct FieldXGCa {
30  double E[2];
31 };
32 
33 // Electric field class
34 template<class Device>
35 struct ElectricField {
36 
37  // Dimensions
38  int nnode;
39  int nphi;
40  int nrho;
41 
42  // Field variables
43  bool turb_efield;
44 
45 #ifdef XGC1
46  Kokkos::View<VectorFieldPlanes**,Kokkos::LayoutRight,Device> E_phi_ff;
47  Kokkos::View<InvVectorFieldPlanes**,Kokkos::LayoutRight,Device> E_rho_ff;
48  Kokkos::View<ScalarFieldPlanes*,Kokkos::LayoutRight,Device> dpot_ff;
49 #ifdef DELTAF_CONV
50  Kokkos::View<Vector2DFieldPlanes*,Kokkos::LayoutRight,Device> E00_ff;
51  Kokkos::View<ScalarFieldPlanes**,Kokkos::LayoutRight,Device> ddpotdt_phi;
52 #endif
53 #ifdef EXPLICIT_EM
54  //For EM
55  Kokkos::View<VectorFieldPlanes**,Kokkos::LayoutRight,Device> dAh_phi_ff;
56  Kokkos::View<InvVectorFieldPlanes**,Kokkos::LayoutRight,Device> dAh_rho_ff;
57  Kokkos::View<ScalarFieldPlanes**,Kokkos::LayoutRight,Device> Ah_phi_ff;
58  Kokkos::View<ScalarFieldPlanes**,Kokkos::LayoutRight,Device> Ah_rho_ff;
59  Kokkos::View<VectorFieldPlanes**,Kokkos::LayoutRight,Device> dAs_phi_ff;
60  Kokkos::View<InvVectorFieldPlanes**,Kokkos::LayoutRight,Device> dAs_rho_ff;
61  Kokkos::View<ScalarFieldPlanes**,Kokkos::LayoutRight,Device> As_phi_ff;
62  Kokkos::View<ScalarFieldPlanes**,Kokkos::LayoutRight,Device> As_rho_ff;
63  Kokkos::View<ScalarFieldPlanes**,Kokkos::LayoutRight,Device> Ah_cv_phi_ff;
64  Kokkos::View<ScalarFieldPlanes**,Kokkos::LayoutRight,Device> Epar_em_phi_ff;
65  Kokkos::View<ScalarFieldPlanes**,Kokkos::LayoutRight,Device> Epar_em_rho_ff;
66 
67  Kokkos::View<double*,Kokkos::LayoutRight,Device> dpot_n0;
68 #endif // end of EXPLICIT_EM
69 #else
70  Kokkos::View<FieldXGCa**,Kokkos::LayoutRight,Device> E_rho;
71  Kokkos::View<double*,Kokkos::LayoutRight,Device> dpot;
72 #endif
73 
74  // Default constructor
76 
77 
78  ElectricField(bool turb_efield_in, int nnode_in, int nphi_in, int nrho_in) :
79 #ifdef XGC1
80  E_phi_ff("E_phi_ff",0,0),
81  E_rho_ff("E_rho_ff",0,0),
82 # ifdef DELTAF_CONV
83  E00_ff("E00_ff",nnode_in),
84  ddpotdt_phi("ddpotdt_phi",0,0),
85 # endif
86 # ifdef EXPLICIT_EM
87  dAs_phi_ff("dAs_phi_ff",0,0),
88  dAs_rho_ff("dAs_rho_ff",0,0),
89  dAh_phi_ff("dAh_phi_ff",0,0),
90  dAh_rho_ff("dAh_rho_ff",0,0),
91  As_phi_ff("As_phi_ff",0,0),
92  As_rho_ff("As_rho_ff",0,0),
93  Ah_phi_ff("Ah_phi_ff",0,0),
94  Ah_rho_ff("Ah_rho_ff",0,0),
95  Ah_cv_phi_ff("Ah_cv_phi_ff",0,0),
96  Epar_em_phi_ff("Epar_em_phi_ff",0,0),
97  Epar_em_rho_ff("Epar_em_rho_ff",0,0),
98  dpot_n0("dpot_n0",nnode_in),
99 # endif
100  dpot_ff("dpot_ff",nnode_in),
101 #else
102  E_rho("E_rho",nnode_in,nrho+1),
103  dpot("dpot",nnode_in),
104 #endif
105  turb_efield(turb_efield_in),
106  nnode(nnode_in),
107  nphi(nphi_in),
108  nrho(nrho_in)
109  {}
110 
111 #ifdef XGC1
112  // Resizes allocations for large arrays that have a phi dimension (i.e used for electron push)
113  void allocate_phi_fields_on_device(){
114  Kokkos::resize(E_phi_ff,nphi, nnode);
115 # ifdef DELTAF_CONV
116  Kokkos::resize(ddpotdt_phi,nphi,nnode);
117 # endif
118 # ifdef EXPLICIT_EM
119  Kokkos::resize(dAs_phi_ff,nphi,nnode);
120  Kokkos::resize(dAh_phi_ff,nphi,nnode);
121  Kokkos::resize(As_phi_ff,nphi,nnode);
122  Kokkos::resize(Ah_phi_ff,nphi,nnode);
123  Kokkos::resize(Ah_cv_phi_ff,nphi,nnode);
124  Kokkos::resize(Epar_em_phi_ff,nphi,nnode);
125 # endif
126  }
127 
128  // Resizes allocations that have a phi dimension to 0, to make room for other data on the device
129  void deallocate_phi_fields_on_device(){
130  Kokkos::resize(E_phi_ff,0,0);
131 # ifdef DELTAF_CONV
132  Kokkos::resize(ddpotdt_phi,0,0);
133 # endif
134 # ifdef EXPLICIT_EM
135  Kokkos::resize(dAs_phi_ff,0,0);
136  Kokkos::resize(dAh_phi_ff,0,0);
137  Kokkos::resize(As_phi_ff,0,0);
138  Kokkos::resize(Ah_phi_ff,0,0);
139  Kokkos::resize(Ah_cv_phi_ff,0,0);
140  Kokkos::resize(Epar_em_phi_ff,0,0);
141 # endif
142  }
143 
144  // Resizes allocations for large arrays that have a rho dimension (i.e used for ions)
145  void allocate_rho_fields_on_device(){
146  Kokkos::resize(E_rho_ff, nnode,nrho+1);
147 # ifdef EXPLICIT_EM
148  Kokkos::resize(dAs_rho_ff,nnode,nrho+1);
149  Kokkos::resize(dAh_rho_ff,nnode,nrho+1);
150  Kokkos::resize(As_rho_ff,nnode,nrho+1);
151  Kokkos::resize(Ah_rho_ff,nnode,nrho+1);
152  Kokkos::resize(Epar_em_rho_ff,nnode,nrho+1);
153 # endif
154  }
155 
156  // Resizes allocations that have a rho dimension to 0, to make room for other data on the device
157  void deallocate_rho_fields_on_device(){
158  Kokkos::resize(E_rho_ff,0,0);
159 # ifdef EXPLICIT_EM
160  Kokkos::resize(dAs_rho_ff,0,0);
161  Kokkos::resize(dAh_rho_ff,0,0);
162  Kokkos::resize(As_rho_ff,0,0);
163  Kokkos::resize(Ah_rho_ff,0,0);
164  Kokkos::resize(Epar_em_rho_ff,0,0);
165 # endif
166  }
167 
168 # ifdef EXPLICIT_EM
169  /* Set of functions used to allocate/deallocate gpu memory for Ah during particle scatters */
170  // Resizes allocation of Ah_cv
171  void allocate_Ah_cv_on_device(){
172  Kokkos::resize(Ah_cv_phi_ff,nphi,nnode);
173  }
174 
175  // Resizes Ah_cv to 0
176  void deallocate_Ah_cv_on_device(){
177  Kokkos::resize(Ah_cv_phi_ff,0,0);
178  }
179 
180  void allocate_Ah_phi_ff_on_device(){
181  Kokkos::resize(Ah_phi_ff,nphi,nnode);
182  }
183 
184  // Resizes Ah_phi_ff to 0
185  void deallocate_Ah_phi_ff_on_device(){
186  Kokkos::resize(Ah_phi_ff,0,0);
187  }
188 
189  // Resizes allocation of Ah_rho_ff
190  void allocate_Ah_rho_ff_on_device(){
191  Kokkos::resize(Ah_rho_ff,nnode,nrho+1);
192  }
193 
194  // Resizes Ah_rho_ff to 0
195  void deallocate_Ah_rho_ff_on_device(){
196  Kokkos::resize(Ah_rho_ff,0,0);
197  }
198 # endif
199 #endif
200 
201 };
202 
203 #endif
Definition: electric_field.hpp:9
double V[3][2]
Definition: electric_field.hpp:10
ElectricField(bool turb_efield_in, int nnode_in, int nphi_in, int nrho_in)
Definition: electric_field.hpp:78
int nrho
Definition: electric_field.hpp:40
Definition: electric_field.hpp:35
Definition: electric_field.hpp:14
Definition: electric_field.hpp:24
double S[2]
Definition: electric_field.hpp:25
Kokkos::View< FieldXGCa **, Kokkos::LayoutRight, Device > E_rho
Definition: electric_field.hpp:70
ElectricField()
Definition: electric_field.hpp:75
double V[2][3]
Definition: electric_field.hpp:15
Definition: electric_field.hpp:29
double E[2]
Definition: electric_field.hpp:30
Definition: electric_field.hpp:19
bool turb_efield
Whether the electric field is turbulent?
Definition: electric_field.hpp:43
int nphi
Definition: electric_field.hpp:39
int nnode
Definition: electric_field.hpp:38
double V[2][2]
Definition: electric_field.hpp:20
Kokkos::View< double *, Kokkos::LayoutRight, Device > dpot
Definition: electric_field.hpp:71