Dune Core Modules (2.7.0)

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
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 private:
146 const std::shared_ptr<const matrix_type>_A_;
147 const communication_type& communication;
148 };
149
152 /*
153 * @addtogroup ISTL_Prec
154 * @{
155 */
169 template<class M, class X, class Y, class C>
170 class ParSSOR : public Preconditioner<X,Y> {
171 public:
173 typedef M matrix_type;
175 typedef X domain_type;
177 typedef Y range_type;
179 typedef typename X::field_type field_type;
182
192 ParSSOR (const matrix_type& A, int n, field_type w, const communication_type& c)
193 : _A_(A), _n(n), _w(w), communication(c)
194 { }
195
201 virtual void pre (X& x, Y& b)
202 {
203 communication.copyOwnerToAll(x,x); // make dirichlet values consistent
204 }
205
211 virtual void apply (X& v, const Y& d)
212 {
213 for (int i=0; i<_n; i++) {
214 bsorf(_A_,v,d,_w);
215 bsorb(_A_,v,d,_w);
216 }
217 communication.copyOwnerToAll(v,v);
218 }
219
225 virtual void post (X& x) {}
226
229 {
231 }
232
233 private:
235 const matrix_type& _A_;
237 int _n;
239 field_type _w;
241 const communication_type& communication;
242 };
243
244 namespace Amg
245 {
246 template<class T> class ConstructionTraits;
247 }
248
272 template<class X, class Y, class C, class P=Preconditioner<X,Y> >
274 friend struct Amg::ConstructionTraits<BlockPreconditioner<X,Y,C,P> >;
275 public:
280 typedef X domain_type;
285 typedef Y range_type;
287 typedef typename X::field_type field_type;
293
302 : _preconditioner(stackobject_to_shared_ptr(p)), _communication(c)
303 { }
304
312 BlockPreconditioner (const std::shared_ptr<P>& p, const communication_type& c)
313 : _preconditioner(p), _communication(c)
314 { }
315
321 virtual void pre (X& x, Y& b)
322 {
323 _communication.copyOwnerToAll(x,x); // make dirichlet values consistent
324 _preconditioner->pre(x,b);
325 }
326
332 virtual void apply (X& v, const Y& d)
333 {
334 _preconditioner->apply(v,d);
335 _communication.copyOwnerToAll(v,v);
336 }
337
338 template<bool forward>
339 void apply (X& v, const Y& d)
340 {
341 _preconditioner->template apply<forward>(v,d);
342 _communication.copyOwnerToAll(v,v);
343 }
344
350 virtual void post (X& x)
351 {
352 _preconditioner->post(x);
353 }
354
357 {
359 }
360
361 private:
363 std::shared_ptr<P> _preconditioner;
364
366 const communication_type& _communication;
367 };
368
371} // end namespace
372
373#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:107
Block parallel preconditioner.
Definition: schwarz.hh:273
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:321
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:280
BlockPreconditioner(const std::shared_ptr< P > &p, const communication_type &c)
Constructor.
Definition: schwarz.hh:312
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: schwarz.hh:332
BlockPreconditioner(P &p, const communication_type &c)
Constructor.
Definition: schwarz.hh:301
void apply(X &v, const Y &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: schwarz.hh:339
C communication_type
The type of the communication object..
Definition: schwarz.hh:292
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:287
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:350
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:285
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: schwarz.hh:356
X::field_type field_type
The field type of the operator.
Definition: operators.hh:72
An overlapping Schwarz operator.
Definition: schwarz.hh:76
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
virtual SolverCategory::Category category() const
Category of the linear operator (see SolverCategory::Category)
Definition: schwarz.hh:140
A parallel SSOR preconditioner.
Definition: schwarz.hh:170
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:179
C communication_type
The type of the communication object.
Definition: schwarz.hh:181
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: schwarz.hh:228
ParSSOR(const matrix_type &A, int n, field_type w, const communication_type &c)
Constructor.
Definition: schwarz.hh:192
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:225
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:175
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:177
M matrix_type
The matrix type the preconditioner is for.
Definition: schwarz.hh:173
virtual void apply(X &v, const Y &d)
Apply the precondtioner.
Definition: schwarz.hh:211
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:201
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
Some generic functions for pretty printing vectors and matrices.
void bsorb(const M &A, X &x, const Y &b, const K &w)
SSOR step.
Definition: gsetc.hh:640
void bsorf(const M &A, X &x, const Y &b, const K &w)
SOR step.
Definition: gsetc.hh:628
Simple iterative methods like Jacobi, Gauss-Seidel, SOR, SSOR, etc. in a generic way.
Dune namespace.
Definition: alignedallocator.hh:14
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
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.
Category
Definition: solvercategory.hh:21
@ overlapping
Category for overlapping solvers.
Definition: solvercategory.hh:27
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)