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 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 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,14 @@ def dtype(self) -> np.dtype:
"""Geometry type of the Mesh that the FunctionSpace is defined on."""
return self._cpp_object.dtype

@property
@cached_property
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.
"""
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: 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