Dune Core Modules (2.7.0)

operators.hh
Go to the documentation of this file.
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_OPERATORS_HH
4 #define DUNE_ISTL_OPERATORS_HH
5 
6 #include <cmath>
7 #include <complex>
8 #include <iostream>
9 #include <iomanip>
10 #include <string>
11 
14 
15 #include "solvercategory.hh"
16 
17 
18 namespace Dune {
19 
42  //=====================================================================
43  // Abstract operator interface
44  //=====================================================================
45 
46 
64  template<class X, class Y>
66  public:
68  typedef X domain_type;
70  typedef Y range_type;
72  typedef typename X::field_type field_type;
73 
78  virtual void apply (const X& x, Y& y) const = 0;
79 
81  virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const = 0;
82 
84  virtual ~LinearOperator () {}
85 
88 #if DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
89  {
90  DUNE_THROW(Dune::Exception,"It is necessary to implement the category method in a derived classes, in the future this method will pure virtual.");
91  };
92 #else
93  = 0;
94 #endif
95  };
96 
97 
106  template<class M, class X, class Y>
108  public:
110  typedef M matrix_type;
111  typedef X domain_type;
112  typedef Y range_type;
113  typedef typename X::field_type field_type;
114 
116  virtual const M& getmat () const = 0;
117 
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  virtual void apply (const X& x, Y& y) const
151  {
152  _A_->mv(x,y);
153  }
154 
156  virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const
157  {
158  _A_->usmv(alpha,x,y);
159  }
160 
162  virtual const M& getmat () const
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
A linear operator exporting itself in matrix form.
Definition: operators.hh:107
virtual const M & getmat() const =0
get matrix via *
M matrix_type
export types, usually they come from the derived class
Definition: operators.hh:110
virtual ~AssembledLinearOperator()
every abstract base class has a virtual destructor
Definition: operators.hh:119
Base class for Dune-Exceptions.
Definition: exceptions.hh:94
A linear operator.
Definition: operators.hh:65
virtual ~LinearOperator()
every abstract base class has a virtual destructor
Definition: operators.hh:84
X::field_type field_type
The field type of the operator.
Definition: operators.hh:72
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const =0
apply operator to x, scale and add:
virtual SolverCategory::Category category() const =0
Category of the linear operator (see SolverCategory::Category)
Y range_type
The type of the range of the operator.
Definition: operators.hh:70
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...
X domain_type
The type of the domain of the operator.
Definition: operators.hh:68
Adapter to turn a matrix into a linear operator.
Definition: operators.hh:135
virtual void applyscaleadd(field_type alpha, const X &x, Y &y) const
apply operator to x, scale and add:
Definition: operators.hh:156
MatrixAdapter(std::shared_ptr< const M > A)
constructor: store an std::shared_ptr to a matrix
Definition: operators.hh:147
MatrixAdapter(const M &A)
constructor: just store a reference to a matrix
Definition: operators.hh:144
virtual const M & getmat() const
get matrix via *
Definition: operators.hh:162
virtual SolverCategory::Category category() const
Category of the solver (see SolverCategory::Category)
Definition: operators.hh:168
virtual void apply(const X &x, Y &y) const
apply operator to x:
Definition: operators.hh:150
M matrix_type
export types
Definition: operators.hh:138
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
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
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Category
Definition: solvercategory.hh:21
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:23
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 9, 22:29, 2024)