Dune Core Modules (unstable)

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// -*- 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 <dune-istl-config.hh> // DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
9
10#include <cmath>
11#include <complex>
12#include <iostream>
13#include <iomanip>
14#include <string>
15
18
19#include "solvercategory.hh"
20
21
22namespace Dune {
23
46 //=====================================================================
47 // Abstract operator interface
48 //=====================================================================
49
50
68 template<class X, class Y>
70 public:
72 typedef X domain_type;
74 typedef Y range_type;
76 typedef typename X::field_type field_type;
77
82 virtual void apply (const X& x, Y& y) const = 0;
83
85 virtual void applyscaleadd (field_type alpha, const X& x, Y& y) const = 0;
86
88 virtual ~LinearOperator () {}
89
92#if DUNE_ISTL_SUPPORT_OLD_CATEGORY_INTERFACE
93 {
94 DUNE_THROW(Dune::Exception,"It is necessary to implement the category method in a derived classes, in the future this method will pure virtual.");
95 };
96#else
97 = 0;
98#endif
99 };
100
101
110 template<class M, class X, class Y>
112 public:
114 typedef M matrix_type;
115 typedef X domain_type;
116 typedef Y range_type;
117 typedef typename X::field_type field_type;
118
120 virtual const M& getmat () const = 0;
121
124 };
125
126
127
128 //=====================================================================
129 // Implementation for ISTL-matrix based operator
130 //=====================================================================
131
137 template<class M, class X, class Y>
139 {
140 public:
142 typedef M matrix_type;
143 typedef X domain_type;
144 typedef Y range_type;
145 typedef typename X::field_type field_type;
146
148 explicit MatrixAdapter (const M& A) : _A_(stackobject_to_shared_ptr(A)) {}
149
151 explicit MatrixAdapter (std::shared_ptr<const M> A) : _A_(A) {}
152
154 void apply (const X& x, Y& y) const override
155 {
156 _A_->mv(x,y);
157 }
158
160 void applyscaleadd (field_type alpha, const X& x, Y& y) const override
161 {
162 _A_->usmv(alpha,x,y);
163 }
164
166 const M& getmat () const override
167 {
168 return *_A_;
169 }
170
173 {
175 }
176
177 private:
178 const std::shared_ptr<const M> _A_;
179 };
180
183} // end namespace
184
185#endif
A linear operator exporting itself in matrix form.
Definition: operators.hh:111
virtual const M & getmat() const =0
get matrix via *
M matrix_type
export types, usually they come from the derived class
Definition: operators.hh:114
virtual ~AssembledLinearOperator()
every abstract base class has a virtual destructor
Definition: operators.hh:123
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
A linear operator.
Definition: operators.hh:69
virtual ~LinearOperator()
every abstract base class has a virtual destructor
Definition: operators.hh:88
X::field_type field_type
The field type of the operator.
Definition: operators.hh:76
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:74
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:72
Adapter to turn a matrix into a linear operator.
Definition: operators.hh:139
MatrixAdapter(std::shared_ptr< const M > A)
constructor: store an std::shared_ptr to a matrix
Definition: operators.hh:151
MatrixAdapter(const M &A)
constructor: just store a reference to a matrix
Definition: operators.hh:148
void applyscaleadd(field_type alpha, const X &x, Y &y) const override
apply operator to x, scale and add:
Definition: operators.hh:160
const M & getmat() const override
get matrix via *
Definition: operators.hh:166
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category)
Definition: operators.hh:172
void apply(const X &x, Y &y) const override
apply operator to x:
Definition: operators.hh:154
M matrix_type
export types
Definition: operators.hh:142
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.111.3 (Jul 15, 22:36, 2024)