Repository navigation
Conversation
Write and read linear tetrahedral meshes in openCARP's ASCII format: nodes (.pts), elements with region tags (.elem), fiber and sheet directions (.lon), and facet or vertex markers (.vtx, .surf). Everything is written in the input ordering and by rank 0, so the files do not depend on the number of processes. Tetrahedra are oriented with positive volume and .surf triangles point out of the mesh. Coordinates are converted to µm with a required scale factor. io4dolfinx.backends.opencarp.write_opencarp writes the mesh, tags and fibers in one call. To support this, MeshData, MeshTagsData and ArrayData get an on_input_mesh flag, and write_cell_data gets an on_input_mesh option that sends cell values to input cell order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like write_cell_data, write_point_data can now send node values in the node ordering of the input mesh, matching write_mesh_input_order. Both use a shared helper that moves values to the process holding their input index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kend Write and read Tr and Qd elements for 2D meshes and Hx elements for 3D meshes, besides Tt. Node orderings and orientations follow openCARP's mesher: counter-clockwise in 2D, positive volume in 3D, and hexahedra listing one face followed by the nodes opposite nodes 0, 3, 2 and 1. 2D meshes are written with z = 0 and read back with 2D coordinates and 2D fibers. Their markers are written as .vtx files only. Facet markers of hexahedral meshes are written as outward Qd faces in .surf files. Errors raised while reading chunks on some ranks are now raised on all ranks, so that no rank waits in a later collective call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
I'm not that keen on this new API entry point. Of course having the new Furthermore, I think this function belongs as a helper function somewhere else, rather than being part of the actual backend, as it is very specific..:P |
Remove io4dolfinx.backends.opencarp.write_opencarp. The backend module documentation now describes how to write a mesh, its tags and its fiber and sheet directions with write_mesh_input_order (or write_mesh), write_meshtags and write_cell_data. The backend accepts data in the DOLFINx ordering as well as the input ordering, as long as every step uses the same one. Only the input ordering gives files that do not depend on the number of processes. The on_input_mesh fields of MeshData, MeshTagsData and ArrayData are no longer needed and are removed. write_cell_data raises a clear error for functions in a quadrature space, which cannot be interpolated into DG-0. The openCARP tests run for both orderings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds an
opencarpbackend that writes and reads linear meshes in the ASCII mesh format of the cardiac simulator openCARP:<base>.ptsz = 0in 2D<base>.elem<base>.lon<base>_<marker>.vtx<base>_<marker>.surfTrorQdfacesio4dolfinx.backends.opencarp.write_opencarpwrites the mesh, tags and fibers in one call:Supported meshes: triangles (
Tr) and quadrilaterals (Qd) in 2D, tetrahedra (Tt) and hexahedra (Hx) in 3D, one element type per mesh.The same files can be written and read through the generic API with
backend="opencarp":write_mesh_input_order,write_meshtags,write_cell_data,read_mesh,read_meshtagsandread_cell_data.Design
Output does not depend on the number of processes. Nodes and elements use the input ordering (
input_global_indices,original_cell_index). Rank 0 gathers and writes everything, and the files are byte-identical on 1–4 ranks.Changes to existing code. Before this PR, cell data could not be passed to a backend in input order. This PR:
on_input_meshoption towrite_cell_data, usingexchange_to_owners;write_point_data, for other backends used withwrite_mesh_input_order(the openCARP backend does not write point data);on_input_mesh: bool = Falsefield toMeshData,MeshTagsDataandArrayData.The backend refuses data without the flag, so a
.lonfile cannot end up out of step with.elem. The defaults leave the other backends unchanged.Units: openCARP uses µm, so
scale(the factor converting mesh coordinates to µm) is required for both writing and reading. There is no default.Node order and orientation follow openCARP's own
mesher, checked against its output:Qdnodes are counter-clockwise, converted from dolfinx's tensor-product order.Hxlists one face (nodes 0–3), followed by the nodes opposite nodes 0, 3, 2 and 1..surffaces point out of the mesh and are written in a fixed order.2D meshes are written with
z = 0and read back with 2D coordinates. Fibers getz = 0in.lonand are read back with two components. Markers are written as.vtxfiles only, as the backend writes.surffiles only for the faces of 3D meshes. Reading rejects 2D elements that do not lie in a plane of constantz(surfaces in 3D).Fibers are interpolated to DG-0 and normalised. Quadrature-space fields are rejected with a clear error, because interpolating them into DG-0 fails in dolfinx 0.11.
.vtxheader isextraby default. openCARP 19 warns thatintrais wrong for indices into the whole mesh.Out of scope: binary formats, higher-order and mixed-type meshes, surface meshes in 3D, and
.igbsimulation output.Testing
tests/test_opencarp.pydoes not need openCARP. It runs serially and under MPI, for all four element types, and covers:Qd/Hxnode pattern,.vtxnodes on the right faces, outward.surfnormals with quadrilateral faces in cyclic order;COMM_WORLDwrite and aCOMM_SELFwrite;tests/test_write_data_input_order.pychecks, without any backend, thatwrite_point_dataandwrite_cell_datawithon_input_mesh=Truegive the same node and cell order and per-rank ranges aswrite_mesh_input_order. It covers tetrahedra and hexahedra and fails if the reordering is removed.All new tests pass serially and on 2, 3 and 4 ranks. The existing original-checkpoint, meshtags, VTKHDF, XDMF and backend tests also pass.
As a manual check, openCARP 19.0.0 (conda-forge) ran a short monodomain simulation on a mesh of each element type, written on 2 ranks. Each run used the region tags for the ionic model and a
.vtxfile as the stimulus. All runs finished with no errors or warnings and finite voltages, and activation spread from the stimulatedface to the opposite face. The.surffiles were not used by these runs.Docs
New page
docs/backends/opencarp.rst, with entries in_toc.ymland the README.🤖 Generated with Claude Code