Repository navigation
Add openCARP backend #93
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
Open
finsberg
wants to merge
8
commits into
main
Choose a base branch
from
finsberg/opencarp-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0b8ad6
Add openCARP backend
finsberg f473e09
Fix mypy
finsberg 786766e
Add on_input_mesh option to write_point_data
finsberg d073dcc
Support triangle, quadrilateral and hexahedral meshes in openCARP bac…
finsberg 682c777
Fix return type of orientation helper in openCARP tests
finsberg f218d9b
Write openCARP files with the generic API in either ordering
finsberg a043513
Fix openCARP marker files and share input-order redistribution
finsberg d54b952
Link to the openCARP examples repository in the docs
finsberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| .. _opencarpbackend: | ||
|
|
||
| openCARP-backend | ||
| ---------------- | ||
|
|
||
| Writes and reads linear meshes in the ASCII mesh format of the cardiac simulator | ||
| `openCARP <https://opencarp.org>`_: node coordinates (``.pts``), elements with region tags | ||
| (``.elem``), fiber and sheet directions per element (``.lon``), and markers as vertex (``.vtx``) | ||
| and surface (``.surf``) files. The backend needs no extra dependencies. | ||
|
|
||
| The mesh, its tags and its fiber and sheet directions are written with | ||
| :func:`io4dolfinx.write_mesh_input_order` (or :func:`io4dolfinx.write_mesh`), | ||
| :func:`io4dolfinx.write_meshtags` and :func:`io4dolfinx.write_cell_data`, as shown in the module | ||
| documentation below. Rank 0 writes all files. openCARP expects coordinates in µm, so the factor | ||
| converting the mesh coordinates to µm must always be given as ``backend_args["scale"]``. | ||
|
|
||
| With ``markers={"ENDO": (1, 2), "EPI": (2, 2)}``, a heart mesh gives ``heart.pts``, | ||
| ``heart.elem``, ``heart.lon``, ``heart_ENDO.vtx``, ``heart_ENDO.surf``, ``heart_EPI.vtx`` and | ||
| ``heart_EPI.surf``, and ``heart.markers.json`` with the name, value and dimension of each marker. | ||
| Writing the mesh again removes the ``.lon`` and marker files of the old mesh, and writing facet tags | ||
| again replaces the facet markers. | ||
|
|
||
| - Triangle (``Tr``) and quadrilateral (``Qd``) meshes in 2D, and tetrahedral (``Tt``) and hexahedral | ||
| (``Hx``) meshes in 3D are supported. 2D meshes are written with ``z = 0``, and read back with 2D | ||
| coordinates. 2D meshes with 3D coordinates in a plane of constant ``z`` are also written. | ||
| - Elements get the orientation used by openCARP's ``mesher``: positive volume in 3D, | ||
| counter-clockwise in 2D. | ||
| - Cells without a cell tag get region ``0`` (set ``backend_args={"default_tag": ...}`` to change it). | ||
| - Fibers and sheets are interpolated into cell midpoints and normalised. 2D directions get | ||
| ``z = 0``, and are read back with two components. Fields in a quadrature space cannot be | ||
| written; generate them in a P-1 or DG-0 space. | ||
| - Each facet marker value gets a ``.vtx`` file with its nodes and, for 3D meshes, a ``.surf`` file | ||
| with its facets (``Tr`` or ``Qd``), oriented out of the mesh. A facet between two elements | ||
| points out of the element whose centre comes first in lexicographic ``(x, y, z)`` order. The files | ||
| are named from ``markers``, or by the value if it has no name; values that would give the same | ||
| file name are rejected. | ||
| Pass ``backend_args={"surf": False}`` to skip the ``.surf`` files. | ||
|
|
||
| Reading takes the path of any of the mesh files. Coordinates are divided by ``scale``: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| args = {"scale": 1000.0, "markers": {"ENDO": (1, 2), "EPI": (2, 2)}} | ||
| mesh = io4dolfinx.read_mesh("heart.elem", MPI.COMM_WORLD, backend="opencarp", backend_args=args) | ||
| regions = io4dolfinx.read_meshtags("heart.elem", mesh, "cell", backend="opencarp") | ||
| facets = io4dolfinx.read_meshtags("heart.elem", mesh, "facet", backend="opencarp", backend_args=args) | ||
| endo = io4dolfinx.read_meshtags("heart.elem", mesh, "ENDO", backend="opencarp", backend_args=args) | ||
| f0 = io4dolfinx.read_cell_data("heart.elem", "fiber", mesh, backend="opencarp") | ||
|
|
||
| ``"facet"`` reads the ``.surf`` files of the facet markers listed in ``heart.markers.json``, with | ||
| their values. A marker name reads its ``.surf`` file, or its ``.vtx`` file as vertex tags if there is | ||
| no ``.surf`` (as for 2D meshes). This also works for marker files written by other tools; their value | ||
| is taken from ``markers``, else from the name if it is an integer, else it is ``1``. | ||
|
|
||
| Examples that write a mesh with this backend, run openCARP on it and read the results back (a planar | ||
| wave in a square, and the Niederer et al. (2011) benchmark) are in | ||
| `opencarp-io4dolfinx-example <https://github.com/finsberg/opencarp-io4dolfinx-example>`_. | ||
|
|
||
| .. automodule:: io4dolfinx.backends.opencarp.backend | ||
| :members: | ||
| :exclude-members: read_attributes, read_timestamps, write_attributes, read_dofmap, read_dofs, read_cell_perms, write_function, read_legacy_mesh, snapshot_checkpoint, read_hdf5_array, read_point_data | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from . import backend | ||
|
|
||
| __all__ = ["backend"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need both?:P