Hello,
I am trying to solve a linear elasticity problem where I already have a manufactured solution, and I am trying to impose it as a Dirichlet boundary condition on the whole boundary. However I keep getting errors of all sorts. Please find attached below the code.
E = 1.0
nu = 0.3
mu = E / (2.0 * (1.0 + nu))
lambda_ = E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu))
def epsilon(u):
return ufl.sym(ufl.grad(u))
def sigma(u):
return lambda_ * ufl.nabla_div(u) * ufl.Identity(len(u)) + 2 * mu * epsilon(u)
def u_ex(x):
return np.array(0.4 * ((x[0] - 0.5) ** 2 + (x[1] -0.5) ** 2), dtype=np.double)
def f(x):
val = -0.8 * (lambda_ + 3*mu) * np.ones_like(x, dtype=np.double)
return val[:-1, :]
def assemble_lhs_rhs(N=100):
comm = MPI.COMM_WORLD
config.mesh_params["degree"] = 1
config.mesh_params["N"] = N
cartesian_mesh_params = {"comm": MPI.COMM_SELF, **config.mesh_params}
cart_mesh = CartesianMesh(**cartesian_mesh_params)
domain = cart_mesh.mesh
vec = True
V = fem.VectorFunctionSpace(domain, ("CG", config.mesh_params["degree"]))
W = fem.FunctionSpace(domain, ("CG", config.mesh_params["degree"]))
def clamped_boundary(x):
return np.ones_like(x[1], dtype=bool)
fdim = domain.topology.dim - 1
boundary_facets = dolfinx.mesh.locate_entities_boundary(domain, fdim, clamped_boundary)
f_dolfinx = dolfinx.fem.Function(V)
f_dolfinx.interpolate(f)
u_dolfinx = dolfinx.fem.Function(W)
u_dolfinx.interpolate(u_ex)
print(u_dolfinx.dtype)
bc0 = fem.dirichletbc(u_dolfinx, fem.locate_dofs_topological(V, fdim, boundary_facets), V.sub(0))
bc1 = fem.dirichletbc(u_dolfinx, fem.locate_dofs_topological(V, fdim, boundary_facets), V.sub(1))
bc = [bc0, bc1]
I get an error when trying to declare bc0 and bc1, either the error says that the boundary condition has no dtype or it has the wrong one… however, I am declaring dtype=np.double above, which is why I am not sure what’s going on under the hood. Any help would be greatly appreciated.
Thanks!