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 72 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 117 of file MatrixFuncs.cpp.

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

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

◆ CalculateIndex()

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

Definition at line 109 of file MatrixFuncs.cpp.

110  {
111  boost::ignore_unused(totalColumns);
112  return curColumn*totalRows + curRow;
113  }

Referenced by Nektar::ConstMatrix< NekMatrix< DataType, InnerMatrixType >::NumberType >::v_GetTransposeFlag().

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

151  {
152  int lda = n,info = 0;
153  DataType dum;
154  char uplo = 'N';
155 
156  if(EigVecs.size() != 0) // calculate Right Eigen Vectors
157  {
158  int lwork = 4*lda;
159  Array<OneD,DataType> work(4*lda);
160  char lrev = 'V';
161  Lapack::DoSgeev(uplo,lrev,lda, A.get(),lda,
162  EigValReal.get(),
163  EigValImag.get(),
164  &dum,1,
165  EigVecs.get(),lda,
166  &work[0],lwork,info);
167  }
168  else
169  {
170  int lwork = 3*lda;
171  Array<OneD,DataType> work(3*lda);
172  char lrev = 'N';
173  Lapack::DoSgeev(uplo,lrev,lda,
174  A.get(),lda,
175  EigValReal.get(),
176  EigValImag.get(),
177  &dum,1,&dum,1,
178  &work[0],lwork,info);
179  }
180  ASSERTL0(info == 0,"Info is not zero");
181 
182  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
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:347

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 104 of file MatrixFuncs.cpp.

105  {
106  return rows*columns;
107  }

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

87  {
88  ASSERTL0(rows==columns, "Only square matrices can be inverted.");
89  ASSERTL0(transpose=='N', "Only untransposed matrices may be inverted.");
90 
91  int m = rows;
92  int n = columns;
93  int info = 0;
94  Array<OneD, int> ipivot(n);
95  Array<OneD, DataType> work(n);
96 
97  if(std::is_floating_point<DataType>::value)
98  {
99  switch ( sizeof(DataType) )
100  {
101  case sizeof(NekDouble):
102  break;
103  case sizeof(NekSingle):
104  break;
105  default:
106  ASSERTL0(false,
107  "Invert DataType is neither NekDouble nor NekSingle");
108  break;
109  }
110  }
111  else
112  {
113  ASSERTL0(false,
114  "FullMatrixFuncs::Invert DataType is not floating point");
115  }
116 
117  Lapack::DoSgetrf(m, n, data.get(), m, ipivot.get(), info);
118 
119  if( info < 0 )
120  {
121  std::string message = "ERROR: The " + std::to_string(-info) + "th parameter had an illegal parameter for dgetrf";
122  ASSERTL0(false, message.c_str());
123  }
124  else if( info > 0 )
125  {
126  std::string message = "ERROR: Element u_" + std::to_string(info) + std::to_string(info) + " is 0 from dgetrf";
127  ASSERTL0(false, message.c_str());
128  }
129 
130  Lapack::DoSgetri(n, data.get(), n, ipivot.get(),
131  work.get(), n, info);
132 
133  if( info < 0 )
134  {
135  std::string message = "ERROR: The " + std::to_string(-info) + "th parameter had an illegal parameter for dgetri";
136  ASSERTL0(false, message.c_str());
137  }
138  else if( info > 0 )
139  {
140  std::string message = "ERROR: Element u_" + std::to_string(info) + std::to_string(info) + " is 0 from dgetri";
141  ASSERTL0(false, message.c_str());
142  }
143  }
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:291
static void DoSgetri(const int &n, double *a, const int &lda, const int *ipiv, double *wk, const int &lwk, int &info)
Generate matrix inverse.
Definition: Lapack.hpp:320
double NekDouble

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

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