dune-istl  2.2.1
schwarz.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_SCHWARZ_HH
4 #define DUNE_SCHWARZ_HH
5 
6 #include <iostream> // for input/output to shell
7 #include <fstream> // for input/output to files
8 #include <vector> // STL vector class
9 #include <sstream>
10 
11 #include <cmath> // Yes, we do some math here
12 
13 #include <dune/common/timer.hh>
14 
15 #include"io.hh"
16 #include"bvector.hh"
17 #include"vbvector.hh"
18 #include"bcrsmatrix.hh"
19 #include"io.hh"
20 #include"gsetc.hh"
21 #include"ilu.hh"
22 #include"operators.hh"
23 #include"solvers.hh"
24 #include"preconditioners.hh"
25 #include"scalarproducts.hh"
26 #include"owneroverlapcopy.hh"
27 
28 namespace Dune {
29 
58  template<class M, class X, class Y, class C>
60  {
61  public:
63  typedef M matrix_type;
65  typedef X domain_type;
67  typedef Y range_type;
69  typedef typename X::field_type field_type;
71  typedef C communication_type;
72 
73  enum {
76  };
77 
86  : _A_(A), communication(com)
87  {}
88 
90  virtual void apply (const X& x, Y& y) const
91  {
92  y = 0;
93  _A_.umv(x,y); // result is consistent on interior+border
94  communication.project(y); // we want this here to avoid it before the preconditioner
95  // since there d is const!
96  }
97 
99  virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const
100  {
101  _A_.usmv(alpha,x,y); // result is consistent on interior+border
102  communication.project(y); // we want this here to avoid it before the preconditioner
103  // since there d is const!
104  }
105 
107  virtual const matrix_type& getmat () const
108  {
109  return _A_;
110  }
111 
112  private:
113  const matrix_type& _A_;
114  const communication_type& communication;
115  };
116 
128  template<class X, class C>
130  {
131  public:
133  typedef X domain_type;
135  typedef typename X::field_type field_type;
138 
141 
147  : communication(com)
148  {}
149 
154  virtual field_type dot (const X& x, const X& y)
155  {
156  field_type result;
157  communication.dot(x,y,result);
158  return result;
159  }
160 
164  virtual double norm (const X& x)
165  {
166  return communication.norm(x);
167  }
168 
169  private:
170  const communication_type& communication;
171  };
172 
173  template<class X, class C>
174  struct ScalarProductChooser<X,C,SolverCategory::overlapping>
175  {
180 
181  enum{
184  };
185 
186  static ScalarProduct* construct(const communication_type& comm)
187  {
188  return new ScalarProduct(comm);
189  }
190  };
191 
198 
199  template<class M, class X, class Y, class C>
200  class ParSSOR : public Preconditioner<X,Y> {
201  public:
203  typedef M matrix_type;
205  typedef X domain_type;
207  typedef Y range_type;
209  typedef typename X::field_type field_type;
212 
213  // define the category
214  enum {
217 
227  ParSSOR (const matrix_type& A, int n, field_type w, const communication_type& c)
228  : _A_(A), _n(n), _w(w), communication(c)
229  { }
230 
236  virtual void pre (X& x, Y& b)
237  {
238  communication.copyOwnerToAll(x,x); // make dirichlet values consistent
239  }
240 
246  virtual void apply (X& v, const Y& d)
247  {
248  for (int i=0; i<_n; i++){
249  bsorf(_A_,v,d,_w);
250  bsorb(_A_,v,d,_w);
251  }
252  communication.copyOwnerToAll(v,v);
253  }
254 
260  virtual void post (X& x) {}
261 
262  private:
264  const matrix_type& _A_;
266  int _n;
268  field_type _w;
270  const communication_type& communication;
271  };
272 
273  namespace Amg
274  {
275  template<class T> class ConstructionTraits;
276  }
277 
286  template<class X, class Y, class C, class T=Preconditioner<X,Y> >
287  class BlockPreconditioner : public Preconditioner<X,Y> {
289  public:
291  typedef X domain_type;
293  typedef Y range_type;
295  typedef typename X::field_type field_type;
298 
299  // define the category
300  enum {
303 
312  : preconditioner(p), communication(c)
313  { }
314 
320  virtual void pre (X& x, Y& b)
321  {
322  communication.copyOwnerToAll(x,x); // make dirichlet values consistent
323  preconditioner.pre(x,b);
324  }
325 
331  virtual void apply (X& v, const Y& d)
332  {
333  preconditioner.apply(v,d);
334  communication.copyOwnerToAll(v,v);
335  }
336 
337  template<bool forward>
338  void apply (X& v, const Y& d)
339  {
340  preconditioner.template apply<forward>(v,d);
341  communication.copyOwnerToAll(v,v);
342  }
343 
349  virtual void post (X& x)
350  {
351  preconditioner.post(x);
352  }
353 
354  private:
356  T& preconditioner;
357 
359  const communication_type& communication;
360  };
361 
364 } // end namespace
365 
366 #endif