Debian Codegraph @

dune/python/istl/operators.hh

raw
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 #ifndef DUNE_PYTHON_ISTL_OPERATORS_HH
4 #define DUNE_PYTHON_ISTL_OPERATORS_HH
5
6 #include <dune/common/typeutilities.hh>
7
8 #include <dune/istl/operators.hh>
9
10 #include <dune/python/pybind11/pybind11.h>
11
12 namespace Dune
13 {
14
15 namespace Python
16 {
17
18 // registerLinearOperator
19 // ----------------------
20
21 template< class LinearOperator, class... options >
22 inline static void registerLinearOperator ( pybind11::class_< LinearOperator, options... > cls )
23 {
24 typedef typename LinearOperator::field_type field_type;
25 typedef typename LinearOperator::domain_type domain_type;
26 typedef typename LinearOperator::range_type range_type;
27
28 using pybind11::operator""_a;
29
30 // application
31 cls.def( "apply", [] ( const LinearOperator &self, const domain_type &x, range_type &y ) {
32 self.apply( x, y );
33 }, "x"_a, "y"_a );
34 cls.def( "applyscaleadd", [] ( const LinearOperator &self, const field_type &alpha, const domain_type &x, range_type &y ) {
35 self.applyscaleadd( alpha, x, y );
36 }, "alpha"_a, "x"_a, "y"_a );
37
38 // linear operator
39 cls.def( "asLinearOperator", [] ( pybind11::object self ) { return self; } );
40 }
41
42 } // namespace Python
43
44 } // namespace Dune
45
46 #endif // #ifndef DUNE_PYTHON_ISTL_BCRSMATRIX_HH