File: operators.hh

package info (click to toggle)
dune-istl 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,504 kB
  • sloc: cpp: 34,844; python: 182; sh: 3; makefile: 3
file content (46 lines) | stat: -rw-r--r-- 1,462 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_PYTHON_ISTL_OPERATORS_HH
#define DUNE_PYTHON_ISTL_OPERATORS_HH

#include <dune/common/typeutilities.hh>

#include <dune/istl/operators.hh>

#include <dune/python/pybind11/pybind11.h>

namespace Dune
{

  namespace Python
  {

    // registerLinearOperator
    // ----------------------

    template< class LinearOperator, class... options >
    inline static void registerLinearOperator ( pybind11::class_< LinearOperator, options... > cls )
    {
      typedef typename LinearOperator::field_type field_type;
      typedef typename LinearOperator::domain_type domain_type;
      typedef typename LinearOperator::range_type range_type;

      using pybind11::operator""_a;

      // application
      cls.def( "apply", [] ( const LinearOperator &self, const domain_type &x, range_type &y ) {
          self.apply( x, y );
        }, "x"_a, "y"_a );
      cls.def( "applyscaleadd", [] ( const LinearOperator &self, const field_type &alpha, const domain_type &x, range_type &y ) {
          self.applyscaleadd( alpha, x, y );
        }, "alpha"_a, "x"_a, "y"_a );

      // linear operator
      cls.def( "asLinearOperator", [] ( pybind11::object self ) { return self; } );
    }

  } // namespace Python

} // namespace Dune

#endif // #ifndef DUNE_PYTHON_ISTL_BCRSMATRIX_HH