when I try to convert a 3d .msh file into .xml file then it shows the following error:
dolfin-convert cyl-0.01.msh cyl-0.01.xml
Converting from Gmsh format (.msh, .gmsh) to DOLFIN XML format
Traceback (most recent call last):
File "/usr/bin/dolfin-convert", line 132, in <module>
main(sys.argv[1:])
File "/usr/bin/dolfin-convert", line 79, in main
meshconvert.convert2xml(ifilename, ofilename, iformat=iformat)
File "/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/meshconvert.py", line 1301, in convert2xml
convert(ifilename, XmlHandler(ofilename), iformat=iformat)
File "/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/meshconvert.py", line 1322, in convert
gmsh2xml(ifilename, handler)
File "/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/meshconvert.py", line 271, in gmsh2xml
num_elements = int(line)
ValueError: invalid literal for int() with base 10: '11 1700338 1 1700338\n'
import meshio
msh = meshio.read("mesho.msh")
# Extract the points and cells from the mesh data
points = msh.points
tri_cells = msh.cells[0].data # Assuming there is only one cell type (triangles), adjust accordingly
# Convert triangles to tetrahedra by adding an extra vertex (assuming a degenerate tetrahedron)
tetra_cells = []
for tri in tri_cells:
tetra_cells.append([tri[0], tri[1], tri[2], tri[0]])
# Create a new meshio.Mesh object with the extracted data
new_mesh = meshio.Mesh(points=points, cells=[("tetra", tetra_cells)])
# Write the mesh to an .xdmf file
meshio.write("mesh.xdmf", new_mesh)
it run and generate two files mesh.xdmf and mesh.h5 …mesh.h5 is not open ,it shows software is not installed.
is it in right direction? how i can use this file in my main code ?
This does not follow what I suggested in the post above. The xdmf file is a text file, that has pointers to appropriate data structures in the binary h5 file.
Thus to open or visualize the data (for instance in paraview) one opens the .XDMFFile
The post i linked to clearly shows how to add facet data to an XDMFFile and how to read it.
import numpy
import meshio
mesh_from_file = meshio.read("mesho.msh")
def create_mesh(mesh, cell_type, prune_z=False):
cells = numpy.vstack(
[cell.data for cell in mesh.cells if cell.type == cell_type])
# Remove z-coordinates from mesh if we have a 2D cell and all points have the same third coordinate
points = mesh.points
if prune_z:
points = points[:, :2]
mesh_new = meshio.Mesh(points=points, cells={cell_type: cells})
return mesh_new
triangle_mesh = create_mesh(mesh_from_file, "triangle")
meshio.write("mesh_3d.xdmf", triangle_mesh)
it works well and it generate four files mesh.xdmf,mesh.h5, mesh_3d.xdmf , mesh_3d.h5
Can you explain it in a short way what we are trying to do? as .h5 is not opened due to sotware installation. Is there any need to install the software ? Can I use these files for ploting in paraview? How I can use these files in my main code ? Please explain i don’t know much about these things.
So you can visualize the .xdmf files with Paraview.
I have already linked you to multiple posts explaining this. Please read what I send to you carefully before asking me to provide you with even more duplicate answers.
I don’t understand what you are saying now. How does mesh.xdmf and mf.xdmf look like in Paraview?
Are they the pictures above? If so, what do you not expect in them?
As you have not provided the msh file, there is no way anyone can reproduce your plots.