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;
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);
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:52
Class for controlling iterative methods.
Definition: solver.hh:413
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
A linear operator.
Definition: operators.hh:68
Iteration(Iteration &&other)
Definition: solver.hh:430
void printOutput(std::ostream &s, const CountType &iter, const DataType &norm) const
helper function for printing solver output
Definition: solver.hh:187
Definition: solver.hh:162
void printHeader(std::ostream &s) const
helper function for printing header of solver output
Definition: solver.hh:165
double conv_rate
Convergence rate (average reduction per step)
Definition: solver.hh:78
Definition: solver.hh:162
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
Default implementation for the scalar case.
Definition: scalarproducts.hh:167
Define base class for scalar product and norm.
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:466
bool _valid
Definition: solver.hh:502
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
static void setMatrix(ISTLLinearSolver &solver, const BCRSMatrix &matrix)
Definition: solver.hh:526
Statistics about the application of an inverse operator.
Definition: solver.hh:49
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:33
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
SolverCategory::Category _category
Definition: solver.hh:512
void clear()
Resets all data.
Definition: solver.hh:58
std::shared_ptr< const LinearOperator< X, Y > > _op
Definition: solver.hh:506
Category for sequential solvers.
Definition: solvercategory.hh:25
InverseOperatorResult & _res
Definition: solver.hh:500
double reduction
Reduction achieved: .
Definition: solver.hh:72
Implementation that works together with iterative ISTL solvers, e.g. Dune::CGSolver or Dune::BiCGSTAB...
Definition: solver.hh:541
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category)
Definition: solver.hh:385
Base class for all implementations of iterative solvers.
Definition: solver.hh:205
X::field_type field_type
The field type of the operator.
Definition: solver.hh:110
void apply(X &x, X &b, double reduction, InverseOperatorResult &res) override
Apply inverse operator with given reduction factor.
Definition: solver.hh:376
real_type _def0
Definition: solver.hh:497
Categories for the solvers.
Definition: solvercategory.hh:21
Helper class for notifying a DUNE-ISTL linear solver about a change of the iteration matrix object in...
Definition: solver.hh:523
Timer _watch
Definition: solver.hh:499
Templates characterizing the type of a solver.
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
~Iteration()
Definition: solver.hh:442
int iterations
Number of iterations.
Definition: solver.hh:69
double condition_estimate
Estimate of condition number.
Definition: solver.hh:81
virtual ~InverseOperator()
Destructor.
Definition: solver.hh:158
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
Definition: solvercategory.hh:54
bool step(CountType i, real_type def)
registers the iteration step, checks for invalid defect norm and convergence.
Definition: solver.hh:457
const IterativeSolver & _parent
Definition: solver.hh:501
std::shared_ptr< Preconditioner< X, Y > > _prec
Definition: solver.hh:507
int _maxit
Definition: solver.hh:510
int _verbose
Definition: solver.hh:511
static void setMatrix(ISTLLinearSolver &solver, const BCRSMatrix &matrix)
Definition: solver.hh:555
bool converged
True if convergence criterion has been met.
Definition: solver.hh:75
real_type _def
Definition: solver.hh:497
scalar_real_type _reduction
Definition: solver.hh:509
Iteration(const IterativeSolver &parent, InverseOperatorResult &res)
Definition: solver.hh:415
CountType _i
Definition: solver.hh:498
virtual SolverCategory::Category category() const =0
Category of the solver (see SolverCategory::Category)
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,.
Simd::Scalar< real_type > scalar_real_type
scalar type underlying the field_type
Definition: solver.hh:116
std::shared_ptr< const ScalarProduct< X > > _sp
Definition: solver.hh:508
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
Category
Definition: solvercategory.hh:23
X domain_type
Type of the domain of the operator to be inverted.
Definition: solver.hh:104
static void setMatrix(ISTLLinearSolver &, const BCRSMatrix &)
Definition: solver.hh:543
Definition: allocator.hh:11
IterativeSolver(std::shared_ptr< const LinearOperator< X, Y > > op, std::shared_ptr< Preconditioner< X, X > > prec, const ParameterTree &configuration)
Constructor.
Definition: solver.hh:292
void finalize()
Definition: solver.hh:482
std::string name() const
Definition: solver.hh:390
Define general, extensible interface for operators. The available implementation wraps a matrix...
double elapsed
Elapsed time in seconds.
Definition: solver.hh:84
Thrown when a solver aborts due to some problem.
Definition: istlexception.hh:46
Abstract base class for all solvers.
Definition: solver.hh:101
Definition: solvertype.hh:15
PropertyMapTypeSelector< Amg::VertexVisitedTag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > >::Type get([[maybe_unused]] const Amg::VertexVisitedTag &tag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > &graph)
Definition: dependency.hh:293
InverseOperatorResult()
Default constructor.
Definition: solver.hh:52