dune-istl  2.11
operators.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 // vi: set et ts=4 sw=2 sts=2:
4 #ifndef DUNE_ISTL_OPERATORS_HH
5 #define DUNE_ISTL_OPERATORS_HH
6 
7 #include <dune-istl-config.hh> // DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
8 
9 #include <cmath>
10 #include <complex>
11 #include <iostream>
12 #include <iomanip>
13 #include <string>
14 
15 #include <dune/common/exceptions.hh>
16 #include <dune/common/shared_ptr.hh>
17 
18 #include "solvercategory.hh"
19 
20 
21 namespace Dune {
22 
45  //=====================================================================
46  // Abstract operator interface
47  //=====================================================================
48 
49 
67  template<class X, class Y>
69  public:
71  typedef X domain_type;
73  typedef Y range_type;
75  typedef typename X::field_type field_type;
76 
81  virtual void apply (const X& x, Y& y) const = 0;
82 
84  virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const = 0;
85 
87  virtual ~LinearOperator () {}
88 
90  virtual SolverCategory::Category category() const
91 #if DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
92  {
93  DUNE_THROW(Dune::Exception,"It is necessary to implement the category method in a derived classes, in the future this method will pure virtual.");
94  };
95 #else
96  = 0;
97 #endif
98  };
99 
100 
109  template<class M, class X, class Y>
111  public:
113  typedef M matrix_type;
114  typedef X domain_type;
115  typedef Y range_type;
116  typedef typename X::field_type field_type;
117 
119  virtual const M& getmat () const = 0;
120  };
121 
122 
123 
124  //=====================================================================
125  // Implementation for ISTL-matrix based operator
126  //=====================================================================
127 
133  template<class M, class X, class Y>
135  {
136  public:
138  typedef M matrix_type;
139  typedef X domain_type;
140  typedef Y range_type;
141  typedef typename X::field_type field_type;
142 
144  explicit MatrixAdapter (const M& A) : _A_(stackobject_to_shared_ptr(A)) {}
145 
147  explicit MatrixAdapter (std::shared_ptr<const M> A) : _A_(A) {}
148 
150  void apply (const X& x, Y& y) const override
151  {
152  _A_->mv(x,y);
153  }
154 
156  void applyscaleadd (field_type alpha, const X& x, Y& y) const override
157  {
158  _A_->usmv(alpha,x,y);
159  }
160 
162  const M& getmat () const override
163  {
164  return *_A_;
165  }
166 
169  {
171  }
172 
173  private:
174  const std::shared_ptr<const M> _A_;
175  };
176 
179 } // end namespace
180 
181 #endif
182 
183 // Emacs configuration
184 // Local Variables:
185 // tab-width: 4
186 // indent-tabs-mode: nil
187 // c-basic-offset: 2
188 // End:
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category)
Definition: operators.hh:168
MatrixAdapter(const M &A)
constructor: just store a reference to a matrix
Definition: operators.hh:144
void apply(const X &x, Y &y) const override
apply operator to x:
Definition: operators.hh:150
A linear operator.
Definition: operators.hh:68
X domain_type
Definition: operators.hh:114
MatrixAdapter(std::shared_ptr< const M > A)
constructor: store an std::shared_ptr to a matrix
Definition: operators.hh:147
Y range_type
The type of the range of the operator.
Definition: operators.hh:73
virtual const M & getmat() const =0
get reference to matrix
X::field_type field_type
Definition: operators.hh:141
Category for sequential solvers.
Definition: solvercategory.hh:25
Y range_type
Definition: operators.hh:115
M matrix_type
export types, usually they come from the derived class
Definition: operators.hh:113
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const =0
apply operator to x, scale and add:
virtual ~LinearOperator()
every abstract base class has a virtual destructor
Definition: operators.hh:87
X::field_type field_type
The field type of the operator.
Definition: operators.hh:75
void applyscaleadd(field_type alpha, const X &x, Y &y) const override
apply operator to x, scale and add:
Definition: operators.hh:156
Adapter to turn a matrix into a linear operator.
Definition: operators.hh:134
X domain_type
Definition: operators.hh:139
Y range_type
Definition: operators.hh:140
const M & getmat() const override
get reference to matrix
Definition: operators.hh:162
X::field_type field_type
Definition: operators.hh:116
virtual SolverCategory::Category category() const =0
Category of the linear operator (see SolverCategory::Category)
X domain_type
The type of the domain of the operator.
Definition: operators.hh:71
Category
Definition: solvercategory.hh:23
Definition: allocator.hh:11
A linear operator exporting itself in matrix form.
Definition: operators.hh:110
virtual void apply(const X &x, Y &y) const =0
apply operator to x: The input vector is consistent and the output must also be consistent on the in...
M matrix_type
export types
Definition: operators.hh:138