1#ifndef DUNE_FEM_SOLVER_INVERSEOPERATORINTERFACE_HH 
    2#define DUNE_FEM_SOLVER_INVERSEOPERATORINTERFACE_HH 
    4#include <dune/fem/function/common/discretefunction.hh> 
    5#include <dune/fem/operator/common/operator.hh> 
    6#include <dune/fem/io/parameter.hh> 
    7#include <dune/fem/solver/parameter.hh> 
    8#include <dune/fem/misc/bartonnackmaninterface.hh> 
   17        SolverInfo(
bool pconverged,
int plinearIterations,
int pnonlinearIterations, 
const std::vector<double>& ptiming)
 
   18          : converged(pconverged), linearIterations(plinearIterations),
 
   19            nonlinearIterations(pnonlinearIterations), timing(ptiming)
 
   22        SolverInfo(
bool pconverged,
int plinearIterations)
 
   23          : SolverInfo(pconverged, plinearIterations, 0, 
std::vector<double> ())
 
   28        int nonlinearIterations;
 
   29        std::vector<double> timing;
 
   33    template <
class Traits>
 
   34    class InverseOperatorInterface :
 
   35      public Dune::Fem::Operator< typename Traits::DiscreteFunctionType, typename Traits::DiscreteFunctionType >,
 
   36      public BartonNackmanInterface< InverseOperatorInterface< Traits >, typename Traits::InverseOperatorType >
 
   39      typedef typename Traits::OperatorType         BaseType;
 
   40      typedef BartonNackmanInterface< InverseOperatorInterface< Traits >, 
typename Traits::InverseOperatorType > Base2Type;
 
   42      using Base2Type :: asImp;
 
   46      typedef typename BaseType :: DomainFunctionType DomainFunctionType;
 
   47      typedef typename BaseType :: RangeFunctionType  RangeFunctionType;
 
   49      typedef typename Traits :: SolverDiscreteFunctionType   SolverDiscreteFunctionType;
 
   50      typedef typename Traits :: OperatorType                 OperatorType;
 
   51      typedef typename Traits :: AssembledOperatorType        AssembledOperatorType;
 
   52      typedef typename Traits :: PreconditionerType           PreconditionerType;
 
   53      typedef typename Traits :: SolverParameterType          SolverParameterType;
 
   55      typedef Impl::SolverInfo SolverInfoType;
 
   58      typedef std::function< bool ( 
const RangeFunctionType &w, 
const RangeFunctionType &dw, 
double residualNorm ) > ErrorMeasureType;
 
   61      static const bool preconditioningAvailable = 
true;
 
   66      InverseOperatorInterface( 
const SolverParameterType& parameter )
 
   67        : parameter_( 
std::make_shared< SolverParameterType >( parameter ) )
 
   68        , verbose_( parameter_->verbose() && 
Dune::Fem::Parameter::verbose() )
 
   81      virtual void operator() ( 
const DomainFunctionType& u, RangeFunctionType& w )
 const 
   97      template <
class DImpl, 
class RImpl>
 
   98      void operator() ( 
const DiscreteFunctionInterface< DImpl >&u,
 
   99                        DiscreteFunctionInterface< RImpl >& w )
 const 
  109      void bind ( 
const OperatorType &op )
 
  112        assembledOperator_ = 
dynamic_cast<const AssembledOperatorType*
>( &op );
 
  121      void bind ( 
const OperatorType &op, 
const PreconditionerType &preconditioner )
 
  124        preconditioner_ = &preconditioner;
 
  128      void unbind () { operator_ = 
nullptr; assembledOperator_ = 
nullptr; preconditioner_ = 
nullptr; rhs_.reset(); x_.reset(); }
 
  131      int iterations ()
 const { 
return iterations_; }
 
  134      virtual SolverInfoType info()
 const { 
return SolverInfoType( 
true, iterations () ); }
 
  139      virtual void setMaxLinearIterations ( 
const int iter ) {
 
  140        parameter_->setMaxIterations( iter );
 
  144      virtual void setMaxIterations ( 
const int iter ) {
 
  145        parameter_->setMaxIterations( iter );
 
  151      void setParameters( 
const SolverParameterType& newParams)
 
  153        std::shared_ptr< SolverParameterType > sharedNewParams = std::make_shared< SolverParameterType > (newParams);
 
  154        parameter_.swap( sharedNewParams );
 
  158      SolverParameterType& parameter ()
 const 
  169      double averageCommTime()
 const 
  175      InverseOperatorInterface(
const InverseOperatorInterface &other)
 
  176        : parameter_(other.parameter_),
 
  178          assembledOperator_(nullptr),
 
  179          preconditioner_(nullptr),
 
  183          rightHandSideCopied_(false)
 
  188      void opApply( 
const SolverDiscreteFunctionType& u, SolverDiscreteFunctionType& w )
 const 
  190        rightHandSideCopied_ = 
false;
 
  191        iterations_ = asImp().apply( u, w );
 
  194      template <
class DImpl, 
class RImpl>
 
  195      void opApply( 
const DiscreteFunctionInterface< DImpl >&u,
 
  196                    DiscreteFunctionInterface< RImpl >& w )
 const 
  198        if( ! assembledOperator_ )
 
  200                                           " for fixed types of domain and range functions to avoid excessive copying!");
 
  204          rhs_.reset( 
new SolverDiscreteFunctionType( 
"InvOp::rhs", u.space() ) );
 
  209          x_.reset( 
new SolverDiscreteFunctionType( 
"InvOp::x", w.space() ) );
 
  214        rightHandSideCopied_ = 
true;
 
  219        iterations_ = asImp().apply( *rhs_, *x_ );
 
  223        rightHandSideCopied_ = 
false;
 
  226      std::shared_ptr<SolverParameterType> parameter_;
 
  228      const OperatorType*                   operator_ = 
nullptr;
 
  229      const AssembledOperatorType* assembledOperator_ = 
nullptr;
 
  230      const PreconditionerType*       preconditioner_ = 
nullptr;
 
  233      mutable std::unique_ptr< SolverDiscreteFunctionType > rhs_;
 
  234      mutable std::unique_ptr< SolverDiscreteFunctionType > x_;
 
  236      mutable int  iterations_ = -1 ;
 
  237      mutable bool rightHandSideCopied_ = false ;
 
  238      mutable bool verbose_;
 
Inverse operator base on CG method. Uses a runtime parameter fem.preconditioning which enables diagon...
Definition: cginverseoperator.hh:408
 
static bool verbose()
obtain the cached value for fem.verbose with default verbosity level 2
Definition: parameter.hh:466
 
Default exception for dummy implementations.
Definition: exceptions.hh:357
 
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
 
Dune namespace.
Definition: alignedallocator.hh:13
 
abstract operator
Definition: operator.hh:34