dune-istl 2.11
Loading...
Searching...
No Matches
schwarz.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_ISTL_SCHWARZ_HH
6#define DUNE_ISTL_SCHWARZ_HH
7
8#include <iostream> // for input/output to shell
9#include <fstream> // for input/output to files
10#include <vector> // STL vector class
11#include <sstream>
12
13#include <cmath> // Yes, we do some math here
14
15#include <dune/common/timer.hh>
16
17#include "io.hh"
18#include "bvector.hh"
19#include "vbvector.hh"
20#include "bcrsmatrix.hh"
21#include "io.hh"
22#include "gsetc.hh"
23#include "ilu.hh"
24#include "operators.hh"
25#include "solvers.hh"
26#include "preconditioners.hh"
27#include "scalarproducts.hh"
28#include "owneroverlapcopy.hh"
29
30namespace Dune {
31
53
73 template<class M, class X, class Y, class C>
75 {
76 public:
81 typedef M matrix_type;
86 typedef X domain_type;
91 typedef Y range_type;
93 typedef typename X::field_type field_type;
99
108 : _A_(stackobject_to_shared_ptr(A)), communication(com)
109 {}
110
111 OverlappingSchwarzOperator (const std::shared_ptr<matrix_type> A, const communication_type& com)
112 : _A_(A), communication(com)
113 {}
114
116 void apply (const X& x, Y& y) const override
117 {
118 y = 0;
119 _A_->umv(x,y); // result is consistent on interior+border
120 communication.project(y); // we want this here to avoid it before the preconditioner
121 // since there d is const!
122 }
123
125 void applyscaleadd (field_type alpha, const X& x, Y& y) const override
126 {
127 _A_->usmv(alpha,x,y); // result is consistent on interior+border
128 communication.project(y); // we want this here to avoid it before the preconditioner
129 // since there d is const!
130 }
131
133 const matrix_type& getmat () const override
134 {
135 return *_A_;
136 }
137
140 {
142 }
143
144
147 {
148 return communication;
149 }
150 private:
151 const std::shared_ptr<const matrix_type>_A_;
152 const communication_type& communication;
153 };
154
156
174 template<class M, class X, class Y, class C>
175 class ParSSOR : public Preconditioner<X,Y> {
176 public:
178 typedef M matrix_type;
180 typedef X domain_type;
182 typedef Y range_type;
184 typedef typename X::field_type field_type;
187
197 ParSSOR (const matrix_type& A, int n, field_type w, const communication_type& c)
198 : _A_(A), _n(n), _w(w), communication(c)
199 { }
200
206 void pre (X& x, [[maybe_unused]] Y& b) override
207 {
208 communication.copyOwnerToAll(x,x); // make dirichlet values consistent
209 }
210
216 void apply (X& v, const Y& d) override
217 {
218 for (int i=0; i<_n; i++) {
219 bsorf(_A_,v,d,_w);
220 bsorb(_A_,v,d,_w);
221 }
222 communication.copyOwnerToAll(v,v);
223 }
224
230 void post ([[maybe_unused]] X& x) override {}
231
234 {
236 }
237
238 private:
240 const matrix_type& _A_;
242 int _n;
244 field_type _w;
246 const communication_type& communication;
247 };
248
249 namespace Amg
250 {
251 template<class T> struct ConstructionTraits;
252 }
253
277 template<class X, class Y, class C, class P=Preconditioner<X,Y> >
279 friend struct Amg::ConstructionTraits<BlockPreconditioner<X,Y,C,P> >;
280 public:
285 typedef X domain_type;
290 typedef Y range_type;
292 typedef typename X::field_type field_type;
298
307 : _preconditioner(stackobject_to_shared_ptr(p)), _communication(c)
308 { }
309
317 BlockPreconditioner (const std::shared_ptr<P>& p, const communication_type& c)
318 : _preconditioner(p), _communication(c)
319 { }
320
326 void pre (X& x, Y& b) override
327 {
328 _communication.copyOwnerToAll(x,x); // make dirichlet values consistent
329 _preconditioner->pre(x,b);
330 }
331
337 void apply (X& v, const Y& d) override
338 {
339 _preconditioner->apply(v,d);
340 _communication.copyOwnerToAll(v,v);
341 }
342
343 template<bool forward>
344 void apply (X& v, const Y& d)
345 {
346 _preconditioner->template apply<forward>(v,d);
347 _communication.copyOwnerToAll(v,v);
348 }
349
355 void post (X& x) override
356 {
357 _preconditioner->post(x);
358 }
359
362 {
364 }
365
366 private:
368 std::shared_ptr<P> _preconditioner;
369
371 const communication_type& _communication;
372 };
373
375
376} // end namespace
377
378#endif
Implementation of the BCRSMatrix class.
Simple iterative methods like Jacobi, Gauss-Seidel, SOR, SSOR, etc. in a generic way.
Classes providing communication interfaces for overlapping Schwarz methods.
Define general preconditioner interface.
Implementations of the inverse operator interface.
Some generic functions for pretty printing vectors and matrices.
Define general, extensible interface for operators. The available implementation wraps a matrix.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Define base class for scalar product and norm.
The incomplete LU factorization kernels.
void bsorb(const M &A, X &x, const Y &b, const K &w)
SSOR step.
Definition gsetc.hh:646
void bsorf(const M &A, X &x, const Y &b, const K &w)
SOR step.
Definition gsetc.hh:634
Definition allocator.hh:11
Definition novlpschwarz.hh:256
Traits class for generically constructing non default constructable types.
Definition construction.hh:39
A linear operator exporting itself in matrix form.
Definition operators.hh:110
const matrix_type & getmat() const override
get the sequential assembled linear operator.
Definition schwarz.hh:133
const communication_type & getCommunication() const
Get the object responsible for communication.
Definition schwarz.hh:146
void apply(const X &x, Y &y) const override
apply operator to x:
Definition schwarz.hh:116
void applyscaleadd(field_type alpha, const X &x, Y &y) const override
apply operator to x, scale and add:
Definition schwarz.hh:125
C communication_type
The type of the communication object.
Definition schwarz.hh:98
SolverCategory::Category category() const override
Category of the linear operator (see SolverCategory::Category).
Definition schwarz.hh:139
X domain_type
The type of the domain.
Definition schwarz.hh:86
M matrix_type
The type of the matrix we operate on.
Definition schwarz.hh:81
Y range_type
The type of the range.
Definition schwarz.hh:91
X::field_type field_type
The field type of the range.
Definition schwarz.hh:93
OverlappingSchwarzOperator(const matrix_type &A, const communication_type &com)
constructor: just store a reference to a matrix.
Definition schwarz.hh:107
OverlappingSchwarzOperator(const std::shared_ptr< matrix_type > A, const communication_type &com)
Definition schwarz.hh:111
Base class for matrix free definition of preconditioners.
Definition preconditioner.hh:33
X::field_type field_type
The field type of the preconditioner.
Definition schwarz.hh:184
C communication_type
The type of the communication object.
Definition schwarz.hh:186
void pre(X &x, Y &b) override
Prepare the preconditioner.
Definition schwarz.hh:206
ParSSOR(const matrix_type &A, int n, field_type w, const communication_type &c)
Constructor.
Definition schwarz.hh:197
X domain_type
The domain type of the preconditioner.
Definition schwarz.hh:180
Y range_type
The range type of the preconditioner.
Definition schwarz.hh:182
M matrix_type
The matrix type the preconditioner is for.
Definition schwarz.hh:178
SolverCategory::Category category() const override
Category of the preconditioner (see SolverCategory::Category).
Definition schwarz.hh:233
void apply(X &v, const Y &d) override
Apply the preconditioner.
Definition schwarz.hh:216
void post(X &x) override
Clean up.
Definition schwarz.hh:230
SolverCategory::Category category() const override
Category of the preconditioner (see SolverCategory::Category).
Definition schwarz.hh:361
void pre(X &x, Y &b) override
Prepare the preconditioner.
Definition schwarz.hh:326
void apply(X &v, const Y &d) override
Apply the preconditioner.
Definition schwarz.hh:337
BlockPreconditioner(const std::shared_ptr< P > &p, const communication_type &c)
Constructor.
Definition schwarz.hh:317
BlockPreconditioner(P &p, const communication_type &c)
Constructor.
Definition schwarz.hh:306
void apply(X &v, const Y &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition schwarz.hh:344
void post(X &x) override
Clean up.
Definition schwarz.hh:355
X::field_type field_type
Definition schwarz.hh:292
Category
Definition solvercategory.hh:23
@ overlapping
Category for overlapping solvers.
Definition solvercategory.hh:29