I am solving the thermoelastic equation and applying a fixed displacement condition at the origin of a rectangle. Currently, I can only achieve this in dolfin, and the code is as follows:
from dolfin import *
mesh = RectangleMesh(Point(0., 0.), Point(1, 1), 10, 10)
class Gamma(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0, DOLFIN_EPS) and near(x[1], 0, DOLFIN_EPS)
Center = Gamma()
E = Constant(50e3)
nu = Constant(0.2)
mu = E/2/(1+nu)
lmbda = E*nu/(1+nu)/(1-2*nu)
alpha = Constant(1e-5)
def eps(v):
return 0.5 * (grad(v) + grad(v).T)
def sigma(v, dT):
return (lmbda*tr(eps(v))- alpha*(3*lmbda+2*mu)*dT)*Identity(2) + 2.0*mu*eps(v)
VU = VectorFunctionSpace(mesh, 'CG', 1)
dU = TrialFunction(VU)
U_ = TestFunction(VU)
Wint = inner(sigma(dU, 1000), eps(U_)) * dx
aM = lhs(Wint)
LM = rhs(Wint)
bcu = DirichletBC(VU, Constant((0, 0)), Center, method="pointwise")
U = Function(VU)
solve(aM == LM, U, bcu)
I’m not sure how to implement the same functionality in dolfinx. Here is the code snippet in dolfinx where I can only impose a fixed displacement condition on a specific boundary:
import numpy as np
from ufl import (tr, grad, Identity, TrialFunction, TestFunction, lhs, rhs, inner, dx)
from dolfinx import (mesh, io, default_scalar_type, fem)
from dolfinx.fem import functionspace, dirichletbc
from dolfinx.fem.petsc import LinearProblem
from mpi4py import MPI
from pathlib import Path
from dolfinx.mesh import create_unit_square
domain = create_unit_square(MPI.COMM_WORLD, 10, 10)
def left(x):
return np.isclose(x[0], 0)
E = 50e3
nu = 0.2
mu = E/2/(1+nu)
lmbda = E*nu/(1+nu)/(1-2*nu)
alpha = 1e-5
def eps(v):
return 0.5 * (grad(v) + grad(v).T)
def sigma(v, dT):
return (lmbda*tr(eps(v))- alpha*(3*lmbda+2*mu)*dT)*Identity(2) + 2.0*mu*eps(v)
VU = functionspace(domain, ("CG", 1, (domain.geometry.dim, )))
dU = TrialFunction(VU)
U_ = TestFunction(VU)
Wint = inner(sigma(dU, 1000), eps(U_)) * dx
aM = lhs(Wint)
LM = rhs(Wint)
fdim = domain.topology.dim - 1
boundary_facets = mesh.locate_entities_boundary(domain, fdim, left)
u_D = np.array([0, 0], dtype = default_scalar_type)
bc = dirichletbc(u_D, fem.locate_dofs_topological(VU, fdim, boundary_facets), VU)
# Compute solution
problem = LinearProblem(aM, LM, bcs=[bc], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
Uf = problem.solve()
I hope someone can help me modify this. Thank you.