Hi eveyone, I am new to fenics, I am trying to solve a cantilever beam problem with point load at free end. However I am getting following error when I run the code.
Traceback (most recent call last):
File “new.py”, line 92, in
main()
File “new.py”, line 36, in main
bc = DirichletBC(V, Constant((0, 0)), root_boundary)
File “/usr/local/lib/python3.6/dist-packages/ufl/coefficient.py”, line 125, in Constant
domain = as_domain(domain)
File “/usr/local/lib/python3.6/dist-packages/ufl/domain.py”, line 296, in as_domain
cell = as_cell(domain)
File “/usr/local/lib/python3.6/dist-packages/ufl/cell.py”, line 327, in as_cell
return TensorProductCell(cell)
File “/usr/local/lib/python3.6/dist-packages/ufl/cell.py”, line 223, in init
self._cells = tuple(as_cell(cell) for cell in cells)
File “/usr/local/lib/python3.6/dist-packages/ufl/cell.py”, line 223, in
self._cells = tuple(as_cell(cell) for cell in cells)
File “/usr/local/lib/python3.6/dist-packages/ufl/cell.py”, line 327, in as_cell
return TensorProductCell(cell)
RecursionError: maximum recursion depth exceeded while calling a Python object
here is my code:
from dolfin import *
from ufl import *
import matplotlib.pyplot as plt
# Cantilever beam with point load
L = 0.5 # length
b = 0.05 # width
E = 70*(10**9) # modulus of elasticity
nu = 0.3 # poissons ratio
Lambda = (E*nu)/((1+nu)*(1-2*nu)) # lames parameter
Mu = E/(2*(1+nu)) # lames parameter
def main():
# Meshing and creating function space
nx = 50 # no. of cells along length
ny = 5 # no. of cells along width
Mesh = RectangleMesh(Point(0.0, 0.0), Point(L, b), nx, ny)
plot(Mesh)
plt.savefig('Mesh.png')
V = VectorFunctionSpace(Mesh, 'Lagrange', 1)
# Boundary conditons
def root_boundary(x, on_boundary):
tol = 1e-14
return on_boundary and x[0]<tol
bc = DirichletBC(V, Constant((0, 0)), root_boundary)
# Application of point load
class PointLoad(UserExpression):
def __init__(self, **kwargs):
super().__init__(degree=kwargs["degree"])
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:
value[0] = 0
value[1] = 0
def value_shape(self):
return (2,)
# Stress and Strain Tensors
def small_strain(u):
return sym(nabla_grad(u))
def cauchy_stress(u):
return Lambda*(tr(small_strain(u)))*Identity(2) + 2*Mu*small_strain(u)
# Variational form
u_trail = TrailFunction(V)
v_test = TestFunction(V)
f = PointLoad(point=(L, b), value=(0,-10000), degree=1)
lhs = inner(cauchy_stress(u_trail), small_strain(v_test))*dx
rhs = dot(f, v_test)*dx
# Solving
u_solution = Function(V)
solve(lhs==rhs, u_solution, bc)
plot(u_solution)
plt.savefig('u_field_image.png')
u_magnitude = sqrt(dot(u, u))
u_magnitude = project(u_magnitude, V)
plot(u_magnitude, 'Displacement magnitude')
plt.savefig('u_magnitude.png')
print('min/max u:',
u_magnitude.vector().get_local().min(),
u_magnitude.vector().get_local().max())
if __name__ == "__main__":
main()
Thank you in advance