Dune Core Modules (2.9.0)

operators.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 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_OPERATORS_HH
6 #define DUNE_ISTL_OPERATORS_HH
7 
8 #include <cmath>
9 #include <complex>
10 #include <iostream>
11 #include <iomanip>
12 #include <string>
13 
16 
17 #include "solvercategory.hh"
18 
19 
20 namespace Dune {
21 
44  //=====================================================================
45  // Abstract operator interface
46  //=====================================================================
47 
48 
66  template<class X, class Y>
68  public:
70  typedef X domain_type;
72  typedef Y range_type;
74  typedef typename X::field_type field_type;
75 
80  virtual void apply (const X& x, Y& y) const = 0;
81 
83  virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const = 0;
84 
86  virtual ~LinearOperator () {}
87 
90 #if DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
91  {
92  DUNE_THROW(Dune::Exception,"It is necessary to implement the category method in a derived classes, in the future this method will pure virtual.");
93  };
94 #else
95  = 0;
96 #endif
97  };
98 
99 
108  template<class M, class X, class Y>
110  public:
112  typedef M matrix_type;
113  typedef X domain_type;
114  typedef Y range_type;
115  typedef typename X::field_type field_type;
116 
118  virtual const M& getmat () const = 0;
119 
122  };
123 
124 
125 
126  //=====================================================================
127  // Implementation for ISTL-matrix based operator
128  //=====================================================================
129 
135  template<class M, class X, class Y>
137  {
138  public:
140  typedef M matrix_type;
141  typedef X domain_type;
142  typedef Y range_type;
143  typedef typename X::field_type field_type;
144 
146  explicit MatrixAdapter (const M& A) : _A_(stackobject_to_shared_ptr(A)) {}
147 
149  explicit MatrixAdapter (std::shared_ptr<const M> A) : _A_(A) {}
150 
152  void apply (const X& x, Y& y) const override
153  {
154  _A_->mv(x,y);
155  }
156 
158  void applyscaleadd (field_type alpha, const X& x, Y& y) const override
159  {
160  _A_->usmv(alpha,x,y);
161  }
162 
164  const M& getmat () const override
165  {
166  return *_A_;
167  }
168 
171  {
173  }
174 
175  private:
176  const std::shared_ptr<const M> _A_;
177  };
178 
181 } // end namespace
182 
183 #endif
A linear operator exporting itself in matrix form.
Definition: operators.hh:109
virtual const M & getmat() const =0
get matrix via *
M matrix_type
export types, usually they come from the derived class
Definition: operators.hh:112
virtual ~AssembledLinearOperator()
every abstract base class has a virtual destructor
Definition: operators.hh:121
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
A linear operator.
Definition: operators.hh:67
virtual ~LinearOperator()
every abstract base class has a virtual destructor
Definition: operators.hh:86
X::field_type field_type
The field type of the operator.
Definition: operators.hh:74
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:72
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:70
Adapter to turn a matrix into a linear operator.
Definition: operators.hh:137
MatrixAdapter(std::shared_ptr< const M > A)
constructor: store an std::shared_ptr to a matrix
Definition: operators.hh:149
MatrixAdapter(const M &A)
constructor: just store a reference to a matrix
Definition: operators.hh:146
void applyscaleadd(field_type alpha, const X &x, Y &y) const override
apply operator to x, scale and add:
Definition: operators.hh:158
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category)
Definition: operators.hh:170
void apply(const X &x, Y &y) const override
apply operator to x:
Definition: operators.hh:152
const M & getmat() const override
get matrix via *
Definition: operators.hh:164
M matrix_type
export types
Definition: operators.hh:140
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
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
This file implements several utilities related to std::shared_ptr.
Category
Definition: solvercategory.hh:23
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:25
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 27, 22:29, 2024)