-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support for tagged domains from legacy h5 files #17
Labels
dolfin-legacy
Issues related to reading data from legacy Dolfin files
enhancement
New feature or request
Comments
Are the meshes and markers in |
Sadly, the whole pipeline ends up with meshes that are in |
The following code can be used to read a facet tags from a tagged mesh (also works in parallel) import adios4dolfinx
import adios2
import numpy as np
comm = MPI.COMM_WORLD
# Mesh file in XDMF
with dolfinx.io.XDMFFile(comm, mesh_file, "r") as xdmf:
mesh = xdmf.read_mesh(name="mesh")
mesh.topology.create_connectivity(mesh.topology.dim, mesh.topology.dim-1)
adios = adios2.ADIOS(mesh.comm)
io_name = "ReadMeshFunction"
io = adios.DeclareIO(io_name)
io.SetEngine("HDF5")
# Read the corresponding H5File
file = io.Open(str(mesh_file.with_suffix(".h5")), adios2.Mode.Read)
file.BeginStep()
in_topology = io.InquireVariable("/MeshFunction/0/mesh/topology")
shape = in_topology.Shape()
local_cell_range = adios4dolfinx.comm_helpers.compute_local_range(comm, shape[0])
in_topology.SetSelection(
[[local_cell_range[0], 0], [local_cell_range[1] - local_cell_range[0], shape[1]]]
)
topology = np.empty(
(local_cell_range[1] - local_cell_range[0], shape[1]),
dtype=in_topology.Type().strip("_t"),
)
file.Get(in_topology, topology, adios2.Mode.Sync)
in_values = io.InquireVariable("/MeshFunction/0/values")
values = np.empty(local_cell_range[1] - local_cell_range[0], dtype=in_values.Type().strip("_t"))
in_values.SetSelection(
[[local_cell_range[0], 0], [local_cell_range[1] - local_cell_range[0], 1]]
)
file.Get(in_values, values, adios2.Mode.Sync)
file.EndStep()
file.Close()
adios.RemoveIO(io_name)
# Convert to int32
values = values.astype(np.int32)
local_entities, local_values = dolfinx.io.utils.distribute_entity_data(mesh, mesh.topology.dim - 1, topology, values)
adj = dolfinx.cpp.graph.AdjacencyList_int32(local_entities)
ct = dolfinx.mesh.meshtags_from_entities(mesh, mesh.topology.dim - 1, adj, local_values.astype(np.int32, copy=False))
ct.name = "Facet tags"
# Save for visualization in paraview
mesh.topology.create_connectivity(mesh.topology.dim - 1, mesh.topology.dim)
with dolfinx.io.XDMFFile(mesh.comm, "ffun.xdmf", "w") as xdmf:
xdmf.write_mesh(mesh)
xdmf.write_meshtags(ct, mesh.geometry) |
Thanks a lot @finsberg ! |
jorgensd
changed the title
Support for tagged domains
Support for tagged domains from legacy h5 files
Mar 1, 2024
jorgensd
added
the
dolfin-legacy
Issues related to reading data from legacy Dolfin files
label
Mar 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
dolfin-legacy
Issues related to reading data from legacy Dolfin files
enhancement
New feature or request
Question:
Is it planned to allow reading meshes that include marked boundaries?
I would guess something along the lines:
Context:
My group's workflow uses tagged meshes (coming from a segmentation procedure from MRI images). We are in the process of updating all our codebase to
dolfinx
, but still many meshes are in the legacyh5
format.The text was updated successfully, but these errors were encountered: