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

Allow UFL element to be created from UFL cell #649

Closed
wants to merge 4 commits into from

Conversation

mscroggs
Copy link
Member

Fixes #648

@@ -1229,6 +1230,8 @@ def create_element(family: _typing.Union[_basix.ElementFamily, str], cell: _typi
gdim: The geometric dimension of the cell.

"""
if isinstance(cell, _ufl.cell.Cell):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could try/except be used here? Nice to avoid C++ style type checks if we can.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see a way to do it that isn't a complete mess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "complete mess" that would make it work:

try:
    cell = cell.cellname()
except:
    pass
try:
    cell = _basix.cell.string_to_type(cell)
except:
   pass

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we only accept a basix.CellType? A lot of merit to there being only one way to do something.

Copy link
Member Author

@mscroggs mscroggs Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_element is a convenience function in the UFL wrapper to make it more user friendly to create elements. I've aimed to make the interface of this function as similar to the current UFL FiniteElement constructor as possible and it saves most users from having to write garbage like:

element = basix.ufl_wrapper.BasixElement(basix.create_element(basix.ElementFamily.P, basix.CellType.triangle, 2, basix.LagrangeVariant.equispaced))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But potentially accepting strings is enough and we don't need this additional option for input

@mscroggs
Copy link
Member Author

Closing this as FEniCS/dolfinx#2604 is a better solution to this

@mscroggs mscroggs closed this Mar 29, 2023
@mscroggs mscroggs deleted the mscroggs/ufl-cell branch May 23, 2024 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow UFL element to be created from UFL cell
2 participants