version 0.4.1
registerferequirements.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
6#include <dune/python/common/typeregistry.hh>
7#include <dune/python/pybind11/pybind11.h>
8
10
11namespace Ikarus::Python {
12
13template <class FE, class... options>
14void registerFERequirement(pybind11::handle scope, pybind11::class_<FE, options...> cls) {
15 using FERequirements = typename FE::Requirement;
16 using SolutionVectorType = typename FERequirements::SolutionVectorType;
17 using ParameterType = typename FERequirements::ParameterType;
18
19 using ParameterType = typename FERequirements::ParameterType;
20 using namespace pybind11::literals;
21
22 cls.def(
23 "createRequirement", [](pybind11::object /* self */) { return FERequirements(); },
24 pybind11::return_value_policy::copy);
25
26 auto includes = Dune::Python::IncludeFiles{"ikarus/finiteelements/ferequirements.hh"};
27 auto [req, isNew] = Dune::Python::insertClass<FERequirements>(
28 scope, "FERequirements", Dune::Python::GenerateTypeName(Dune::className<FERequirements>()), includes);
29
30 if (isNew) {
31 req.def(pybind11::init());
32 req.def(pybind11::init<SolutionVectorType&, ParameterType&>());
33
34 req.def(
35 "insertGlobalSolution",
36 [](FERequirements& self, SolutionVectorType solVec) { self.insertGlobalSolution(solVec); },
37 "solutionVector"_a.noconvert());
38 req.def(
39 "globalSolution", [](FERequirements& self) { return self.globalSolution(); },
40 pybind11::return_value_policy::reference_internal);
41 req.def(
42 "insertParameter",
43 [](FERequirements& self, ScalarWrapper<double>& parVal) { self.insertParameter(parVal.value()); },
44 pybind11::keep_alive<1, 2>(), "parameterValue"_a.noconvert());
45
46 req.def("parameter", [](const FERequirements& self) { return self.parameter(); });
47 }
48}
49} // namespace Ikarus::Python
Provides a wrapper for scalar types to support passing by reference in Python bindings.
void init(int argc, char **argv, bool enableFileLogger=true)
Initializes the Ikarus framework.
Definition: init.hh:82
Definition: flatassembler.hh:21
void registerFERequirement(pybind11::handle scope, pybind11::class_< FE, options... > cls)
Definition: registerferequirements.hh:14
Class representing the requirements for finite element calculations.
Definition: ferequirements.hh:252
SV SolutionVectorType
Definition: ferequirements.hh:268
PM ParameterType
Definition: ferequirements.hh:269
SolutionVectorReturnType globalSolution()
Get the global solution vector.
Definition: ferequirements.hh:308
FERequirements & insertParameter(ParameterInputType val)
Insert a parameter into the requirements.
Definition: ferequirements.hh:284
FERequirements & insertGlobalSolution(SolutionVectorInputType solVec)
Insert a global solution vector into the requirements.
Definition: ferequirements.hh:297
PMHelper::ConstReturnType parameter() const
Get the parameter value.
Definition: ferequirements.hh:325
RequirementType< requirementDetected >::type Requirement
Definition: mixin.hh:89
A wrapper class for scalar types to facilitate reference passing in Python bindings.
Definition: scalarwrapper.hh:27
const RawScalarType & value() const
Gets the wrapped scalar value as a constant reference.
Definition: scalarwrapper.hh:47