Hello everyone, I have an issue on my code.
Here is my input:
import numpy as np
from dolfinx import mesh, fem, io, plot
from mpi4py import MPI
import matplotlib.pyplot as plt
from basix import ufl
from ufl import TrialFunction, TestFunction, dx, inner, grad, div
# Load the mesh
mesh_path = 'TTpath26x.xdmf'
with io.XDMFFile(MPI.COMM_WORLD, mesh_path, "r") as xdmf:
domain_mesh = xdmf.read_mesh(name="Grid")
# Material properties definition
E = 2200 # Young's modulus for ABS in MPa
nu = 0.35 # Poisson's ratio for ABS
rho = 1040 # Density of ABS (kg/m^3)
g = 9.81 # Acceleration due to gravity (m/s^2)
mu = E / (2 * (1 + nu))
lambda_ = E * nu / ((1 + nu) * (1 - 2 * nu))
# Function spaces and test functions
element = ufl.element("Lagrange", domain_mesh.ufl_cell(), 1, shape=3)
V = fem.FunctionSpace(domain_mesh, element)
u = TrialFunction(V)
v = TestFunction(V)
# Define boundary conditions
def boundary_bottom(x):
return np.isclose(x[2], 0.01, atol=0.21) # z = 0.01 to -0.20
def boundary_top(x):
return np.isclose(x[2], 2.02, atol=0.01) # z = 2.02
bc_bottom = fem.dirichletbc(value=np.array([0, 0, 0]), dofs=V.locate_dofs_geometrical(boundary_bottom), V=V)
bc_top = fem.dirichletbc(value=np.array([0, 0, -1000]), dofs=V.locate_dofs_geometrical(boundary_top), V=V)
# Force definition
f = fem.Constant(domain_mesh, (0, 0, -rho * g * 0.01**2)) # Gravitational force
# Weak formulation
a = (inner(grad(u), grad(v)) + lambda_ * div(u) * div(v)) * dx
L = inner(f, v) * dx
# Solve the problem
problem = fem.petsc.LinearProblem(a, L, bcs=[bc_bottom, bc_top])
u_solution = problem.solve()
# Visualize the solution and save to a file
fig = plt.figure()
plotting_mesh = plot.create_vtk_mesh(V)
p = plot.plot(u_solution, mesh=plotting_mesh)
plt.colorbar(p)
plt.savefig('simulation_result.png') # File path
plt.close()
output of the code:
Traceback (most recent call last): File "/home/mtm/FEA_yeni2.py", line 22, in <module> element = ufl.element("Lagrange", domain_mesh.ufl_cell(), 1, shape=3) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mtm/miniconda3/envs/fenicsx-env/lib/python3.12/site-packages/basix/ufl.py", line 1988, in element family = _basix.finite_element.string_to_family(family, cell.name) AttributeError: 'Cell' object has no attribute 'name'
I am new at FEA and Fenics. I couldn’t solve this error. What should I do to fix it?