11#include <dune/python/common/typeregistry.hh>
12#include <dune/python/pybind11/eigen.h>
13#include <dune/python/pybind11/pybind11.h>
14#include <dune/python/pybind11/stl.h>
15#include <dune/python/pybind11/stl_bind.h>
28 template <
typename NewType,
typename F,
typename... Args,
size_t... Indices>
29 decltype(
auto) forward_last_as(F&& f, std::index_sequence<Indices...>, Args&&... args) {
30 auto tup = std::forward_as_tuple(args...);
31 return f(std::get<Indices>(tup)..., NewType(std::get<
sizeof...(Args) - 1>(tup)));
34 template <
typename NewType,
typename F>
35 auto wrapFunctionAndReplaceLastType(F&& f) {
36 return [f](
auto&&... args) ->
decltype(
auto) {
37 return forward_last_as<NewType>(f, std::make_index_sequence<
sizeof...(args) - 1>{},
38 std::forward<decltype(args)>(args)...);
50 std::reference_wrapper<Eigen::SparseMatrix<T>>
matrixRef;
55 auto includes = Dune::Python::IncludeFiles{
"ikarus/finiteelements/flatassemblermanipulator.hh"};
56 auto [lv, isNotRegistered] = Dune::Python::insertClass<SparseMatrixWrapper<T>>(
59 if (isNotRegistered) {
62 double val) { self.
matrixRef.get().coeffRef(index[0], index[1]) = val; })
64 return self.
matrixRef.get().coeffRef(index[0], index[1]);
71 using pybind11::operator
""_a;
74 registerSparseMatrixWrapper<double>(scope);
76 using UnderlyingAssembler =
typename AssemblerManipulator::WrappedAssembler;
80 using NewArgs = std::tuple<
82 Eigen::Ref<typename AssemblerManipulator::VectorType>,
83 std::conditional_t<std::is_same_v<typename AssemblerManipulator::MatrixType, Eigen::SparseMatrix<double>>,
85 Dune::Hybrid::forEach(Dune::Hybrid::integralRange(
86 Dune::index_constant<std::tuple_size_v<typename AssemblerManipulator::CallBackTypes>>()),
88 using F = std::tuple_element_t<i, typename AssemblerManipulator::CallBackTypes>;
89 using NewArg = std::tuple_element_t<i, NewArgs>;
90 std::string name = std::string(
"add") +
94 std::string(
"CallBack");
96 constexpr int lastIndex = Traits::numberOfArguments - 1;
106 F fOrig = Impl::wrapFunctionAndReplaceLastType<NewArg>(std::forward<FMod>(f));
108 self.bind(std::move(fOrig));
Contains stl-like type traits.
Python bindings for assemblers.
Provides a wrapper for scalar types to support passing by reference in Python bindings.
Definition of the LinearElastic class for finite element mechanics computations.
void registerFlatAssembler(pybind11::handle scope, pybind11::class_< Assembler, options... > cls)
Register Python bindings for a assembler class. .
Definition: flatassembler.hh:41
void init(int argc, char **argv, bool enableFileLogger=true)
Initializes the Ikarus framework.
Definition: init.hh:82
Definition: flatassembler.hh:21
void registerSparseMatrixWrapper(pybind11::handle scope)
Definition: flatassemblermanipulator.hh:54
void registerAssemblerManipulator(pybind11::handle scope, pybind11::class_< AssemblerManipulator, options... > cls)
Definition: flatassemblermanipulator.hh:70
The AssemblerManipulator defines a decorator for the assemblers that helps to manipulate the assemble...
Definition: assemblermanipulatorfuser.hh:36
Definition: flatassemblermanipulator.hh:47
std::reference_wrapper< Eigen::SparseMatrix< T > > matrixRef
Definition: flatassemblermanipulator.hh:50
SparseMatrixWrapper(Eigen::SparseMatrix< T > &matrix)
Definition: flatassemblermanipulator.hh:48
A wrapper class for scalar types to facilitate reference passing in Python bindings.
Definition: scalarwrapper.hh:27
Type trait for extracting information about functions.
Definition: traits.hh:331
Main function to wrap the type at position pos in a std::function.
Definition: traits.hh:453
Wrapper around Dune-functions global basis.