Hi,
I am trying to import mesh file created by using third-party software. And I am simply trying to reproduce the example posted here: Hyperelasticity — FEniCSx tutorial by using externally (importing) created mesh.
# Scaled variable
L = 1
W = 0.2
mu = 1
rho = 1
delta = W/L
gamma = 0.4*delta**2
beta = 1.25
lambda_ = beta
g = gamma
import dolfinx
import numpy as np
from mpi4py import MPI
from dolfinx.cpp.mesh import CellType
from dolfinx.io import (XDMFFile, extract_gmsh_geometry,
extract_gmsh_topology_and_markers, ufl_mesh_from_gmsh)
print(f"DOLFINx version: {dolfinx.__version__} is installed")
#mesh = Mesh("solid-mec-00.xdmf");
import dolfinx
import numpy as np
from mpi4py import MPI
from dolfinx.cpp.mesh import CellType
filename="solid-mec-00.xdmf"
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "solid-mec-00.xdmf", "r") as xdmf:
mesh = xdmf.read_mesh(name="Grid")
def clamped_boundary(x):
return np.isclose(x[0], 0)
fdim = mesh.topology.dim - 1
boundary_facets = dolfinx.mesh.locate_entities_boundary(mesh, fdim, clamped_boundary)
u_D = dolfinx.Function(V)
with u_D.vector.localForm() as loc:
loc.set(0)
bc = dolfinx.DirichletBC(u_D, dolfinx.fem.locate_dofs_topological(V, fdim, boundary_facets))
T = dolfinx.Constant(mesh, (0, 0, 0))
import ufl
ds = ufl.Measure("ds", domain=mesh)
def epsilon(u):
return ufl.sym(ufl.grad(u)) # Equivalent to 0.5*(ufl.nabla_grad(u) + ufl.nabla_grad(u).T)
def sigma(u):
return lambda_ * ufl.nabla_div(u) * ufl.Identity(u.geometric_dimension()) + 2*mu*epsilon(u)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
f = dolfinx.Constant(mesh, (0, 0, -rho*g))
a = ufl.inner(sigma(u), epsilon(v)) * ufl.dx
L = ufl.dot(f, v) * ufl.dx + ufl.dot(T, v) * ds
problem = dolfinx.fem.LinearProblem(a, L, bcs=[bc], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
uh = problem.solve()
and I am getting the following error:
DOLFINx version: 0.3.1.0 is installed
Traceback (most recent call last):
File "LE.py", line 39, in <module>
mesh = xdmf.read_mesh(name="Grid")
File "/python-venv/lib/python3.8/site-packages/dolfinx/io.py", line 50, in read_mesh
cell_shape, cell_degree = super().read_cell_type(name, xpath)
RuntimeError: Cannot recognise cell type. Unknown value: mixed
Could you please tell me where I am making a mistake?
Thanks!