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,
unsigned int totalColumns,
55 unsigned int subDiags,
unsigned int superDiags);
57 static unsigned int CalculateNumberOfDiags(
unsigned int totalRows,
unsigned int diags);
59 static unsigned int CalculateNumberOfRows(
unsigned int totalRows,
unsigned int subDiags,
unsigned int superDiags);
61 static unsigned int CalculateIndex(
unsigned int totalRows,
62 unsigned int totalColumns,
63 unsigned int row,
unsigned int column,
64 unsigned int sub,
unsigned int super);
67 static std::tuple<unsigned int, unsigned int>
68 Advance(
const unsigned int totalRows,
const unsigned int totalColumns,
69 const unsigned int curRow,
const unsigned int curColumn);
75 static unsigned int GetRequiredStorageSize(
unsigned int rows,
unsigned int columns);
76 static unsigned int CalculateIndex(
unsigned int totalRows,
unsigned int totalColumns,
unsigned int curRow,
unsigned int curColumn);
79 static std::tuple<unsigned int, unsigned int>
80 Advance(
const unsigned int totalRows,
const unsigned int totalColumns,
81 const unsigned int curRow,
const unsigned int curColumn);
83 template<
typename DataType>
84 static void Invert(
unsigned int rows,
unsigned int columns,
88 ASSERTL0(rows==columns,
"Only square matrices can be inverted.");
89 ASSERTL0(transpose==
'N',
"Only untransposed matrices may be inverted.");
97 if(std::is_floating_point<DataType>::value)
99 switch (
sizeof(DataType) )
107 "Invert DataType is neither NekDouble nor NekSingle");
114 "FullMatrixFuncs::Invert DataType is not floating point");
121 std::string message =
"ERROR: The " + std::to_string(-info) +
"th parameter had an illegal parameter for dgetrf";
126 std::string message =
"ERROR: Element u_" + std::to_string(info) + std::to_string(info) +
" is 0 from dgetrf";
131 work.
get(), n, info);
135 std::string message =
"ERROR: The " + std::to_string(-info) +
"th parameter had an illegal parameter for dgetri";
140 std::string message =
"ERROR: Element u_" + std::to_string(info) + std::to_string(info) +
" is 0 from dgetri";
145 template<
typename DataType>
152 int lda = n,info = 0;
156 if(EigVecs.
size() != 0)
166 &work[0],lwork,info);
178 &work[0],lwork,info);
180 ASSERTL0(info == 0,
"Info is not zero");
187 static unsigned int GetRequiredStorageSize(
unsigned int rows,
unsigned int columns);
192 static unsigned int CalculateIndex(
unsigned int curRow,
unsigned int curColumn);
194 static std::tuple<unsigned int, unsigned int>
195 Advance(
const unsigned int totalRows,
const unsigned int totalColumns,
196 const unsigned int curRow,
const unsigned int curColumn);
202 static unsigned int CalculateIndex(
unsigned int totalColumns,
unsigned int curRow,
unsigned int curColumn);
204 static std::tuple<unsigned int, unsigned int>
205 Advance(
const unsigned int totalRows,
const unsigned int totalColumns,
206 const unsigned int curRow,
const unsigned int curColumn,
207 char transpose =
'N');
216 static unsigned int CalculateIndex(
unsigned int curRow,
unsigned int curColumn);
218 template<
typename DataType>
219 static void Invert(
unsigned int rows,
unsigned int columns,
222 ASSERTL0(rows==columns,
"Only square matrices can be inverted.");
233 std::string message =
"ERROR: The " + std::to_string(-info) +
"th parameter had an illegal parameter for dsptrf";
238 std::string message =
"ERROR: Element u_" + std::to_string(info) + std::to_string(info) +
" is 0 from dsptrf";
247 std::string message =
"ERROR: The " + std::to_string(-info) +
"th parameter had an illegal parameter for dsptri";
252 std::string message =
"ERROR: Element u_" + std::to_string(info) + std::to_string(info) +
" is 0 from dsptri";
257 static std::tuple<unsigned int, unsigned int>
258 Advance(
const unsigned int totalRows,
const unsigned int totalColumns,
259 const unsigned int curRow,
const unsigned int curColumn);
264 static std::tuple<unsigned int, unsigned int>
265 Advance(
const unsigned int totalRows,
const unsigned int totalColumns,
266 const unsigned int curRow,
const unsigned int curColumn);
268 template<
typename DataType>
269 static void Invert(
unsigned int rows,
unsigned int columns,
272 ASSERTL0(rows==columns,
"Only square matrices can be inverted.");
273 for(
unsigned int i = 0; i < rows; ++i)
275 data[i] = 1.0/data[i];
279 static unsigned int GetRequiredStorageSize(
unsigned int rows,
unsigned int columns);
281 static unsigned int CalculateIndex(
unsigned int row,
unsigned int col);
287 static unsigned int GetRequiredStorageSize(
unsigned int rows,
unsigned int columns,
288 unsigned int nSubSuperDiags);
305 static unsigned int CalculateIndex(
unsigned int curRow,
unsigned int curColumn,
306 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 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)
Generate 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.
The above copyright notice and this permission notice shall be included.
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)