Unable to import mesh created using 'Hypermesh' software

Hi all,
I have a mesh file that is created using Hypermesh in the .inp format. I want to import and read it in FEniCS, but I am facing some issues with it. I got the following error.
Here is the .inp file attached.

**
** ABAQUS Input Deck Generated by HyperMesh Version  : 13.0.110.31
** Generated using HyperMesh-Abaqus Template Version : 13.0.110
**
**   Template:  ABAQUS/STANDARD 3D
**
*NODE
         1,  0.0            ,  0.0            ,  0.0            
         2,  0.05           ,  0.0            ,  0.0            
         3,  0.1            ,  0.0            ,  0.0            
         4,  0.15           ,  0.0            ,  0.0            
         5,  0.2            ,  0.0            ,  0.0            
         6,  0.0            ,  0.05           ,  0.0            
         7,  0.049999500005 ,  0.049999500005 ,  0.0            
         8,  0.09999900001  ,  0.049999500005 ,  0.0            
         9,  0.149998500015 ,  0.049999500005 ,  0.0            
        10,  0.2            ,  0.05           ,  0.0            
        11,  0.0            ,  0.1            ,  0.0            
        12,  0.049999500005 ,  0.09999900001  ,  0.0            
        13,  0.09999900001  ,  0.09999900001  ,  0.0            
        14,  0.149998500015 ,  0.09999900001  ,  0.0            
        15,  0.2            ,  0.1            ,  0.0            
        16,  0.0            ,  0.15           ,  0.0            
        17,  0.049999500005 ,  0.149998500015 ,  0.0            
        18,  0.09999900001  ,  0.149998500015 ,  0.0            
        19,  0.149998500015 ,  0.149998500015 ,  0.0            
        20,  0.2            ,  0.15           ,  0.0            
        21,  0.0            ,  0.2            ,  0.0            
        22,  0.05           ,  0.2            ,  0.0            
        23,  0.1            ,  0.2            ,  0.0            
        24,  0.15           ,  0.2            ,  0.0            
        25,  0.2            ,  0.2            ,  0.0            
**HWCOLOR COMP          1    11
*ELEMENT,TYPE=S4,ELSET=auto1
         1,         1,         2,         7,         6
         2,         2,         3,         8,         7
         3,         3,         4,         9,         8
         4,         4,         5,        10,         9
         5,         6,         7,        12,        11
         6,         7,         8,        13,        12
         7,         8,         9,        14,        13
         8,         9,        10,        15,        14
         9,        11,        12,        17,        16
        10,        12,        13,        18,        17
        11,        13,        14,        19,        18
        12,        14,        15,        20,        19
        13,        16,        17,        22,        21
        14,        17,        18,        23,        22
        15,        18,        19,        24,        23
        16,        19,        20,        25,        24
*****

Here is the code attached.

from fenics import *
import matplotlib.pyplot as plt
pip install --user meshio
pip install --user h5py
import meshio
mesh_from_file = meshio.read("Abaqus-hypermeshsample.inp")
import h5py

import numpy
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(mesh_from_file, "line", prune_z=True)
meshio.write("facet_mesh.xdmf", line_mesh)

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

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-9-5dea5c7603fb> in <module>
----> 1 line_mesh = create_mesh(mesh_from_file, "line", prune_z=True)
      2 meshio.write("facet_mesh.xdmf", line_mesh)
      3 
      4 triangle_mesh = create_mesh(mesh_from_file, "triangle", prune_z=True)
      5 meshio.write("mesh.xdmf", triangle_mesh)

<ipython-input-8-90f22cb4147e> in create_mesh(mesh, cell_type, prune_z)
      2 def create_mesh(mesh, cell_type, prune_z=False):
      3     cells = mesh.get_cells_type(cell_type)
----> 4     cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
      5     out_mesh = meshio.Mesh(points=mesh.points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
      6     if prune_z:

~/.local/lib/python3.6/site-packages/meshio/_mesh.py in get_cell_data(self, name, cell_type)
    226     def get_cell_data(self, name: str, cell_type: str):
    227         return np.concatenate(
--> 228             [d for c, d in zip(self.cells, self.cell_data[name]) if c.type == cell_type]
    229         )
    230 

KeyError: 'gmsh:physical'


Thanks

The error message is quite clear.

----> 4     cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
...
KeyError: 'gmsh:physical'

There is no cell_data in your mesh. And as far as I can tell, Abaqus does not have cell_data or point_data fields in .inp. Remove that line and you should be good to go. You can see it by printing the mesh, which looks fine to me:

>>> import meshio, vedo as vm
>>> msh = meshio.abaqus.read("foo.inp")
>>> vm.show(vm.Mesh([msh.points, msh.get_cells_type("quad")]).lw(1).c("b")) 

gives

2 Likes

Hi,
I have read mesh file successfully using this line.

msh = meshio.abaqus.read("Abaqus-hypermeshsample.inp")

but I am facing a problem with the package vedo.

pip install --user vedo
import vedo
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-d17b821e82be> in <module>
----> 1 import vedo

~/.local/lib/python3.6/site-packages/vedo/__init__.py in <module>
     13 
     14 from vedo.version import _version as __version__
---> 15 from vedo.plotter import *
     16 from vedo.shapes import *
     17 from vedo.io import *

~/.local/lib/python3.6/site-packages/vedo/plotter.py in <module>
      3 import time
      4 import sys
----> 5 import vtk
      6 import os.path
      7 import numpy as np

~/.local/lib/python3.6/site-packages/vtk.py in <module>
     28     import importlib
     29     # import vtkmodules.all
---> 30     all_m = importlib.import_module('vtkmodules.all')
     31 
     32     # import vtkmodules

/usr/lib/python3.6/importlib/__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

~/.local/lib/python3.6/site-packages/vtkmodules/all.py in <module>
     27 from .vtkImagingMath import *
     28 from .vtkRenderingUI import *
---> 29 from .vtkRenderingOpenGL2 import *
     30 from .vtkRenderingVolume import *
     31 from .vtkRenderingVolumeOpenGL2 import *

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

I am not understanding why this error is coming.
Please help me in that. Thanks

it says libGL.so.1 is missing. You need to make sure it’s installed.

How can I install it?
I am getting this error.

pip install --user libGL.so.1
ERROR: Could not find a version that satisfies the requirement libGL.so.1 (from versions: none)
ERROR: No matching distribution found for libGL.so.1
Note: you may need to restart the kernel to use updated packages.

It’s not a python package, it’s a graphics library. You’ll need to review how you installed graphics libraries or graphics drivers.

Hi, I am new to FEniCS. I have installed it using docker on my Windows system.
Can you please explore how can I install this libraries.
Is there any other way to import .inp format mesh in FEniCS, if there are any examples or tutorials regarding this, please suggest to me.

Thanks

I think it should be pulled in by the docker recipe used for the installation. I’m not an expert in docker, hopefully others can help with it.

1 Like

You don’t need vedo for importing your mesh in dolfin. I was just exemplifying that nothing was wrong with the mesh by plotting it.

1 Like

Please clarify.
As you told, I have successfully read the mesh using

msh = meshio.abaqus.read("Abaqus-hypermeshsample.inp")

But I am not able to convert it into .xdmf format

import numpy
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

quad_mesh = create_mesh(msh, "quad", prune_z=True)
meshio.write("mesh.xdmf", quad_mesh)

How do I visualize that mesh in my jupyter notebook and run simulation on it?

When you say “not able to convert it into .xdmf format”, what do you mean exactly? Your code snippet here runs perfectly fine for me (linux installation).

1 Like

What is the error you are getting? I think the code you have posted should work. In order to read the mesh into dolfin, use for instance

from dolfin import Mesh, XDMFFile

mesh = Mesh()
XDMFFile("mesh.xdmf").read(mesh)

How do I visualize that mesh in my jupyter notebook and run simulation on it?

Note that quad meshes cannot be visualized by matplotlib. Hence you should either use vedo or write it into vtk/xdmf format and use an external visualization tool such as Paraview.

2 Likes

And I should add that the support for quad meshes in dolfin is limited. If you want to use quad meshes I would recommend working with dolfinx instead.

2 Likes

Thanks. It worked for me.