Dune Core Modules (unstable)

schwarz.hh
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 
30 namespace Dune {
31 
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;
98  typedef C communication_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  virtual void apply (const X& x, Y& y) const
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  virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const
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  virtual const matrix_type& getmat () const
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 
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  virtual void pre (X& x, [[maybe_unused]] Y& b)
207  {
208  communication.copyOwnerToAll(x,x); // make dirichlet values consistent
209  }
210 
216  virtual void apply (X& v, const Y& d)
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  virtual void post ([[maybe_unused]] X& x) {}
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> >
278  class BlockPreconditioner : public 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  virtual void pre (X& x, Y& b)
327  {
328  _communication.copyOwnerToAll(x,x); // make dirichlet values consistent
329  _preconditioner->pre(x,b);
330  }
331 
337  virtual void apply (X& v, const Y& d)
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  virtual void post (X& x)
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 
376 } // end namespace
377 
378 #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...
A linear operator exporting itself in matrix form.
Definition: operators.hh:109
Block parallel preconditioner.
Definition: schwarz.hh:278
virtual void pre(X &x, Y &b)
Prepare the preconditioner.
Definition: schwarz.hh:326
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:285
BlockPreconditioner(const std::shared_ptr< P > &p, const communication_type &c)
Constructor.
Definition: schwarz.hh:317
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: schwarz.hh:337
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
C communication_type
The type of the communication object..
Definition: schwarz.hh:297
X::field_type field_type
The field type of the preconditioner.
Definition: schwarz.hh:292
virtual void post(X &x)
Clean up.
Definition: schwarz.hh:355
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:290
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: schwarz.hh:361
X::field_type field_type
The field type of the operator.
Definition: operators.hh:74
An overlapping Schwarz operator.
Definition: schwarz.hh:75
const communication_type & getCommunication() const
Get the object responsible for communication.
Definition: schwarz.hh:146
virtual const matrix_type & getmat() const
get the sequential assembled linear operator.
Definition: schwarz.hh:133
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const
apply operator to x, scale and add:
Definition: schwarz.hh:125
virtual void apply(const X &x, Y &y) const
apply operator to x:
Definition: schwarz.hh:116
C communication_type
The type of the communication object.
Definition: schwarz.hh:98
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
virtual SolverCategory::Category category() const
Category of the linear operator (see SolverCategory::Category)
Definition: schwarz.hh:139
A parallel SSOR preconditioner.
Definition: schwarz.hh:175
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
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: schwarz.hh:233
virtual void pre(X &x, [[maybe_unused]] Y &b)
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
virtual void post([[maybe_unused]] X &x)
Clean up.
Definition: schwarz.hh:230
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
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: schwarz.hh:216
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:32
X::field_type field_type
The field type of the preconditioner.
Definition: preconditioner.hh:39
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:646
void bsorf(const M &A, X &x, const Y &b, const K &w)
SOR step.
Definition: gsetc.hh:634
Simple iterative methods like Jacobi, Gauss-Seidel, SOR, SSOR, etc. in a generic way.
The incomplete LU factorization kernels.
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
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.
Traits class for generically constructing non default constructable types.
Definition: construction.hh:39
Category
Definition: solvercategory.hh:23
@ overlapping
Category for overlapping solvers.
Definition: solvercategory.hh:29
A simple timing class.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 27, 22:29, 2024)