XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lagrange_weights.hpp
Go to the documentation of this file.
1 
15 #ifndef LAGRANGE_WEIGHTS_HPP
16 #define LAGRANGE_WEIGHTS_HPP
17 
18 #define LAGRANGE_MAX_ORDER 8
19 
20 #include "globals.hpp"
21 
38 
39  int idx = 0;
40  double w[LAGRANGE_MAX_ORDER] = { 0.0 };
41 
42  KOKKOS_INLINE_FUNCTION lagrange_weights(){}
43 
44  // Allow set in the constructor for legibility
45  KOKKOS_INLINE_FUNCTION lagrange_weights(double var, double inv_d, int order){
46  set(var, inv_d, order);
47  }
48 
58  KOKKOS_INLINE_FUNCTION void set(double var, double inv_d, int order){
59  double var_over_d, cell_loc, delta;
60 
61  var_over_d = (order > 0) ? var*inv_d/order : var*inv_d;
62  idx = floor(var_over_d);
63  cell_loc = var_over_d - idx; // Varies from 0.0 to 1.0
64  if (order > 0){
65  delta = 1.0/order;
66  }
67  else if(cell_loc > 0.5){ // For order 0 set idx to nearest grid point
68  idx += 1;
69  }
70 
71  // double w_sum = 0.0, m_sum = 0.0, e_sum = 0.0; // Temporary for debugging
72 
73  for (int kk = 0; kk <= order; kk++){
74  w[kk] = 1.0;
75  for (int jj = 0; jj <= order; jj++){
76  if (kk != jj){
77  w[kk] *= (cell_loc - jj*delta)/(kk*delta - jj*delta);
78  }
79  }
80  // w_sum += w[kk]; // Temporary for debugging
81  // m_sum += w[kk]*(double)kk/order; // Temporary for debugging
82  // e_sum += w[kk]*((double)kk/order)*((double)kk/order); // Temporary for debugging
83  }
84 
85  // Temporary for debugging
86  // double tol = 1.0e-10;
87  // assert_XGC(1.0 - tol <= w_sum && w_sum <= 1.0 + tol,
88  // "\nERROR: lagrange weights density error\n");
89  // assert_XGC(cell_loc - tol <= m_sum && m_sum <= cell_loc + tol,
90  // "\nERROR: lagrange weights momentum error\n");
91  // assert_XGC(cell_loc*cell_loc - tol <= e_sum && e_sum <= cell_loc*cell_loc + tol,
92  // "\nERROR: lagrange weights energy error\n");
93  }
94 
95  KOKKOS_INLINE_FUNCTION void set_idx(int new_idx){
96  idx = new_idx;
97  }
98 
99 };
100 
101 #endif
int idx
The lower cell index on the grid where one cell comprises order+1 grid points.
Definition: lagrange_weights.hpp:39
KOKKOS_INLINE_FUNCTION lagrange_weights(double var, double inv_d, int order)
Definition: lagrange_weights.hpp:45
KOKKOS_INLINE_FUNCTION void set(double var, double inv_d, int order)
Definition: lagrange_weights.hpp:58
This struct contains interpolation weights for 1D Lagrange interpolating polynomials of arbitrary ord...
Definition: lagrange_weights.hpp:37
#define LAGRANGE_MAX_ORDER
Definition: lagrange_weights.hpp:18
double w[LAGRANGE_MAX_ORDER]
Stores the Lagrange weights of the grid points i, i+1, i+2, ..., i+order in one cell.
Definition: lagrange_weights.hpp:40
KOKKOS_INLINE_FUNCTION lagrange_weights()
Definition: lagrange_weights.hpp:42
KOKKOS_INLINE_FUNCTION void set_idx(int new_idx)
Definition: lagrange_weights.hpp:95