Dune Core Modules (2.3.1)

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_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
28namespace 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;
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
140 enum {category=SolverCategory::overlapping};
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 {
177 typedef OverlappingSchwarzScalarProduct<X,C> ScalarProduct;
179 typedef C communication_type;
180
181 enum {
184 };
185
186 static ScalarProduct* construct(const communication_type& comm)
187 {
188 return new ScalarProduct(comm);
189 }
190 };
191
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> >
289 friend class Amg::ConstructionTraits<BlockPreconditioner<X,Y,C,T> >;
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
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:39
A linear operator exporting itself in matrix form.
Definition: operators.hh:94
Block parallel preconditioner.
Definition: schwarz.hh:288
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:292
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
C communication_type
The type of the communication object.
Definition: schwarz.hh:298
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:351
void apply(X &v, const Y &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: schwarz.hh:340
@ category
The category the precondtioner is part of.
Definition: schwarz.hh:303
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:322
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:296
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: schwarz.hh:333
X::field_type field_type
The field type of the operator.
Definition: operators.hh:69
An overlapping schwarz operator.
Definition: schwarz.hh:60
virtual const matrix_type & getmat() const
get matrix via *
Definition: schwarz.hh:107
@ category
The solver category.
Definition: schwarz.hh:75
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const
apply operator to x, scale and add:
Definition: schwarz.hh:99
virtual void apply(const X &x, Y &y) const
apply operator to x:
Definition: schwarz.hh:90
C communication_type
The type of the communication object.
Definition: schwarz.hh:71
X domain_type
The type of the domain.
Definition: schwarz.hh:65
M matrix_type
The type of the matrix we operate on.
Definition: schwarz.hh:63
Y range_type
The type of the range.
Definition: schwarz.hh:67
X::field_type field_type
The field type of the range.
Definition: schwarz.hh:69
OverlappingSchwarzOperator(const matrix_type &A, const communication_type &com)
constructor: just store a reference to a matrix.
Definition: schwarz.hh:85
Scalar product for overlapping schwarz methods.
Definition: schwarz.hh:130
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
C communication_type
The type of the communication object.
Definition: schwarz.hh:137
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
X domain_type
The type of the domain.
Definition: schwarz.hh:133
X::field_type field_type
The type of the range.
Definition: schwarz.hh:135
OverlappingSchwarzScalarProduct(const communication_type &com)
Constructor needs to know the grid.
Definition: schwarz.hh:146
A parallel SSOR preconditioner.
Definition: schwarz.hh:200
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:209
@ category
The category the precondtioner is part of.
Definition: schwarz.hh:216
C communication_type
The type of the communication object.
Definition: schwarz.hh:211
ParSSOR(const matrix_type &A, int n, field_type w, const communication_type &c)
Constructor.
Definition: schwarz.hh:228
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:261
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:205
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:207
M matrix_type
The matrix type the preconditioner is for.
Definition: schwarz.hh:203
virtual void apply(X &v, const Y &d)
Apply the precondtioner.
Definition: schwarz.hh:247
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:237
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:43
void bsorb(const M &A, X &x, const Y &b, const K &w)
SSOR step.
Definition: gsetc.hh:624
void bsorf(const M &A, X &x, const Y &b, const K &w)
SOR step.
Definition: gsetc.hh:612
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:14
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:78
@ solverCategory
The solver category.
Definition: scalarproducts.hh:82
@ overlapping
Category for ovelapping solvers.
Definition: solvercategory.hh:26
A simple timing class.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)