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 extern "C" void set_cden00_1d_fort(int npsi00, double* cden00_1d_h);
11 
12 // Charge class
13 template<class Device, KinType KT>
14 class Charge {
15  public:
16 
18  bool use_current;
19 
20  // Host views
21  View<double**,CLayout,HostType> density_h;
22  View<double*,CLayout,HostType> density0_h;
23  View<double*,CLayout,HostType> den00_1d_h;
24 
25  View<double**,CLayout,HostType> jpar_h;
26  View<double*,CLayout,HostType> jpar0_h;
27 
28  View<double**,CLayout,HostType> den_f0_h;
29 
30  // ions only
31  View<double***,CLayout,HostType> den_rho_ff_h;
32  View<double***,CLayout,HostType> jpar_rho_ff_h;
33 
34  // Device views
37 
38  // Default constructor
39  Charge(){}
40 
41  // Constructor
42  Charge(bool use_current, int nnode, int nphi, int nrho, int npsi00, bool is_electrons)
43  : is_electrons(is_electrons),
44  use_current(use_current),
45  // Host views
46  density_h("density_h", nphi, nnode),
47  density0_h("density0_h", nnode),
48  den00_1d_h("den00_1d_h", npsi00),
49 
50  jpar_h("jpar_h", nphi, use_current ? nnode : 0),
51  jpar0_h("jpar0_h", use_current ? nnode : 0),
52 
53  den_f0_h("den_f0_h", nrho+1, nnode),
54 
55  // ions only
56  den_rho_ff_h("den_rho_ff_h", nrho+1, nphi, nnode),
57  jpar_rho_ff_h("jpar_rho_ff_h", nrho+1, nphi, use_current ? nnode : 0),
58 
59  // Device views
60  jpar("jpar", 1, nrho, use_current ? nnode : 0), // nphi=1
61  density("density", 1, nrho, nnode) // nphi=1
62  {
63 #ifndef NO_FORTRAN_MODULES
64  int phi_ind0 = 2 - nphi; // Starting index for fortran density = 1 for XGCA, 0 for XGC1
65  if(is_electrons){
66  set_electron_charge_pointers(nnode, npsi00, phi_ind0, density_h.data(), density0_h.data(), den00_1d_h.data());
67  if(use_current) set_electron_charge_pointers_em(nnode, jpar_h.data(), jpar0_h.data());
68  }else{
69  set_ion_charge_pointers(nnode, npsi00, phi_ind0, density_h.data(), density0_h.data(), den00_1d_h.data());
70  if(use_current) set_ion_charge_pointers_em(nnode, jpar_h.data(), jpar0_h.data());
71  }
72 #endif
73  }
74 
75  void reset_to_zero(){
76  density.reset_to_zero();
77  if(use_current) jpar.reset_to_zero();
78  }
79 };
80 
81 struct Charges{
84 
85  View<double*,CLayout,HostType> cden00_1d_h;
86 
87  Charges(const Grid<DeviceType>& grid, const Simulation<DeviceType>& sml, int nrho){
88  int nphi = (sml.is_XGCa ? 1 : 2);
90  ion = Charge<DeviceType,KinType::GyroKin>(sml.explicit_electromagnetic, grid.nnode, nphi, nrho, grid.psi00.n, false);
91  cden00_1d_h = View<double*,CLayout,HostType>("cden00_1d_h", grid.psi00.n);
92 #ifndef NO_FORTRAN_MODULES
93  set_cden00_1d_fort(grid.psi00.n, cden00_1d_h.data());
94 #endif
95  }
96 };
97 
98 #endif
View< double ***, CLayout, HostType > jpar_rho_ff_h
Definition: charge.hpp:32
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:81
void set_cden00_1d_fort(int npsi00, double *cden00_1d_h)
View< double **, CLayout, HostType > jpar_h
Definition: charge.hpp:25
bool use_current
Whether the class will handle current in addition to charge density.
Definition: charge.hpp:18
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:42
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)
View< double *, CLayout, HostType > cden00_1d_h
Definition: charge.hpp:85
Charge< DeviceType, KinType::DriftKin > electron
Definition: charge.hpp:82
void reset_to_zero()
Definition: charge.hpp:75
bool is_electrons
Definition: charge.hpp:17
View< double *, CLayout, HostType > den00_1d_h
Definition: charge.hpp:23
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:35
void set_electron_charge_pointers_em(int nnode, double *jpar_h, double *jpar0_h)
View< double **, CLayout, HostType > den_f0_h
Definition: charge.hpp:28
View< double ***, CLayout, HostType > den_rho_ff_h
Definition: charge.hpp:31
UniformRange psi00
Definition: grid.hpp:164
Charge< DeviceType, KinType::GyroKin > ion
Definition: charge.hpp:83
View< double *, CLayout, HostType > jpar0_h
Definition: charge.hpp:26
View< double **, CLayout, HostType > density_h
Definition: charge.hpp:21
Definition: charge.hpp:14
GridField< Device, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KT, SCATTER_TYPE_GLOBAL > jpar
Current density distribution.
Definition: charge.hpp:36
int nnode
Number of grid nodes.
Definition: grid.hpp:154
Charges(const Grid< DeviceType > &grid, const Simulation< DeviceType > &sml, int nrho)
Definition: charge.hpp:87
View< double *, CLayout, HostType > density0_h
Definition: charge.hpp:22
int n
Definition: uniform_range.hpp:7
Charge()
Definition: charge.hpp:39