XGCa
 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 template<class Device>
13  public: // for testing
15 
16  int nrho;
17  double rhomax;
18  double inv_drho;
19  int nphi;
21 
22  // Access individual matrices (may not be necessary eventually)
23  Matrix<Device> operator [](int i) const {return matrices(i);}
24  Matrix<Device>& operator [](int i) {return matrices(i);}
25 
26  public:
27 
28  GyroAverageMatrices(){} // For testing
29 
30  // Construct the gyromatrices used on this MPI rank
31  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);
32 
33  // Create a mirror with a different device type
34  template<class Device2>
36  GPTLstart("GET_POT_GRAD_GYROMAT_SETUP");
38  const std::string label ("v_outer");
40  for(int i=0; i<matrices.size(); i++){
41  m.matrices(i) = matrices(i).template mirror<Device2>();
42  }
43 
44  m.nrho = nrho;
45  m.rhomax = rhomax;
46  m.inv_drho = inv_drho;
47  m.nphi = nphi;
48  m.task_group = task_group; // Can't be used from a device kernel, but no harm in sending it
49 
50  GPTLstop("GET_POT_GRAD_GYROMAT_SETUP");
51 
52  return m;
53  }
54 
55  // Could be a constructor of a new GyroMatrix class (which could be a derived Matrix class)
56  void init_one_gyro_avg_mat(const Grid<DeviceType>& grid, const MagneticField<DeviceType>& magnetic_field, Matrix<Device>& matrix, int iphi, int irho, bool is_field_following, int n_larmor_pts);
57 
58  void gyroaverage_field(const Grid<DeviceType>& grid, View<double***,CLayout,HostType>& field_rho
59 #ifdef USE_MPI
60  , const MPI_Comm& plane_comm
61 #endif
62  ) const;
63 
64  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;
65 
66  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;
67 
68  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;
69 
70  void gyroaverage_moments(const View<double**, CLayout, DeviceType>& density_rho,
71  const View<double**, CLayout, DeviceType>& flow_rho,
72  const View<double**, CLayout, DeviceType>& energy_rho,
73  const View<double**, CLayout, DeviceType>& density_f0g_rho,
74  const View<double*, CLayout, DeviceType>& density,
75  const View<double*, CLayout, DeviceType>& flow,
76  const View<double*, CLayout, DeviceType>& energy,
77  const View<double*, CLayout, DeviceType>& density_f0g
78 #ifdef USE_MPI
79  , const MPI_Comm& plane_comm
80 #endif
81  ) const;
82 
83 
85 
86  void iterative_gyroaverage(Matrix<DeviceType>& gyromatrix, bool print_residual, View<double*, CLayout, DeviceType>& view) const;
87 
88  void smooth_with_last_gyroaverage(bool print_residual, View<double*, CLayout, DeviceType>& delta_n) const;
89 };
90 
91 #endif
void iterative_gyroaverage(Matrix< DeviceType > &gyromatrix, bool print_residual, View< double *, CLayout, DeviceType > &view) const
static int GPTLstart(const char *name)
Definition: timer_macro.hpp:9
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) const
Definition: gyro_avg_mat.hpp:12
void smooth_with_last_gyroaverage(bool print_residual, View< double *, CLayout, DeviceType > &delta_n) const
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:12
GyroAverageMatrices< Device2 > mirror() const
Definition: gyro_avg_mat.hpp:35
TaskGroup task_group
Definition: gyro_avg_mat.hpp:20
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:16
A class that manages the distribution and execution of tasks in parallel using the MPI library...
Definition: task_group.hpp:14
int find_a_plane_rank_with_last_gyromatrix() const
double inv_drho
Definition: gyro_avg_mat.hpp:18
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 gyroaverage_field(const Grid< DeviceType > &grid, View< double ***, CLayout, HostType > &field_rho) const
Definition: matrix.hpp:13
HostArray< Matrix< Device > > matrices
Definition: gyro_avg_mat.hpp:14
Matrix< Device > operator[](int i) const
Definition: gyro_avg_mat.hpp:23
GyroAverageMatrices()
Definition: gyro_avg_mat.hpp:28
int nphi
Definition: gyro_avg_mat.hpp:19
Definition: magnetic_field.F90:1
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
Definition: host_array.hpp:11
double rhomax
Definition: gyro_avg_mat.hpp:17
static int GPTLstop(const char *name)
Definition: timer_macro.hpp:10
void init_one_gyro_avg_mat(const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, Matrix< Device > &matrix, int iphi, int irho, bool is_field_following, int n_larmor_pts)
Definition: gyro_avg_mat.cpp:75