1#ifndef DUNE_FEM_SOLVER_EIGEN_HH
2#define DUNE_FEM_SOLVER_EIGEN_HH
6#include <Eigen/IterativeLinearSolvers>
8#include <dune/fem/io/parameter.hh>
9#include <dune/fem/operator/linear/eigenoperator.hh>
10#include <dune/fem/solver/parameter.hh>
17 template <
class DiscreteFunction>
18 struct EigenInverseOperatorTraits
20 typedef Fem::EigenLinearOperator< DiscreteFunction, DiscreteFunction> OperatorType;
21 typedef typename OperatorType::MatrixType::MatrixStorageType Matrix;
24 template<
class DiscreteFunction,
class EigenOp >
25 class EigenInverseOperator
26 :
public Fem::Operator< DiscreteFunction, DiscreteFunction >
28 typedef Fem::Operator< DiscreteFunction, DiscreteFunction > Base;
31 typedef typename Base::DomainFunctionType DomainFunction;
32 typedef typename Base::RangeFunctionType RangeFunction;
34 typedef Fem::EigenLinearOperator< RangeFunction, DomainFunction > OperatorType;
37 typedef typename OperatorType::MatrixType::MatrixStorageType Matrix;
40 EigenInverseOperator (
double redEps,
double absLimit,
unsigned int maxIter,
bool verbose,
41 const ParameterReader ¶meter = Parameter::container() )
42 : solver_(
std::make_unique<EigenOp>()), absLimit_( absLimit )
46 const ParameterReader ¶meter = Parameter::container() )
47 : solver_(
std::make_unique<EigenOp>()), absLimit_( absLimit )
50 EigenInverseOperator (
const OperatorType &op,
double redEps,
double absLimit,
unsigned int maxIter,
bool verbose,
51 const ParameterReader ¶meter = Parameter::container() )
52 : solver_(
std::make_unique<EigenOp>()), absLimit_( absLimit )
57 EigenInverseOperator (
const OperatorType &op,
double redEps,
double absLimit,
unsigned int maxIter,
58 const ParameterReader ¶meter = Parameter::container() )
59 : solver_(
std::make_unique<EigenOp>()), absLimit_( absLimit )
64 EigenInverseOperator (
const OperatorType &op,
65 double reduction,
double absLimit,
66 const SolverParameter ¶meter )
67 : EigenInverseOperator( reduction, absLimit,
std::numeric_limits<int>::
max(), parameter.parameter() )
69 EigenInverseOperator (
double reduction,
double absLimit,
70 const SolverParameter ¶meter )
71 : EigenInverseOperator( reduction, absLimit,
std::numeric_limits<int>::
max(), parameter.parameter() )
74 void bind (
const OperatorType &op )
79 void unbind() { op_ =
nullptr; }
81 virtual void operator() (
const DomainFunction &u, RangeFunction &w )
const
84 w.dofVector().array().coefficients() = solver_->solve( u.dofVector().array().coefficients() );
87 unsigned int iterations ()
const {
return solver_->iterations(); }
88 void setMaxIterations (
unsigned int ) {}
94 solver_->setTolerance( absLimit_ );
95 solver_->analyzePattern( op_->matrix().data() );
96 solver_->factorize( op_->matrix().data() );
99 const OperatorType *op_ =
nullptr;
100 std::unique_ptr<EigenOp> solver_;
104 template<
class DiscreteFunction>
105 using EigenCGInverseOperator = EigenInverseOperator<DiscreteFunction,
106 Eigen::ConjugateGradient<typename EigenInverseOperatorTraits<DiscreteFunction>::Matrix> >;
108 template<
class DiscreteFunction>
109 using EigenBiCGStabInverseOperator = EigenInverseOperator<DiscreteFunction,
110 Eigen::BiCGSTAB<typename EigenInverseOperatorTraits<DiscreteFunction>::Matrix> >;
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
Dune namespace.
Definition: alignedallocator.hh:13