Compadre  1.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Compadre_Misc.hpp
Go to the documentation of this file.
1 #ifndef _COMPADRE_MISC_HPP_
2 #define _COMPADRE_MISC_HPP_
3 
4 #include "Compadre_Operators.hpp"
5 
6 namespace Compadre {
7 
8 struct XYZ {
9 
10  KOKKOS_INLINE_FUNCTION
11  XYZ() : x(0), y(0), z(0) {}
12 
13  KOKKOS_INLINE_FUNCTION
14  XYZ(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {}
15 
16  double x;
17  double y;
18  double z;
19 
20  KOKKOS_INLINE_FUNCTION
21  double& operator [](const int i) {
22  switch (i) {
23  case 0:
24  return x;
25  case 1:
26  return y;
27  default:
28  return z;
29  }
30  }
31 
32  KOKKOS_INLINE_FUNCTION
33  XYZ operator *(double scalar) {
34  XYZ result;
35  result.x = scalar*x;
36  result.y = scalar*y;
37  result.z = scalar*z;
38  return result;
39  }
40 }; // XYZ
41 
42 KOKKOS_INLINE_FUNCTION
43 int getAdditionalAlphaSizeFromConstraint(DenseSolverType dense_solver_type, ConstraintType constraint_type) {
44  // Return the additional constraint size
45  if (constraint_type == NEUMANN_GRAD_SCALAR) {
46  return 1;
47  } else {
48  return 0;
49  }
50 }
51 
52 KOKKOS_INLINE_FUNCTION
53 int getAdditionalCoeffSizeFromConstraintAndSpace(DenseSolverType dense_solver_type, ConstraintType constraint_type, ReconstructionSpace reconstruction_space, const int dimension) {
54  // Return the additional constraint size
55  int added_alpha_size = getAdditionalAlphaSizeFromConstraint(dense_solver_type, constraint_type);
56  if (reconstruction_space == VectorTaylorPolynomial) {
57  return dimension*added_alpha_size;
58  } else {
59  return added_alpha_size;
60  }
61 }
62 
63 KOKKOS_INLINE_FUNCTION
64 int getRHSSquareDim(DenseSolverType dense_solver_type, ConstraintType constraint_type, ReconstructionSpace reconstruction_space, const int dimension, const int M, const int N) {
65  // Return the appropriate size for _RHS. Since in LU, the system solves P^T*P against P^T*W.
66  // We store P^T*P in the RHS space, which means RHS can be much smaller compared to the
67  // case for QR/SVD where the system solves PsqrtW against sqrtW*Identity
68 
69  int added_coeff_size = getAdditionalCoeffSizeFromConstraintAndSpace(dense_solver_type, constraint_type, reconstruction_space, dimension);
70 
71  if (constraint_type == NEUMANN_GRAD_SCALAR) {
72  return N + added_coeff_size;
73  } else {
74  if (dense_solver_type != LU) {
75  return M;
76  } else {
77  return N + added_coeff_size;
78  }
79  }
80 }
81 
82 KOKKOS_INLINE_FUNCTION
83 void getPDims(DenseSolverType dense_solver_type, ConstraintType constraint_type, ReconstructionSpace reconstruction_space, const int dimension, const int M, const int N, int &out_row, int &out_col) {
84  // Return the appropriate size for _P.
85  // In the case of solving with LU and additional constraint is used, _P needs
86  // to be resized to include additional row(s) based on the type of constraint.
87 
88  int added_coeff_size = getAdditionalCoeffSizeFromConstraintAndSpace(dense_solver_type, constraint_type, reconstruction_space, dimension);
89  int added_alpha_size = getAdditionalAlphaSizeFromConstraint(dense_solver_type, constraint_type);
90 
91  if (constraint_type == NEUMANN_GRAD_SCALAR) {
92  out_row = M + added_alpha_size;
93  out_col = N + added_coeff_size;
94  } else {
95  if (dense_solver_type == LU) {
96  out_row = M + added_alpha_size;
97  out_col = N + added_coeff_size;
98  } else {
99  out_row = M;
100  out_col = N;
101  }
102  }
103 }
104 
105 } // Compadre
106 
107 #endif
KOKKOS_INLINE_FUNCTION int getAdditionalAlphaSizeFromConstraint(DenseSolverType dense_solver_type, ConstraintType constraint_type)
KOKKOS_INLINE_FUNCTION int getAdditionalCoeffSizeFromConstraintAndSpace(DenseSolverType dense_solver_type, ConstraintType constraint_type, ReconstructionSpace reconstruction_space, const int dimension)
Neumann Gradient Scalar Type.
KOKKOS_INLINE_FUNCTION XYZ operator*(double scalar)
KOKKOS_INLINE_FUNCTION double & operator[](const int i)
ReconstructionSpace
Space in which to reconstruct polynomial.
KOKKOS_INLINE_FUNCTION XYZ(double _x, double _y, double _z)
KOKKOS_INLINE_FUNCTION void getPDims(DenseSolverType dense_solver_type, ConstraintType constraint_type, ReconstructionSpace reconstruction_space, const int dimension, const int M, const int N, int &out_row, int &out_col)
DenseSolverType
Dense solver type.
LU factorization performed on P^T*W*P matrix.
KOKKOS_INLINE_FUNCTION int getRHSSquareDim(DenseSolverType dense_solver_type, ConstraintType constraint_type, ReconstructionSpace reconstruction_space, const int dimension, const int M, const int N)
KOKKOS_INLINE_FUNCTION XYZ()
Vector polynomial basis having # of components _dimensions, or (_dimensions-1) in the case of manifol...
ConstraintType
Constraint type.