3#ifndef DUNE_DYNMATRIXEIGENVALUES_HH
4#define DUNE_DYNMATRIXEIGENVALUES_HH
22 namespace DynamicMatrixHelp {
25 using Dune::FMatrixHelp::eigenValuesNonsymLapackCall;
36 template <
typename K,
class C>
45 const long int N = matrix.
rows();
46 const char jobvl =
'n';
47 const char jobvr = eigenVectors ?
'v' :
'n';
51 auto matrixVector = std::make_unique<double[]>(N*N);
55 for(
int i=0; i<N; ++i)
57 for(
int j=0; j<N; ++j, ++row)
59 matrixVector[ row ] = matrix[ i ][ j ];
64 auto eigenR = std::make_unique<double[]>(N);
65 auto eigenI = std::make_unique<double[]>(N);
67 const long int lwork = eigenVectors ? 4*N : 3*N;
68 auto work = std::make_unique<double[]>(lwork);
69 auto vr = eigenVectors ? std::make_unique<double[]>(N*N) : std::unique_ptr<double[]>{};
75 eigenValuesNonsymLapackCall(&jobvl, &jobvr, &N, matrixVector.get(), &N,
76 eigenR.get(), eigenI.get(),
nullptr, &N, vr.get(), &N, work.get(),
81 std::cerr <<
"For matrix " << matrix <<
" eigenvalue calculation failed! " << std::endl;
85 eigenValues.resize(N);
86 for (
int i=0; i<N; ++i)
87 eigenValues[i] = std::complex<double>(eigenR[i], eigenI[i]);
90 eigenVectors->resize(N);
91 for (
int i = 0; i < N; ++i) {
92 auto& v = (*eigenVectors)[i];
94 std::copy(vr.get() + N*i, vr.get() + N*(i+1), &v[0]);
constexpr size_type rows() const
number of rows
Definition: densematrix.hh:737
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
Default exception for dummy implementations.
Definition: exceptions.hh:261
This file implements a dense matrix with dynamic numbers of rows and columns.
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:37
Eigenvalue computations for the FieldMatrix class.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:11