XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gyro_avg_mat.hpp
Go to the documentation of this file.
1 #ifndef GYRO_AVG_MAT_HPP
2 #define GYRO_AVG_MAT_HPP
3 
4 #include "space_settings.hpp"
5 #include "matrix.hpp"
6 #include "task_group.hpp"
7 #include "host_array.hpp"
8 #include "grid.hpp"
10 
11 enum class GyroCommMethod{
12  PlaneComm=0,
14  SelfComm
15 };
16 
17 template<class Device>
19  public: // for testing
22 
23  int nrho;
24  double rhomax;
25  double inv_drho;
26  int nphi;
29 
31 
32  public:
33 
34  // Default constructor used if species is drift-kinetic
36  : nrho(0),
38  {}
39 
40  // Construct the gyromatrices used on this MPI rank
41  GyroAverageMatrices(NLReader::NamelistReader& nlr, const Grid<DeviceType>& grid, const DomainDecomposition<DeviceType>& pol_decomp, const MagneticField<DeviceType>& magnetic_field, bool is_field_following, int n_larmor_pts, int nrho_in, double rhomax_in);
42 
43  // Copy matrices to device
45  for(int i=0; i<matrices.size(); i++){
46  matrices(i) = matrices_h(i).template mirror<Device>();
47  }
48  }
49 
51  if(!resident_on_device){
53  }
54  }
55 
57  if(!resident_on_device){
58  for(int i=0; i<matrices.size(); i++){
59  matrices(i) = Matrix<Device>();
60  }
61  }
62  }
63 
65 
66 #ifdef USE_MPI
67  MPI_Comm choose_comm(const DomainDecomposition<DeviceType>& pol_decomp, int ntasks) const;
68 #endif
69 
70  // Could be a constructor of a new GyroMatrix class (which could be a derived Matrix class)
71  void init_one_gyro_avg_mat(const Grid<DeviceType>& grid, const MagneticField<DeviceType>& magnetic_field, Matrix<HostType>& matrix, int iphi, int irho, bool is_field_following, int n_larmor_pts);
72 
73  void gyroaverage_field(const Grid<DeviceType>& grid, const View<double***,CLayout,DeviceType>& field_rho,
74 #ifdef USE_MPI
75  const MPI_Comm& plane_comm,
76 #endif
77  const View<double**,CLayout,HostType>& field) const;
78 
79  void get_pot_mat_mult(const View<double***,CLayout, DeviceType>& field_rho, const View<double****,CLayout, DeviceType>& gradient_rho, const View<double***,CLayout, DeviceType>& E_para_em, bool potential_requested, bool gradient_requested, bool E_para_em_requested) const;
80 
81  void broadcast_potentials(const View<double***,CLayout, DeviceType>& potential_rho, const View<double****,CLayout, DeviceType>& gradient_rho, const View<double***,CLayout, DeviceType>& E_para_em, bool potential_requested, bool gradient_requested, bool E_para_em_requested) const;
82 
83  void get_gyroaveraged(const View<double***,CLayout, DeviceType>& field_rho, const View<double****,CLayout, DeviceType>& gradient_rho, const View<double***,CLayout, DeviceType>& E_para_em, bool potential_requested, bool gradient_requested, bool E_para_em_requested) const;
84 
85  void gyroaverage_moments(const View<double**, CLayout, DeviceType>& density_rho,
86  const View<double**, CLayout, DeviceType>& flow_rho,
87  const View<double**, CLayout, DeviceType>& energy_rho,
88  const View<double**, CLayout, DeviceType>& density_f0g_rho,
89  const View<double*, CLayout, DeviceType>& density,
90  const View<double*, CLayout, DeviceType>& flow,
91  const View<double*, CLayout, DeviceType>& energy,
92  const View<double*, CLayout, DeviceType>& density_f0g
93 #ifdef USE_MPI
94  , const MPI_Comm& plane_comm
95 #endif
96  );
97 
98 
100 
101  void iterative_gyroaverage(Matrix<DeviceType>& gyromatrix, bool print_residual, View<double*, CLayout, DeviceType>& view) const;
102 
103  void smooth_with_last_gyroaverage(bool print_residual, View<double*, CLayout, DeviceType>& delta_n) const;
104 };
105 
106 #endif
void gyroaverage_moments(const View< double **, CLayout, DeviceType > &density_rho, const View< double **, CLayout, DeviceType > &flow_rho, const View< double **, CLayout, DeviceType > &energy_rho, const View< double **, CLayout, DeviceType > &density_f0g_rho, const View< double *, CLayout, DeviceType > &density, const View< double *, CLayout, DeviceType > &flow, const View< double *, CLayout, DeviceType > &energy, const View< double *, CLayout, DeviceType > &density_f0g)
GyroCommMethod gyro_comm_method
Definition: gyro_avg_mat.hpp:27
Definition: gyro_avg_mat.hpp:18
void init_one_gyro_avg_mat(const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, Matrix< HostType > &matrix, int iphi, int irho, bool is_field_following, int n_larmor_pts)
Definition: gyro_avg_mat.cpp:100
void copy_to_device_if_not_resident()
Definition: gyro_avg_mat.hpp:50
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:12
void gyroaverage_field(const Grid< DeviceType > &grid, const View< double ***, CLayout, DeviceType > &field_rho, const View< double **, CLayout, HostType > &field) const
TaskGroup task_group
Definition: gyro_avg_mat.hpp:30
void iterative_gyroaverage(Matrix< DeviceType > &gyromatrix, bool print_residual, View< double *, CLayout, DeviceType > &view) const
Definition: gyro_avg_mat.cpp:742
void broadcast_potentials(const View< double ***, CLayout, DeviceType > &potential_rho, const View< double ****, CLayout, DeviceType > &gradient_rho, const View< double ***, CLayout, DeviceType > &E_para_em, bool potential_requested, bool gradient_requested, bool E_para_em_requested) const
int nrho
Definition: gyro_avg_mat.hpp:23
A class that manages the distribution and execution of tasks in parallel using the MPI library...
Definition: task_group.hpp:14
void deallocate_device_matrices_if_not_resident()
Definition: gyro_avg_mat.hpp:56
bool resident_on_device
Definition: gyro_avg_mat.hpp:28
GyroCommMethod
Definition: gyro_avg_mat.hpp:11
double inv_drho
Definition: gyro_avg_mat.hpp:25
void get_pot_mat_mult(const View< double ***, CLayout, DeviceType > &field_rho, const View< double ****, CLayout, DeviceType > &gradient_rho, const View< double ***, CLayout, DeviceType > &E_para_em, bool potential_requested, bool gradient_requested, bool E_para_em_requested) const
void smooth_with_last_gyroaverage(bool print_residual, View< double *, CLayout, DeviceType > &delta_n) const
Definition: gyro_avg_mat.cpp:767
Definition: matrix.hpp:11
HostArray< Matrix< Device > > matrices
Definition: gyro_avg_mat.hpp:20
HostArray< Matrix< HostType > > matrices_h
Definition: gyro_avg_mat.hpp:21
GyroAverageMatrices()
Definition: gyro_avg_mat.hpp:35
int nphi
Definition: gyro_avg_mat.hpp:26
GyroCommMethod read_gyro_comm_method(NLReader::NamelistReader &nlr) const
Definition: gyro_avg_mat.cpp:12
Definition: magnetic_field.F90:1
int find_a_plane_rank_with_last_gyromatrix() const
Definition: gyro_avg_mat.cpp:721
void get_gyroaveraged(const View< double ***, CLayout, DeviceType > &field_rho, const View< double ****, CLayout, DeviceType > &gradient_rho, const View< double ***, CLayout, DeviceType > &E_para_em, bool potential_requested, bool gradient_requested, bool E_para_em_requested) const
size_t size() const
Definition: host_array.hpp:78
void copy_matrices_to_device()
Definition: gyro_avg_mat.hpp:44
Definition: host_array.hpp:11
double rhomax
Definition: gyro_avg_mat.hpp:24