6#ifndef DUNE_ISTL_SOLVER_HH
7#define DUNE_ISTL_SOLVER_HH
14#include <dune/common/exceptions.hh>
15#include <dune/common/shared_ptr.hh>
16#include <dune/common/simd/io.hh>
17#include <dune/common/simd/simd.hh>
18#include <dune/common/parametertree.hh>
19#include <dune/common/timer.hh>
98 template<
class X,
class Y>
111 typedef typename FieldTraits<field_type>::real_type
real_type;
147#ifdef DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
149 DUNE_THROW(Dune::Exception,
"It is necessary to implement the category method in a derived classes, in the future this method will pure virtual.");
167 s << std::setw(
normSpacing) <<
"Rate" << std::endl;
171 template <
typename CountType,
typename DataType>
173 const CountType& iter,
174 const DataType& norm,
175 const DataType& norm_old)
const
177 const DataType rate = norm/norm_old;
179 s << std::setw(
normSpacing) << Simd::io(norm) <<
" ";
180 s << std::setw(
normSpacing) << Simd::io(rate) << std::endl;
184 template <
typename CountType,
typename DataType>
186 const CountType& iter,
187 const DataType& norm)
const
190 s << std::setw(
normSpacing) << Simd::io(norm) << std::endl;
202 template<
class X,
class Y>
231 _op(stackobject_to_shared_ptr(op)),
232 _prec(stackobject_to_shared_ptr(prec)),
264 _op(stackobject_to_shared_ptr(op)),
265 _prec(stackobject_to_shared_ptr(prec)),
266 _sp(stackobject_to_shared_ptr(sp)),
270 DUNE_THROW(
InvalidSolverCategory,
"LinearOperator and Preconditioner must have the same SolverCategory!");
272 DUNE_THROW(
InvalidSolverCategory,
"LinearOperator and ScalarProduct must have the same SolverCategory!");
293 configuration.
get<int>(
"maxit"),
294 configuration.
get<int>(
"verbose"))
316 configuration.
get<int>(
"maxit"),
317 configuration.
get<int>(
"verbose"))
351 DUNE_THROW(
InvalidSolverCategory,
"LinearOperator and Preconditioner must have the same SolverCategory!");
353 DUNE_THROW(
InvalidSolverCategory,
"LinearOperator and ScalarProduct must have the same SolverCategory!");
378 this->
apply(x,b,res);
389 std::string
name = className(*
this);
390 return name.substr(0,
name.find(
"<"));
410 template<
class CountType =
unsigned int>
421 std::cout <<
"=== " << parent.
name() << std::endl;
437 other._valid =
false;
456 if (!Simd::allTrue(isFinite(def)))
459 std::cout <<
"=== " <<
_parent.
name() <<
": abort due to infinite or NaN defect"
463 <<
" is infinite or NaN");
504 std::shared_ptr<const LinearOperator<X,Y>>
_op;
505 std::shared_ptr<Preconditioner<X,Y>>
_prec;
506 std::shared_ptr<const ScalarProduct<X>>
_sp;
520 template <
typename ISTLLinearSolver,
typename BCRSMatrix>
527 static const bool is_direct_solver
538 template <
bool is_direct_solver,
typename Dummy =
void>
550 template <
typename Dummy>
556 solver.setMatrix(matrix);
Define base class for scalar product and norm.
Define general, extensible interface for operators. The available implementation wraps a matrix.
Templates characterizing the type of a solver.
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: bcrsmatrix.hh:466
Thrown when a solver aborts due to some problem.
Definition: istlexception.hh:46
A linear operator.
Definition: operators.hh:67
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:32
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:48
InverseOperatorResult()
Default constructor.
Definition: solver.hh:50
double condition_estimate
Estimate of condition number.
Definition: solver.hh:79
double elapsed
Elapsed time in seconds.
Definition: solver.hh:82
int iterations
Number of iterations.
Definition: solver.hh:67
double reduction
Reduction achieved: .
Definition: solver.hh:70
void clear()
Resets all data.
Definition: solver.hh:56
double conv_rate
Convergence rate (average reduction per step)
Definition: solver.hh:76
bool converged
True if convergence criterion has been met.
Definition: solver.hh:73
Abstract base class for all solvers.
Definition: solver.hh:99
void printHeader(std::ostream &s) const
helper function for printing header of solver output
Definition: solver.hh:163
virtual ~InverseOperator()
Destructor.
Definition: solver.hh:156
void printOutput(std::ostream &s, const CountType &iter, const DataType &norm) const
helper function for printing solver output
Definition: solver.hh:185
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:172
virtual void apply(X &x, Y &b, double reduction, InverseOperatorResult &res)=0
apply inverse operator, with given convergence criteria.
Simd::Scalar< real_type > scalar_real_type
scalar type underlying the field_type
Definition: solver.hh:114
Y range_type
Type of the range of the operator to be inverted.
Definition: solver.hh:105
@ normSpacing
Definition: solver.hh:160
@ iterationSpacing
Definition: solver.hh:160
X domain_type
Type of the domain of the operator to be inverted.
Definition: solver.hh:102
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:108
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:111
virtual SolverCategory::Category category() const =0
Category of the solver (see SolverCategory::Category)
Base class for all implementations of iterative solvers.
Definition: solver.hh:203
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:313
IterativeSolver(std::shared_ptr< const LinearOperator< X, Y > > op, std::shared_ptr< Preconditioner< X, X > > prec, const ParameterTree &configuration)
Constructor.
Definition: solver.hh:290
virtual void apply(X &x, X &b, double reduction, InverseOperatorResult &res)
Apply inverse operator with given reduction factor.
Definition: solver.hh:374
std::shared_ptr< const ScalarProduct< X > > _sp
Definition: solver.hh:506
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:340
std::string name() const
Definition: solver.hh:388
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:230
std::shared_ptr< const LinearOperator< X, Y > > _op
Definition: solver.hh:504
int _maxit
Definition: solver.hh:508
int _verbose
Definition: solver.hh:509
scalar_real_type _reduction
Definition: solver.hh:507
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:262
SolverCategory::Category _category
Definition: solver.hh:510
std::shared_ptr< Preconditioner< X, Y > > _prec
Definition: solver.hh:505
virtual SolverCategory::Category category() const
Category of the solver (see SolverCategory::Category)
Definition: solver.hh:383
Class for controlling iterative methods.
Definition: solver.hh:411
Iteration(const IterativeSolver &parent, InverseOperatorResult &res)
Definition: solver.hh:413
Iteration(Iteration &&other)
Definition: solver.hh:428
InverseOperatorResult & _res
Definition: solver.hh:498
const IterativeSolver & _parent
Definition: solver.hh:499
Timer _watch
Definition: solver.hh:497
Iteration(const Iteration &)=delete
CountType _i
Definition: solver.hh:496
real_type _def0
Definition: solver.hh:495
bool step(CountType i, real_type def)
registers the iteration step, checks for invalid defect norm and convergence.
Definition: solver.hh:455
void finalize()
Definition: solver.hh:480
real_type _def
Definition: solver.hh:495
~Iteration()
Definition: solver.hh:440
bool _valid
Definition: solver.hh:500
Helper class for notifying a DUNE-ISTL linear solver about a change of the iteration matrix object in...
Definition: solver.hh:522
static void setMatrix(ISTLLinearSolver &solver, const BCRSMatrix &matrix)
Definition: solver.hh:524
Implementation that works together with iterative ISTL solvers, e.g. Dune::CGSolver or Dune::BiCGSTAB...
Definition: solver.hh:540
static void setMatrix(ISTLLinearSolver &, const BCRSMatrix &)
Definition: solver.hh:541
static void setMatrix(ISTLLinearSolver &solver, const BCRSMatrix &matrix)
Definition: solver.hh:553
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