Nektar++
Static Public Member Functions | List of all members
Nektar::FullMatrixFuncs Struct Reference

#include <MatrixFuncs.h>

Static Public Member Functions

static unsigned int GetRequiredStorageSize (unsigned int rows, unsigned int columns)
 
static unsigned int CalculateIndex (unsigned int totalRows, unsigned int totalColumns, unsigned int curRow, unsigned int curColumn)
 
static std::tuple< unsigned int, unsigned int > Advance (const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
 
template<typename DataType >
static void Invert (unsigned int rows, unsigned int columns, Array< OneD, DataType > &data, const char transpose)
 
template<typename DataType >
static void EigenSolve (unsigned int n, const Array< OneD, const DataType > &A, Array< OneD, DataType > &EigValReal, Array< OneD, DataType > &EigValImag, Array< OneD, DataType > &EigVecs)
 

Detailed Description

Definition at line 76 of file MatrixFuncs.h.

Member Function Documentation

◆ Advance()

std::tuple< unsigned int, unsigned int > Nektar::FullMatrixFuncs::Advance ( const unsigned int  totalRows,
const unsigned int  totalColumns,
const unsigned int  curRow,
const unsigned int  curColumn 
)
static

Definition at line 121 of file MatrixFuncs.cpp.

124{
125 unsigned int nextRow = curRow;
126 unsigned int nextColumn = curColumn;
127
128 if (nextRow < totalRows)
129 {
130 ++nextRow;
131 }
132
133 if (nextRow >= totalRows)
134 {
135 nextRow = 0;
136 ++nextColumn;
137 }
138
139 if (nextColumn >= totalColumns)
140 {
141 nextRow = std::numeric_limits<unsigned int>::max();
142 nextColumn = std::numeric_limits<unsigned int>::max();
143 }
144
145 return std::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
146}

Referenced by Nektar::NekMatrix< DataType, StandardMatrixTag >::Advance(), and Nektar::FullMatrixStoragePolicyUnitTests::BOOST_AUTO_TEST_CASE().

◆ CalculateIndex()

unsigned int Nektar::FullMatrixFuncs::CalculateIndex ( unsigned int  totalRows,
unsigned int  totalColumns,
unsigned int  curRow,
unsigned int  curColumn 
)
static

Definition at line 114 of file MatrixFuncs.cpp.

117{
118 return curColumn * totalRows + curRow;
119}

Referenced by Nektar::FullMatrixStoragePolicyUnitTests::BOOST_AUTO_TEST_CASE().

◆ EigenSolve()

template<typename DataType >
static void Nektar::FullMatrixFuncs::EigenSolve ( unsigned int  n,
const Array< OneD, const DataType > &  A,
Array< OneD, DataType > &  EigValReal,
Array< OneD, DataType > &  EigValImag,
Array< OneD, DataType > &  EigVecs 
)
inlinestatic

Definition at line 160 of file MatrixFuncs.h.

164 {
165 int lda = n, info = 0;
166 DataType dum;
167 char uplo = 'N';
168
169 if (EigVecs.size() != 0) // calculate Right Eigen Vectors
170 {
171 int lwork = 4 * lda;
172 Array<OneD, DataType> work(4 * lda);
173 char lrev = 'V';
174 Lapack::DoSgeev(uplo, lrev, lda, A.data(), lda, EigValReal.data(),
175 EigValImag.data(), &dum, 1, EigVecs.data(), lda,
176 &work[0], lwork, info);
177 }
178 else
179 {
180 int lwork = 3 * lda;
181 Array<OneD, DataType> work(3 * lda);
182 char lrev = 'N';
183 Lapack::DoSgeev(uplo, lrev, lda, A.data(), lda, EigValReal.data(),
184 EigValImag.data(), &dum, 1, &dum, 1, &work[0],
185 lwork, info);
186 }
187 ASSERTL0(info == 0, "Info is not zero");
188 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
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.
Definition: Lapack.hpp:307

References ASSERTL0, Nektar::Array< OneD, DataType >::data(), Lapack::DoSgeev(), and Nektar::Array< OneD, const DataType >::size().

Referenced by Nektar::NekMatrix< DataType, StandardMatrixTag >::EigenSolve().

◆ GetRequiredStorageSize()

unsigned int Nektar::FullMatrixFuncs::GetRequiredStorageSize ( unsigned int  rows,
unsigned int  columns 
)
static

Definition at line 108 of file MatrixFuncs.cpp.

110{
111 return rows * columns;
112}

Referenced by Nektar::ConstMatrix< DataType >::GetRequiredStorageSize().

◆ Invert()

template<typename DataType >
static void Nektar::FullMatrixFuncs::Invert ( unsigned int  rows,
unsigned int  columns,
Array< OneD, DataType > &  data,
const char  transpose 
)
inlinestatic

Definition at line 91 of file MatrixFuncs.h.

93 {
94 ASSERTL0(rows == columns, "Only square matrices can be inverted.");
95 ASSERTL0(transpose == 'N',
96 "Only untransposed matrices may be inverted.");
97
98 int m = rows;
99 int n = columns;
100 int info = 0;
101 Array<OneD, int> ipivot(n);
102 Array<OneD, DataType> work(n);
103
104 if (std::is_floating_point_v<DataType>)
105 {
106 switch (sizeof(DataType))
107 {
108 case sizeof(NekDouble):
109 break;
110 case sizeof(NekSingle):
111 break;
112 default:
113 ASSERTL0(
114 false,
115 "Invert DataType is neither NekDouble nor NekSingle");
116 break;
117 }
118 }
119 else
120 {
121 ASSERTL0(false,
122 "FullMatrixFuncs::Invert DataType is not floating point");
123 }
124
125 Lapack::DoSgetrf(m, n, data.data(), m, ipivot.data(), info);
126
127 if (info < 0)
128 {
129 std::string message =
130 "ERROR: The " + std::to_string(-info) +
131 "th parameter had an illegal parameter for dgetrf";
132 ASSERTL0(false, message.c_str());
133 }
134 else if (info > 0)
135 {
136 std::string message = "ERROR: Element u_" + std::to_string(info) +
137 std::to_string(info) + " is 0 from dgetrf";
138 ASSERTL0(false, message.c_str());
139 }
140
141 Lapack::DoSgetri(n, data.data(), n, ipivot.data(), work.data(), n,
142 info);
143
144 if (info < 0)
145 {
146 std::string message =
147 "ERROR: The " + std::to_string(-info) +
148 "th parameter had an illegal parameter for dgetri";
149 ASSERTL0(false, message.c_str());
150 }
151 else if (info > 0)
152 {
153 std::string message = "ERROR: Element u_" + std::to_string(info) +
154 std::to_string(info) + " is 0 from dgetri";
155 ASSERTL0(false, message.c_str());
156 }
157 }
static void DoSgetrf(const int &m, const int &n, double *a, const int &lda, int *ipiv, int &info)
General matrix LU factorisation.
Definition: Lapack.hpp:248
static void DoSgetri(const int &n, double *a, const int &lda, const int *ipiv, double *wk, const int &lwk, int &info)
General matrix inverse.
Definition: Lapack.hpp:277
double NekDouble

References ASSERTL0, Nektar::Array< OneD, DataType >::data(), Lapack::DoSgetrf(), and Lapack::DoSgetri().

Referenced by Nektar::NekMatrix< DataType, StandardMatrixTag >::Invert().