Loading [MathJax]/extensions/tex2jax.js

DUNE-FEM (2.10)

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 };
122
123
124
125 //=====================================================================
126 // Implementation for ISTL-matrix based operator
127 //=====================================================================
128
134 template<class M, class X, class Y>
136 {
137 public:
139 typedef M matrix_type;
140 typedef X domain_type;
141 typedef Y range_type;
142 typedef typename X::field_type field_type;
143
145 explicit MatrixAdapter (const M& A) : _A_(stackobject_to_shared_ptr(A)) {}
146
148 explicit MatrixAdapter (std::shared_ptr<const M> A) : _A_(A) {}
149
151 void apply (const X& x, Y& y) const override
152 {
153 _A_->mv(x,y);
154 }
155
157 void applyscaleadd (field_type alpha, const X& x, Y& y) const override
158 {
159 _A_->usmv(alpha,x,y);
160 }
161
163 const M& getmat () const override
164 {
165 return *_A_;
166 }
167
170 {
172 }
173
174 private:
175 const std::shared_ptr<const M> _A_;
176 };
177
180} // end namespace
181
182#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
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:136
MatrixAdapter(std::shared_ptr< const M > A)
constructor: store an std::shared_ptr to a matrix
Definition: operators.hh:148
MatrixAdapter(const M &A)
constructor: just store a reference to a matrix
Definition: operators.hh:145
void applyscaleadd(field_type alpha, const X &x, Y &y) const override
apply operator to x, scale and add:
Definition: operators.hh:157
const M & getmat() const override
get matrix via *
Definition: operators.hh:163
SolverCategory::Category category() const override
Category of the solver (see SolverCategory::Category)
Definition: operators.hh:169
void apply(const X &x, Y &y) const override
apply operator to x:
Definition: operators.hh:151
M matrix_type
export types
Definition: operators.hh:139
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 & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 5, 23:02, 2025)