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

Update basix.ufl.mixed_element factory function for case of a single element #882

Closed
wants to merge 6 commits into from
Closed
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
7 changes: 5 additions & 2 deletions python/basix/ufl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2229,12 +2229,15 @@ def mixed_element(elements: list[_ElementBase]) -> _ElementBase:
"""Create a UFL compatible mixed element from a list of elements.

Args:
elements: The list of elements
elements: List of elements.

Returns:
A mixed finite element.
"""
return _MixedElement(elements)
if len(elements) > 1:
return _MixedElement(elements)
else:
return elements[0]


def quadrature_element(
Expand Down
12 changes: 12 additions & 0 deletions test/test_ufl_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,23 @@ def test_enriched_element(elements):
"e,space0,space1",
[
(basix.ufl.element("Lagrange", basix.CellType.triangle, 2), "H1", basix.SobolevSpace.H1),
(
basix.ufl.mixed_element([basix.ufl.element("Lagrange", basix.CellType.triangle, 2)]),
"H1",
basix.SobolevSpace.H1,
),
(
basix.ufl.element("Discontinuous Lagrange", basix.CellType.triangle, 0),
"L2",
basix.SobolevSpace.L2,
),
(
basix.ufl.mixed_element(
[basix.ufl.element("Discontinuous Lagrange", basix.CellType.triangle, 0)]
),
"L2",
basix.SobolevSpace.L2,
),
(
basix.ufl.mixed_element(
[
Expand Down