dune-pdelab  2.4-dev
istl/ovlpistlsolverbackend.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 #ifndef DUNE_OVLPISTLSOLVERBACKEND_HH
4 #define DUNE_OVLPISTLSOLVERBACKEND_HH
5 
6 #include <dune/common/deprecated.hh>
7 #include <dune/common/parallel/mpihelper.hh>
8 
9 #include <dune/istl/owneroverlapcopy.hh>
10 #include <dune/istl/solvercategory.hh>
11 #include <dune/istl/operators.hh>
12 #include <dune/istl/solvers.hh>
13 #include <dune/istl/preconditioners.hh>
14 #include <dune/istl/scalarproducts.hh>
15 #include <dune/istl/paamg/amg.hh>
16 #include <dune/istl/paamg/pinfo.hh>
17 #include <dune/istl/io.hh>
18 #include <dune/istl/superlu.hh>
19 
26 
27 namespace Dune {
28  namespace PDELab {
29 
33 
34  //========================================================
35  // Generic support for overlapping grids
36  // (need to be used with appropriate constraints)
37  //========================================================
38 
39  // operator that resets result to zero at constrained DOFS
40  template<class CC, class M, class X, class Y>
42  : public Dune::AssembledLinearOperator<M,X,Y>
43  {
44  public:
46  typedef M matrix_type;
47  typedef X domain_type;
48  typedef Y range_type;
49  typedef typename X::ElementType field_type;
50 
51  //redefine the category, that is the only difference
52  enum {category=Dune::SolverCategory::overlapping};
53 
54  OverlappingOperator (const CC& cc_, const M& A)
55  : cc(cc_), _A_(A)
56  {}
57 
59  virtual void apply (const domain_type& x, range_type& y) const
60  {
61  using Backend::native;
62  native(_A_).mv(native(x),native(y));
64  }
65 
67  virtual void applyscaleadd (field_type alpha, const domain_type& x, range_type& y) const
68  {
69  using Backend::native;
70  native(_A_).usmv(alpha,native(x),native(y));
72  }
73 
75  virtual const M& getmat () const
76  {
77  return _A_;
78  }
79 
80  private:
81  const CC& cc;
82  const M& _A_;
83  };
84 
85  // new scalar product assuming at least overlap 1
86  // uses unique partitioning of nodes for parallelization
87  template<class GFS, class X>
89  : public Dune::ScalarProduct<X>
90  {
91  public:
93  typedef X domain_type;
94  typedef typename X::ElementType field_type;
95 
97  enum {category=Dune::SolverCategory::overlapping};
98 
101  OverlappingScalarProduct (const GFS& gfs_, const istl::ParallelHelper<GFS>& helper_)
102  : gfs(gfs_), helper(helper_)
103  {}
104 
105 
110  virtual field_type dot (const X& x, const X& y)
111  {
112  // do local scalar product on unique partition
113  field_type sum = helper.disjointDot(x,y);
114 
115  // do global communication
116  return gfs.gridView().comm().sum(sum);
117  }
118 
122  virtual double norm (const X& x)
123  {
124  return sqrt(static_cast<double>(this->dot(x,x)));
125  }
126 
127  private:
128  const GFS& gfs;
129  const istl::ParallelHelper<GFS>& helper;
130  };
131 
132  // wrapped sequential preconditioner
133  template<class CC, class GFS, class P>
135  : public Dune::Preconditioner<Dune::PDELab::Backend::Vector<GFS,typename P::domain_type::field_type>,
136  Dune::PDELab::Backend::Vector<GFS,typename P::range_type::field_type>>
137  {
138  public:
143 
144  // define the category
145  enum {
147  category=Dune::SolverCategory::overlapping
148  };
149 
151  OverlappingWrappedPreconditioner (const GFS& gfs_, P& prec_, const CC& cc_,
152  const istl::ParallelHelper<GFS>& helper_)
153  : gfs(gfs_), prec(prec_), cc(cc_), helper(helper_)
154  {}
155 
159  virtual void pre (domain_type& x, range_type& b)
160  {
161  prec.pre(x,b);
162  }
163 
167  virtual void apply (domain_type& v, const range_type& d)
168  {
169  range_type dd(d);
170  set_constrained_dofs(cc,0.0,dd);
171  prec.apply(Backend::native(v),Backend::native(dd));
173  if (gfs.gridView().comm().size()>1)
174  gfs.gridView().communicate(adddh,Dune::All_All_Interface,Dune::ForwardCommunication);
175  }
176 
180  virtual void post (domain_type& x)
181  {
182  prec.post(Backend::native(x));
183  }
184 
185  private:
186  const GFS& gfs;
187  P& prec;
188  const CC& cc;
189  const istl::ParallelHelper<GFS>& helper;
190  };
191 
192 
193 #if HAVE_SUPERLU
194  // exact subdomain solves with SuperLU as preconditioner
195  template<class GFS, class M, class X, class Y>
196  class SuperLUSubdomainSolver : public Dune::Preconditioner<X,Y>
197  {
198  typedef Backend::Native<M> ISTLM;
199 
200  public:
202  typedef X domain_type;
204  typedef Y range_type;
206  typedef typename X::ElementType field_type;
207 
208 
209  // define the category
210  enum {
212  category=Dune::SolverCategory::overlapping
213  };
214 
221  SuperLUSubdomainSolver (const GFS& gfs_, const M& A_)
222  : gfs(gfs_), solver(Backend::native(A_),false) // this does the decomposition
223  {}
224 
228  virtual void pre (X& x, Y& b) {}
229 
233  virtual void apply (X& v, const Y& d)
234  {
235  Dune::InverseOperatorResult stat;
236  Y b(d); // need copy, since solver overwrites right hand side
237  solver.apply(Backend::native(v),Backend::native(b),stat);
238  if (gfs.gridView().comm().size()>1)
239  {
240  AddDataHandle<GFS,X> adddh(gfs,v);
241  gfs.gridView().communicate(adddh,Dune::All_All_Interface,Dune::ForwardCommunication);
242  }
243  }
244 
248  virtual void post (X& x) {}
249 
250  private:
251  const GFS& gfs;
252  Dune::SuperLU<ISTLM> solver;
253  };
254 
255  // exact subdomain solves with SuperLU as preconditioner
256  template<class GFS, class M, class X, class Y>
257  class RestrictedSuperLUSubdomainSolver : public Dune::Preconditioner<X,Y>
258  {
259  typedef typename M::BaseT ISTLM;
260 
261  public:
263  typedef X domain_type;
265  typedef Y range_type;
267  typedef typename X::ElementType field_type;
268 
269 
270  // define the category
271  enum {
273  category=Dune::SolverCategory::overlapping
274  };
275 
283  RestrictedSuperLUSubdomainSolver (const GFS& gfs_, const M& A_,
284  const istl::ParallelHelper<GFS>& helper_)
285  : gfs(gfs_), solver(Backend::native(A_),false), helper(helper_) // this does the decomposition
286  {}
287 
291  virtual void pre (X& x, Y& b) {}
292 
296  virtual void apply (X& v, const Y& d)
297  {
298  using Backend::native;
299  Dune::InverseOperatorResult stat;
300  Y b(d); // need copy, since solver overwrites right hand side
301  solver.apply(native(v),native(b),stat);
302  if (gfs.gridView().comm().size()>1)
303  {
304  helper.maskForeignDOFs(native(v));
305  AddDataHandle<GFS,X> adddh(gfs,v);
306  gfs.gridView().communicate(adddh,Dune::InteriorBorder_All_Interface,Dune::ForwardCommunication);
307  }
308  }
309 
313  virtual void post (X& x) {}
314 
315  private:
316  const GFS& gfs;
317  Dune::SuperLU<ISTLM> solver;
318  const istl::ParallelHelper<GFS>& helper;
319  };
320 #endif
321 
322  template<typename GFS>
324  {
325  public:
327  : gfs(gfs_), helper(gfs_)
328  {}
329 
334  template<typename X>
335  typename X::ElementType dot (const X& x, const X& y) const
336  {
337  // do local scalar product on unique partition
338  typename X::ElementType sum = helper.disjointDot(x,y);
339 
340  // do global communication
341  return gfs.gridView().comm().sum(sum);
342  }
343 
347  template<typename X>
348  typename X::ElementType norm (const X& x) const
349  {
350  return sqrt(static_cast<double>(this->dot(x,x)));
351  }
352 
354  {
355  return helper;
356  }
357 
358  // need also non-const version;
359  istl::ParallelHelper<GFS>& parallelHelper() // P.B.: needed for createIndexSetAndProjectForAMG
360  {
361  return helper;
362  }
363 
364  private:
365  const GFS& gfs;
367  };
368 
369 
370  template<typename GFS, typename X>
372  : public ScalarProduct<X>
373  {
374  public:
375  enum {category=Dune::SolverCategory::overlapping};
377  : implementation(implementation_)
378  {}
379 
380  virtual typename X::BaseT::field_type dot(const X& x, const X& y)
381  {
382  return implementation.dot(x,y);
383  }
384 
385  virtual typename X::BaseT::field_type norm (const X& x)
386  {
387  return sqrt(static_cast<double>(this->dot(x,x)));
388  }
389 
390  private:
391  const OVLPScalarProductImplementation<GFS>& implementation;
392  };
393 
394  template<class GFS, class C,
395  template<class,class,class,int> class Preconditioner,
396  template<class> class Solver>
399  {
400  public:
409  ISTLBackend_OVLP_Base (const GFS& gfs_, const C& c_, unsigned maxiter_=5000,
410  int steps_=5, int verbose_=1)
411  : OVLPScalarProductImplementation<GFS>(gfs_), gfs(gfs_), c(c_), maxiter(maxiter_), steps(steps_), verbose(verbose_)
412  {}
413 
421  template<class M, class V, class W>
422  void apply(M& A, V& z, W& r, typename V::ElementType reduction)
423  {
424  using Backend::Native;
425  using Backend::native;
426  typedef OverlappingOperator<C,M,V,W> POP;
427  POP pop(c,A);
428  typedef OVLPScalarProduct<GFS,V> PSP;
429  PSP psp(*this);
430  typedef Preconditioner<
431  Native<M>,
432  Native<V>,
433  Native<W>,
434  1
435  > SeqPrec;
436  SeqPrec seqprec(native(A),steps,1.0);
438  WPREC wprec(gfs,seqprec,c,this->parallelHelper());
439  int verb=0;
440  if (gfs.gridView().comm().rank()==0) verb=verbose;
441  Solver<V> solver(pop,psp,wprec,reduction,maxiter,verb);
442  Dune::InverseOperatorResult stat;
443  solver.apply(z,r,stat);
444  res.converged = stat.converged;
445  res.iterations = stat.iterations;
446  res.elapsed = stat.elapsed;
447  res.reduction = stat.reduction;
448  res.conv_rate = stat.conv_rate;
449  }
450  private:
451  const GFS& gfs;
452  const C& c;
453  unsigned maxiter;
454  int steps;
455  int verbose;
456  };
457 
458  // Base class for ILU0 as preconditioner
459  template<class GFS, class C,
460  template<class> class Solver>
463  {
464  public:
472  ISTLBackend_OVLP_ILU0_Base (const GFS& gfs_, const C& c_, unsigned maxiter_=5000, int verbose_=1)
473  : OVLPScalarProductImplementation<GFS>(gfs_), gfs(gfs_), c(c_), maxiter(maxiter_), verbose(verbose_)
474  {}
475 
483  template<class M, class V, class W>
484  void apply(M& A, V& z, W& r, typename V::ElementType reduction)
485  {
486  using Backend::Native;
487  using Backend::native;
488  typedef OverlappingOperator<C,M,V,W> POP;
489  POP pop(c,A);
490  typedef OVLPScalarProduct<GFS,V> PSP;
491  PSP psp(*this);
492  typedef SeqILU0<
493  Native<M>,
494  Native<V>,
495  Native<W>,
496  1
497  > SeqPrec;
498  SeqPrec seqprec(native(A),1.0);
500  WPREC wprec(gfs,seqprec,c,this->parallelHelper());
501  int verb=0;
502  if (gfs.gridView().comm().rank()==0) verb=verbose;
503  Solver<V> solver(pop,psp,wprec,reduction,maxiter,verb);
504  Dune::InverseOperatorResult stat;
505  solver.apply(z,r,stat);
506  res.converged = stat.converged;
507  res.iterations = stat.iterations;
508  res.elapsed = stat.elapsed;
509  res.reduction = stat.reduction;
510  res.conv_rate = stat.conv_rate;
511  }
512  private:
513  const GFS& gfs;
514  const C& c;
515  unsigned maxiter;
516  int steps;
517  int verbose;
518  };
519 
520  // Base class for ILUn as preconditioner
521  template<class GFS, class C,
522  template<class> class Solver>
525  {
526  public:
535  ISTLBackend_OVLP_ILUn_Base (const GFS& gfs_, const C& c_, int n_=1, unsigned maxiter_=5000, int verbose_=1)
536  : OVLPScalarProductImplementation<GFS>(gfs_), gfs(gfs_), c(c_), n(n_), maxiter(maxiter_), verbose(verbose_)
537  {}
538 
546  template<class M, class V, class W>
547  void apply(M& A, V& z, W& r, typename V::ElementType reduction)
548  {
549  using Backend::Native;
550  using Backend::native;
551  typedef OverlappingOperator<C,M,V,W> POP;
552  POP pop(c,A);
553  typedef OVLPScalarProduct<GFS,V> PSP;
554  PSP psp(*this);
555  typedef SeqILUn<
556  Native<M>,
557  Native<V>,
558  Native<W>,
559  1
560  > SeqPrec;
561  SeqPrec seqprec(native(A),n,1.0);
563  WPREC wprec(gfs,seqprec,c,this->parallelHelper());
564  int verb=0;
565  if (gfs.gridView().comm().rank()==0) verb=verbose;
566  Solver<V> solver(pop,psp,wprec,reduction,maxiter,verb);
567  Dune::InverseOperatorResult stat;
568  solver.apply(z,r,stat);
569  res.converged = stat.converged;
570  res.iterations = stat.iterations;
571  res.elapsed = stat.elapsed;
572  res.reduction = stat.reduction;
573  res.conv_rate = stat.conv_rate;
574  }
575  private:
576  const GFS& gfs;
577  const C& c;
578  int n;
579  unsigned maxiter;
580  int steps;
581  int verbose;
582  };
583 
586 
592  template<class GFS, class CC>
594  : public ISTLBackend_OVLP_Base<GFS,CC,Dune::SeqSSOR, Dune::BiCGSTABSolver>
595  {
596  public:
605  ISTLBackend_OVLP_BCGS_SSORk (const GFS& gfs, const CC& cc, unsigned maxiter=5000,
606  int steps=5, int verbose=1)
607  : ISTLBackend_OVLP_Base<GFS,CC,Dune::SeqSSOR, Dune::BiCGSTABSolver>(gfs, cc, maxiter, steps, verbose)
608  {}
609  };
615  template<class GFS, class CC>
617  : public ISTLBackend_OVLP_ILU0_Base<GFS,CC,Dune::BiCGSTABSolver>
618  {
619  public:
627  ISTLBackend_OVLP_BCGS_ILU0 (const GFS& gfs, const CC& cc, unsigned maxiter=5000, int verbose=1)
628  : ISTLBackend_OVLP_ILU0_Base<GFS,CC,Dune::BiCGSTABSolver>(gfs, cc, maxiter, verbose)
629  {}
630  };
636  template<class GFS, class CC>
638  : public ISTLBackend_OVLP_ILUn_Base<GFS,CC,Dune::BiCGSTABSolver>
639  {
640  public:
649  ISTLBackend_OVLP_BCGS_ILUn (const GFS& gfs, const CC& cc, int n=1, unsigned maxiter=5000, int verbose=1)
650  : ISTLBackend_OVLP_ILUn_Base<GFS,CC,Dune::BiCGSTABSolver>(gfs, cc, n, maxiter, verbose)
651  {}
652  };
658  template<class GFS, class CC>
660  : public ISTLBackend_OVLP_Base<GFS,CC,Dune::SeqSSOR, Dune::CGSolver>
661  {
662  public:
671  ISTLBackend_OVLP_CG_SSORk (const GFS& gfs, const CC& cc, unsigned maxiter=5000,
672  int steps=5, int verbose=1)
673  : ISTLBackend_OVLP_Base<GFS,CC,Dune::SeqSSOR, Dune::CGSolver>(gfs, cc, maxiter, steps, verbose)
674  {}
675  };
676 
682  template<class GFS, class CC>
685  {
686  public:
694  ISTLBackend_OVLP_GMRES_ILU0 (const GFS& gfs_, const CC& cc_, unsigned maxiter_=5000, int verbose_=1,
695  int restart_ = 20)
696  : OVLPScalarProductImplementation<GFS>(gfs_), gfs(gfs_), cc(cc_), maxiter(maxiter_), verbose(verbose_),
697  restart(restart_)
698  {}
699 
706  template<class M, class V, class W>
707  void apply(M& A, V& z, W& r, typename V::ElementType reduction)
708  {
709  using Backend::Native;
710  using Backend::native;
711  typedef OverlappingOperator<CC,M,V,W> POP;
712  POP pop(cc,A);
713  typedef OVLPScalarProduct<GFS,V> PSP;
714  PSP psp(*this);
715  typedef SeqILU0<
716  Native<M>,
717  Native<V>,
718  Native<W>,
719  1
720  > SeqPrec;
721  SeqPrec seqprec(native(A),1.0);
723  WPREC wprec(gfs,seqprec,cc,this->parallelHelper());
724  int verb=0;
725  if (gfs.gridView().comm().rank()==0) verb=verbose;
726  RestartedGMResSolver<V> solver(pop,psp,wprec,reduction,restart,maxiter,verb);
727  Dune::InverseOperatorResult stat;
728  solver.apply(z,r,stat);
729  res.converged = stat.converged;
730  res.iterations = stat.iterations;
731  res.elapsed = stat.elapsed;
732  res.reduction = stat.reduction;
733  res.conv_rate = stat.conv_rate;
734  }
735 
736  private:
737  const GFS& gfs;
738  const CC& cc;
739  unsigned maxiter;
740  int steps;
741  int verbose;
742  int restart;
743  };
744 
746 
747  template<class GFS, class C, template<typename> class Solver>
750  {
751  public:
759  ISTLBackend_OVLP_SuperLU_Base (const GFS& gfs_, const C& c_, unsigned maxiter_=5000,
760  int verbose_=1)
761  : OVLPScalarProductImplementation<GFS>(gfs_), gfs(gfs_), c(c_), maxiter(maxiter_), verbose(verbose_)
762  {}
763 
771  template<class M, class V, class W>
772  void apply(M& A, V& z, W& r, typename V::ElementType reduction)
773  {
774  typedef OverlappingOperator<C,M,V,W> POP;
775  POP pop(c,A);
776  typedef OVLPScalarProduct<GFS,V> PSP;
777  PSP psp(*this);
778 #if HAVE_SUPERLU
779  typedef SuperLUSubdomainSolver<GFS,M,V,W> PREC;
780  PREC prec(gfs,A);
781  int verb=0;
782  if (gfs.gridView().comm().rank()==0) verb=verbose;
783  Solver<V> solver(pop,psp,prec,reduction,maxiter,verb);
784  Dune::InverseOperatorResult stat;
785  solver.apply(z,r,stat);
786  res.converged = stat.converged;
787  res.iterations = stat.iterations;
788  res.elapsed = stat.elapsed;
789  res.reduction = stat.reduction;
790  res.conv_rate = stat.conv_rate;
791 #else
792  std::cout << "No superLU support, please install and configure it." << std::endl;
793 #endif
794  }
795 
796  private:
797  const GFS& gfs;
798  const C& c;
799  unsigned maxiter;
800  int verbose;
801  };
802 
805 
810  template<class GFS, class CC>
812  : public ISTLBackend_OVLP_SuperLU_Base<GFS,CC,Dune::BiCGSTABSolver>
813  {
814  public:
815 
823  ISTLBackend_OVLP_BCGS_SuperLU (const GFS& gfs_, const CC& cc_, unsigned maxiter_=5000,
824  int verbose_=1)
825  : ISTLBackend_OVLP_SuperLU_Base<GFS,CC,Dune::BiCGSTABSolver>(gfs_,cc_,maxiter_,verbose_)
826  {}
827  };
828 
834  template<class GFS, class CC>
836  : public ISTLBackend_OVLP_SuperLU_Base<GFS,CC,Dune::CGSolver>
837  {
838  public:
839 
847  ISTLBackend_OVLP_CG_SuperLU (const GFS& gfs_, const CC& cc_,
848  unsigned maxiter_=5000,
849  int verbose_=1)
850  : ISTLBackend_OVLP_SuperLU_Base<GFS,CC,Dune::CGSolver>(gfs_,cc_,maxiter_,verbose_)
851  {}
852  };
853 
854 
858  template<class GFS>
860  : public LinearResultStorage
861  {
862  public:
867  explicit ISTLBackend_OVLP_ExplicitDiagonal (const GFS& gfs_)
868  : gfs(gfs_)
869  {}
870 
872  : gfs(other_.gfs)
873  {}
874 
879  template<class V>
880  typename V::ElementType norm(const V& v) const
881  {
882  static_assert
884  "ISTLBackend_OVLP_ExplicitDiagonal::norm() should not be "
885  "neccessary, so we skipped the implementation. If you have a "
886  "scenario where you need it, please implement it or report back to "
887  "us.");
888  }
889 
897  template<class M, class V, class W>
898  void apply(M& A, V& z, W& r, typename W::ElementType reduction)
899  {
900  using Backend::Native;
901  using Backend::native;
902  Dune::SeqJac<
903  Native<M>,
904  Native<V>,
905  Native<W>
906  > jac(native(A),1,1.0);
907  jac.pre(native(z),native(r));
908  jac.apply(native(z),native(r));
909  jac.post(native(z));
910  if (gfs.gridView().comm().size()>1)
911  {
912  CopyDataHandle<GFS,V> copydh(gfs,z);
913  gfs.gridView().communicate(copydh,Dune::InteriorBorder_All_Interface,Dune::ForwardCommunication);
914  }
915  res.converged = true;
916  res.iterations = 1;
917  res.elapsed = 0.0;
918  res.reduction = static_cast<double>(reduction);
919  res.conv_rate = static_cast<double>(reduction); // pow(reduction,1.0/1)
920  }
921 
922  private:
923  const GFS& gfs;
924  };
926 
927  template<class GO, int s, template<class,class,class,int> class Preconditioner,
928  template<class> class Solver>
930  {
931  typedef typename GO::Traits::TrialGridFunctionSpace GFS;
933  typedef typename GO::Traits::Jacobian M;
934  typedef Backend::Native<M> MatrixType;
935  typedef typename GO::Traits::Domain V;
936  typedef Backend::Native<V> VectorType;
938 #if HAVE_MPI
939  typedef Preconditioner<MatrixType,VectorType,VectorType,1> Smoother;
940  typedef Dune::BlockPreconditioner<VectorType,VectorType,Comm,Smoother> ParSmoother;
941  typedef Dune::OverlappingSchwarzOperator<MatrixType,VectorType,VectorType,Comm> Operator;
942 #else
943  typedef Preconditioner<MatrixType,VectorType,VectorType,1> ParSmoother;
944  typedef Dune::MatrixAdapter<MatrixType,VectorType,VectorType> Operator;
945 #endif
946  typedef typename Dune::Amg::SmootherTraits<ParSmoother>::Arguments SmootherArgs;
947  typedef Dune::Amg::AMG<Operator,VectorType,ParSmoother,Comm> AMG;
948 
949  typedef typename V::ElementType RF;
950 
951  public:
952 
956  typedef Dune::Amg::Parameters Parameters;
957 
958  public:
959  ISTLBackend_AMG(const GFS& gfs_, unsigned maxiter_=5000,
960  int verbose_=1, bool reuse_=false,
961  bool usesuperlu_=true)
962  : gfs(gfs_), phelper(gfs,verbose_), maxiter(maxiter_), params(15,2000),
963  verbose(verbose_), reuse(reuse_), firstapply(true),
964  usesuperlu(usesuperlu_)
965  {
966  params.setDefaultValuesIsotropic(GFS::Traits::GridViewType::Traits::Grid::dimension);
967  params.setDebugLevel(verbose_);
968 #if !HAVE_SUPERLU
969  if (gfs.gridView().comm().rank() == 0 && usesuperlu == true)
970  {
971  std::cout << "WARNING: You are using AMG without SuperLU!"
972  << " Please consider installing SuperLU,"
973  << " or set the usesuperlu flag to false"
974  << " to suppress this warning." << std::endl;
975  }
976 #endif
977  }
978 
983  void setParameters(const Parameters& params_)
984  {
985  params = params_;
986  }
987 
988  void setparams(Parameters params_) DUNE_DEPRECATED_MSG("setparams() is deprecated, use setParameters() instead")
989  {
990  params = params_;
991  }
992 
1000  const Parameters& parameters() const
1001  {
1002  return params;
1003  }
1004 
1009  typename V::ElementType norm (const V& v) const
1010  {
1011  typedef OverlappingScalarProduct<GFS,V> PSP;
1012  PSP psp(gfs,phelper);
1013  return psp.norm(v);
1014  }
1015 
1023  void apply(M& A, V& z, V& r, typename V::ElementType reduction)
1024  {
1025  Timer watch;
1026  Comm oocc(gfs.gridView().comm());
1027  MatrixType& mat=Backend::native(A);
1028  typedef Dune::Amg::CoarsenCriterion<Dune::Amg::SymmetricCriterion<MatrixType,
1029  Dune::Amg::FirstDiagonal> > Criterion;
1030 #if HAVE_MPI
1031  phelper.createIndexSetAndProjectForAMG(A, oocc);
1032  Operator oop(mat, oocc);
1033  Dune::OverlappingSchwarzScalarProduct<VectorType,Comm> sp(oocc);
1034 #else
1035  Operator oop(mat);
1036  Dune::SeqScalarProduct<VectorType> sp;
1037 #endif
1038  SmootherArgs smootherArgs;
1039  smootherArgs.iterations = 1;
1040  smootherArgs.relaxationFactor = 1;
1041  Criterion criterion(params);
1042  stats.tprepare=watch.elapsed();
1043  watch.reset();
1044 
1045  int verb=0;
1046  if (gfs.gridView().comm().rank()==0) verb=verbose;
1047  //only construct a new AMG if the matrix changes
1048  if (reuse==false || firstapply==true){
1049  amg.reset(new AMG(oop, criterion, smootherArgs, oocc));
1050  firstapply = false;
1051  stats.tsetup = watch.elapsed();
1052  stats.levels = amg->maxlevels();
1053  stats.directCoarseLevelSolver=amg->usesDirectCoarseLevelSolver();
1054  }
1055  watch.reset();
1056  Solver<VectorType> solver(oop,sp,*amg,RF(reduction),maxiter,verb);
1057  Dune::InverseOperatorResult stat;
1058 
1059  solver.apply(Backend::native(z),Backend::native(r),stat);
1060  stats.tsolve= watch.elapsed();
1061  res.converged = stat.converged;
1062  res.iterations = stat.iterations;
1063  res.elapsed = stat.elapsed;
1064  res.reduction = stat.reduction;
1065  res.conv_rate = stat.conv_rate;
1066  }
1067 
1073  {
1074  return stats;
1075  }
1076 
1077  private:
1078  const GFS& gfs;
1079  PHELPER phelper;
1080  unsigned maxiter;
1081  Parameters params;
1082  int verbose;
1083  bool reuse;
1084  bool firstapply;
1085  bool usesuperlu;
1086  shared_ptr<AMG> amg;
1087  ISTLAMGStatistics stats;
1088  };
1089 
1092 
1099  template<class GO, int s=96>
1101  : public ISTLBackend_AMG<GO, s, Dune::SeqSSOR, Dune::CGSolver>
1102  {
1103  typedef typename GO::Traits::TrialGridFunctionSpace GFS;
1104  public:
1114  ISTLBackend_CG_AMG_SSOR(const GFS& gfs_, unsigned maxiter_=5000,
1115  int verbose_=1, bool reuse_=false,
1116  bool usesuperlu_=true)
1117  : ISTLBackend_AMG<GO, s, Dune::SeqSSOR, Dune::CGSolver>
1118  (gfs_, maxiter_, verbose_, reuse_, usesuperlu_)
1119  {}
1120  };
1121 
1128  template<class GO, int s=96>
1130  : public ISTLBackend_AMG<GO, s, Dune::SeqSSOR, Dune::BiCGSTABSolver>
1131  {
1132  typedef typename GO::Traits::TrialGridFunctionSpace GFS;
1133  public:
1143  ISTLBackend_BCGS_AMG_SSOR(const GFS& gfs_, unsigned maxiter_=5000,
1144  int verbose_=1, bool reuse_=false,
1145  bool usesuperlu_=true)
1146  : ISTLBackend_AMG<GO, s, Dune::SeqSSOR, Dune::BiCGSTABSolver>
1147  (gfs_, maxiter_, verbose_, reuse_, usesuperlu_)
1148  {}
1149  };
1150 
1157  template<class GO, int s=96>
1159  : public ISTLBackend_AMG<GO, s, Dune::SeqILU0, Dune::BiCGSTABSolver>
1160  {
1161  typedef typename GO::Traits::TrialGridFunctionSpace GFS;
1162  public:
1172  ISTLBackend_BCGS_AMG_ILU0(const GFS& gfs_, unsigned maxiter_=5000,
1173  int verbose_=1, bool reuse_=false,
1174  bool usesuperlu_=true)
1175  : ISTLBackend_AMG<GO, s, Dune::SeqILU0, Dune::BiCGSTABSolver>
1176  (gfs_, maxiter_, verbose_, reuse_, usesuperlu_)
1177  {}
1178  };
1179 
1181 
1183 
1184  } // namespace PDELab
1185 } // namespace Dune
1186 
1187 #endif
virtual X::BaseT::field_type dot(const X &x, const X &y)
Definition: istl/ovlpistlsolverbackend.hh:380
M matrix_type
export types
Definition: istl/ovlpistlsolverbackend.hh:46
ISTLBackend_AMG(const GFS &gfs_, unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Definition: istl/ovlpistlsolverbackend.hh:959
void apply(M &A, V &z, W &r, typename V::ElementType reduction)
solve the given linear system
Definition: istl/ovlpistlsolverbackend.hh:772
ISTLBackend_CG_AMG_SSOR(const GFS &gfs_, unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Constructor.
Definition: istl/ovlpistlsolverbackend.hh:1114
X::ElementType norm(const X &x) const
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition...
Definition: istl/ovlpistlsolverbackend.hh:348
ISTLBackend_OVLP_GMRES_ILU0(const GFS &gfs_, const CC &cc_, unsigned maxiter_=5000, int verbose_=1, int restart_=20)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:694
Solver to be used for explicit time-steppers with (block-)diagonal mass matrix.
Definition: istl/ovlpistlsolverbackend.hh:859
Definition: istl/ovlpistlsolverbackend.hh:323
Definition: solver.hh:42
void set_constrained_dofs(const CG &cg, typename XG::ElementType x, XG &xg)
construct constraints from given boundary condition function
Definition: constraints.hh:803
Dune::PDELab::Backend::Vector< GFS, typename P::domain_type::field_type > domain_type
The domain type of the preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:140
void apply(M &A, V &z, W &r, typename W::ElementType reduction)
solve the given linear system
Definition: istl/ovlpistlsolverbackend.hh:898
ISTLBackend_BCGS_AMG_SSOR(const GFS &gfs_, unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Constructor.
Definition: istl/ovlpistlsolverbackend.hh:1143
Definition: istl/ovlpistlsolverbackend.hh:375
The category the preconditioner is part of.
Definition: istl/ovlpistlsolverbackend.hh:147
double tsetup
The time needed for building the AMG hierarchy (coarsening).
Definition: istl/seqistlsolverbackend.hh:553
ISTLBackend_OVLP_SuperLU_Base(const GFS &gfs_, const C &c_, unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:759
Definition: istl/ovlpistlsolverbackend.hh:523
Dune::Amg::Parameters Parameters
Parameters object to customize matrix hierachy building.
Definition: istl/ovlpistlsolverbackend.hh:956
Definition: istl/ovlpistlsolverbackend.hh:134
void setParameters(const Parameters &params_)
set AMG parameters
Definition: istl/ovlpistlsolverbackend.hh:983
const Parameters & parameters() const
Get the parameters describing the behaviuour of AMG.
Definition: istl/ovlpistlsolverbackend.hh:1000
Overlapping parallel BiCGStab solver preconditioned with AMG smoothed by SSOR.
Definition: istl/ovlpistlsolverbackend.hh:1129
Definition: istl/ovlpistlsolverbackend.hh:52
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition: backend/interface.hh:112
Overlapping parallel BiCGStab solver with ILU0 preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:616
RFType reduction
Definition: solver.hh:35
Definition: parallelhelper.hh:45
double tprepare
The needed for computing the parallel information and for adapting the linear system.
Definition: istl/seqistlsolverbackend.hh:547
ISTLBackend_OVLP_BCGS_ILUn(const GFS &gfs, const CC &cc, int n=1, unsigned maxiter=5000, int verbose=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:649
Overlapping parallel CG solver with SuperLU preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:835
X domain_type
export types
Definition: istl/ovlpistlsolverbackend.hh:93
unsigned int iterations
Definition: solver.hh:33
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
ISTLBackend_OVLP_ILUn_Base(const GFS &gfs_, const C &c_, int n_=1, unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:535
virtual void post(domain_type &x)
Clean up.
Definition: istl/ovlpistlsolverbackend.hh:180
virtual double norm(const X &x)
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition...
Definition: istl/ovlpistlsolverbackend.hh:122
OVLPScalarProduct(const OVLPScalarProductImplementation< GFS > &implementation_)
Definition: istl/ovlpistlsolverbackend.hh:376
void apply(M &A, V &z, V &r, typename V::ElementType reduction)
solve the given linear system
Definition: istl/ovlpistlsolverbackend.hh:1023
Definition: istl/ovlpistlsolverbackend.hh:88
Y range_type
Definition: istl/ovlpistlsolverbackend.hh:48
Dune::PDELab::Backend::Vector< GFS, typename P::range_type::field_type > range_type
The range type of the preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:142
X::ElementType dot(const X &x, const X &y) const
Dot product of two vectors. It is assumed that the vectors are consistent on the interior+border part...
Definition: istl/ovlpistlsolverbackend.hh:335
Definition: istl/ovlpistlsolverbackend.hh:371
Definition: istl/ovlpistlsolverbackend.hh:97
virtual void apply(const domain_type &x, range_type &y) const
apply operator to x:
Definition: istl/ovlpistlsolverbackend.hh:59
bool directCoarseLevelSolver
True if a direct solver was used on the coarset level.
Definition: istl/seqistlsolverbackend.hh:557
ISTLBackend_OVLP_BCGS_ILU0(const GFS &gfs, const CC &cc, unsigned maxiter=5000, int verbose=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:627
std::enable_if< std::is_base_of< impl::WrapperBase, T >::value, Native< T > & >::type native(T &t)
Definition: backend/interface.hh:198
virtual void applyscaleadd(field_type alpha, const domain_type &x, range_type &y) const
apply operator to x, scale and add:
Definition: istl/ovlpistlsolverbackend.hh:67
bool converged
Definition: solver.hh:32
Definition: istl/ovlpistlsolverbackend.hh:461
virtual void pre(domain_type &x, range_type &b)
Prepare the preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:159
Overlapping parallel BiCGStab solver preconditioned with AMG smoothed by ILU0.
Definition: istl/ovlpistlsolverbackend.hh:1158
RFType conv_rate
Definition: solver.hh:36
double elapsed
Definition: solver.hh:34
V::ElementType norm(const V &v) const
compute global norm of a vector
Definition: istl/ovlpistlsolverbackend.hh:1009
Definition: istl/ovlpistlsolverbackend.hh:929
void apply(M &A, V &z, W &r, typename V::ElementType reduction)
solve the given linear system
Definition: istl/ovlpistlsolverbackend.hh:484
X::ElementType field_type
Definition: istl/ovlpistlsolverbackend.hh:94
virtual const M & getmat() const
get matrix via *
Definition: istl/ovlpistlsolverbackend.hh:75
Definition: genericdatahandle.hh:622
OverlappingScalarProduct(const GFS &gfs_, const istl::ParallelHelper< GFS > &helper_)
Constructor needs to know the grid function space.
Definition: istl/ovlpistlsolverbackend.hh:101
Definition: istl/ovlpistlsolverbackend.hh:397
virtual void apply(domain_type &v, const range_type &d)
Apply the preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:167
Definition: adaptivity.hh:27
V::ElementType norm(const V &v) const
compute global norm of a vector
Definition: istl/ovlpistlsolverbackend.hh:880
void apply(M &A, V &z, W &r, typename V::ElementType reduction)
solve the given linear system
Definition: istl/ovlpistlsolverbackend.hh:422
Dune::Amg::SequentialInformation type
Definition: parallelhelper.hh:421
Overlapping parallel CGS solver with SSOR preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:659
void setparams(Parameters params_)
Definition: istl/ovlpistlsolverbackend.hh:988
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:182
Overlapping parallel BiCGStab solver with SSOR preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:593
void createIndexSetAndProjectForAMG(MatrixType &m, Comm &c)
Makes the matrix consistent and creates the parallel information for AMG.
const istl::ParallelHelper< GFS > & parallelHelper() const
Definition: istl/ovlpistlsolverbackend.hh:353
void apply(M &A, V &z, W &r, typename V::ElementType reduction)
solve the given linear system
Definition: istl/ovlpistlsolverbackend.hh:707
void apply(M &A, V &z, W &r, typename V::ElementType reduction)
solve the given linear system
Definition: istl/ovlpistlsolverbackend.hh:547
virtual field_type dot(const X &x, const X &y)
Dot product of two vectors. It is assumed that the vectors are consistent on the interior+border part...
Definition: istl/ovlpistlsolverbackend.hh:110
Definition: genericdatahandle.hh:685
ISTLBackend_OVLP_CG_SSORk(const GFS &gfs, const CC &cc, unsigned maxiter=5000, int steps=5, int verbose=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:671
ISTLBackend_OVLP_Base(const GFS &gfs_, const C &c_, unsigned maxiter_=5000, int steps_=5, int verbose_=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:409
ISTLBackend_OVLP_CG_SuperLU(const GFS &gfs_, const CC &cc_, unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:847
Overlapping parallel restarted GMRes solver with ILU0 preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:683
OVLPScalarProductImplementation(const GFS &gfs_)
Definition: istl/ovlpistlsolverbackend.hh:326
Definition: istl/ovlpistlsolverbackend.hh:41
OverlappingOperator(const CC &cc_, const M &A)
Definition: istl/ovlpistlsolverbackend.hh:54
int levels
the number of levels in the AMG hierarchy.
Definition: istl/seqistlsolverbackend.hh:549
const std::string s
Definition: function.hh:1102
virtual X::BaseT::field_type norm(const X &x)
Definition: istl/ovlpistlsolverbackend.hh:385
Definition: istl/ovlpistlsolverbackend.hh:748
X::ElementType field_type
Definition: istl/ovlpistlsolverbackend.hh:49
Class providing some statistics of the AMG solver.
Definition: istl/seqistlsolverbackend.hh:541
Dune::PDELab::LinearSolverResult< double > res
Definition: solver.hh:52
const ISTLAMGStatistics & statistics() const
Get statistics of the AMG solver (no of levels, timings).
Definition: istl/ovlpistlsolverbackend.hh:1072
ISTLBackend_OVLP_BCGS_SuperLU(const GFS &gfs_, const CC &cc_, unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:823
ISTLBackend_OVLP_ExplicitDiagonal(const ISTLBackend_OVLP_ExplicitDiagonal &other_)
Definition: istl/ovlpistlsolverbackend.hh:871
ISTLBackend_OVLP_ILU0_Base(const GFS &gfs_, const C &c_, unsigned maxiter_=5000, int verbose_=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:472
Overlapping parallel BiCGStab solver with SuperLU preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:811
Overlapping parallel BiCGStab solver with ILU0 preconditioner.
Definition: istl/ovlpistlsolverbackend.hh:637
istl::ParallelHelper< GFS > & parallelHelper()
Definition: istl/ovlpistlsolverbackend.hh:359
double tsolve
The time spent in solving the system (without building the hierarchy.
Definition: istl/seqistlsolverbackend.hh:551
ISTLBackend_OVLP_BCGS_SSORk(const GFS &gfs, const CC &cc, unsigned maxiter=5000, int steps=5, int verbose=1)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:605
ISTLBackend_BCGS_AMG_ILU0(const GFS &gfs_, unsigned maxiter_=5000, int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
Constructor.
Definition: istl/ovlpistlsolverbackend.hh:1172
OverlappingWrappedPreconditioner(const GFS &gfs_, P &prec_, const CC &cc_, const istl::ParallelHelper< GFS > &helper_)
Constructor.
Definition: istl/ovlpistlsolverbackend.hh:151
X domain_type
Definition: istl/ovlpistlsolverbackend.hh:47
Overlapping parallel conjugate gradient solver preconditioned with AMG smoothed by SSOR...
Definition: istl/ovlpistlsolverbackend.hh:1100
ISTLBackend_OVLP_ExplicitDiagonal(const GFS &gfs_)
make a linear solver object
Definition: istl/ovlpistlsolverbackend.hh:867