XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gradient_matrices.hpp
Go to the documentation of this file.
1 #ifndef GRADIENT_MATRICES_HPP
2 #define GRADIENT_MATRICES_HPP
3 
4 #include "matrix.hpp"
5 #include "grid.hpp"
6 
7 extern "C" void get_grad_mat_data(int ind, int* m, int* n, int* w, int* nnz, int* is_csr_int, int** csr_ridx_or_eindex, int** csr_cidx_or_nelement, double** values);
8 
9 template<class Device>
13 
14  public:
15 
16  /* Set up gradx and grady on GPU by (for now) copying from the fortran matrix */
18  int m, n, w, nnz, is_csr_int;
19  int* csr_ridx_or_eindex;
20  int* csr_cidx_or_nelement;
21  double* values;
22  const int X=0;
23  const int Y=1;
24  // gradx
25  get_grad_mat_data(X, &m, &n, &w, &nnz, &is_csr_int, &csr_ridx_or_eindex, &csr_cidx_or_nelement, &values);
26  gradx = Matrix<Device>(m, n, w, nnz, (is_csr_int==1), csr_ridx_or_eindex, csr_cidx_or_nelement, values);
27 
28  // grady
29  get_grad_mat_data(Y, &m, &n, &w, &nnz, &is_csr_int, &csr_ridx_or_eindex, &csr_cidx_or_nelement, &values);
30  grady = Matrix<Device>(m, n, w, nnz, (is_csr_int==1), csr_ridx_or_eindex, csr_cidx_or_nelement, values);
31  }
32 
47  void grid_deriv(const Grid<Device>& grid, const Kokkos::View<double*,Kokkos::LayoutRight,Device>& qty, const Kokkos::View<double*,Kokkos::LayoutRight,Device>& qty_deriv_x, const Kokkos::View<double*,Kokkos::LayoutRight,Device>& qty_deriv_y, bool discard_when_basis_is_one) const{
48  // Take the gradient of qty
49  gradx.mult(qty, qty_deriv_x);
50  grady.mult(qty, qty_deriv_y);
51 
52  // Discard poloidal electric field (only for vertices using the psi-theta basis)
53  if (discard_when_basis_is_one){
54  Kokkos::parallel_for("grid_deriv", Kokkos::RangePolicy<ExSpace>(0,grid.nnode), KOKKOS_LAMBDA( const int i ){
55  if ( grid.basis(i)==0 ){
56  qty_deriv_y(i) = 0.0;
57  }
58  });
59  }
60 
61  }
62 
63 };
64 #endif
Definition: gradient_matrices.hpp:10
Definition: grid.hpp:10
void get_grad_mat_data(int ind, int *m, int *n, int *w, int *nnz, int *is_csr_int, int **csr_ridx_or_eindex, int **csr_cidx_or_nelement, double **values)
Kokkos::View< int *, Kokkos::LayoutRight, Device > basis
A basis for the guesses?
Definition: grid.hpp:91
Definition: matrix.hpp:11
void grid_deriv(const Grid< Device > &grid, const Kokkos::View< double *, Kokkos::LayoutRight, Device > &qty, const Kokkos::View< double *, Kokkos::LayoutRight, Device > &qty_deriv_x, const Kokkos::View< double *, Kokkos::LayoutRight, Device > &qty_deriv_y, bool discard_when_basis_is_one) const
Definition: gradient_matrices.hpp:47
Matrix< Device > grady
Definition: gradient_matrices.hpp:12
void parallel_for(const std::string name, int n_ptl, Function func, Option option, HostAoSoA aosoa_h, DeviceAoSoA aosoa_d)
Definition: streamed_parallel_for.hpp:252
Matrix< Device > gradx
Definition: gradient_matrices.hpp:11
int nnode
Number of grid nodes.
Definition: grid.hpp:83
GradientMatrices()
Definition: gradient_matrices.hpp:17