Thank you, The code is like this now, I got this error.
AttributeError: ‘PointLoad’ object has no attribute ‘_ufl_shape’
from dolfin import *
from ufl import nabla_div
# Load mesh and define function space
L = 10.
W = 1.
# Mesh for cantilever beam
Omega = BoxMesh(Point(0, 0, 0), Point(L, W, W),100, 3, 3)
Omega.init()
V = VectorFunctionSpace(Omega, "CG", 1)
tol = 1.e-8 # tolerance
# Left boundary
class Left(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0.0)
# Right boundary
class Right(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], L)
class PointLoad(UserExpression):
def __init__(self, **kwargs):
self.point = kwargs['point']
self.value = kwargs['value']
def eval(self, value, x):
if near (x[0], self.point[0]) and near(x[1], self.point[1]):
value[0] = self.value[0]
value[1] = self.value[1]
else: # Reset the input variable because it's likely to be reused
values[0] = 0
values[1] = 0
def value_shape(self):
return (2,)
# Point (8,0.5,0.5) at which load is added
#class point(SubDomain):
# def inside(self, x, on_boundary):
# return near(x[0],L) and near(x[1],0.8,1e-5) and near(x[2],0.8,1e-5)
## dokken: @0.5 no dof
#class point(SubDomain):
# def inside(self, x, on_boundary):
# return on_boundary and abs(x[0]-L) < 0.2 and abs(x[1]-0.5) < 0.2 and abs(x[1]-0.5) < 0.2
#Boundary segments
left = Left()
pt = point()
right = Right()
boundaries = MeshFunction("size_t", Omega,0)
boundaries.set_all(0)
left.mark(boundaries, 1)
pt.mark(boundaries, 2)
u = TrialFunction(V)
v = TestFunction(V)
f = Constant((0.0, 0.0, -1e-3))
# Elasticity parameters
E = 1e5
nu = 0.3
mu, lmbda = Constant(E/(2*(1 + nu))), Constant(E*nu/((1 + nu)*(1 - 2*nu)))
# Strain
def eps(u):
return sym(grad(u))
model = "plane_stress"
mu = E/2/(1+nu)
lmbda = E*nu/(1+nu)/(1-2*nu)
if model == "plane_stress":
lmbda = 2*mu*lmbda/(lmbda+2*mu)
def sigma(u):
return lmbda*tr(eps(u))*Identity(3) + 2.0*mu*eps(u)
# Define variational problem
ds= Measure("ds", domain=Omega, subdomain_data=boundaries)
#g_T= Constant((0.0, 0.0, -0))`Preformatted text`
T = PointLoad(point=(L,.2), value=(0,-10), degree=0)
a = inner(sigma(u), grad(v))*dx
left_end_displacement = Constant((0.0, 0.0, 0.0))
bc = [DirichletBC(V, left_end_displacement, left)]
l= dot(f, v)*dx +dot(v,T)*ds
# Compute solution
u = Function(V)
solve(a == l, u, bc)
print("Maximal deflection:", -u(L,1,1)[2])