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(), and Nektar::ConstMatrix< DataType >::CalculateIndex().

◆ 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 159 of file MatrixFuncs.h.

163 {
164 int lda = n, info = 0;
165 DataType dum;
166 char uplo = 'N';
167
168 if (EigVecs.size() != 0) // calculate Right Eigen Vectors
169 {
170 int lwork = 4 * lda;
171 Array<OneD, DataType> work(4 * lda);
172 char lrev = 'V';
173 Lapack::DoSgeev(uplo, lrev, lda, A.get(), lda, EigValReal.get(),
174 EigValImag.get(), &dum, 1, EigVecs.get(), lda,
175 &work[0], lwork, info);
176 }
177 else
178 {
179 int lwork = 3 * lda;
180 Array<OneD, DataType> work(3 * lda);
181 char lrev = 'N';
182 Lapack::DoSgeev(uplo, lrev, lda, A.get(), lda, EigValReal.get(),
183 EigValImag.get(), &dum, 1, &dum, 1, &work[0], lwork,
184 info);
185 }
186 ASSERTL0(info == 0, "Info is not zero");
187 }
#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, Lapack::DoSgeev(), Nektar::Array< OneD, DataType >::get(), 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<DataType>::value)
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.get(), m, ipivot.get(), 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.get(), n, ipivot.get(), work.get(), n, info);
142
143 if (info < 0)
144 {
145 std::string message =
146 "ERROR: The " + std::to_string(-info) +
147 "th parameter had an illegal parameter for dgetri";
148 ASSERTL0(false, message.c_str());
149 }
150 else if (info > 0)
151 {
152 std::string message = "ERROR: Element u_" + std::to_string(info) +
153 std::to_string(info) + " is 0 from dgetri";
154 ASSERTL0(false, message.c_str());
155 }
156 }
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, Lapack::DoSgetrf(), Lapack::DoSgetri(), and Nektar::Array< OneD, DataType >::get().

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