3#ifndef DUNE_ISTL_EIGENVALUE_TEST_MATRIXINFO_HH
4#define DUNE_ISTL_EIGENVALUE_TEST_MATRIXINFO_HH
21#include "../arpackpp.hh"
22#include "../poweriteration.hh"
39template <
typename BCRSMatrix>
44 typedef typename BCRSMatrix::field_type
Real;
62 const bool verbose =
false,
63 const unsigned int arppp_a_verbosity_level = 0,
64 const unsigned int pia_verbosity_level = 0)
67 arppp_a_verbosity_level_(arppp_a_verbosity_level*verbose),
68 pia_verbosity_level_(pia_verbosity_level*verbose),
69 cond_2_(-1.0), symmetricity_assumed_(false)
73 (Dune::blockLevel<BCRSMatrix>() == 2,
74 "Only BCRSMatrices with blocklevel 2 are supported.");
78 (BCRSMatrix::block_type::rows == BCRSMatrix::block_type::cols,
79 "Only BCRSMatrices with square blocks are supported.");
82 const int nrows = m_.M() * BCRSMatrix::block_type::rows;
83 const int ncols = m_.N() * BCRSMatrix::block_type::cols;
86 << nrows <<
"x" << ncols <<
").");
92 if (cond_2_ == -1.0 || symmetricity_assumed_ != assume_symmetric)
95 std::cout <<
" MatrixInfo: Computing 2-norm condition number"
96 << (assume_symmetric ?
" (assuming that matrix is symmetric)." :
".")
104 symmetricity_assumed_ = assume_symmetric;
125 Real lambda_max{}, lambda_min{}, cond_2{};
134 const ARPPP_A arppp_a(m_,100000,arppp_a_verbosity_level_);
139 PIA pia(m_,20000,pia_verbosity_level_);
140 static const bool avoidLinSolverCrime =
true;
146 const unsigned int piaLS_verbosity = 0;
147 PIALS piaLS(pia.getIterationMatrix(),piaLS_verbosity);
152 typename PIA::IterationOperator::domain_type,
153 typename PIA::IterationOperator::range_type> PIAPC;
154 PIAPC piaPC(pia.getIterationMatrix(),2,1.0);
155 const double piaLS_reduction = 1e-02;
156 const unsigned int piaLS_max_iter = 1000;
157 const unsigned int piaLS_verbosity = 0;
159 PIALS piaLS(pia.getIterationOperator(),piaPC,
160 piaLS_reduction,piaLS_max_iter,piaLS_verbosity);
167 const Real epsilon = 0.0;
169 arppp_a.computeSymMaxMagnitude(epsilon,x,lambda_max);
175 const Real epsilonPI = 1e-02;
176 const Real epsilonTLIME = 1e-08;
180 pia.applyPowerIteration(epsilonPI,x,lambda_max);
182 const Real gamma = m_.infinity_norm();
183 const Real eta = 0.0;
184 const Real delta = 1e-03;
186 pia.template applyTLIMEIteration<PIALS,avoidLinSolverCrime>
187 (gamma,eta,epsilonTLIME,piaLS,delta,2,external,x,lambda_max);
195 const Real epsilon = std::sqrt(std::numeric_limits<Real>::epsilon());
199 const Real gamma = 0.0;
200 const Real eta = 0.0;
201 const Real delta = 1e-03;
203 pia.template applyTLIMEIteration<PIALS,avoidLinSolverCrime>
204 (gamma,eta,epsilon,piaLS,delta,2,external,x,lambda_min);
211 if (std::abs(lambda_max) > m_.infinity_norm())
213 <<
"largest magnitude eigenvalue is greater than "
214 <<
"infinity norm of the matrix!");
218 std::cout <<
" Largest magnitude eigenvalue λ_max = "
219 << lambda_max << std::endl;
223 std::cout <<
" Smallest magnitude eigenvalue λ_min = "
224 << lambda_min << std::endl;
228 cond_2 = std::abs(lambda_max / lambda_min);
232 std::cout <<
" 2-norm condition number cond_2 = "
233 << cond_2 << std::endl;
245 Real sigma_max, sigma_min, cond_2;
254 const ARPPP_A arppp_a(m_,100000,arppp_a_verbosity_level_);
263 Real lambda_max{}, lambda_min{};
268 PIA pia(mtm,20000,pia_verbosity_level_);
269 static const bool avoidLinSolverCrime =
true;
275 const unsigned int piaLS_verbosity = 0;
276 PIALS piaLS(pia.getIterationMatrix(),piaLS_verbosity);
281 typename PIA::IterationOperator::domain_type,
282 typename PIA::IterationOperator::range_type> PIAPC;
283 PIAPC piaPC(pia.getIterationMatrix(),2,1.0);
284 const double piaLS_reduction = 1e-02;
285 const unsigned int piaLS_max_iter = 1000;
286 const unsigned int piaLS_verbosity = 0;
288 PIALS piaLS(pia.getIterationOperator(),piaPC,
289 piaLS_reduction,piaLS_max_iter,piaLS_verbosity);
295 const Real epsilon = 0.0;
297 arppp_a.computeNonSymMax(epsilon,x,sigma_max);
304 const Real epsilonPI = 1e-02;
305 const Real epsilonTLIME = 1e-08;
309 pia.applyPowerIteration(epsilonPI,x,lambda_max);
311 const Real gamma = mtm.infinity_norm();
312 const Real eta = 0.0;
313 const Real delta = 1e-03;
315 pia.template applyTLIMEIteration<PIALS,avoidLinSolverCrime>
316 (gamma,eta,epsilonTLIME,piaLS,delta,2,external,x,lambda_max);
319 sigma_max = std::sqrt(lambda_max);
326 const Real epsilon = std::sqrt(std::numeric_limits<Real>::epsilon());
330 const Real gamma = 0.0;
331 const Real eta = 0.0;
332 const Real delta = 1e-03;
334 pia.template applyTLIMEIteration<PIALS,avoidLinSolverCrime>
335 (gamma,eta,epsilon,piaLS,delta,2,external,x,lambda_min);
338 sigma_min = std::sqrt(lambda_min);
344 if (std::abs(lambda_max) > mtm.infinity_norm())
346 <<
"largest magnitude eigenvalue is greater than "
347 <<
"infinity norm of the matrix!");
351 std::cout <<
" Largest singular value σ_max = "
352 << sigma_max << std::endl;
356 std::cout <<
" Smallest singular value σ_min = "
357 << sigma_min << std::endl;
360 cond_2 = sigma_max / sigma_min;
364 std::cout <<
" 2-norm condition number cond_2 = "
365 << cond_2 << std::endl;
373 const BCRSMatrix& m_;
377 const unsigned int arppp_a_verbosity_level_;
378 const unsigned int pia_verbosity_level_;
382 mutable Real cond_2_;
383 mutable bool symmetricity_assumed_;
Helper functions for determining the vector/matrix block level.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Wrapper to use a range of ARPACK++ eigenvalue solvers.
Definition: arpackpp.hh:243
Bi-conjugate Gradient Stabilized (BiCG-STAB)
Definition: solvers.hh:416
A vector of blocks with memory management.
Definition: bvector.hh:393
Base class for Dune-Exceptions.
Definition: exceptions.hh:94
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Iterative eigenvalue algorithms based on power iteration.
Definition: poweriteration.hh:174
Sequential SOR preconditioner.
Definition: preconditioners.hh:259
SuperLu Solver.
Definition: superlu.hh:269
Class template which yields information related to a square matrix like its spectral (i....
Definition: matrixinfo.hh:41
MatrixInfo(const BCRSMatrix &m, const bool verbose=false, const unsigned int arppp_a_verbosity_level=0, const unsigned int pia_verbosity_level=0)
Construct from required parameters.
Definition: matrixinfo.hh:61
Real computeSymCond2() const
Definition: matrixinfo.hh:121
Real getCond2(const bool assume_symmetric=true) const
return spectral (i.e. 2-norm) condition number of the matrix
Definition: matrixinfo.hh:90
BCRSMatrix::field_type Real
Type of the underlying field of the matrix.
Definition: matrixinfo.hh:44
static const int bvBlockSize
Definition: matrixinfo.hh:112
Real computeNonSymCond2() const
Definition: matrixinfo.hh:241
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
void transposeMatMultMat(BCRSMatrix< FieldMatrix< T, n, m >, A > &res, const BCRSMatrix< FieldMatrix< T, k, n >, A1 > &mat, const BCRSMatrix< FieldMatrix< T, k, m >, A2 > &matt, bool tryHard=false)
Calculate product of a transposed sparse matrix with another sparse matrices ( ).
Definition: matrixmatrix.hh:588
provides functions for sparse matrix matrix multiplication.
Define general preconditioner interface.
Implementations of the inverse operator interface.
Classes for using SuperLU with ISTL matrices.