I try to do the 2D mesh as following:
Firstly, I created a 2D mesh using Gmsh and record in a file named: “untitled.msh”
Then I try to convert in .xdmf file using following code:
import gmsh
import pygmsh
import meshio
import numpy
from dolfin import *
msh = meshio.read(“untitled.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)
However, when I run, there is an error type:
OSError Traceback (most recent call last)
in
** 2 matplotlib.use(“Agg”)**
** 3 import matplotlib.pyplot as plt**
----> 4 import gmsh
** 5 import pygmsh**
** 6 import meshio**
~/.local/lib/python3.6/site-packages/gmsh.py in
** 51 libpath = find_library(“gmsh”)**
** 52 **
—> 53 lib = CDLL(libpath)
** 54 **
** 55 try_numpy = True # set this to False to never use numpy**
/usr/lib/python3.6/ctypes/init.py in init(self, name, mode, handle, use_errno, use_last_error)
** 346 **
** 347 if handle is None:**
→ 348 self._handle = _dlopen(self._name, mode)
** 349 else:**
** 350 self._handle = handle**
OSError: libGLU.so.1: cannot open shared object file: No such file or directory