Hello,
I’m learing how to use FESTIM and currently working on Workshop 8. I downloaded the mesh.med file from GitHub, but when I run the script, it doesn’t work.
Here’s the code I’m using:
Import meshio
def convert_med_to_xdmf(
med_file,
cell_file="mesh_domains.xdmf",
facet_file="mesh_boundaries.xdmf",
cell_type="tetra",
facet_type="triangle",
):
"""Converts a MED mesh to XDMF
Args:
med_file (str): the name of the MED file
cell_file (str, optional): the name of the file containing the
volume markers. Defaults to "mesh_domains.xdmf".
facet_file (str, optional): the name of the file containing the
surface markers.. Defaults to "mesh_boundaries.xdmf".
cell_type (str, optional): The topology of the cells. Defaults to "tetra".
facet_type (str, optional): The topology of the facets. Defaults to "triangle".
Returns:
dict, dict: the correspondance dict, the cell types
"""
msh = meshio.read(med_file)
correspondance_dict = msh.cell_tags
cell_data_types = msh.cell_data_dict["cell_tags"].keys()
for mesh_block in msh.cells:
if mesh_block.type == cell_type:
meshio.write_points_cells(
cell_file,
msh.points,
[mesh_block],
cell_data={"f": [-1 * msh.cell_data_dict["cell_tags"][cell_type]]},
)
elif mesh_block.type == facet_type:
meshio.write_points_cells(
facet_file,
msh.points,
[mesh_block],
cell_data={"f": [-1 * msh.cell_data_dict["cell_tags"][facet_type]]},
)
return correspondance_dict, cell_data_types
correspondance_dict, cell_data_types = convert_med_to_xdmf("mesh.med", cell_file="mesh_domains.xdmf", facet_file="mesh_boundaries.xdmf")
print(correspondance_dict)
However, I get the following error:
File "/home/ndrea_i_aio/festim/CAD integration.py", line 47, in <module>
correspondance_dict, cell_data_types = convert_med_to_xdmf("mesh.med", cell_file="mesh_domains.xdmf", facet_file="mesh_boundaries.xdmf")
File "/home/ndrea_i_aio/festim/CAD integration.py", line 27, in convert_med_to_xdmf
cell_data_types = msh.cell_data_dict["cell_tags"].keys()
KeyError: 'cell_tags'
How can I solve this issue?
Thank you in advance!