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)
 
static void EigenSolve (unsigned int n, const Array< OneD, const double > &A, Array< OneD, NekDouble > &EigValReal, Array< OneD, NekDouble > &EigValImag, Array< OneD, NekDouble > &EigVecs=NullNekDouble1DArray)
 

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.

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

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  }

◆ 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.

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

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

◆ EigenSolve()

static void Nektar::FullMatrixFuncs::EigenSolve ( unsigned int  n,
const Array< OneD, const double > &  A,
Array< OneD, NekDouble > &  EigValReal,
Array< OneD, NekDouble > &  EigValImag,
Array< OneD, NekDouble > &  EigVecs = NullNekDouble1DArray 
)
inlinestatic

Definition at line 125 of file MatrixFuncs.h.

References ASSERTL0, Lapack::Dgeev(), and Nektar::NullNekDouble1DArray.

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

130  {
131  int lda = n,info = 0;
132  NekDouble dum;
133  char uplo = 'N';
134 
135  if(EigVecs != NullNekDouble1DArray) // calculate Right Eigen Vectors
136  {
137  int lwork = 4*lda;
138  Array<OneD,NekDouble> work(4*lda);
139  char lrev = 'V';
140  Lapack::Dgeev(uplo,lrev,lda, A.get(),lda,
141  EigValReal.get(),
142  EigValImag.get(),
143  &dum,1,
144  EigVecs.get(),lda,
145  &work[0],lwork,info);
146  }
147  else
148  {
149  int lwork = 3*lda;
150  Array<OneD,NekDouble> work(3*lda);
151  char lrev = 'N';
152  Lapack::Dgeev(uplo,lrev,lda,
153  A.get(),lda,
154  EigValReal.get(),
155  EigValImag.get(),
156  &dum,1,&dum,1,
157  &work[0],lwork,info);
158  }
159  ASSERTL0(info == 0,"Info is not zero");
160 
161  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
static Array< OneD, NekDouble > NullNekDouble1DArray
static void Dgeev(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:211
double NekDouble

◆ GetRequiredStorageSize()

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

Definition at line 104 of file MatrixFuncs.cpp.

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

105  {
106  return rows*columns;
107  }

◆ 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.

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

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

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  Lapack::Dgetrf(m, n, data.get(), m, ipivot.get(), info);
98 
99  if( info < 0 )
100  {
101  std::string message = "ERROR: The " + std::to_string(-info) + "th parameter had an illegal parameter for dgetrf";
102  ASSERTL0(false, message.c_str());
103  }
104  else if( info > 0 )
105  {
106  std::string message = "ERROR: Element u_" + std::to_string(info) + std::to_string(info) + " is 0 from dgetrf";
107  ASSERTL0(false, message.c_str());
108  }
109 
110  Lapack::Dgetri(n, data.get(), n, ipivot.get(),
111  work.get(), n, info);
112 
113  if( info < 0 )
114  {
115  std::string message = "ERROR: The " + std::to_string(-info) + "th parameter had an illegal parameter for dgetri";
116  ASSERTL0(false, message.c_str());
117  }
118  else if( info > 0 )
119  {
120  std::string message = "ERROR: Element u_" + std::to_string(info) + std::to_string(info) + " is 0 from dgetri";
121  ASSERTL0(false, message.c_str());
122  }
123  }
static void Dgetrf(const int &m, const int &n, double *a, const int &lda, int *ipiv, int &info)
General matrix LU factorisation.
Definition: Lapack.hpp:183
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
static void Dgetri(const int &n, double *a, const int &lda, const int *ipiv, double *wk, const int &lwk, int &info)
Generate matrix inverse.
Definition: Lapack.hpp:198