dune-istl  2.8.0
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_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 
109  : _A_(stackobject_to_shared_ptr(A)), communication(com)
110  {}
111 
112  OverlappingSchwarzOperator (const std::shared_ptr<matrix_type> A, const communication_type& com)
113  : _A_(A), communication(com)
114  {}
115 
117  virtual void apply (const X& x, Y& y) const
118  {
119  y = 0;
120  _A_->umv(x,y); // result is consistent on interior+border
121  communication.project(y); // we want this here to avoid it before the preconditioner
122  // since there d is const!
123  }
124 
126  virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const
127  {
128  _A_->usmv(alpha,x,y); // result is consistent on interior+border
129  communication.project(y); // we want this here to avoid it before the preconditioner
130  // since there d is const!
131  }
132 
134  virtual const matrix_type& getmat () const
135  {
136  return *_A_;
137  }
138 
141  {
143  }
144 
145 
148  {
149  return communication;
150  }
151  private:
152  const std::shared_ptr<const matrix_type>_A_;
153  const communication_type& communication;
154  };
155 
158  /*
159  * @addtogroup ISTL_Prec
160  * @{
161  */
175  template<class M, class X, class Y, class C>
176  class ParSSOR : public Preconditioner<X,Y> {
177  public:
179  typedef M matrix_type;
181  typedef X domain_type;
183  typedef Y range_type;
185  typedef typename X::field_type field_type;
188 
198  ParSSOR (const matrix_type& A, int n, field_type w, const communication_type& c)
199  : _A_(A), _n(n), _w(w), communication(c)
200  { }
201 
207  virtual void pre (X& x, Y& b)
208  {
209  communication.copyOwnerToAll(x,x); // make dirichlet values consistent
210  }
211 
217  virtual void apply (X& v, const Y& d)
218  {
219  for (int i=0; i<_n; i++) {
220  bsorf(_A_,v,d,_w);
221  bsorb(_A_,v,d,_w);
222  }
223  communication.copyOwnerToAll(v,v);
224  }
225 
231  virtual void post (X& x) {}
232 
235  {
237  }
238 
239  private:
241  const matrix_type& _A_;
243  int _n;
245  field_type _w;
247  const communication_type& communication;
248  };
249 
250  namespace Amg
251  {
252  template<class T> struct ConstructionTraits;
253  }
254 
278  template<class X, class Y, class C, class P=Preconditioner<X,Y> >
279  class BlockPreconditioner : public Preconditioner<X,Y> {
280  friend struct Amg::ConstructionTraits<BlockPreconditioner<X,Y,C,P> >;
281  public:
286  typedef X domain_type;
291  typedef Y range_type;
293  typedef typename X::field_type field_type;
299 
308  : _preconditioner(stackobject_to_shared_ptr(p)), _communication(c)
309  { }
310 
318  BlockPreconditioner (const std::shared_ptr<P>& p, const communication_type& c)
319  : _preconditioner(p), _communication(c)
320  { }
321 
327  virtual void pre (X& x, Y& b)
328  {
329  _communication.copyOwnerToAll(x,x); // make dirichlet values consistent
330  _preconditioner->pre(x,b);
331  }
332 
338  virtual void apply (X& v, const Y& d)
339  {
340  _preconditioner->apply(v,d);
341  _communication.copyOwnerToAll(v,v);
342  }
343 
344  template<bool forward>
345  void apply (X& v, const Y& d)
346  {
347  _preconditioner->template apply<forward>(v,d);
348  _communication.copyOwnerToAll(v,v);
349  }
350 
356  virtual void post (X& x)
357  {
358  _preconditioner->post(x);
359  }
360 
363  {
365  }
366 
367  private:
369  std::shared_ptr<P> _preconditioner;
370 
372  const communication_type& _communication;
373  };
374 
377 } // end namespace
378 
379 #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...
Simple iterative methods like Jacobi, Gauss-Seidel, SOR, SSOR, etc. in a generic way.
The incomplete LU factorization kernels.
Some generic functions for pretty printing vectors and matrices.
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.
void bsorb(const M &A, X &x, const Y &b, const K &w)
SSOR step.
Definition: gsetc.hh:644
void bsorf(const M &A, X &x, const Y &b, const K &w)
SOR step.
Definition: gsetc.hh:632
Definition: allocator.hh:9
Traits class for generically constructing non default constructable types.
Definition: construction.hh:37
X::field_type field_type
The field type of the operator.
Definition: operators.hh:72
A linear operator exporting itself in matrix form.
Definition: operators.hh:107
An overlapping Schwarz operator.
Definition: schwarz.hh:76
const communication_type & getCommunication() const
Get the object responsible for communication.
Definition: schwarz.hh:147
virtual const matrix_type & getmat() const
get the sequential assembled linear operator.
Definition: schwarz.hh:134
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const
apply operator to x, scale and add:
Definition: schwarz.hh:126
virtual void apply(const X &x, Y &y) const
apply operator to x:
Definition: schwarz.hh:117
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
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:108
OverlappingSchwarzOperator(const std::shared_ptr< matrix_type > A, const communication_type &com)
Definition: schwarz.hh:112
virtual SolverCategory::Category category() const
Category of the linear operator (see SolverCategory::Category)
Definition: schwarz.hh:140
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:30
X::field_type field_type
The field type of the preconditioner.
Definition: preconditioner.hh:37
A parallel SSOR preconditioner.
Definition: schwarz.hh:176
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:185
C communication_type
The type of the communication object.
Definition: schwarz.hh:187
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: schwarz.hh:234
ParSSOR(const matrix_type &A, int n, field_type w, const communication_type &c)
Constructor.
Definition: schwarz.hh:198
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:231
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:181
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:183
M matrix_type
The matrix type the preconditioner is for.
Definition: schwarz.hh:179
virtual void apply(X &v, const Y &d)
Apply the precondtioner.
Definition: schwarz.hh:217
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:207
Block parallel preconditioner.
Definition: schwarz.hh:279
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:327
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:286
BlockPreconditioner(const std::shared_ptr< P > &p, const communication_type &c)
Constructor.
Definition: schwarz.hh:318
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: schwarz.hh:338
BlockPreconditioner(P &p, const communication_type &c)
Constructor.
Definition: schwarz.hh:307
void apply(X &v, const Y &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: schwarz.hh:345
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:293
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:356
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:291
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: schwarz.hh:362
Category
Definition: solvercategory.hh:21
@ overlapping
Category for overlapping solvers.
Definition: solvercategory.hh:27