The kernel appears to have died. It will restart automatically

Dears
I have a problem when I try to read mesh in fenics from Gmsh file:

I don’t understand the problem
could you help me please!

In the code you have in the background of the screenshot you do not use any functions from dolfin.

For the post to be relevant for the forum and follow the guidelines, please follow Read before posting: How do I get my question answered?

I’m so sorry to post the screenshot!
However my problem is written following:
Firstly, the mesh was created using Gmsh and recorded in the Untitle.msh with the geometry:
//+
Point(1) = {0, 0, 0, 1.0};
//+
Point(2) = {25, 0, 0, 1.0};
//+
Point(3) = {25, 1, 0, 1.0};
//+
Point(4) = {0, 1, 0, 1.0};
//+
Line(1) = {1, 2};
//+
Line(2) = {2, 3};
//+
Line(3) = {3, 4};
//+
Line(4) = {4, 1};
//+
Curve Loop(1) = {3, 4, 1, 2};
//+
Plane Surface(1) = {1};
//+
Physical Curve(“botside”, 1) = {1};
//+
Physical Curve(“rightside”, 2) = {2};
//+
Physical Curve(“upside”, 3) = {3};
//+
Physical Curve(“leftside”, 4) = {4};
//+
Physical Surface(“Dam1”, 5) = {1};

Then, It was convert to file.xdmf as following code:

from dolfin import *

import meshio
msh = meshio.read(“untitled.msh”)
meshio.write(“mesh.xdmf”, meshio.Mesh(points=msh.points, cells={“triangle”: msh.cells[“triangle”]}))
meshio.write(“mf.xdmf”, meshio.Mesh(points=msh.points, cells={“line”: msh.cells[“line”]}, cell_data={“line”: {“name_to_read”: msh.cell_data[“line”][“gmsh:physical”]}}))

However, there is an error type like that:
TypeError Traceback (most recent call last)
in
3 import meshio
4 msh = meshio.read(“untitled.msh”)
----> 5 meshio.write(“mesh.xdmf”, meshio.Mesh(points=msh.points, cells={“triangle”: msh.cells[“triangle”]}))
6 meshio.write(“mf.xdmf”, meshio.Mesh(points=msh.points, cells={“line”: msh.cells[“line”]}, cell_data={“line”: {“name_to_read”: msh.cell_data[“line”][“gmsh:physical”]}}))

TypeError: list indices must be integers or slices, not str

Could you please help me to solve this problem
Best regards

You have changed your code from the screenshot. In your current code, you try to access:

which is not what you had in your original code.
Note that msh.cells is not a dictionary:

In [2]: msh.cells
Out[2]: 
[<meshio CellBlock, type: line, num cells: 25, tags: []>,
 <meshio CellBlock, type: line, num cells: 1, tags: []>,
 <meshio CellBlock, type: line, num cells: 25, tags: []>,
 <meshio CellBlock, type: line, num cells: 1, tags: []>,
 <meshio CellBlock, type: triangle, num cells: 100, tags: []>]

As a side note, please use markdown syntax for formatting code or input/output, i.e.

```python
Add your code here
```
```bash
Add your terminal output here
```

My old code on screenshot was:

import meshio
import numpy
from dolfin import *
msh = meshio.read("Square.msh")

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

line_mesh = create_mesh(msh, "line", prune_z=True)
meshio.write("mf.xdmf", line_mesh)

triangle_mesh = create_mesh(msh, "triangle", prune_z=True)
meshio.write("mesh.xdmf", triangle_mesh)


mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
    infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 1)

with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
File("dolfinmesh.pvd").write(mesh)
File("dolfincellfunc.pvd").write(mf)

The output with error is following:

![image|690x431](upload://620UvyPAtR7tqnAWkle0SJntMJD.png)



The Square.geo is following:
//+
Point(1) = {0, 0, 0, 1.0};
//+
Point(2) = {5, 0, 0, 1.0};
//+
Point(3) = {5, 5, 0, 1.0};
//+
Point(4) = {0, 5, 0, 1.0};
//+
Line(1) = {1, 2};
//+
Line(2) = {2, 3};
//+
Line(3) = {3, 4};
//+
Line(4) = {4, 1};
//+
Curve Loop(1) = {3, 4, 1, 2};
//+
Plane Surface(1) = {1};
//+
Physical Curve(“botside”, 5) = {1};
//+
Physical Curve(“rightside”, 6) = {2};
//+
Physical Curve(“upside”, 7) = {3};
//+
Physical Curve(“leftside”, 8) = {4};
//+
Physical Surface(“fluid”, 9) = {1};

Your code is using an outdated version of the create_mesh script as prune_z_0 no longer exists in meshio, see: Need help converting GMSH to FEniCS - #61 by dokken

So can I solve this problem?

As referred to in the link I’ve already provided, you can use

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)
    points = mesh.points
    if prune_z:
        points = mesh.points[:,:2]
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
    return out_mesh

I’ve just try with your provided code. However, there is still the same problem

I rewrite my code as following, however the same error happens again:

```python
import meshio
import numpy
from dolfin import *



mesh = meshio.read("Square.msh")

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)
    points = mesh.points
    if prune_z:
        points = mesh.points[:,:2]
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
    return out_mesh

line_mesh = create_mesh(mesh, "line", prune_z=True)
meshio.write("facet_mesh.xdmf", line_mesh)

triangle_mesh = create_mesh(mesh, "triangle", prune_z=True)
meshio.write("mesh.xdmf", triangle_mesh)

I cannot reproduce this with:

import meshio
import numpy
from dolfin import *


mesh = meshio.read("Square.msh")


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)
    points = mesh.points
    if prune_z:
        points = mesh.points[:, :2]
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={
                           "name_to_read": [cell_data]})
    return out_mesh


line_mesh = create_mesh(mesh, "line", prune_z=True)
meshio.write("facet_mesh.xdmf", line_mesh)

triangle_mesh = create_mesh(mesh, "triangle", prune_z=True)
meshio.write("mesh.xdmf", triangle_mesh)

Geo file

//+
Point(1) = {0, 0, 0, 1.0};
//+
Point(2) = {25, 0, 0, 1.0};
//+
Point(3) = {25, 1, 0, 1.0};
//+
Point(4) = {0, 1, 0, 1.0};
//+
Line(1) = {1, 2};
//+
Line(2) = {2, 3};
//+
Line(3) = {3, 4};
//+
Line(4) = {4, 1};
//+
Curve Loop(1) = {3, 4, 1, 2};
//+
Plane Surface(1) = {1};
//+
Physical Curve("botside", 1) = {1};
//+
Physical Curve("rightside", 2) = {2};
//+
Physical Curve("upside", 3) = {3};
//+
Physical Curve("leftside", 4) = {4};
//+
Physical Surface("Dam1", 5) = {1};

Environment:

docker run -ti --network=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $(pwd):/fenics/shared -w /fenics/shared --rm --shm-size=512m quay.io/fenicsproject/dev:latest
python -m pip install --no-binary=h5py h5py meshio

So, what wrong with my code?

As you have not provided how you installed meshio, h5py or Gmsh, I cannot give you any further pointers.

As I also mentioned earlier, this has nothing to do with dolfin, as you only use meshio and gmsh, and should consider contacting the developers of meshio on their GitHub.

to install meshio, h5py and Gmsh, I run the following command via docker:
pip install --user meshio
pip install --user h5py
pip install --user Gmsh

What docker image are you using?
As a side note, you should not install the binary of h5py if it is based on either dolfin or dolfinx, as I showed above by calling:

Yes, I did not install the binary of h5py by calling:

pip install --no-binary=h5py h5py meshio

and the output is:

Requirement already satisfied: h5py in /home/fenics/.local/lib/python3.6/site-packages (3.1.0)
Requirement already satisfied: meshio in /home/fenics/.local/lib/python3.6/site-packages (4.4.6)
Requirement already satisfied: cached-property; python_version < "3.8" in /home/fenics/.local/lib/python3.6/site-packages (from h5py) (1.5.2)
Requirement already satisfied: numpy>=1.12; python_version == "3.6" in /usr/lib/python3/dist-packages (from h5py) (1.13.3)
Requirement already satisfied: importlib-metadata; python_version < "3.8" in /usr/local/lib/python3.6/dist-packages (from meshio) (1.3.0)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/dist-packages (from importlib-metadata; python_version < "3.8"->meshio) (0.6.0)
Requirement already satisfied: more-itertools in /usr/local/lib/python3.6/dist-packages (from zipp>=0.5->importlib-metadata; python_version < "3.8"->meshio) (8.0.2)
WARNING: You are using pip version 19.3.1; however, version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Note: you may need to restart the kernel to use updated packages.
but the problem still happened

You need to first uninstall your current version of h5py before trying to reinstall it

Thank you for your helps
however, I tried to uninstall h5py via docker by following command:

pip uninstall h5py

and the out put is:

Uninstalling h5py-3.1.0:
  Would remove:
    /home/fenics/.local/lib/python3.6/site-packages/h5py-3.1.0.dist-info/*
    /home/fenics/.local/lib/python3.6/site-packages/h5py.libs/libaec-9c9e97eb.so.0.0.10
    /home/fenics/.local/lib/python3.6/site-packages/h5py.libs/libhdf5-00e8fae8.so.200.0.0
    /home/fenics/.local/lib/python3.6/site-packages/h5py.libs/libhdf5_hl-383c339f.so.200.0.0
    /home/fenics/.local/lib/python3.6/site-packages/h5py.libs/libsz-e7aa62f5.so.2.0.1
    /home/fenics/.local/lib/python3.6/site-packages/h5py.libs/libz-eb09ad1d.so.1.2.3
    /home/fenics/.local/lib/python3.6/site-packages/h5py/*
Proceed (y/n)? 

I enter “y” to continue the uninstallation, however, nothing happened, the h5py cannot be uninstall
Could you tell me how to uninstall h5py via docker
Best regards

Without providing the rest of the output (you pressing y and the next output) i cant really help you

When I press “y”, nothing happened (there was not any output, unfortunately)