3 #ifndef DUNE_DYNMATRIXEIGENVALUES_HH
4 #define DUNE_DYNMATRIXEIGENVALUES_HH
22 namespace DynamicMatrixHelp {
34 template <
typename K,
class C>
41 const long int N = matrix.
rows();
42 const char jobvl =
'n';
43 const char jobvr = eigenVectors ?
'v' :
'n';
47 auto matrixVector = std::make_unique<double[]>(N*N);
51 for(
int i=0; i<N; ++i)
53 for(
int j=0; j<N; ++j, ++row)
55 matrixVector[ row ] = matrix[ i ][ j ];
60 auto eigenR = std::make_unique<double[]>(N);
61 auto eigenI = std::make_unique<double[]>(N);
63 const long int lwork = eigenVectors ? 4*N : 3*N;
64 auto work = std::make_unique<double[]>(lwork);
65 auto vr = eigenVectors ? std::make_unique<double[]>(N*N) : std::unique_ptr<double[]>{};
72 eigenR.get(), eigenI.get(),
nullptr, &N, vr.get(), &N, work.get(),
77 std::cerr <<
"For matrix " << matrix <<
" eigenvalue calculation failed! " << std::endl;
82 for (
int i=0; i<N; ++i)
83 eigenValues[i] = std::complex<double>(eigenR[i], eigenI[i]);
86 eigenVectors->resize(N);
87 for (
int i = 0; i < N; ++i) {
88 auto& v = (*eigenVectors)[i];
90 std::copy(vr.get() + N*i, vr.get() + N*(i+1), &v[0]);
This file implements a dense matrix with dynamic numbers of rows and columns.
Eigenvalue computations for the FieldMatrix class.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:14
static void eigenValuesNonSym(const DynamicMatrix< K > &matrix, DynamicVector< C > &eigenValues, std::vector< DynamicVector< K >> *eigenVectors=nullptr)
calculates the eigenvalues of a symmetric field matrix
Definition: dynmatrixev.hh:35
void eigenValuesNonsymLapackCall(const char *jobvl, const char *jobvr, const long int *n, double *a, const long int *lda, double *wr, double *wi, double *vl, const long int *ldvl, double *vr, const long int *ldvr, double *work, const long int *lwork, long int *info)
Definition: fmatrixev.cc:223
static void eigenValues(const FieldMatrix< K, 1, 1 > &matrix, FieldVector< K, 1 > &eigenvalues)
calculates the eigenvalues of a symmetric field matrix
Definition: fmatrixev.hh:46
size_type rows() const
number of rows
Definition: densematrix.hh:736
Construct a matrix with a dynamic size.
Definition: dynmatrix.hh:59
Construct a vector with a dynamic size.
Definition: dynvector.hh:57
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:279