37#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_FUNCS_H
38#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_FUNCS_H
54 static unsigned int GetRequiredStorageSize(
unsigned int totalRows,
55 unsigned int totalColumns,
56 unsigned int subDiags,
57 unsigned int superDiags);
59 static unsigned int CalculateNumberOfDiags(
unsigned int totalRows,
62 static unsigned int CalculateNumberOfRows(
unsigned int totalRows,
63 unsigned int subDiags,
64 unsigned int superDiags);
66 static unsigned int CalculateIndex(
unsigned int totalRows,
67 unsigned int totalColumns,
68 unsigned int row,
unsigned int column,
69 unsigned int sub,
unsigned int super);
71 static std::tuple<unsigned int, unsigned int> Advance(
72 const unsigned int totalRows,
const unsigned int totalColumns,
73 const unsigned int curRow,
const unsigned int curColumn);
79 static unsigned int GetRequiredStorageSize(
unsigned int rows,
80 unsigned int columns);
81 static unsigned int CalculateIndex(
unsigned int totalRows,
82 unsigned int totalColumns,
84 unsigned int curColumn);
86 static std::tuple<unsigned int, unsigned int> Advance(
87 const unsigned int totalRows,
const unsigned int totalColumns,
88 const unsigned int curRow,
const unsigned int curColumn);
90 template <
typename DataType>
91 static void Invert(
unsigned int rows,
unsigned int columns,
94 ASSERTL0(rows == columns,
"Only square matrices can be inverted.");
96 "Only untransposed matrices may be inverted.");
104 if (std::is_floating_point<DataType>::value)
106 switch (
sizeof(DataType))
115 "Invert DataType is neither NekDouble nor NekSingle");
122 "FullMatrixFuncs::Invert DataType is not floating point");
129 std::string message =
130 "ERROR: The " + std::to_string(-info) +
131 "th parameter had an illegal parameter for dgetrf";
136 std::string message =
"ERROR: Element u_" + std::to_string(info) +
137 std::to_string(info) +
" is 0 from dgetrf";
145 std::string message =
146 "ERROR: The " + std::to_string(-info) +
147 "th parameter had an illegal parameter for dgetri";
152 std::string message =
"ERROR: Element u_" + std::to_string(info) +
153 std::to_string(info) +
" is 0 from dgetri";
158 template <
typename DataType>
164 int lda = n, info = 0;
168 if (EigVecs.
size() != 0)
174 EigValImag.
get(), &dum, 1, EigVecs.
get(), lda,
175 &work[0], lwork, info);
183 EigValImag.
get(), &dum, 1, &dum, 1, &work[0], lwork,
186 ASSERTL0(info == 0,
"Info is not zero");
192 static unsigned int GetRequiredStorageSize(
unsigned int rows,
193 unsigned int columns);
199 static unsigned int CalculateIndex(
unsigned int curRow,
200 unsigned int curColumn);
202 static std::tuple<unsigned int, unsigned int> Advance(
203 const unsigned int totalRows,
const unsigned int totalColumns,
204 const unsigned int curRow,
const unsigned int curColumn);
210 static unsigned int CalculateIndex(
unsigned int totalColumns,
212 unsigned int curColumn);
214 static std::tuple<unsigned int, unsigned int> Advance(
215 const unsigned int totalRows,
const unsigned int totalColumns,
216 const unsigned int curRow,
const unsigned int curColumn,
217 char transpose =
'N');
226 static unsigned int CalculateIndex(
unsigned int curRow,
227 unsigned int curColumn);
229 template <
typename DataType>
230 static void Invert(
unsigned int rows,
unsigned int columns,
233 ASSERTL0(rows == columns,
"Only square matrices can be inverted.");
244 std::string message =
245 "ERROR: The " + std::to_string(-info) +
246 "th parameter had an illegal parameter for dsptrf";
251 std::string message =
"ERROR: Element u_" + std::to_string(info) +
252 std::to_string(info) +
" is 0 from dsptrf";
260 std::string message =
261 "ERROR: The " + std::to_string(-info) +
262 "th parameter had an illegal parameter for dsptri";
267 std::string message =
"ERROR: Element u_" + std::to_string(info) +
268 std::to_string(info) +
" is 0 from dsptri";
273 static std::tuple<unsigned int, unsigned int> Advance(
274 const unsigned int totalRows,
const unsigned int totalColumns,
275 const unsigned int curRow,
const unsigned int curColumn);
280 static std::tuple<unsigned int, unsigned int> Advance(
281 const unsigned int totalRows,
const unsigned int totalColumns,
282 const unsigned int curRow,
const unsigned int curColumn);
284 template <
typename DataType>
285 static void Invert(
unsigned int rows,
unsigned int columns,
288 ASSERTL0(rows == columns,
"Only square matrices can be inverted.");
289 for (
unsigned int i = 0; i < rows; ++i)
291 data[i] = 1.0 / data[i];
295 static unsigned int GetRequiredStorageSize(
unsigned int rows,
296 unsigned int columns);
298 static unsigned int CalculateIndex(
unsigned int row,
unsigned int col);
303 static unsigned int GetRequiredStorageSize(
unsigned int rows,
304 unsigned int columns,
305 unsigned int nSubSuperDiags);
325 static unsigned int CalculateIndex(
unsigned int curRow,
326 unsigned int curColumn,
327 unsigned int nSuperDiags);
#define ASSERTL0(condition, msg)
#define LIB_UTILITIES_EXPORT
1D Array of constant elements with garbage collection and bounds checking.
size_type size() const
Returns the array's size.
static void DoSsptrf(const char &uplo, const int &n, double *ap, int *ipiv, int &info)
factor a real packed-symmetric matrix using Bunch-Kaufman pivoting.
static void DoSsptri(const char &uplo, const int &n, const double *ap, const int *ipiv, double *work, int &info)
Invert a real packed-symmetric matrix problem.
static void DoSgetrf(const int &m, const int &n, double *a, const int &lda, int *ipiv, int &info)
General matrix LU factorisation.
static void DoSgetri(const int &n, double *a, const int &lda, const int *ipiv, double *wk, const int &lwk, int &info)
General matrix inverse.
static void DoSgeev(const char &uplo, const char &lrev, const int &n, const double *a, const int &lda, double *wr, double *wi, double *rev, const int &ldr, double *lev, const int &ldv, double *work, const int &lwork, int &info)
Solve general real matrix eigenproblem.
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data)
static void EigenSolve(unsigned int n, const Array< OneD, const DataType > &A, Array< OneD, DataType > &EigValReal, Array< OneD, DataType > &EigValImag, Array< OneD, DataType > &EigVecs)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data, const char transpose)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns, unsigned int nSubSuperDiags)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns)