Dune Core Modules (2.4.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
28namespace 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;
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;
178
180 enum {category=SolverCategory::overlapping};
181
187 : communication(com)
188 {}
189
194 virtual field_type dot (const X& x, const X& y)
195 {
196 field_type result;
197 communication.dot(x,y,result);
198 return result;
199 }
200
204 virtual double norm (const X& x)
205 {
206 return communication.norm(x);
207 }
208
209 private:
210 const communication_type& communication;
211 };
212
213 template<class X, class C>
214 struct ScalarProductChooser<X,C,SolverCategory::overlapping>
215 {
217 typedef OverlappingSchwarzScalarProduct<X,C> ScalarProduct;
219 typedef C communication_type;
220
221 enum {
224 };
225
226 static ScalarProduct* construct(const communication_type& comm)
227 {
228 return new ScalarProduct(comm);
229 }
230 };
231
251 template<class M, class X, class Y, class C>
252 class ParSSOR : public Preconditioner<X,Y> {
253 public:
255 typedef M matrix_type;
257 typedef X domain_type;
259 typedef Y range_type;
261 typedef typename X::field_type field_type;
264
265 // define the category
266 enum {
269 };
270
280 ParSSOR (const matrix_type& A, int n, field_type w, const communication_type& c)
281 : _A_(A), _n(n), _w(w), communication(c)
282 { }
283
289 virtual void pre (X& x, Y& b)
290 {
291 communication.copyOwnerToAll(x,x); // make dirichlet values consistent
292 }
293
299 virtual void apply (X& v, const Y& d)
300 {
301 for (int i=0; i<_n; i++) {
302 bsorf(_A_,v,d,_w);
303 bsorb(_A_,v,d,_w);
304 }
305 communication.copyOwnerToAll(v,v);
306 }
307
313 virtual void post (X& x) {}
314
315 private:
317 const matrix_type& _A_;
319 int _n;
321 field_type _w;
323 const communication_type& communication;
324 };
325
326 namespace Amg
327 {
328 template<class T> class ConstructionTraits;
329 }
330
354 template<class X, class Y, class C, class T=Preconditioner<X,Y> >
356 friend class Amg::ConstructionTraits<BlockPreconditioner<X,Y,C,T> >;
357 public:
362 typedef X domain_type;
367 typedef Y range_type;
369 typedef typename X::field_type field_type;
375
376 // define the category
377 enum {
380 };
381
390 : preconditioner(p), communication(c)
391 { }
392
398 virtual void pre (X& x, Y& b)
399 {
400 communication.copyOwnerToAll(x,x); // make dirichlet values consistent
401 preconditioner.pre(x,b);
402 }
403
409 virtual void apply (X& v, const Y& d)
410 {
411 preconditioner.apply(v,d);
412 communication.copyOwnerToAll(v,v);
413 }
414
415 template<bool forward>
416 void apply (X& v, const Y& d)
417 {
418 preconditioner.template apply<forward>(v,d);
419 communication.copyOwnerToAll(v,v);
420 }
421
427 virtual void post (X& x)
428 {
429 preconditioner.post(x);
430 }
431
432 private:
434 T& preconditioner;
435
437 const communication_type& communication;
438 };
439
442} // end namespace
443
444#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:355
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:362
@ category
The category the precondtioner is part of.
Definition: schwarz.hh:379
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:367
BlockPreconditioner(T &p, const communication_type &c)
Constructor.
Definition: schwarz.hh:389
C communication_type
The type of the communication object..
Definition: schwarz.hh:374
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:427
void apply(X &v, const Y &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: schwarz.hh:416
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:398
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:369
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: schwarz.hh:409
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
@ category
The solver category.
Definition: schwarz.hh:103
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:113
Scalar product for overlapping schwarz methods.
Definition: schwarz.hh:164
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:204
C communication_type
The type of the communication object.
Definition: schwarz.hh:177
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:194
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:186
A parallel SSOR preconditioner.
Definition: schwarz.hh:252
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:261
C communication_type
The type of the communication object.
Definition: schwarz.hh:263
@ category
The category the precondtioner is part of.
Definition: schwarz.hh:268
ParSSOR(const matrix_type &A, int n, field_type w, const communication_type &c)
Constructor.
Definition: schwarz.hh:280
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:313
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:257
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:259
M matrix_type
The matrix type the preconditioner is for.
Definition: schwarz.hh:255
virtual void apply(X &v, const Y &d)
Apply the precondtioner.
Definition: schwarz.hh:299
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:289
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: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:10
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 ovelapping solvers.
Definition: solvercategory.hh:25
A simple timing class.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)