XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
charge.hpp
Go to the documentation of this file.
1 #ifndef CHARGE_HPP
2 #define CHARGE_HPP
3 #include "space_settings.hpp"
4 #include "electric_field.hpp"
5 
6 extern "C" void set_electron_charge_pointers(int nnode, int npsi00, int phi_ind0, double* density_h, double* density0_h, double* den00_1d_h);
7 extern "C" void set_electron_charge_pointers_em(int nnode, double* jpar_h, double* jpar0_h);
8 extern "C" void set_ion_charge_pointers(int nnode, int npsi00, int phi_ind0, double* density_h, double* density0_h, double* den00_1d_h);
9 extern "C" void set_ion_charge_pointers_em(int nnode, double* jpar_h, double* jpar0_h);
10 
11 // Charge class
12 template<class Device, KinType KT>
13 class Charge {
14  public:
15 
17  bool use_current;
18 
19  // Host views
20  View<double**,CLayout,HostType> density_h;
21  View<double*,CLayout,HostType> density0_h;
22  View<double*,CLayout,HostType> den00_1d_h;
23 
24  View<double**,CLayout,HostType> jpar_h;
25  View<double*,CLayout,HostType> jpar0_h;
26 
27  View<double**,CLayout,HostType> den_f0_h;
28 
29  // ions only
30  View<double***,CLayout,HostType> den_rho_ff_h;
31  View<double***,CLayout,HostType> jpar_rho_ff_h;
32 
33  // Device views
36 
37  // Default constructor
38  Charge(){}
39 
40  // Constructor
41  Charge(bool use_current, int nnode, int nphi, int nrho, int npsi00, bool is_electrons)
42  : is_electrons(is_electrons),
43  use_current(use_current),
44  // Host views
45  density_h("density_h", nphi, nnode),
46  density0_h("density0_h", nnode),
47  den00_1d_h("den00_1d_h", npsi00),
48 
49  jpar_h("jpar_h", nphi, use_current ? nnode : 0),
50  jpar0_h("jpar0_h", use_current ? nnode : 0),
51 
52  den_f0_h("den_f0_h", nrho+1, nnode),
53 
54  // ions only
55  den_rho_ff_h("den_rho_ff_h", nrho+1, nphi, nnode),
56  jpar_rho_ff_h("jpar_rho_ff_h", nrho+1, nphi, use_current ? nnode : 0),
57 
58  // Device views
59  jpar("jpar", 1, nrho, use_current ? nnode : 0), // nphi=1
60  density("density", 1, nrho, nnode) // nphi=1
61  {
62 #ifndef NO_FORTRAN_MODULES
63  int phi_ind0 = 2 - nphi; // Starting index for fortran density = 1 for XGCA, 0 for XGC1
64  if(is_electrons){
65  set_electron_charge_pointers(nnode, npsi00, phi_ind0, density_h.data(), density0_h.data(), den00_1d_h.data());
66  if(use_current) set_electron_charge_pointers_em(nnode, jpar_h.data(), jpar0_h.data());
67  }else{
68  set_ion_charge_pointers(nnode, npsi00, phi_ind0, density_h.data(), density0_h.data(), den00_1d_h.data());
69  if(use_current) set_ion_charge_pointers_em(nnode, jpar_h.data(), jpar0_h.data());
70  }
71 #endif
72  }
73 
74  void reset_to_zero(){
75  density.reset_to_zero();
76  if(use_current) jpar.reset_to_zero();
77  }
78 };
79 
80 struct Charges{
83 
84  Charges(const Grid<DeviceType>& grid, const Simulation<DeviceType>& sml, int nrho){
85  int nphi = (sml.is_XGCa ? 1 : 2);
87  ion = Charge<DeviceType,KinType::GyroKin>(sml.explicit_electromagnetic, grid.nnode, nphi, nrho, grid.psi00.n, false);
88  }
89 
90  // Probably temporary: constructor that doesn't require Grid or PerturbedBField as inputs so that it can be constructed independently
91  Charges(const Simulation<DeviceType>& sml, int nnode, int npsi00, int nrho){
92  int nphi = (sml.is_XGCa ? 1 : 2);
93  electron = Charge<DeviceType,KinType::DriftKin>(sml.explicit_electromagnetic, nnode, nphi, 0, npsi00, true);
94  ion = Charge<DeviceType,KinType::GyroKin>(sml.explicit_electromagnetic, nnode, nphi, nrho, npsi00, false);
95  }
96 };
97 
98 #endif
View< double ***, CLayout, HostType > jpar_rho_ff_h
Definition: charge.hpp:31
void set_ion_charge_pointers(int nnode, int npsi00, int phi_ind0, double *density_h, double *density0_h, double *den00_1d_h)
Definition: charge.hpp:80
View< double **, CLayout, HostType > jpar_h
Definition: charge.hpp:24
bool use_current
Whether the class will handle current in addition to charge density.
Definition: charge.hpp:17
Definition: sml.hpp:8
static constexpr bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:19
Charge(bool use_current, int nnode, int nphi, int nrho, int npsi00, bool is_electrons)
Definition: charge.hpp:41
static constexpr bool explicit_electromagnetic
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:37
void set_ion_charge_pointers_em(int nnode, double *jpar_h, double *jpar0_h)
Charge< DeviceType, KinType::DriftKin > electron
Definition: charge.hpp:81
Charges(const Simulation< DeviceType > &sml, int nnode, int npsi00, int nrho)
Definition: charge.hpp:91
void reset_to_zero()
Definition: charge.hpp:74
bool is_electrons
Definition: charge.hpp:16
View< double *, CLayout, HostType > den00_1d_h
Definition: charge.hpp:22
void set_electron_charge_pointers(int nnode, int npsi00, int phi_ind0, double *density_h, double *density0_h, double *den00_1d_h)
GridField< Device, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KT, SCATTER_TYPE_GLOBAL > density
Charge density distribution.
Definition: charge.hpp:34
void set_electron_charge_pointers_em(int nnode, double *jpar_h, double *jpar0_h)
View< double **, CLayout, HostType > den_f0_h
Definition: charge.hpp:27
View< double ***, CLayout, HostType > den_rho_ff_h
Definition: charge.hpp:30
UniformRange psi00
Definition: grid.hpp:293
Charge< DeviceType, KinType::GyroKin > ion
Definition: charge.hpp:82
View< double *, CLayout, HostType > jpar0_h
Definition: charge.hpp:25
View< double **, CLayout, HostType > density_h
Definition: charge.hpp:20
Definition: charge.hpp:13
GridField< Device, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KT, SCATTER_TYPE_GLOBAL > jpar
Current density distribution.
Definition: charge.hpp:35
int nnode
Number of grid nodes.
Definition: grid.hpp:273
Charges(const Grid< DeviceType > &grid, const Simulation< DeviceType > &sml, int nrho)
Definition: charge.hpp:84
View< double *, CLayout, HostType > density0_h
Definition: charge.hpp:21
int n
Definition: uniform_range.hpp:7
Charge()
Definition: charge.hpp:38