Error when importing a mesh from mshr

Hello,
I followed the instructions in this post to convert a .msh file generated with mshr into a .py script that I want to use with Fenics. In the script.py file, I have

from __future__ import print_function
from fenics import *
from mshr import *
import matplotlib.pyplot as plt
import meshio


msh = meshio.read("t1.msh")
meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points, cells={"tetra": msh.cells["tetra"]}))
meshio.write("mf.xdmf", meshio.Mesh(points=msh.points, cells={"triangle": msh.cells["triangle"]},
                                    cell_data={"triangle": {"name_to_read": msh.cell_data["triangle"]["gmsh:physical"]}}))

[...]

however, I get the following error

$  python3 script.py 
Traceback (most recent call last):
  File "script.py", line 21, in <module>
    meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points, cells={"tetra": msh.cells["tetra"]}))
TypeError: list indices must be integers or slices, not str

Also, here is the .msh file

May you please tell me what I am doing wrong ?
Thanks

You are clearly not following the post

as it uses


def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    out_mesh = meshio.Mesh(points=mesh.points, cells={
                           cell_type: cells}, cell_data={"name_to_read": [cell_data]})
    if prune_z:
        out_mesh.prune_z_0()
    return out_mesh

not

Please also note that this is not a mshr issue, but a meshio API issue.
Please also note that you are looking at a 3 year old post, and should probably be looking at:

instead.

The code in the post that you suggested prompts a lot of errors too.
Do you have a working example of how to read a .msh file into a python script and generate a mesh to use in fenics?

Thank you

See: Mesh generation and conversion with GMSH and PYGMSH | Jørgen S. Dokken

Please note that you are not showing the code or errors you are getting, so it is getting trickier to give any guidance.

Thank you for your reply, I went to the link that you suggested, but cannot even set up the docker image, I get the following error

 %  docker run -v $(pwd):/root/shared -ti -w "/root/shared" --rm ghcr.io/jorgensd/jorgensd.github.io:main

[I 2024-03-21 13:44:46.956 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2024-03-21 13:44:46.958 ServerApp] jupyterlab | extension was successfully linked.
[I 2024-03-21 13:44:46.958 ServerApp] jupytext | extension was successfully linked.
[I 2024-03-21 13:44:46.959 ServerApp] nbclassic | extension was successfully linked.
[I 2024-03-21 13:44:46.959 ServerApp] Writing Jupyter server cookie secret to /root/.local/share/jupyter/runtime/jupyter_cookie_secret
[I 2024-03-21 13:44:47.031 ServerApp] notebook_shim | extension was successfully linked.
[I 2024-03-21 13:44:47.037 ServerApp] notebook_shim | extension was successfully loaded.
[I 2024-03-21 13:44:47.038 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2024-03-21 13:44:47.038 LabApp] JupyterLab extension loaded from /usr/local/lib/python3.10/dist-packages/jupyterlab
[I 2024-03-21 13:44:47.038 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab
[I 2024-03-21 13:44:47.039 ServerApp] jupyterlab | extension was successfully loaded.
[W 2024-03-21 13:44:47.039 ServerApp] [Jupytext Server Extension] Async contents managers like AsyncLargeFileManager are not supported at the moment (https://github.com/mwouts/jupytext/issues/1020). We will derive a contents manager from LargeFileManager instead.
[I 2024-03-21 13:44:47.039 ServerApp] [Jupytext Server Extension] Deriving a JupytextContentsManager from LargeFileManager
[I 2024-03-21 13:44:47.039 ServerApp] jupytext | extension was successfully loaded.
[I 2024-03-21 13:44:47.040 ServerApp] nbclassic | extension was successfully loaded.
[I 2024-03-21 13:44:47.040 ServerApp] Serving notebooks from local directory: /root/shared
[I 2024-03-21 13:44:47.040 ServerApp] Jupyter Server 2.0.5 is running at:
[I 2024-03-21 13:44:47.040 ServerApp] http://910bf87e7de2:8888/lab?token=be38a068c037bfc887191d12bbb8f86a7ca3dae68d063713
[I 2024-03-21 13:44:47.040 ServerApp]  or http://127.0.0.1:8888/lab?token=be38a068c037bfc887191d12bbb8f86a7ca3dae68d063713
[I 2024-03-21 13:44:47.040 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2024-03-21 13:44:47.041 ServerApp] 
    
    To access the server, open this file in a browser:
        file:///root/.local/share/jupyter/runtime/jpserver-1-open.html
    Or copy and paste one of these URLs:
        http://910bf87e7de2:8888/lab?token=be38a068c037bfc887191d12bbb8f86a7ca3dae68d063713
     or http://127.0.0.1:8888/lab?token=be38a068c037bfc887191d12bbb8f86a7ca3dae68d063713



After these lines, everything is stuck and nothing happens, I don’t know what to do.
If I paste any of the URLs in my browser, nothing happens, I get the error message ‘Unable to reach site’

I feel like you are deviating from the actual error. What i was asking you to have a look at was how to use create_mesh, as referenced in the post, not how to use the docker images.

None of my docker images will have mshr in them, as it is deprecated, as mentioned before. To run legacy dolfin in a docker container without mshr, you should for instance use:

 docker run -v $(pwd):/root/shared -ti -w "/root/shared" --rm  ghcr.io/scientificcomputing/fenics-gmsh:2024-02-19