Dune Core Modules (2.5.2)

schwarz.hh
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_ISTL_SCHWARZ_HH
4 #define DUNE_ISTL_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 
74  template<class M, class X, class Y, class C>
76  {
77  public:
82  typedef M matrix_type;
87  typedef X domain_type;
92  typedef Y range_type;
94  typedef typename X::field_type field_type;
99  typedef C communication_type;
100 
101  enum {
104  };
105 
114  : _A_(A), communication(com)
115  {}
116 
118  virtual void apply (const X& x, Y& y) const
119  {
120  y = 0;
121  _A_.umv(x,y); // result is consistent on interior+border
122  communication.project(y); // we want this here to avoid it before the preconditioner
123  // since there d is const!
124  }
125 
127  virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const
128  {
129  _A_.usmv(alpha,x,y); // result is consistent on interior+border
130  communication.project(y); // we want this here to avoid it before the preconditioner
131  // since there d is const!
132  }
133 
135  virtual const matrix_type& getmat () const
136  {
137  return _A_;
138  }
139 
140  private:
141  const matrix_type& _A_;
142  const communication_type& communication;
143  };
144 
162  template<class X, class C>
164  {
165  public:
170  typedef X domain_type;
172  typedef typename X::field_type field_type;
173  typedef typename FieldTraits<field_type>::real_type real_type;
179 
181  enum {category=SolverCategory::overlapping};
182 
188  : communication(com)
189  {}
190 
195  virtual field_type dot (const X& x, const X& y)
196  {
197  field_type result;
198  communication.dot(x,y,result);
199  return result;
200  }
201 
205  virtual real_type norm (const X& x)
206  {
207  return communication.norm(x);
208  }
209 
210  private:
211  const communication_type& communication;
212  };
213 
214  template<class X, class C>
215  struct ScalarProductChooser<X,C,SolverCategory::overlapping>
216  {
218  typedef OverlappingSchwarzScalarProduct<X,C> ScalarProduct;
220  typedef C communication_type;
221 
222  enum {
225  };
226 
227  static ScalarProduct* construct(const communication_type& comm)
228  {
229  return new ScalarProduct(comm);
230  }
231  };
232 
252  template<class M, class X, class Y, class C>
253  class ParSSOR : public Preconditioner<X,Y> {
254  public:
256  typedef M matrix_type;
258  typedef X domain_type;
260  typedef Y range_type;
262  typedef typename X::field_type field_type;
265 
266  // define the category
267  enum {
270  };
271 
281  ParSSOR (const matrix_type& A, int n, field_type w, const communication_type& c)
282  : _A_(A), _n(n), _w(w), communication(c)
283  { }
284 
290  virtual void pre (X& x, Y& b)
291  {
292  communication.copyOwnerToAll(x,x); // make dirichlet values consistent
293  }
294 
300  virtual void apply (X& v, const Y& d)
301  {
302  for (int i=0; i<_n; i++) {
303  bsorf(_A_,v,d,_w);
304  bsorb(_A_,v,d,_w);
305  }
306  communication.copyOwnerToAll(v,v);
307  }
308 
314  virtual void post (X& x) {}
315 
316  private:
318  const matrix_type& _A_;
320  int _n;
322  field_type _w;
324  const communication_type& communication;
325  };
326 
327  namespace Amg
328  {
329  template<class T> class ConstructionTraits;
330  }
331 
355  template<class X, class Y, class C, class T=Preconditioner<X,Y> >
356  class BlockPreconditioner : public Preconditioner<X,Y> {
357  friend class Amg::ConstructionTraits<BlockPreconditioner<X,Y,C,T> >;
358  public:
363  typedef X domain_type;
368  typedef Y range_type;
370  typedef typename X::field_type field_type;
376 
377  // define the category
378  enum {
381  };
382 
391  : preconditioner(p), communication(c)
392  { }
393 
399  virtual void pre (X& x, Y& b)
400  {
401  communication.copyOwnerToAll(x,x); // make dirichlet values consistent
402  preconditioner.pre(x,b);
403  }
404 
410  virtual void apply (X& v, const Y& d)
411  {
412  preconditioner.apply(v,d);
413  communication.copyOwnerToAll(v,v);
414  }
415 
416  template<bool forward>
417  void apply (X& v, const Y& d)
418  {
419  preconditioner.template apply<forward>(v,d);
420  communication.copyOwnerToAll(v,v);
421  }
422 
428  virtual void post (X& x)
429  {
430  preconditioner.post(x);
431  }
432 
433  private:
435  T& preconditioner;
436 
438  const communication_type& communication;
439  };
440 
443 } // end namespace
444 
445 #endif
Implementation of the BCRSMatrix class.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Traits class for generically constructing non default constructable types.
Definition: construction.hh:38
A linear operator exporting itself in matrix form.
Definition: operators.hh:94
Block parallel preconditioner.
Definition: schwarz.hh:356
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:363
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:368
@ category
The category the precondtioner is part of.
Definition: schwarz.hh:380
BlockPreconditioner(T &p, const communication_type &c)
Constructor.
Definition: schwarz.hh:390
C communication_type
The type of the communication object..
Definition: schwarz.hh:375
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:428
void apply(X &v, const Y &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: schwarz.hh:417
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:399
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:370
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: schwarz.hh:410
X::field_type field_type
The field type of the operator.
Definition: operators.hh:69
An overlapping schwarz operator.
Definition: schwarz.hh:76
virtual const matrix_type & getmat() const
get the sequential assembled linear operator.
Definition: schwarz.hh:135
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const
apply operator to x, scale and add:
Definition: schwarz.hh:127
virtual void apply(const X &x, Y &y) const
apply operator to x:
Definition: schwarz.hh:118
C communication_type
The type of the communication object.
Definition: schwarz.hh:99
X domain_type
The type of the domain.
Definition: schwarz.hh:87
M matrix_type
The type of the matrix we operate on.
Definition: schwarz.hh:82
@ category
The solver category.
Definition: schwarz.hh:103
Y range_type
The type of the range.
Definition: schwarz.hh:92
X::field_type field_type
The field type of the range.
Definition: schwarz.hh:94
OverlappingSchwarzOperator(const matrix_type &A, const communication_type &com)
constructor: just store a reference to a matrix.
Definition: schwarz.hh:113
Scalar product for overlapping schwarz methods.
Definition: schwarz.hh:164
C communication_type
The type of the communication object.
Definition: schwarz.hh:178
virtual real_type norm(const X &x)
Norm of a right-hand side vector. The vector must be consistent on the interior+border partition.
Definition: schwarz.hh:205
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:195
X domain_type
The type of the vector to compute the scalar product on.
Definition: schwarz.hh:170
X::field_type field_type
The field type used by the vector type domain_type.
Definition: schwarz.hh:172
OverlappingSchwarzScalarProduct(const communication_type &com)
Constructor needs to know the grid.
Definition: schwarz.hh:187
A parallel SSOR preconditioner.
Definition: schwarz.hh:253
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:262
C communication_type
The type of the communication object.
Definition: schwarz.hh:264
@ category
The category the precondtioner is part of.
Definition: schwarz.hh:269
ParSSOR(const matrix_type &A, int n, field_type w, const communication_type &c)
Constructor.
Definition: schwarz.hh:281
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:314
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:258
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:260
M matrix_type
The matrix type the preconditioner is for.
Definition: schwarz.hh:256
virtual void apply(X &v, const Y &d)
Apply the precondtioner.
Definition: schwarz.hh:300
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:290
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:26
X::field_type field_type
The field type of the preconditioner.
Definition: preconditioner.hh:33
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:44
void bsorb(const M &A, X &x, const Y &b, const K &w)
SSOR step.
Definition: gsetc.hh:591
void bsorf(const M &A, X &x, const Y &b, const K &w)
SOR step.
Definition: gsetc.hh:579
Simple iterative methods like Jacobi, Gauss-Seidel, SOR, SSOR, etc. in a generic way.
Some generic functions for pretty printing vectors and matrices.
Dune namespace.
Definition: alignment.hh:11
Define general, extensible interface for operators. The available implementation wraps a matrix.
Classes providing communication interfaces for overlapping Schwarz methods.
Define general preconditioner interface.
Define base class for scalar product and norm.
Implementations of the inverse operator interface.
C communication_type
The type of the communication object.
Definition: scalarproducts.hh:79
@ solverCategory
The solver category.
Definition: scalarproducts.hh:83
@ overlapping
Category for overlapping solvers.
Definition: solvercategory.hh:25
A simple timing class.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 10, 22:30, 2024)