DUNE PDELab (git)

two_level_schwarz.hh
1#ifndef TWO_LEVEL_SCHWARZ_HH
2#define TWO_LEVEL_SCHWARZ_HH
3
4#if HAVE_SUITESPARSE_UMFPACK
5
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:
22 typedef Dune::PDELab::Backend::Native<M> ISTLM;
23
26
27 // define the category
28 virtual Dune::SolverCategory::Category category() const
29 {
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
69 solverf_.apply(v,b,result);
70
71 if (!coarse_space_active_) {
72
73 Dune::PDELab::AddDataHandle<GFS,X> adddh(gfs_,v);
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
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
Representation of a coarse space intended for two-level Schwarz preconditioners.
Definition: coarsespace.hh:8
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:466
A vector of blocks with memory management.
Definition: bvector.hh:392
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:33
A simple stop watch.
Definition: timer.hh:43
double elapsed() const noexcept
Get elapsed user-time from last reset until now/last stop in seconds.
Definition: timer.hh:77
@ ForwardCommunication
communicate as given in InterfaceType
Definition: gridenums.hh:171
@ All_All_Interface
send all and receive all entities
Definition: gridenums.hh:91
Dune namespace.
Definition: alignedallocator.hh:13
Statistics about the application of an inverse operator.
Definition: solver.hh:50
Category
Definition: solvercategory.hh:23
@ overlapping
Category for overlapping solvers.
Definition: solvercategory.hh:29
A simple timing class.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)