Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python wrapper for FiniteElement.basix_element #3624

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions python/dolfinx/fem/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""Finite elements."""

import typing
from functools import singledispatch
from functools import cached_property, singledispatch

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -189,14 +189,18 @@ def dtype(self) -> np.dtype:
"""Geometry type of the Mesh that the FunctionSpace is defined on."""
return self._cpp_object.dtype

@property
@cached_property
schnellerhase marked this conversation as resolved.
Show resolved Hide resolved
def basix_element(self) -> basix.finite_element.FiniteElement:
"""Return underlying Basix C++ element (if it exists).

Raises:
Runtime error if Basix element does not exist.

Note:
Cached property: Wrapper constructed on initial call and not updated on subsequent
calls.
"""
return self._cpp_object.basix_element
return basix.finite_element.FiniteElement(self._cpp_object.basix_element)

@property
def num_sub_elements(self) -> int:
Expand Down
7 changes: 6 additions & 1 deletion python/dolfinx/fem/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,12 @@ def ufl_function_space(self) -> ufl.FunctionSpace:

@cached_property
def element(self) -> FiniteElement:
"""Function space finite element."""
"""Function space finite element.

Note:
Cached property: Wrapper constructed on initial call and not updated on subsequent
calls.
"""
return FiniteElement(self._cpp_object.element)

@property
Expand Down
7 changes: 2 additions & 5 deletions python/test/unit/fem/test_function_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,11 @@ def test_cell_mismatch(mesh):
@pytest.mark.skipif(default_real_type != np.float64, reason="float32 not supported yet")
def test_basix_element(V, W, Q, V2):
for V_ in (V, W, V2):
e = V_.element.basix_element
assert isinstance(
e, (basix._basixcpp.FiniteElement_float64, basix._basixcpp.FiniteElement_float32)
)
assert isinstance(V_.element.basix_element, basix.finite_element.FiniteElement)

# Mixed spaces do not yet return a basix element
with pytest.raises(RuntimeError):
e = Q.element.basix_element
_ = Q.element.basix_element


@pytest.mark.skip_in_parallel
Expand Down
Loading