Reading msh.file

Hello all, I want to use a stent cad in FEniCS therefore I editted my cad file as a shell mesh in ANSA and then exported it and opened it in gmsh to use it as a msh.file. Now it is a msh.file but I cannot read it in FEniCS. What kind of code should I use to read it in FEniCS and use as a mesh in my code. You can also see the picture of my mesh.

Bests,

Please read Read before posting: How do I get my question answered?

The question is too broad. For instance, do you want to read the file in dolfin or in dolfinx? What have you tried to read it? If that doesn’t work, what error does it give?

Hello, Firstly thank you so much for your response. The code that I used to read it is like that :

from dolfin import *
import numpy as np
import matplotlib.pyplot as plt

mesh = Mesh("stentmeshedfromansa.msh")

For this I get the error belowed:

Traceback (most recent call last):
File “/home/fenics/denemekodu.py”, line 6, in
mesh = Mesh(“stentmeshedfromansa.msh”)
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at


*** fenics-support@googlegroups.com


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to open file.
*** Reason: Unknown file type (“.msh”) for file “stentmeshedfromansa.msh”.
*** Where: This error was encountered inside File.cpp.
*** Process: 0


*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: ubuntu
*** -------------------------------------------------------------------------

I also tried this method but it also was not work:

import meshio

# GMSH formatındaki dosyayı XDMF formatına dönüştür
msh = meshio.read("stentmeshedfromansa.msh")
meshio.write("stent.xdmf", msh)

For this code I also get the error belowed:

Traceback (most recent call last):
File “/home/fenics/denemekodu.py”, line 4, in
msh = meshio.read(“stentmeshedfromansa.msh”)
File “/home/fenics/.local/lib/python3.10/site-packages/meshio/_helpers.py”, line 71, in read
return _read_file(Path(filename), file_format)
File “/home/fenics/.local/lib/python3.10/site-packages/meshio/_helpers.py”, line 103, in _read_file
return reader_mapfile_format
File “/home/fenics/.local/lib/python3.10/site-packages/meshio/gmsh/main.py”, line 19, in read
mesh = read_buffer(f)
File “/home/fenics/.local/lib/python3.10/site-packages/meshio/gmsh/main.py”, line 48, in read_buffer
return reader.read_buffer(f, is_ascii, data_size)
File “/home/fenics/.local/lib/python3.10/site-packages/meshio/gmsh/_gmsh22.py”, line 60, in read_buffer
has_additional_tag_data, cell_tags = _read_cells(
File “/home/fenics/.local/lib/python3.10/site-packages/meshio/gmsh/_gmsh22.py”, line 136, in _read_cells
point_tags = np.asarray(point_tags, dtype=np.int32) - 1
TypeError: int() argument must be a string, a bytes-like object or a real number, not ‘NoneType’

Please make sure that you learn how to format the code and the error messages in this forum.

There are plenty of posts about reading gmsh files in dolfin. For instance see Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio , which is literally the most read topic in this forum. It’s a very long post, so you may want to start reading it from the very end to get the latest updates first.