dune-istl  2.3beta2
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  };
218 
228  ParSSOR (const matrix_type& A, int n, field_type w, const communication_type& c)
229  : _A_(A), _n(n), _w(w), communication(c)
230  { }
231 
237  virtual void pre (X& x, Y& b)
238  {
239  communication.copyOwnerToAll(x,x); // make dirichlet values consistent
240  }
241 
247  virtual void apply (X& v, const Y& d)
248  {
249  for (int i=0; i<_n; i++) {
250  bsorf(_A_,v,d,_w);
251  bsorb(_A_,v,d,_w);
252  }
253  communication.copyOwnerToAll(v,v);
254  }
255 
261  virtual void post (X& x) {}
262 
263  private:
265  const matrix_type& _A_;
267  int _n;
269  field_type _w;
271  const communication_type& communication;
272  };
273 
274  namespace Amg
275  {
276  template<class T> class ConstructionTraits;
277  }
278 
287  template<class X, class Y, class C, class T=Preconditioner<X,Y> >
288  class BlockPreconditioner : public Preconditioner<X,Y> {
290  public:
292  typedef X domain_type;
294  typedef Y range_type;
296  typedef typename X::field_type field_type;
299 
300  // define the category
301  enum {
304  };
305 
314  : preconditioner(p), communication(c)
315  { }
316 
322  virtual void pre (X& x, Y& b)
323  {
324  communication.copyOwnerToAll(x,x); // make dirichlet values consistent
325  preconditioner.pre(x,b);
326  }
327 
333  virtual void apply (X& v, const Y& d)
334  {
335  preconditioner.apply(v,d);
336  communication.copyOwnerToAll(v,v);
337  }
338 
339  template<bool forward>
340  void apply (X& v, const Y& d)
341  {
342  preconditioner.template apply<forward>(v,d);
343  communication.copyOwnerToAll(v,v);
344  }
345 
351  virtual void post (X& x)
352  {
353  preconditioner.post(x);
354  }
355 
356  private:
358  T& preconditioner;
359 
361  const communication_type& communication;
362  };
363 
366 } // end namespace
367 
368 #endif