XGC1
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 // Charge class
8 template<class Device, KinType KT>
9 class Charge {
10  public:
11 
13  bool use_current;
14 
15  // Host views
16  View<double**,CLayout,HostType> density_h;
17  View<double*,CLayout,HostType> density0_h;
18  View<double*,CLayout,HostType> density00_h;
19  View<double*,CLayout,HostType> den00_1d_h;
20 
21  View<double**,CLayout,HostType> jpar_h;
22  View<double*,CLayout,HostType> jpar0_h;
23 
24  View<double**,CLayout,HostType> den_f0_h;
25 
26  // Device views
29 
30  // Unmanaged View of the device views, for access when transposed
31  View<double***,CLayout,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> den_rho_ff;
32  View<double***,CLayout,Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>> jpar_rho_ff;
33 
34  // Default constructor
35  Charge(){}
36 
37  // Constructor
38  Charge(bool use_current, int nnode, int nphi, int nrho, int npsi00, bool use_fsa_den, bool is_electrons)
41  // Host views
42  density_h("density_h", nphi, nnode),
43  density0_h("density0_h", nnode),
44  density00_h("density00_h", use_fsa_den ? nnode : 0),
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> rhs_offset0_h;
71 
72  View<double*,CLayout,HostType> cden00_1d_h;
73 
74  Charges(){}
75 
76  Charges(const Grid<DeviceType>& grid, const Simulation<DeviceType>& sml, int nrho)
77  : electron(sml.explicit_electromagnetic, grid.nnode, (sml.is_XGCa ? 1 : 2), 0, grid.psi00.n, !grid.axisymmetric, true),
78  ion( sml.explicit_electromagnetic, grid.nnode, (sml.is_XGCa ? 1 : 2), nrho, grid.psi00.n, !grid.axisymmetric, false),
79  rhs_offset0_h("rhs_offset0_h", grid.nnode),
80  cden00_1d_h("cden00_1d_h", grid.psi00.n)
81  {}
82 
83  void read_checkpoint_files(const XGC_IO_Stream& stream){
84  // Check whether variable is present in the checkpoint
85  bool is_present_edensity0 = XGC_IO::is_present<double>(stream, "edensity0");
86  bool is_present_rhs_offset0 = XGC_IO::is_present<double>(stream, "rhs_offset0");
87 
88  if(!is_present_edensity0 && !is_present_rhs_offset0){
89  return;
90  }
91 
92  // Object to manage adding parameters/data and writing them
93  XGC_IO xgc_io;
94 
95  if(is_present_edensity0){ // for backward compatibility despite the version of restart file.
96  xgc_io.add(
97  IOArray("edensity0", rhs_offset0_h)
98  );
99  }
100  else if(is_present_rhs_offset0){
101  xgc_io.add(
102  IOArray("rhs_offset0", rhs_offset0_h)
103  );
104  }
105 
106  // Read data
107  xgc_io.read(stream);
108  }
109 
110  void write_checkpoint_files(const XGC_IO_Stream& stream) const{
111  // Object to manage adding parameters/data and writing them
112  XGC_IO xgc_io;
113 
114  xgc_io.add(
115  IOArray("rhs_offset0", rhs_offset0_h)
116  );
117 
118  // Write data
119  xgc_io.write(stream);
120  }
121 };
122 
123 #endif
Definition: charge.hpp:9
View< double *, CLayout, HostType > density0_h
Definition: charge.hpp:17
View< double *, CLayout, HostType > density00_h
3D flux-surface averaged density
Definition: charge.hpp:18
View< double ***, CLayout, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged > > den_rho_ff
Definition: charge.hpp:31
bool is_electrons
Definition: charge.hpp:12
View< double **, CLayout, HostType > density_h
Definition: charge.hpp:16
GridField< Device, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KT, SCATTER_TYPE_GLOBAL > density
Charge density distribution.
Definition: charge.hpp:27
bool use_current
Whether the class will handle current in addition to charge density.
Definition: charge.hpp:13
View< double *, CLayout, HostType > den00_1d_h
Definition: charge.hpp:19
View< double **, CLayout, HostType > den_f0_h
Definition: charge.hpp:24
GridField< Device, VarType::Scalar, PIT_GLOBAL, TorType::OnePlane, KT, SCATTER_TYPE_GLOBAL > jpar
Current density distribution.
Definition: charge.hpp:28
void reset_to_zero()
Definition: charge.hpp:60
Charge()
Definition: charge.hpp:35
Charge(bool use_current, int nnode, int nphi, int nrho, int npsi00, bool use_fsa_den, bool is_electrons)
Definition: charge.hpp:38
View< double **, CLayout, HostType > jpar_h
Definition: charge.hpp:21
View< double ***, CLayout, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged > > jpar_rho_ff
Definition: charge.hpp:32
View< double *, CLayout, HostType > jpar0_h
Definition: charge.hpp:22
Definition: sml.hpp:9
Definition: xgc_io.hpp:24
Definition: xgc_io.hpp:192
void add(const T &new_data)
Definition: xgc_io.hpp:199
void read(const XGC_IO_Stream &stream)
Definition: xgc_io.hpp:227
void write(const XGC_IO_Stream &stream) const
Definition: xgc_io.hpp:211
logical false
Definition: module.F90:102
logical true
Definition: module.F90:102
Definition: charge.hpp:66
Charge< DeviceType, KinType::GyroKin > ion
Definition: charge.hpp:68
Charges()
Definition: charge.hpp:74
void read_checkpoint_files(const XGC_IO_Stream &stream)
Definition: charge.hpp:83
Charge< DeviceType, KinType::DriftKin > electron
Definition: charge.hpp:67
void write_checkpoint_files(const XGC_IO_Stream &stream) const
Definition: charge.hpp:110
View< double *, CLayout, HostType > cden00_1d_h
Definition: charge.hpp:72
Charges(const Grid< DeviceType > &grid, const Simulation< DeviceType > &sml, int nrho)
Definition: charge.hpp:76
View< double *, CLayout, HostType > rhs_offset0_h
Axisymmetric RHS offset for solving Poisson equation – replacing edensity0 for full-f.
Definition: charge.hpp:70
Definition: xgc_io.hpp:117