6#ifndef DUNE_ISTL_SOLVER_HH
7#define DUNE_ISTL_SOLVER_HH
9#include <dune-istl-config.hh>
16#include <dune/common/exceptions.hh>
17#include <dune/common/shared_ptr.hh>
18#include <dune/common/simd/io.hh>
19#include <dune/common/simd/simd.hh>
20#include <dune/common/parametertree.hh>
21#include <dune/common/timer.hh>
100 template<
class X,
class Y>
113 typedef typename FieldTraits<field_type>::real_type
real_type;
149#ifdef DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
151 DUNE_THROW(Dune::Exception,
"It is necessary to implement the category method in a derived classes, in the future this method will pure virtual.");
169 s << std::setw(
normSpacing) <<
"Rate" << std::endl;
173 template <
typename CountType,
typename DataType>
175 const CountType& iter,
176 const DataType& norm,
177 const DataType& norm_old)
const
179 const DataType rate = norm/norm_old;
181 s << std::setw(
normSpacing) << Simd::io(norm) <<
" ";
182 s << std::setw(
normSpacing) << Simd::io(rate) << std::endl;
186 template <
typename CountType,
typename DataType>
188 const CountType& iter,
189 const DataType& norm)
const
192 s << std::setw(
normSpacing) << Simd::io(norm) << std::endl;
204 template<
class X,
class Y>
233 _op(stackobject_to_shared_ptr(op)),
234 _prec(stackobject_to_shared_ptr(prec)),
266 _op(stackobject_to_shared_ptr(op)),
267 _prec(stackobject_to_shared_ptr(prec)),
268 _sp(stackobject_to_shared_ptr(sp)),
272 DUNE_THROW(
InvalidSolverCategory,
"LinearOperator and Preconditioner must have the same SolverCategory!");
274 DUNE_THROW(
InvalidSolverCategory,
"LinearOperator and ScalarProduct must have the same SolverCategory!");
295 configuration.
get<int>(
"maxit"),
296 configuration.
get<int>(
"verbose"))
318 configuration.
get<int>(
"maxit"),
319 configuration.
get<int>(
"verbose"))
353 DUNE_THROW(
InvalidSolverCategory,
"LinearOperator and Preconditioner must have the same SolverCategory!");
355 DUNE_THROW(
InvalidSolverCategory,
"LinearOperator and ScalarProduct must have the same SolverCategory!");
380 this->
apply(x,b,res);
391 std::string
name = className(*
this);
392 return name.substr(0,
name.find(
"<"));
412 template<
class CountType =
unsigned int>
423 std::cout <<
"=== " << parent.name() << std::endl;
424 if(_parent._verbose > 1)
425 _parent.printHeader(std::cout);
439 other._valid =
false;
458 if (!Simd::allTrue(isFinite(def)))
461 std::cout <<
"=== " <<
_parent.
name() <<
": abort due to infinite or NaN defect"
465 <<
" is infinite or NaN");
506 std::shared_ptr<const LinearOperator<X,Y>>
_op;
507 std::shared_ptr<Preconditioner<X,Y>>
_prec;
508 std::shared_ptr<const ScalarProduct<X>>
_sp;
522 template <
typename ISTLLinearSolver,
typename BCRSMatrix>
529 static const bool is_direct_solver
540 template <
bool is_direct_solver,
typename Dummy =
void>
552 template <
typename Dummy>
558 solver.setMatrix(matrix);
Define base class for scalar product and norm.
Templates characterizing the type of a solver.
Define general, extensible interface for operators. The available implementation wraps a matrix.
Definition allocator.hh:11
PropertyMapTypeSelector< Amg::VertexVisitedTag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > >::Type get(const Amg::VertexVisitedTag &tag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > &graph)
Definition dependency.hh:293
A sparse block matrix with compressed row storage.
Definition matrixutils.hh:24
Thrown when a solver aborts due to some problem.
Definition istlexception.hh:46
A linear operator.
Definition operators.hh:69
Base class for matrix free definition of preconditioners.
Definition preconditioner.hh:33
Base class for scalar product and norm computation.
Definition scalarproducts.hh:52
Default implementation for the scalar case.
Definition scalarproducts.hh:168
Statistics about the application of an inverse operator.
Definition solver.hh:50
InverseOperatorResult()
Default constructor.
Definition solver.hh:52
double condition_estimate
Estimate of condition number.
Definition solver.hh:81
double elapsed
Elapsed time in seconds.
Definition solver.hh:84
int iterations
Number of iterations.
Definition solver.hh:69
double reduction
Reduction achieved: .
Definition solver.hh:72
void clear()
Resets all data.
Definition solver.hh:58
double conv_rate
Convergence rate (average reduction per step)
Definition solver.hh:78
bool converged
True if convergence criterion has been met.
Definition solver.hh:75
Abstract base class for all solvers.
Definition solver.hh:101
void printHeader(std::ostream &s) const
helper function for printing header of solver output
Definition solver.hh:165
virtual ~InverseOperator()
Destructor.
Definition solver.hh:158
void printOutput(std::ostream &s, const CountType &iter, const DataType &norm) const
helper function for printing solver output
Definition solver.hh:187
X domain_type
Type of the domain of the operator to be inverted.
Definition solver.hh:104
void printOutput(std::ostream &s, const CountType &iter, const DataType &norm, const DataType &norm_old) const
helper function for printing solver output
Definition solver.hh:174
virtual void apply(X &x, Y &b, double reduction, InverseOperatorResult &res)=0
apply inverse operator, with given convergence criteria.
FieldTraits< field_type >::real_type real_type
The real type of the field type (is the same if using real numbers, but differs for std::complex)
Definition solver.hh:113
@ normSpacing
Definition solver.hh:162
@ iterationSpacing
Definition solver.hh:162
Y range_type
Type of the range of the operator to be inverted.
Definition solver.hh:107
virtual void apply(X &x, Y &b, InverseOperatorResult &res)=0
Apply inverse operator,.
X::field_type field_type
The field type of the operator.
Definition solver.hh:110
Simd::Scalar< real_type > scalar_real_type
scalar type underlying the field_type
Definition solver.hh:116
virtual SolverCategory::Category category() const =0
Category of the solver (see SolverCategory::Category)
Base class for all implementations of iterative solvers.
Definition solver.hh:205
IterativeSolver(std::shared_ptr< const LinearOperator< X, Y > > op, std::shared_ptr< const ScalarProduct< X > > sp, std::shared_ptr< Preconditioner< X, X > > prec, const ParameterTree &configuration)
Constructor.
Definition solver.hh:315
IterativeSolver(std::shared_ptr< const LinearOperator< X, Y > > op, std::shared_ptr< Preconditioner< X, X > > prec, const ParameterTree &configuration)
Constructor.
Definition solver.hh:292
virtual void apply(X &x, X &b, double reduction, InverseOperatorResult &res)
Apply inverse operator with given reduction factor.
Definition solver.hh:376
std::shared_ptr< const ScalarProduct< X > > _sp
Definition solver.hh:508
IterativeSolver(std::shared_ptr< const LinearOperator< X, Y > > op, std::shared_ptr< const ScalarProduct< X > > sp, std::shared_ptr< Preconditioner< X, Y > > prec, scalar_real_type reduction, int maxit, int verbose)
General constructor to initialize an iterative solver.
Definition solver.hh:342
std::string name() const
Definition solver.hh:390
IterativeSolver(const LinearOperator< X, Y > &op, Preconditioner< X, Y > &prec, scalar_real_type reduction, int maxit, int verbose)
General constructor to initialize an iterative solver.
Definition solver.hh:232
std::shared_ptr< const LinearOperator< X, Y > > _op
Definition solver.hh:506
int _maxit
Definition solver.hh:510
int _verbose
Definition solver.hh:511
scalar_real_type _reduction
Definition solver.hh:509
IterativeSolver(const LinearOperator< X, Y > &op, const ScalarProduct< X > &sp, Preconditioner< X, Y > &prec, scalar_real_type reduction, int maxit, int verbose)
General constructor to initialize an iterative solver.
Definition solver.hh:264
SolverCategory::Category _category
Definition solver.hh:512
std::shared_ptr< Preconditioner< X, Y > > _prec
Definition solver.hh:507
virtual SolverCategory::Category category() const
Category of the solver (see SolverCategory::Category)
Definition solver.hh:385
Class for controlling iterative methods.
Definition solver.hh:413
Iteration(const IterativeSolver &parent, InverseOperatorResult &res)
Definition solver.hh:415
Iteration(Iteration &&other)
Definition solver.hh:430
InverseOperatorResult & _res
Definition solver.hh:500
const IterativeSolver & _parent
Definition solver.hh:501
Timer _watch
Definition solver.hh:499
Iteration(const Iteration &)=delete
CountType _i
Definition solver.hh:498
real_type _def0
Definition solver.hh:497
bool step(CountType i, real_type def)
registers the iteration step, checks for invalid defect norm and convergence.
Definition solver.hh:457
void finalize()
Definition solver.hh:482
real_type _def
Definition solver.hh:497
~Iteration()
Definition solver.hh:442
bool _valid
Definition solver.hh:502
Helper class for notifying a DUNE-ISTL linear solver about a change of the iteration matrix object in...
Definition solver.hh:524
static void setMatrix(ISTLLinearSolver &solver, const BCRSMatrix &matrix)
Definition solver.hh:526
Implementation that works together with iterative ISTL solvers, e.g. Dune::CGSolver or Dune::BiCGSTAB...
Definition solver.hh:542
static void setMatrix(ISTLLinearSolver &, const BCRSMatrix &)
Definition solver.hh:543
static void setMatrix(ISTLLinearSolver &solver, const BCRSMatrix &matrix)
Definition solver.hh:555
Categories for the solvers.
Definition solvercategory.hh:22
Category
Definition solvercategory.hh:23
@ sequential
Category for sequential solvers.
Definition solvercategory.hh:25
static Category category(const OP &op, decltype(op.category()) *=nullptr)
Helperfunction to extract the solver category either from an enum, or from the newly introduced virtu...
Definition solvercategory.hh:34
Definition solvercategory.hh:54
Definition solvertype.hh:16