Hello,
I seem to be having the same problem with the same example. I am running fenicsx 0.9.0 under anaconda 3. The operating system is ubuntu 24.04 and the desktop computer has 16 cores and 32Gb of RAM.
In order to mimc the previous posts I created the following minimal code (cut down from linearelasticity_code.py
and appropriate for version 0.9.0):
from dolfinx import mesh, fem, default_scalar_type
from dolfinx.fem.petsc import LinearProblem
from mpi4py import MPI
import ufl
import numpy as np
import time
L = 1
W = 0.2
mu = 1
rho = 1
delta = W / L
gamma = 0.4 * delta**2
beta = 1.25
lambda_ = beta
g = gamma
domain = mesh.create_box(MPI.COMM_WORLD, [np.array([0, 0, 0]), np.array([L, W, W])],
[20, 6, 6], cell_type=mesh.CellType.hexahedron)
V = fem.functionspace(domain, ("Lagrange", 1, (domain.geometry.dim, )))
def clamped_boundary(x):
return np.isclose(x[0], 0)
fdim = domain.topology.dim - 1
boundary_facets = mesh.locate_entities_boundary(domain, fdim, clamped_boundary)
u_D = np.array([0, 0, 0], dtype=default_scalar_type)
bc = fem.dirichletbc(u_D, fem.locate_dofs_topological(V, fdim, boundary_facets), V)
T = fem.Constant(domain, default_scalar_type((0, 0, 0)))
ds = ufl.Measure("ds", domain=domain)
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(len(u)) + 2 * mu * epsilon(u)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
f = fem.Constant(domain, default_scalar_type((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 = LinearProblem(a, L, bcs=[bc], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
start_time = time.time()
uh = problem.solve()
end_time = time.time()
print('Time = %.5f (s)' %(end_time-start_time))
My results are as follows:
(fenicsx-env) peter:fenicsx % mpirun -n 1 python lin_elas.py
Time = 0.18598 (s)
(fenicsx-env) peter:fenicsx % mpirun -n 2 python lin_elas.py
Time = 0.21867 (s)
Time = 0.21867 (s)
(fenicsx-env) peter:fenicsx % mpirun -n 4 python lin_elas.py
Time = 0.34490 (s)
Time = 0.34489 (s)
Time = 0.34490 (s)
Time = 0.34489 (s)
(fenicsx-env) peter:fenicsx % mpirun -n 8 python lin_elas.py
Time = 0.51458 (s)
Time = 0.51459 (s)
Time = 0.51552 (s)
Time = 0.51552 (s)
Time = 0.51551 (s)
Time = 0.51550 (s)
Time = 0.51551 (s)
Time = 0.51552 (s)
I assume that I must have missed something somewhere. I did run the program in a new window with a fresh start of conda. The only thing I havenβt tried is a reboot of the computer.
Any thoughts would be much appreciated.
Thank you,
Peter.