MED-backend#

Reads meshes and mesh tags from MED files, as exported by Salome and Code_Aster. The backend is read-only and relies on h5py, which must be MPI compatible to read in parallel (see the H5PY backend).

In a MED file each entity stores a family id, and each family lists the named groups it belongs to. An entity in several groups gets a family of its own for that combination of groups. Mesh tags can be read in two ways:

  • meshtag_name="cell" or meshtag_name="facet" returns the family ids of the cells or facets (entities without a family are skipped). MED element family ids are negative, while integral subdomain ids must be non-negative, so the ids are negated: family -6 gives tag 6.

  • Any other meshtag_name is a group name, and returns the entities of that group tagged with 1.

mesh = io4dolfinx.read_mesh("mesh.med", MPI.COMM_WORLD, backend="med")
facet_families = io4dolfinx.read_meshtags("mesh.med", mesh, meshtag_name="facet", backend="med")
inlet = io4dolfinx.read_meshtags("mesh.med", mesh, meshtag_name="inlet", backend="med")

Use io4dolfinx.backends.med.backend.read_groups() to list the groups and their family ids. If a file holds several meshes, select one with mesh_name.

A time-dependent mesh stores one step per time. Select the step with time when reading the mesh, and with backend_args={"time": t} when reading its tags (the first step is used if no time is given). A mesh with a single step is read whatever the time.

mesh = io4dolfinx.read_mesh("mesh.med", MPI.COMM_WORLD, backend="med", time=0.5)
cells = io4dolfinx.read_meshtags(
    "mesh.med", mesh, meshtag_name="cell", backend="med", backend_args={"time": 0.5}
)

The cells must be of a single type. Linear and quadratic Lagrange cells (SE3, TR6, QU9, T10, P18, H27) and the quadratic serendipity cells QU8 and H20 are supported. The serendipity cells require the main branch of DOLFINx. MED node orderings are converted with tables derived from MEDCoupling’s MED cell model.

MED interface to io4dolfinx.

MED is the HDF5 based mesh format of Salome and Code_Aster. See https://docs.salome-platform.org/latest/dev/MEDCoupling/developer/med-file.html

Families and groups, in DOLFINx terms:

  • Every entity stores one family id (MAI/<type>/FAM for elements, negative; NOE/FAM for nodes, positive; 0 for none). Per element type, these ids are the values of a dolfinx.mesh.MeshTags, with family 0 meaning untagged.

  • FAS/<mesh> maps each family id to the named groups it belongs to, which MeshTags has no equivalent of.

  • A family is one combination of groups, so overlapping groups (an entity in both inlet and wall) get a family of their own. A group is the union of its families, read as a separate MeshTags with value 1.

Element family ids are negated when read, as integral subdomain ids in DOLFINx/FFCx must be non-negative.

SPDX License identifier: MIT

Copyright: Jørgen S. Dokken and Simula Research Laboratory

io4dolfinx.backends.med.backend.geometry_layout(med_type: str) → tuple[CellType, int, bool][source]#

Get the coordinate element layout of a MED element type.

Parameters:

med_type – MED element type, e.g. "T10"

Returns:

  • The DOLFINx cell type

  • The degree of the coordinate element

  • True if the coordinate element is the nodal serendipity element (QU8, H20), False if it is Lagrange

Return type:

Tuple containing

io4dolfinx.backends.med.backend.get_mesh_step_and_families(h5file: File, filename: Path | str, backend_args: dict[str, Any] | None, time: str | float | None) → tuple[Group, Group][source]#

Get the groups holding the nodes, connectivity and families of a mesh.

In DOLFINx terms, NOE (nœuds) holds the geometry nodes, i.e. the coordinates in mesh.geometry.x, and MAI (mailles) the connectivity: one block per element type, listing the nodes of each cell, facet, edge or point element.

A time-dependent mesh has one group per computation step, named by its step and iteration numbers so that the names sort in time order. A step only stores data that changed, and links to the earlier step for the rest.

Parameters:
  • h5file – The MED file

  • filename – Path to the file, used in error messages

  • backend_args – Arguments to backend. "name" selects the mesh; if it is not given and the file holds a single mesh, that mesh is used.

  • time – Time of the step to read. Ignored for a mesh with a single step, and None selects the first step.

Returns:

  • The step group, holding NOE and MAI

  • The families of the mesh (FAS/<mesh>)

Return type:

Tuple containing

io4dolfinx.backends.med.backend.num_entities(block: Group) → int[source]#

Get the global number of entities of one MED element type.

Parameters:

block – Connectivity block of the element type (MAI/<med_type>)

Returns:

The number of entities, stored as the NBR attribute of the connectivity

io4dolfinx.backends.med.backend.read_entities(element_blocks: Group, dim: int, comm: Comm) → tuple[str, list[int], ndarray[tuple[Any, ...], dtype[int64]]] | None[source]#

Read the entities of one topological dimension, distributed over all processes.

Parameters:
  • element_blocks – The group holding one connectivity block per element type (MAI in the MED file)

  • dim – Topological dimension of the entities

  • comm – MPI communicator to distribute the entities over

Returns:

None if the mesh has no entities of dimension dim, otherwise a tuple containing:

  • The MED element type of the entities, e.g. "TR3"

  • The range [start, end) of entities read on this process

  • Their connectivity as global input node indices in DOLFINx node order, of shape (end - start, num_nodes_per_entity)

io4dolfinx.backends.med.backend.read_entity_families(block: Group, local_range: list[int]) → ndarray[tuple[Any, ...], dtype[int32]][source]#

Read the family id of each entity of one MED element type on this process.

Each entity has exactly one family, so this is a tag value per entity. Which groups a family belongs to is read with read_family_groups().

Parameters:
  • block – Connectivity block of the element type (MAI/<med_type>)

  • local_range – Range [start, end) of entities to read on this process

Returns:

Family ids of shape (end - start,). A block without FAM has every entity in family 0, i.e. in no group.

io4dolfinx.backends.med.backend.read_family_groups(families: Group, kind: Literal['ELEME', 'NOEUD']) → dict[int, list[str]][source]#

Read which named groups each family of a mesh belongs to.

A family is one combination of groups, so one family can belong to several groups. The family of each entity is read with read_entity_families().

Parameters:
  • families – The families of the mesh (FAS/<mesh>)

  • kind – "ELEME" (éléments) for element families, "NOEUD" (nœuds) for node families

Returns:

Map from family id to the names of its groups. Empty if the mesh has no groups of this kind, in which case MED does not write kind.

io4dolfinx.backends.med.backend.read_groups(filename: Path | str, comm: Comm, backend_args: dict[str, Any] | None = None) → dict[str, list[int]][source]#

Read the element groups of a MED mesh and the families that make them up.

Use this to find the group names accepted by read_meshtags_data(), or to decode the (negated) family ids returned for "cell" and "facet".

Parameters:
  • filename – Path to file

  • comm – MPI communicator used in storage

  • backend_args – Arguments to backend, "name" selects the mesh

Returns:

Map from group name to the negated family ids that belong to the group

io4dolfinx.backends.med.backend.read_mesh_data(filename: Path | str, comm: Comm, time: str | float | None = 0.0, read_from_partition: bool = False, backend_args: dict[str, Any] | None = None) → ReadMeshData[source]#

Read mesh data from a MED file.

Only cells of the highest topological dimension are read; these must all be of the same type. Lagrange layouts up to degree 2 (e.g. TR6, T10, H27) and the serendipity QU8 and H20 are supported. Node and cell data is read in contiguous chunks on each process.

Parameters:
  • filename – Path to input file

  • comm – The MPI communciator to distribute the mesh over

  • time – Time of the step to read from a time-dependent mesh. Ignored for a mesh with a single step, and None selects the first step.

  • read_from_partition – Read mesh with partition from file (not supported)

  • backend_args – Arguments to backend, "name" selects the mesh

Returns:

The mesh topology, geometry, UFL domain and partition function

io4dolfinx.backends.med.backend.read_meshtags_data(filename: str | Path, comm: Comm, name: str, backend_args: dict[str, Any] | None = None) → MeshTagsData[source]#

Read mesh tags from a MED file.

Parameters:
  • filename – Path to file to read from

  • comm – MPI communicator used in storage

  • name – "cell" or "facet" for the entities of the highest topological dimension or one below, otherwise the name of a MED group (see read_groups())

  • backend_args – Arguments to backend, "name" selects the mesh and "time" the step of a time-dependent mesh (the first step if not given)

Returns:

Internal data structure for the mesh tags read from file. For "cell" and "facet", each entity is tagged with its negated MED family id, and entities without a family (id 0) are skipped. For a group, its entities are tagged with 1.