XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
linear_weights.hpp
Go to the documentation of this file.
1 #ifndef LINEAR_WEIGHTS_HPP
2 #define LINEAR_WEIGHTS_HPP
3 
4 #include "globals.hpp"
5 
6 // A convenient struct for the many times a linear weight needs to be calculated and stored
7 struct LinearWeights{
8  int i; // the lower index
9  double w[2]; // the weights of i and i+1
10 
11  KOKKOS_INLINE_FUNCTION LinearWeights(){}
12 
13  // Allow set in the constructor for legibility
14  KOKKOS_INLINE_FUNCTION LinearWeights(double var, double inv_d ){
15  set(var, inv_d);
16  }
17 
18  KOKKOS_INLINE_FUNCTION LinearWeights(double var, double inv_d, int i_max ){
19  set(var, inv_d, i_max);
20  }
21 
22  // Calculate the weights
23  KOKKOS_INLINE_FUNCTION void set(double var, double inv_d ){
24  double var_over_d = var*inv_d;
25  i = floor(var_over_d);
26 
27  w[1] = var_over_d - i;
28  w[0] = 1.0 - w[1];
29  }
30 
31  // Calculate the weights with a max index to be safe
32  // This check shouldnt be necessary and it gives buggy weights if caught
33  KOKKOS_INLINE_FUNCTION void set(double var, double inv_d, int i_max){
34  double var_over_d = var*inv_d;
35  i = floor(var_over_d);
36 
37  i = min(i,i_max-1);
38  w[1] = min(1.0,var_over_d - i);
39  w[0] = 1.0 - w[1];
40  }
41 
42 };
43 
44 
45 #endif
Definition: linear_weights.hpp:7
KOKKOS_INLINE_FUNCTION LinearWeights()
Definition: linear_weights.hpp:11
KOKKOS_INLINE_FUNCTION void set(double var, double inv_d)
Definition: linear_weights.hpp:23
double w[2]
Definition: linear_weights.hpp:9
KOKKOS_INLINE_FUNCTION LinearWeights(double var, double inv_d, int i_max)
Definition: linear_weights.hpp:18
int i
Definition: linear_weights.hpp:8
KOKKOS_INLINE_FUNCTION LinearWeights(double var, double inv_d)
Definition: linear_weights.hpp:14
KOKKOS_INLINE_FUNCTION void set(double var, double inv_d, int i_max)
Definition: linear_weights.hpp:33