1 #ifndef DUNE_FEMPY_NUMPYOPERATOR_HH 2 #define DUNE_FEMPY_NUMPYOPERATOR_HH 3 4 // dune-fem includes 5 #include <dune/fem/operator/linear/spoperator.hh> 6 7 // local includes 8 #include <dune/fempy/pybind11/pybind11.hh> 9 10 namespace Dune 11 { 12 13 namespace Fem 14 { 15 16 //! NumpyLinearOperator 17 template< class DomainFunction, class RangeFunction > 18 struct NumpyLinearOperator 19 : public SparseRowMatrixObject< typename DomainFunction::DiscreteFunctionSpaceType, 20 typename RangeFunction::DiscreteFunctionSpaceType, 21 SparseRowMatrix< double, size_t, 22 pybind11::array_t< double >, 23 pybind11::array_t<size_t> > >, 24 public Fem::AssembledOperator< DomainFunction, RangeFunction > 25 { 26 typedef typename DomainFunction::DiscreteFunctionSpaceType DomainSpaceType; 27 typedef typename RangeFunction::DiscreteFunctionSpaceType RangeSpaceType; 28 typedef NumpyLinearOperator< DomainFunction, RangeFunction > ThisType; 29 // for numpy backend we need to use different storage classes 30 typedef SparseRowMatrix< double, size_t, pybind11::array_t< double >, pybind11::array_t<size_t> > Matrix; 31 typedef SparseRowMatrixObject< DomainSpaceType, RangeSpaceType, Matrix > BaseType; 32 33 static constexpr bool assembled = true; 34 35 using BaseType::apply; 36 NumpyLinearOperatorDune::Fem::NumpyLinearOperator37 NumpyLinearOperator( const std::string & , 38 const DomainSpaceType &domainSpace, 39 const RangeSpaceType &rangeSpace, 40 const SolverParameter& param = SolverParameter() ) : 41 BaseType( domainSpace, rangeSpace, param ) 42 {} 43 operator ()Dune::Fem::NumpyLinearOperator44 virtual void operator()( const DomainFunction &arg, RangeFunction &dest ) const 45 { 46 apply( arg, dest ); 47 } 48 systemMatrixDune::Fem::NumpyLinearOperator49 const BaseType &systemMatrix() const 50 { 51 return *this; 52 } 53 systemMatrixDune::Fem::NumpyLinearOperator54 BaseType &systemMatrix() 55 { 56 return *this; 57 } 58 }; 59 60 } // namespace Fem 61 62 } // namespace Dune 63 64 #endif // #ifndef DUNE_FEM_SPOPERATOR_HH 65