XGCa
 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 "simd.hpp"
5 #include "globals.hpp"
6 
7 // A convenient struct for the many times a linear weight needs to be calculated and stored
8 struct LinearWeights{
9  int i; // the lower index
10  double w[2]; // the weights of i and i+1
11 
12  KOKKOS_INLINE_FUNCTION LinearWeights(){}
13 
14  // Allow set in the constructor for legibility
15  KOKKOS_INLINE_FUNCTION LinearWeights(double var, double inv_d ){
16  set(var, inv_d);
17  }
18 
19  KOKKOS_INLINE_FUNCTION LinearWeights(double var, double inv_d, int i_max ){
20  set(var, inv_d, i_max);
21  }
22 
23  // Calculate the weights
24  KOKKOS_INLINE_FUNCTION void set(double var, double inv_d ){
25  double var_over_d = var*inv_d;
26  i = floor(var_over_d);
27 
28  w[1] = var_over_d - i;
29  w[0] = 1.0 - w[1];
30  }
31 
32  // Calculate the weights with a max index to be safe
33  // This check shouldnt be necessary and it gives buggy weights if caught
34  KOKKOS_INLINE_FUNCTION void set(double var, double inv_d, int i_max){
35  double var_over_d = var*inv_d;
36  i = floor(var_over_d);
37 
38  i = min(i,i_max-1);
39  w[1] = min(1.0,var_over_d - i);
40  w[0] = 1.0 - w[1];
41  }
42 
43 };
44 
45 
47  Simd<int> i; // the lower index
48  Simd<double> w[2]; // the weights of i and i+1
49 
50  KOKKOS_INLINE_FUNCTION SimdLinearWeights(){}
51 
52  // Allow set in the constructor for legibility
53  KOKKOS_INLINE_FUNCTION SimdLinearWeights(Simd<double> var, double inv_d ){
54  set(var, inv_d);
55  }
56 
57  KOKKOS_INLINE_FUNCTION SimdLinearWeights(Simd<double> var, double inv_d, int i_max ){
58  set(var, inv_d, i_max);
59  }
60 
61  // Calculate the weights
62  KOKKOS_INLINE_FUNCTION void set(Simd<double> var, double inv_d ){
63  for(int i_simd = 0; i_simd<SIMD_SIZE; i_simd++){
64  double var_over_d = var[i_simd]*inv_d;
65  i[i_simd] = floor(var_over_d);
66 
67  w[1][i_simd] = var_over_d - i[i_simd];
68  w[0][i_simd] = 1.0 - w[1][i_simd];
69  }
70  }
71 
72  // Calculate the weights with a max index to be safe
73  // This check shouldnt be necessary and it gives buggy weights if caught
74  KOKKOS_INLINE_FUNCTION void set(Simd<double> var, double inv_d, int i_max){
75  for(int i_simd = 0; i_simd<SIMD_SIZE; i_simd++){
76  double var_over_d = var[i_simd]*inv_d;
77  i[i_simd] = floor(var_over_d);
78 
79  i[i_simd] = min(i[i_simd],i_max-1);
80  w[1][i_simd] = min(1.0,var_over_d - i[i_simd]);
81  w[0][i_simd] = 1.0 - w[1][i_simd];
82  }
83  }
84 
85 };
86 
87 
88 #endif
Simd< int > i
Definition: linear_weights.hpp:47
Definition: linear_weights.hpp:46
Definition: linear_weights.hpp:8
KOKKOS_INLINE_FUNCTION SimdLinearWeights()
Definition: linear_weights.hpp:50
KOKKOS_INLINE_FUNCTION SimdLinearWeights(Simd< double > var, double inv_d, int i_max)
Definition: linear_weights.hpp:57
KOKKOS_INLINE_FUNCTION LinearWeights()
Definition: linear_weights.hpp:12
Simd< double > w[2]
Definition: linear_weights.hpp:48
KOKKOS_INLINE_FUNCTION void set(double var, double inv_d)
Definition: linear_weights.hpp:24
KOKKOS_INLINE_FUNCTION SimdLinearWeights(Simd< double > var, double inv_d)
Definition: linear_weights.hpp:53
KOKKOS_INLINE_FUNCTION void set(Simd< double > var, double inv_d)
Definition: linear_weights.hpp:62
double w[2]
Definition: linear_weights.hpp:10
KOKKOS_INLINE_FUNCTION LinearWeights(double var, double inv_d, int i_max)
Definition: linear_weights.hpp:19
int i
Definition: linear_weights.hpp:9
KOKKOS_INLINE_FUNCTION LinearWeights(double var, double inv_d)
Definition: linear_weights.hpp:15
KOKKOS_INLINE_FUNCTION void set(double var, double inv_d, int i_max)
Definition: linear_weights.hpp:34
KOKKOS_INLINE_FUNCTION void set(Simd< double > var, double inv_d, int i_max)
Definition: linear_weights.hpp:74