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 #include "xgc_io.hpp"
6 
7 extern "C" void set_cden00_1d_fort(int npsi00, double* cden00_1d_h);
8 
9 // Charge class
10 template<class Device, KinType KT>
11 class Charge {
12  public:
13 
15  bool use_current;
16 
17  // Host views
18  View<double**,CLayout,HostType> density_h;
19  View<double*,CLayout,HostType> density0_h;
20  View<double*,CLayout,HostType> den00_1d_h;
21 
22  View<double**,CLayout,HostType> jpar_h;
23  View<double*,CLayout,HostType> jpar0_h;
24 
25  View<double**,CLayout,HostType> den_f0_h;
26 
27  // Device views
30 
31  // Unmanaged View of the device views, for access when transposed
32  View<double***,CLayout,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> den_rho_ff;
33  View<double***,CLayout,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> jpar_rho_ff;
34 
35  // Default constructor
36  Charge(){}
37 
38  // Constructor
39  Charge(bool use_current, int nnode, int nphi, int nrho, int npsi00, bool is_electrons)
40  : is_electrons(is_electrons),
41  use_current(use_current),
42  // Host views
43  density_h("density_h", nphi, nnode),
44  density0_h("density0_h", nnode),
45  den00_1d_h("den00_1d_h", npsi00),
46 
47  jpar_h("jpar_h", nphi, use_current ? nnode : 0),
48  jpar0_h("jpar0_h", use_current ? nnode : 0),
49 
50  den_f0_h("den_f0_h", nrho+1, nnode),
51 
52  // Device views
53  density("density", 1, nrho, nnode), // nphi=1
54  den_rho_ff((double*)(density.data()), nrho+1, nphi, nnode),
55 
56  jpar("jpar", 1, nrho, use_current ? nnode : 0), // nphi=1
57  jpar_rho_ff((double*)(jpar.data()), nrho+1, nphi, use_current ? nnode : 0)
58  {}
59 
60  void reset_to_zero(){
61  density.reset_to_zero();
62  if(use_current) jpar.reset_to_zero();
63  }
64 };
65 
66 struct Charges{
69 
70  View<double*,CLayout,HostType> cden00_1d_h;
71 
72  Charges(const Grid<DeviceType>& grid, const Simulation<DeviceType>& sml, int nrho){
73  int nphi = (sml.is_XGCa ? 1 : 2);
75  ion = Charge<DeviceType,KinType::GyroKin>(sml.explicit_electromagnetic, grid.nnode, nphi, nrho, grid.psi00.n, false);
76  cden00_1d_h = View<double*,CLayout,HostType>("cden00_1d_h", grid.psi00.n);
77 #ifndef NO_FORTRAN_MODULES
78  set_cden00_1d_fort(grid.psi00.n, cden00_1d_h.data());
79 #endif
80  }
81 
82  void read_checkpoint_files(const XGC_IO_Stream& stream){
83  // Check whether variable is present in the checkpoint
84  if(!XGC_IO::is_present<double>(stream, "edensity0")){
85  return;
86  }
87 
88  // Object to manage adding parameters/data and writing them
89  XGC_IO xgc_io;
90 
91  xgc_io.add(
92  IOArray("edensity0", electron.density0_h),
93  IOArray("eden00_1d", electron.den00_1d_h)
94  );
95 
96  // Read data
97  xgc_io.read(stream);
98  }
99 
100  void write_checkpoint_files(const XGC_IO_Stream& stream) const{
101  // Object to manage adding parameters/data and writing them
102  XGC_IO xgc_io;
103 
104  xgc_io.add(
105  IOArray("edensity0", electron.density0_h),
106  IOArray("eden00_1d", electron.den00_1d_h)
107  );
108 
109  // Write data
110  xgc_io.write(stream);
111  }
112 };
113 
114 #endif
void read_checkpoint_files(const XGC_IO_Stream &stream)
Definition: charge.hpp:82
Definition: charge.hpp:66
void write(const XGC_IO_Stream &stream) const
Definition: xgc_io.hpp:211
Definition: xgc_io.hpp:192
void set_cden00_1d_fort(int npsi00, double *cden00_1d_h)
View< double **, CLayout, HostType > jpar_h
Definition: charge.hpp:22
bool use_current
Whether the class will handle current in addition to charge density.
Definition: charge.hpp:15
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:39
static constexpr bool explicit_electromagnetic
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:37
View< double *, CLayout, HostType > cden00_1d_h
Definition: charge.hpp:70
Charge< DeviceType, KinType::DriftKin > electron
Definition: charge.hpp:67
void read(const XGC_IO_Stream &stream)
Definition: xgc_io.hpp:227
View< double ***, CLayout, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged > > den_rho_ff
Definition: charge.hpp:32
void add(const T &new_data)
Definition: xgc_io.hpp:199
View< double ***, CLayout, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged > > jpar_rho_ff
Definition: charge.hpp:33
Definition: xgc_io.hpp:117
void reset_to_zero()
Definition: charge.hpp:60
bool is_electrons
Definition: charge.hpp:14
View< double *, CLayout, HostType > den00_1d_h
Definition: charge.hpp:20
GridField< Device, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KT, SCATTER_TYPE_GLOBAL > density
Charge density distribution.
Definition: charge.hpp:28
Definition: xgc_io.hpp:24
View< double **, CLayout, HostType > den_f0_h
Definition: charge.hpp:25
UniformRange psi00
Definition: grid.hpp:169
Charge< DeviceType, KinType::GyroKin > ion
Definition: charge.hpp:68
View< double *, CLayout, HostType > jpar0_h
Definition: charge.hpp:23
View< double **, CLayout, HostType > density_h
Definition: charge.hpp:18
Definition: charge.hpp:11
GridField< Device, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KT, SCATTER_TYPE_GLOBAL > jpar
Current density distribution.
Definition: charge.hpp:29
int nnode
Number of grid nodes.
Definition: grid.hpp:159
Charges(const Grid< DeviceType > &grid, const Simulation< DeviceType > &sml, int nrho)
Definition: charge.hpp:72
void write_checkpoint_files(const XGC_IO_Stream &stream) const
Definition: charge.hpp:100
View< double *, CLayout, HostType > density0_h
Definition: charge.hpp:19
int n
Definition: uniform_range.hpp:7
Charge()
Definition: charge.hpp:36