dune-localfunctions 2.12-git
Loading...
Searching...
No Matches
python/localfunctions/localfiniteelement.hh
Go to the documentation of this file.
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_LOCALFUNCTIONS_LOCALFINITEELEMENT_HH
4#define DUNE_PYTHON_LOCALFUNCTIONS_LOCALFINITEELEMENT_HH
5
6#include <dune/python/pybind11/pybind11.h>
7
11#include <dune/python/common/typeregistry.hh>
12
13namespace Dune {
14namespace Python {
15
16namespace detail {
17
18template<typename LocalBasis>
19DUNE_EXPORT auto registerLocalBasis(pybind11::handle scope)
20{
21 static auto cls = pybind11::class_<LocalBasis>(scope, "LocalBasis");
22
23 cls.def("__len__", [](const LocalBasis& basis) { return basis.size(); });
24 cls.def_property_readonly("order", [](const LocalBasis& basis) { return basis.order(); });
25 cls.def("evaluateFunction",
26 [](const LocalBasis& basis, const typename LocalBasis::Traits::DomainType& in) {
28 basis.evaluateFunction(in, out);
29 return out;
30 });
31 cls.def("evaluateJacobian",
32 [](const LocalBasis& basis, const typename LocalBasis::Traits::DomainType& in) {
34 basis.evaluateJacobian(in, out);
35 return out;
36 });
37 return cls;
38}
39
40DUNE_EXPORT auto registerLocalKey(pybind11::handle scope)
41{
42 // static auto cls = pybind11::class_<LocalKey>(scope, "LocalKey");
43 auto [cls,newlyInserted] = insertClass<LocalKey>(scope, "LocalKey",
44 GenerateTypeName("Dune::LocalKey"),IncludeFiles{"dune/localfunctions/common/localkey.hh"}
45 );
46 if (!newlyInserted)
47 return cls;
48
49 cls.def_property_readonly("subEntity", &LocalKey::subEntity);
50 cls.def_property_readonly("codim", &LocalKey::codim);
51 cls.def_property("index",
52 [](const LocalKey& key) { return key.index(); },
53 [](LocalKey& key, unsigned int index) { key.index(index); });
54 cls.def("__lt__", &LocalKey::operator<);
55
56 return cls;
57}
58
59} /* namespace detail */
60
61template<typename LocalFiniteElement>
62DUNE_EXPORT auto registerLocalFiniteElement(pybind11::handle scope, const char* name = "LocalFiniteElement")
63{
64 static auto cls = pybind11::class_<LocalFiniteElement>(scope, name);
65
66 detail::registerLocalBasis<typename LocalFiniteElement::Traits::LocalBasisType>(cls);
67
68 cls.def_property_readonly("localBasis", &LocalFiniteElement::localBasis, pybind11::return_value_policy::reference_internal);
69 // cls.def_property_readonly("localCoefficients", &LocalFiniteElement::localCoefficients);
70 // cls.def_property_readonly("localInterpolation", &LocalFiniteElement::localInterpolation);
71 cls.def("__len__", [](const LocalFiniteElement& lf) { return lf.size(); });
72 cls.def("size", [](const LocalFiniteElement& lf) { return lf.size(); });
73 cls.def_property_readonly("type", &LocalFiniteElement::type);
74
75 return cls;
76}
77
78
79} /* namespace Python */
80} /* namespace Dune */
81
82#endif
#define DUNE_EXPORT
std::ptrdiff_t index() const
DUNE_EXPORT auto registerLocalFiniteElement(pybind11::handle scope, const char *name="LocalFiniteElement")
Definition python/localfunctions/localfiniteelement.hh:62
Type erasure class storing a local finite element.
Definition localfunctions/common/localfiniteelement.hh:40
const Traits::LocalBasisType & localBasis() const
Access the LocalBasis of the stored local finite element.
Definition localfunctions/common/localfiniteelement.hh:156
unsigned int size() const
Get the number of basis functions of the stored local finite element.
Definition localfunctions/common/localfiniteelement.hh:188
const GeometryType & type() const
Get the GeometryType of the stored local finite element.
Definition localfunctions/common/localfiniteelement.hh:198
Describe position of one degree of freedom.
Definition localkey.hh:24
constexpr unsigned int index() const noexcept
Return offset within subentity.
Definition localkey.hh:70
constexpr unsigned int codim() const noexcept
Return codim of associated entity.
Definition localkey.hh:63
constexpr unsigned int subEntity() const noexcept
Return number of associated subentity.
Definition localkey.hh:56