dune-pdelab 2.7-git
Loading...
Searching...
No Matches
two_level_schwarz.hh
Go to the documentation of this file.
1#ifndef TWO_LEVEL_SCHWARZ_HH
2#define TWO_LEVEL_SCHWARZ_HH
3
4#if HAVE_SUITESPARSE_UMFPACK
5
6#include <dune/common/timer.hh>
7
8#include "coarsespace.hh"
9
10namespace Dune {
11 namespace PDELab {
12 namespace ISTL {
13
17 template<class GFS, class M, class X, class Y>
18 class TwoLevelOverlappingAdditiveSchwarz
19 : public Dune::Preconditioner<X,Y>
20 {
21 public:
23
24 typedef Dune::BlockVector<Dune::FieldVector<double,1> > COARSE_V;
25 typedef Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1> > COARSE_M;
26
27 // define the category
28 virtual Dune::SolverCategory::Category category() const
29 {
30 return Dune::SolverCategory::overlapping;
31 }
32
40 TwoLevelOverlappingAdditiveSchwarz (const GFS& gfs, const M& AF, std::shared_ptr<CoarseSpace<X> > coarse_space, bool coarse_space_active = true, int verbosity = 0)
41 : verbosity_(verbosity),
42 coarse_space_active_(coarse_space_active),
43 gfs_(gfs),
44 solverf_(Dune::PDELab::Backend::native(AF),false),
45 coarse_space_(coarse_space),
46 coarse_solver_ (*coarse_space_->get_coarse_system()),
47 coarse_defect_(coarse_space_->basis_size(), coarse_space_->basis_size()),
48 prolongated_(gfs_, 0.0)
49 { }
50
56 virtual void pre (X& x, Y& b)
57 { }
58
64 virtual void apply (X& v, const Y& d)
65 {
66 // first the subdomain solves
67 Y b(d); // need copy, since solver overwrites right hand side
68 Dune::InverseOperatorResult result;
69 solverf_.apply(v,b,result);
70
71 if (!coarse_space_active_) {
72
74 // Just add local results and return in 1-level Schwarz case
75 gfs_.gridView().communicate(adddh,Dune::All_All_Interface,Dune::ForwardCommunication);
76
77 } else {
78
79 gfs_.gridView().comm().barrier();
80 Dune::Timer timer_coarse_solve;
81
82 coarse_space_->restrict (d, coarse_defect_);
83
84 // Solve coarse system
85 Dune::InverseOperatorResult result;
86 COARSE_V v0(coarse_space_->basis_size(),coarse_space_->basis_size());
87 coarse_solver_.apply(v0, coarse_defect_, result);
88
89 // Prolongate coarse solution on local domain
90 coarse_space_->prolongate(v0, prolongated_);
91 v += prolongated_;
92
93 coarse_time_ += timer_coarse_solve.elapsed();
94 apply_calls_++;
95
96 Dune::PDELab::AddDataHandle<GFS,X> result_addh(gfs_,v);
97 gfs_.gridView().communicate(result_addh,Dune::All_All_Interface,Dune::ForwardCommunication);
98 }
99 }
100
106 virtual void post (X& x) {
107 if (verbosity_ > 0) std::cout << "Coarse time CT=" << coarse_time_ << std::endl;
108 if (verbosity_ > 0) std::cout << "Coarse time per apply CTA=" << coarse_time_ / apply_calls_ << std::endl;
109 }
110
111 private:
112 int verbosity_;
113 bool coarse_space_active_;
114
115 double coarse_time_ = 0.0;
116 int apply_calls_ = 0;
117
118 const GFS& gfs_;
119 Dune::UMFPack<ISTLM> solverf_;
120 std::shared_ptr<CoarseSpace<X> > coarse_space_;
121 Dune::UMFPack<COARSE_M> coarse_solver_;
122
123 typename CoarseSpace<X>::COARSE_V coarse_defect_;
124 X prolongated_;
125 };
126 }
127 }
128}
129#endif
130
131#endif
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
std::enable_if< std::is_base_of< impl::WrapperBase, T >::value, Native< T > & >::type native(T &t)
Definition: backend/interface.hh:192
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
Representation of a coarse space intended for two-level Schwarz preconditioners.
Definition: coarsespace.hh:8
Dune::BlockVector< Dune::FieldVector< double, 1 > > COARSE_V
Definition: coarsespace.hh:11
Definition: genericdatahandle.hh:667