3 #ifndef DUNE_PDELAB_BACKEND_ISTL_SEQISTLSOLVERBACKEND_HH 4 #define DUNE_PDELAB_BACKEND_ISTL_SEQISTLSOLVERBACKEND_HH 9 #include <dune/common/deprecated.hh> 10 #include <dune/common/parallel/mpihelper.hh> 12 #include <dune/istl/owneroverlapcopy.hh> 13 #include <dune/istl/solvercategory.hh> 14 #include <dune/istl/operators.hh> 15 #include <dune/istl/solvers.hh> 16 #include <dune/istl/preconditioners.hh> 17 #include <dune/istl/scalarproducts.hh> 18 #include <dune/istl/paamg/amg.hh> 19 #include <dune/istl/paamg/pinfo.hh> 20 #include <dune/istl/io.hh> 21 #include <dune/istl/superlu.hh> 22 #include <dune/istl/umfpack.hh> 37 template<
typename X,
typename Y,
typename GOS>
45 enum {
category=Dune::SolverCategory::sequential};
51 virtual void apply (
const X& x, Y& y)
const 54 gos.jacobian_apply(x,y);
61 gos.jacobian_apply(x,temp);
74 template<
template<
class,
class,
class,
int>
class Preconditioner,
75 template<
class>
class Solver>
86 : maxiter(maxiter_), verbose(verbose_)
98 template<
class M,
class V,
class W>
99 void apply(M& A, V& z, W& r,
typename Dune::template FieldTraits<typename W::ElementType >::real_type reduction)
104 Dune::MatrixAdapter<Native<M>,
106 Native<W>> opa(
native(A));
107 Preconditioner<Native<M>,
110 1> prec(
native(A), 3, 1.0);
111 Solver<Native<V>> solver(opa, prec, reduction, maxiter, verbose);
112 Dune::InverseOperatorResult stat;
114 res.converged = stat.converged;
115 res.iterations = stat.iterations;
116 res.elapsed = stat.elapsed;
117 res.reduction = stat.reduction;
118 res.conv_rate = stat.conv_rate;
126 template<
template<
typename>
class Solver>
137 : maxiter(maxiter_), verbose(verbose_)
146 template<
class M,
class V,
class W>
147 void apply(M& A, V& z, W& r,
typename Dune::template FieldTraits<typename W::ElementType >::real_type reduction)
151 Dune::MatrixAdapter<Native<M>,
153 Native<W>> opa(
native(A));
154 Dune::SeqILU0<Native<M>,
158 Solver<Native<V>> solver(opa, ilu0, reduction, maxiter, verbose);
159 Dune::InverseOperatorResult stat;
161 res.converged = stat.converged;
162 res.iterations = stat.iterations;
163 res.elapsed = stat.elapsed;
164 res.reduction = stat.reduction;
165 res.conv_rate = stat.conv_rate;
172 template<
template<
typename>
class Solver>
184 : n_(n), w_(w), maxiter(maxiter_), verbose(verbose_)
193 template<
class M,
class V,
class W>
194 void apply(M& A, V& z, W& r,
typename Dune::template FieldTraits<typename W::ElementType >::real_type reduction)
198 Dune::MatrixAdapter<Native<M>,
202 Dune::SeqILUn<Native<M>,
205 > ilun(
native(A), n_, w_);
206 Solver<Native<V>> solver(opa, ilun, reduction, maxiter, verbose);
207 Dune::InverseOperatorResult stat;
209 res.converged = stat.converged;
210 res.iterations = stat.iterations;
211 res.elapsed = stat.elapsed;
212 res.reduction = stat.reduction;
213 res.conv_rate = stat.conv_rate;
395 #if HAVE_SUPERLU || DOXYGEN 428 template<
class M,
class V,
class W>
429 void apply(M& A, V& z, W& r,
typename Dune::template FieldTraits<typename W::ElementType >::real_type reduction)
433 using ISTLM = Native<M>;
434 Dune::SuperLU<ISTLM> solver(
native(A), verbose);
435 Dune::InverseOperatorResult stat;
437 res.converged = stat.converged;
438 res.iterations = stat.iterations;
439 res.elapsed = stat.elapsed;
440 res.reduction = stat.reduction;
441 res.conv_rate = stat.conv_rate;
447 #endif // HAVE_SUPERLU || DOXYGEN 449 #if HAVE_SUITESPARSE_UMFPACK || DOXYGEN 482 template<
class M,
class V,
class W>
483 void apply(M& A, V& z, W& r,
typename Dune::template FieldTraits<typename W::ElementType >::real_type reduction)
487 Dune::UMFPack<ISTLM> solver(
native(A), verbose);
488 Dune::InverseOperatorResult stat;
490 res.converged = stat.converged;
491 res.iterations = stat.iterations;
492 res.elapsed = stat.elapsed;
493 res.reduction = stat.reduction;
494 res.conv_rate = stat.conv_rate;
500 #endif // HAVE_SUITESPARSE_UMFPACK || DOXYGEN 519 template<
class M,
class V,
class W>
520 void apply(M& A, V& z, W& r,
typename Dune::template FieldTraits<typename W::ElementType >::real_type reduction)
523 Dune::SeqJac<Native<M>,
530 res.converged =
true;
533 res.reduction = reduction;
534 res.conv_rate = reduction;
563 template<
class GO,
template<
class,
class,
class,
int>
class Preconditioner,
template<
class>
class Solver,
564 bool skipBlocksizeCheck =
false>
567 typedef typename GO::Traits::TrialGridFunctionSpace GFS;
568 typedef typename GO::Traits::Jacobian M;
570 typedef typename GO::Traits::Domain V;
572 typedef Preconditioner<MatrixType,VectorType,VectorType,1> Smoother;
573 typedef Dune::MatrixAdapter<MatrixType,VectorType,VectorType> Operator;
574 typedef typename Dune::Amg::SmootherTraits<Smoother>::Arguments SmootherArgs;
575 typedef Dune::Amg::AMG<Operator,VectorType,Smoother> AMG;
576 typedef Dune::Amg::Parameters Parameters;
580 bool reuse_=
false,
bool usesuperlu_=
true)
581 : maxiter(maxiter_), params(15,2000), verbose(verbose_),
582 reuse(reuse_), firstapply(true), usesuperlu(usesuperlu_)
584 params.setDefaultValuesIsotropic(GFS::Traits::GridViewType::Traits::Grid::dimension);
585 params.setDebugLevel(verbose_);
587 if (usesuperlu ==
true)
589 std::cout <<
"WARNING: You are using AMG without SuperLU!" 590 <<
" Please consider installing SuperLU," 591 <<
" or set the usesuperlu flag to false" 592 <<
" to suppress this warning." << std::endl;
622 typename V::ElementType
norm (
const V& v)
const 634 void apply(M& A, V& z, V& r,
typename Dune::template FieldTraits<typename V::ElementType >::real_type reduction)
638 typedef Dune::Amg::CoarsenCriterion<Dune::Amg::SymmetricCriterion<MatrixType,
639 Dune::Amg::FirstDiagonal> > Criterion;
640 SmootherArgs smootherArgs;
641 smootherArgs.iterations = 1;
642 smootherArgs.relaxationFactor = 1;
644 Criterion criterion(params);
646 if (reuse==
false || firstapply==
true){
647 oop.reset(
new Operator(mat));
648 amg.reset(
new AMG(*oop, criterion, smootherArgs));
650 stats.tsetup = watch.elapsed();
651 stats.levels = amg->maxlevels();
652 stats.directCoarseLevelSolver=amg->usesDirectCoarseLevelSolver();
655 Dune::InverseOperatorResult stat;
657 Solver<VectorType> solver(*oop,*amg,reduction,maxiter,verbose);
659 stats.tsolve= watch.elapsed();
660 res.converged = stat.converged;
661 res.iterations = stat.iterations;
662 res.elapsed = stat.elapsed;
663 res.reduction = stat.reduction;
664 res.conv_rate = stat.conv_rate;
684 std::shared_ptr<Operator> oop;
685 std::shared_ptr<AMG> amg;
712 bool reuse_=
false,
bool usesuperlu_=
true)
714 (maxiter_, verbose_, reuse_, usesuperlu_)
738 bool reuse_=
false,
bool usesuperlu_=
true)
740 (maxiter_, verbose_, reuse_, usesuperlu_)
764 bool reuse_=
false,
bool usesuperlu_=
true)
766 (maxiter_, verbose_, reuse_, usesuperlu_)
790 bool reuse_=
false,
bool usesuperlu_=
true)
792 (maxiter_, verbose_, reuse_, usesuperlu_)
816 bool reuse_=
false,
bool usesuperlu_=
true)
818 (maxiter_, verbose_, reuse_, usesuperlu_)
839 : restart(restart_), maxiter(maxiter_), verbose(verbose_)
849 template<
class M,
class V,
class W>
850 void apply(M& A, V& z, W& r,
typename Dune::template FieldTraits<typename W::ElementType>::real_type reduction)
864 Dune::RestartedGMResSolver<Native<V>> solver(opa,ilu0,reduction,restart,maxiter,verbose);
865 Dune::InverseOperatorResult stat;
867 res.converged = stat.converged;
868 res.iterations = stat.iterations;
869 res.elapsed = stat.elapsed;
870 res.reduction = stat.reduction;
871 res.conv_rate = stat.conv_rate;
875 int restart, maxiter, verbose;
884 #endif // DUNE_PDELAB_BACKEND_ISTL_SEQISTLSOLVERBACKEND_HH Solver to be used for explicit time-steppers with (block-)diagonal mass matrix.
Definition: seqistlsolverbackend.hh:503
ISTLBackend_SEQ_CG_SSOR(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:357
void apply(M &A, V &z, W &r, typename Dune::template FieldTraits< typename W::ElementType >::real_type reduction)
solve the given linear system
Definition: seqistlsolverbackend.hh:483
Definition: seqistlsolverbackend.hh:127
std::enable_if< std::is_base_of< impl::WrapperBase, T >::value, Native< T > &>::type native(T &t)
Definition: backend/interface.hh:192
Linear solver backend for Restarted GMRes preconditioned with ILU(0)
Definition: seqistlsolverbackend.hh:827
Sequential BiCGSTAB solver preconditioned with AMG smoothed by SOR.
Definition: seqistlsolverbackend.hh:750
ISTLBackend_SEQ_BCGS_SSOR(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:270
V::ElementType norm(const V &v) const
compute global norm of a vector
Definition: seqistlsolverbackend.hh:622
typename native_type< T >::type Native
Alias of the native container type associated with T or T itself if it is not a backend wrapper...
Definition: backend/interface.hh:176
Definition: seqistlsolverbackend.hh:76
ISTLBackend_SEQ_AMG(unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Definition: seqistlsolverbackend.hh:579
ISTLBackend_SEQ_CG_ILUn(int n_, double w_=1.0, unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:340
ISTLBackend_SEQ_CG_ILU0(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:304
Y range_type
Definition: seqistlsolverbackend.hh:42
virtual void apply(const X &x, Y &y) const
Definition: seqistlsolverbackend.hh:51
ISTLBackend_SEQ_BCGS_AMG_SSOR(unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Constructor.
Definition: seqistlsolverbackend.hh:737
void apply(M &A, V &z, W &r, typename Dune::template FieldTraits< typename W::ElementType >::real_type reduction)
solve the given linear system
Definition: seqistlsolverbackend.hh:429
Definition: seqistlsolverbackend.hh:173
OnTheFlyOperator(GOS &gos_)
Definition: seqistlsolverbackend.hh:47
ISTLBackend_SEQ_LOOP_Jac(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:237
ISTLBackend_SEQ_LS_AMG_SOR(unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Constructor.
Definition: seqistlsolverbackend.hh:815
void apply(M &A, V &z, W &r, typename Dune::template FieldTraits< typename W::ElementType >::real_type reduction)
solve the given linear system
Definition: seqistlsolverbackend.hh:194
ISTLBackend_SEQ_MINRES_SSOR(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:374
Backend for sequential conjugate gradient solver with ILU0 preconditioner.
Definition: seqistlsolverbackend.hh:295
const ISTLAMGStatistics & statistics() const
Get statistics of the AMG solver (no of levels, timings).
Definition: seqistlsolverbackend.hh:672
ISTLBackend_SEQ_ILUn(int n, double w, unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:183
ISTLBackend_SEQ_BCGS_AMG_SOR(unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Constructor.
Definition: seqistlsolverbackend.hh:763
double tsolve
The time spent in solving the system (without building the hierarchy.
Definition: seqistlsolverbackend.hh:554
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
void apply(M &A, V &z, V &r, typename Dune::template FieldTraits< typename V::ElementType >::real_type reduction)
solve the given linear system
Definition: seqistlsolverbackend.hh:634
double tsetup
The time needed for building the AMG hierarchy (coarsening).
Definition: seqistlsolverbackend.hh:556
void setReuse(bool reuse_)
Set whether the AMG should be reused again during call to apply().
Definition: seqistlsolverbackend.hh:607
Backend for conjugate gradient solver with Jacobi preconditioner.
Definition: seqistlsolverbackend.hh:382
void apply(M &A, V &z, W &r, typename Dune::template FieldTraits< typename W::ElementType >::real_type reduction)
solve the given linear system
Definition: seqistlsolverbackend.hh:850
Backend for sequential BiCGSTAB solver with Jacobi preconditioner.
Definition: seqistlsolverbackend.hh:245
void apply(M &A, V &z, W &r, typename Dune::template FieldTraits< typename W::ElementType >::real_type reduction)
solve the given linear system
Definition: seqistlsolverbackend.hh:520
Definition: seqistlsolverbackend.hh:565
ISTLBackend_SEQ_SuperLU(int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:407
int levels
the number of levels in the AMG hierarchy.
Definition: seqistlsolverbackend.hh:552
void apply(M &A, V &z, W &r, typename Dune::template FieldTraits< typename W::ElementType >::real_type reduction)
solve the given linear system
Definition: seqistlsolverbackend.hh:147
ISTLBackend_SEQ_UMFPack(int maxiter, int verbose_)
make a linear solver object
Definition: seqistlsolverbackend.hh:471
ISTLBackend_SEQ_ILU0(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:136
Sequential congute gradient solver with ILU0 preconditioner.
Definition: seqistlsolverbackend.hh:328
ISTLBackend_SEQ_ExplicitDiagonal()
make a linear solver object
Definition: seqistlsolverbackend.hh:509
bool getReuse() const
Return whether the AMG is reused during call to apply()
Definition: seqistlsolverbackend.hh:613
Sequential Loop solver preconditioned with AMG smoothed by SOR.
Definition: seqistlsolverbackend.hh:802
Backend for sequential BiCGSTAB solver with ILU0 preconditioner.
Definition: seqistlsolverbackend.hh:278
bool directCoarseLevelSolver
True if a direct solver was used on the coarset level.
Definition: seqistlsolverbackend.hh:560
Definition: seqistlsolverbackend.hh:45
Backend for sequential loop solver with Jacobi preconditioner.
Definition: seqistlsolverbackend.hh:229
double tprepare
The needed for computing the parallel information and for adapting the linear system.
Definition: seqistlsolverbackend.hh:550
ISTLBackend_SEQ_LS_AMG_SSOR(unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Constructor.
Definition: seqistlsolverbackend.hh:789
ISTLBackend_SEQ_CG_AMG_SSOR(unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Constructor.
Definition: seqistlsolverbackend.hh:711
Solver backend using UMFPack as a direct solver.
Definition: seqistlsolverbackend.hh:453
ISTLBackend_SEQ_SuperLU(int maxiter, int verbose_)
make a linear solver object
Definition: seqistlsolverbackend.hh:417
Backend using a MINRes solver preconditioned by SSOR.
Definition: seqistlsolverbackend.hh:365
void apply(M &A, V &z, W &r, typename Dune::template FieldTraits< typename W::ElementType >::real_type reduction)
solve the given linear system
Definition: seqistlsolverbackend.hh:99
ISTLBackend_SEQ_BCGS_Jac(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:253
Sequential BiCGStab solver with ILU0 preconditioner.
Definition: seqistlsolverbackend.hh:310
X::field_type field_type
Definition: seqistlsolverbackend.hh:43
X domain_type
Definition: seqistlsolverbackend.hh:41
int iterations
The number of iterations performed until convergence was reached.
Definition: seqistlsolverbackend.hh:558
Backend for sequential BiCGSTAB solver with SSOR preconditioner.
Definition: seqistlsolverbackend.hh:261
ISTLBackend_SEQ_BCGS_ILU0(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:287
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const
Definition: seqistlsolverbackend.hh:57
ISTLBackend_SEQ_CG_Jac(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:390
ISTLBackend_SEQ_UMFPack(int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:461
VTKWriter & w
Definition: function.hh:829
Sequential BiCGStab solver preconditioned with AMG smoothed by SSOR.
Definition: seqistlsolverbackend.hh:724
ISTLBackend_SEQ_GMRES_ILU0(int restart_=200, int maxiter_=5000, int verbose_=1)
make linear solver object
Definition: seqistlsolverbackend.hh:838
Class providing some statistics of the AMG solver.
Definition: seqistlsolverbackend.hh:544
ISTLBackend_SEQ_Base(unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:85
Solver backend using SuperLU as a direct solver.
Definition: seqistlsolverbackend.hh:399
Backend for sequential conjugate gradient solver with SSOR preconditioner.
Definition: seqistlsolverbackend.hh:348
ISTLBackend_SEQ_BCGS_ILUn(int n_, double w_=1.0, unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: seqistlsolverbackend.hh:322
Definition: seqistlsolverbackend.hh:38
void setparams(Parameters params_)
set AMG parameters
Definition: seqistlsolverbackend.hh:601
Sequential Loop solver preconditioned with AMG smoothed by SSOR.
Definition: seqistlsolverbackend.hh:776
Sequential conjugate gradient solver preconditioned with AMG smoothed by SSOR.
Definition: seqistlsolverbackend.hh:698