dune-istl  2.3.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>
59  class OverlappingSchwarzOperator : public AssembledLinearOperator<M,X,Y>
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 
187  {
188  return new ScalarProduct(comm);
189  }
190  };
191 
198  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
X::field_type field_type
Definition: scalarproducts.hh:47
void bsorf(const M &A, X &x, const Y &b, const K &w)
SOR step.
Definition: gsetc.hh:612
void apply(X &v, const Y &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: schwarz.hh:340
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:26
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:351
ParSSOR(const matrix_type &A, int n, field_type w, const communication_type &c)
Constructor.
Definition: schwarz.hh:228
virtual void apply(const X &x, Y &y) const
apply operator to x:
Definition: schwarz.hh:90
Category for ovelapping solvers.
Definition: solvercategory.hh:26
Classes providing communication interfaces for overlapping Schwarz methods.
void bsorb(const M &A, X &x, const Y &b, const K &w)
SSOR step.
Definition: gsetc.hh:624
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:43
The category the precondtioner is part of.
Definition: schwarz.hh:303
This file implements a vector space as a tensor product of a given vector space. The number of compon...
???
C communication_type
The type of the communication object to use.
Definition: schwarz.hh:179
OverlappingSchwarzScalarProduct(const communication_type &com)
Constructor needs to know the grid.
Definition: schwarz.hh:146
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: schwarz.hh:154
static ScalarProduct * construct(const communication_type &comm)
Definition: schwarz.hh:186
virtual const matrix_type & getmat() const
get matrix via *
Definition: schwarz.hh:107
Y range_type
The type of the range.
Definition: schwarz.hh:67
Categories for the solvers.
Definition: solvercategory.hh:18
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:294
BlockPreconditioner(T &p, const communication_type &c)
Constructor.
Definition: schwarz.hh:313
The solver category.
Definition: schwarz.hh:75
X::field_type field_type
The field type of the range.
Definition: schwarz.hh:69
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:261
OverlappingSchwarzScalarProduct< X, C > ScalarProduct
The type of the scalar product for the overlapping case.
Definition: schwarz.hh:177
virtual double norm(const X &x)
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition...
Definition: schwarz.hh:164
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:237
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const
apply operator to x, scale and add:
Definition: schwarz.hh:99
M matrix_type
The type of the matrix we operate on.
Definition: schwarz.hh:63
Traits class for generically constructing non default constructable types.
Definition: novlpschwarz.hh:326
Implementations of the inverse operator interface.
C communication_type
The type of the communication object.
Definition: schwarz.hh:71
X::field_type field_type
The type of the range.
Definition: schwarz.hh:135
X::field_type field_type
The field type of the operator.
Definition: operators.hh:69
Matrix & A
Definition: matrixmatrix.hh:216
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:292
Implementation of the BCRSMatrix class.
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:209
A parallel SSOR preconditioner.
Definition: schwarz.hh:200
Block parallel preconditioner.
Definition: schwarz.hh:288
Define general, extensible interface for operators. The available implementation wraps a matrix...
X::field_type field_type
The field type of the preconditioner.
Definition: preconditioner.hh:33
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:205
Scalar product for overlapping schwarz methods.
Definition: schwarz.hh:129
OverlappingSchwarzOperator(const matrix_type &A, const communication_type &com)
constructor: just store a reference to a matrix.
Definition: schwarz.hh:85
X domain_type
The type of the domain.
Definition: schwarz.hh:133
C communication_type
The type of the communication object.
Definition: schwarz.hh:211
Choose the approriate scalar product for a solver category.
Definition: scalarproducts.hh:75
virtual void apply(X &v, const Y &d)
Apply the precondtioner.
Definition: schwarz.hh:247
C communication_type
The type of the communication object.
Definition: schwarz.hh:298
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:296
Define base class for scalar product and norm.
Some generic functions for pretty printing vectors and matrices.
The solver category.
Definition: scalarproducts.hh:82
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:207
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:322
The category the precondtioner is part of.
Definition: schwarz.hh:216
X domain_type
The type of the domain.
Definition: schwarz.hh:65
Define general preconditioner interface.
Simple iterative methods like Jacobi, Gauss-Seidel, SOR, SSOR, etc. in a generic way.
M matrix_type
The matrix type the preconditioner is for.
Definition: schwarz.hh:203
C communication_type
The type of the communication object.
Definition: schwarz.hh:137
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: schwarz.hh:333