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 create_entity_markers function #34

Merged
merged 8 commits into from
Sep 24, 2024
Merged

Add create_entity_markers function #34

merged 8 commits into from
Sep 24, 2024

Conversation

jorgensd
Copy link
Member

Convenience function for creating meshtags based of python functions.

Based of what @bleyerj suggested in #26.

I've modified it slightly:

  • added some notes on duplicate markers
  • added on_boundary option.
  • type-hints

Added a demo to highlight how to use it and visualize meshtags with pyvista.

@jorgensd jorgensd requested a review from finsberg September 22, 2024 20:27
@finsberg
Copy link
Member

finsberg commented Sep 23, 2024

Thanks this look great! Another option here is to pass the entities as a list of dictionaries so that the user can have entities both with and without on_boundary=True, e.g

entities = [
    {"id": 1, "locator": left, "on_boundary": True},
    {"id": 2, "locator": right, "on_boundary": False},
]

Now, to type this we could use a TypedDict, e.g

import typing

class Tag(typingTypedDict):
    id: int
    locator: typing.Callable[[npt.NDArray[np.floating]], npt.NDArray[np.bool_]]
    on_bounary: bool


entities: list[Tag]

BTW, I solved this using a NamedTuple in fenicsx-pulse, see https://github.com/finsberg/fenicsx-pulse/blob/6c5b8fa4c05352589c7158ec13f6c844aa162abc/src/fenicsx_pulse/geometry.py#L32, but I think a dictionary is probably better since you don't need to import any extra stuff.

@jorgensd
Copy link
Member Author

Thanks this look great! Another option here is to pass the entities as a list of dictionaries so that the user can have entities both with and without on_boundary=True, e.g

entities = [
    {"id": 1, "locator": left, "on_boundary": True},
    {"id": 2, "locator": right, "on_boundary": False},
]

Now, to type this we could use a TypedDict, e.g

import typing

class Tag(typingTypedDict):
    id: int
    locator: typing.Callable[[npt.NDArray[np.floating]], npt.NDArray[np.bool_]]
    on_bounary: bool


entities: list[Tag]

BTW, I solved this using a NamedTuple in fenicsx-pulse, see https://github.com/finsberg/fenicsx-pulse/blob/6c5b8fa4c05352589c7158ec13f6c844aa162abc/src/fenicsx_pulse/geometry.py#L32, but I think a dictionary is probably better since you don't need to import any extra stuff.

I am fine with that as long as we keep the complexity of the input arguments relatively low.

Do you want to make these adaptations and make a test?
@bleyerj what do you think?

@finsberg
Copy link
Member

Instead of using dictionaries we have now using tuples instead, where the elements are (tag, locator, on_boundary), with on_boundary being optional.

@jorgensd jorgensd changed the title Add create_meshtags function Add create_entity_markers function Sep 24, 2024
@jorgensd jorgensd merged commit 4595137 into main Sep 24, 2024
8 checks passed
@finsberg finsberg deleted the dokken/create_meshtags branch November 20, 2024 11:03
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.

2 participants