What are the right boundary conditions to add in order to obtain the right results on uniaxial plate compression of a cube. I need to kill some translations and rotations. So here some BCs are missing.
I tried everything I was thinking about, but the results are never the ones intended.
Here is the code:
from dolfinx import mesh, fem, plot, io, default_scalar_type
from dolfinx.fem.petsc import LinearProblem
from mpi4py import MPI
import ufl
import numpy as np
W = 1.0
mu = 1.0
rho = 1.0
d = W/20
beta = 1.25
lambda_ = beta
############# Domain
domain = mesh.create_box(
MPI.COMM_WORLD,
[np.array([0, 0, 0]), np.array([W, W, W])],
[20, 20, 20],
cell_type=mesh.CellType.hexahedron,
)
V = fem.functionspace(domain, ("Lagrange", 1, (domain.geometry.dim,)))
######## scalar BC for compression
# Function subspace
Vx = V.sub(0)
Vy = V.sub(1)
Vz = V.sub(2)
# Boundary markers
def boundary_left(x):
return np.isclose(x[0], 0)
def boundary_right(x):
return np.isclose(x[0], W)
fdim = domain.topology.dim - 1
facets_l = mesh.locate_entities_boundary(domain, fdim, boundary_left)
facets_r = mesh.locate_entities_boundary(domain, fdim, boundary_right)
# Locate dofs (IMPORTANT tuple syntax)
dofs_l_x = fem.locate_dofs_topological((Vx, V), fdim, facets_l)[1]
dofs_r_x = fem.locate_dofs_topological((Vx, V), fdim, facets_r)[1]
# Dirichlet BCs on ux only
bc_l = fem.dirichletbc(
fem.Constant(domain, default_scalar_type(d)),
dofs_l_x,
Vx
)
bc_r = fem.dirichletbc(
fem.Constant(domain, default_scalar_type(0.0)),
dofs_r_x,
Vx
)
# --- Combine with left/right compression BCs ---
bcs = [
bc_l, # ux on x=0
bc_r
]
T = fem.Constant(domain, default_scalar_type((0, 0, 0)))
ds = ufl.Measure("ds", domain=domain)
########## Variational formulation
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)
a = ufl.inner(sigma(u), epsilon(v)) * ufl.dx
L = ufl.dot(T, v) * ds
########### Solve the linear variational problem
problem = LinearProblem(
a,
L,
bcs=bcs,
petsc_options={"ksp_type": "preonly", "pc_type": "lu"}#,
#petsc_options_prefix="linear_elasticity", ########### -> error: not recognized: TypeError: LinearProblem.__init__() got an unexpected keyword argument 'petsc_options_prefix'
)
uh = problem.solve()
The core of the code comes from this tutorial.
(Note that petsc_options_prefix=“linear_elasticity” is not working for me for print(dolfinx.version)
→0.9.0).
The code gives this kind of results (or variations of it following the other BC I tried)
Thx in advance
