I am trying to solve a simple 3D elasticity problem, but I can’t apply the force correctly.
I want to fix the displacement in all directions on left_face, and apply a force in -X direction on the right_face.
So I defined the subdomains and want to make the integral of the load f on right_boundary, so I defined ds on that subdomain. But I am not sure if this is correct…
> from __future__ import print_function
> from fenics import *
> from ufl import nabla_div
> import dolfin
> import mshr
> import math
>
> # creating the mesh
> L = 300
> y = 30
> z = 30
> pt1 = Point(0,0,0)
> pt2 = Point(L,y,z)
> rectangle = mshr.Box(pt1,pt2)
> mesh = mshr.generate_mesh(rectangle,10)
>
> # defining subdomains
> V = VectorFunctionSpace(mesh, 'Lagrange', degree=1)
>
> class Left_face(SubDomain):
> def inside(self, x, on_boundary):
> return on_boundary and near(x[0],0)
>
> class Right_face(SubDomain):
> def inside(self, x, on_boundary):
> return on_boundary and near(x[0],L)
>
> left_face = Left_face()
> right_face = Right_face()
>
> sub_domains = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
> sub_domains.set_all(0)
>
> left_face.mark(sub_domains, 1)
> right_face.mark(sub_domains, 2)
>
> ds = ds(subdomain_data = sub_domains, subdomain_id = 2)
>
> bc = DirichletBC(V, Constant((0.,0.,0.)), bcs = right_face)
>
>
> # define structural analysis
> E = Constant(1e5)
> nu = Constant(0.3)
>
> mu = E/2/(1+nu)
> lmbda = E*nu/(1+nu)/(1-2*nu)
>
> def eps(v):
> return sym(grad(v))
>
> def sigma(v):
> return lmbda*tr(eps(v))*Identity(3) + 2*mu*eps(v)
>
> f = Constant((-200,0,0)) ##########
> du = TrialFunction(V)
> u_ = TestFunction(V)
> a = inner(sigma(du),eps(u_))*dx
> l = dot(f,u_)*ds(1) #############
>
> u = Function(V, name='Displacement')
> solve(a == l, u, bcs=bc)
That error is occurring when I run the code:
> runfile('/home/jiri/Desktop/linux/codigos/untitled0.py', wdir='/home/jiri/Desktop/linux/codigos')
> Traceback (most recent call last):
>
> File "<ipython-input-43-121d3ee6abe0>", line 1, in <module>
> runfile('/home/jiri/Desktop/linux/codigos/untitled0.py', wdir='/home/jiri/Desktop/linux/codigos')
>
> File "/usr/lib/python3/dist-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
> execfile(filename, namespace)
>
> File "/usr/lib/python3/dist-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
> exec(compile(f.read(), filename, 'exec'), namespace)
>
> File "/home/jiri/Desktop/linux/codigos/untitled0.py", line 48, in <module>
> bc = DirichletBC(V, Constant((0.,0.,0.)), bcs = right_face)
>
> File "/usr/lib/python3/dist-packages/dolfin/fem/dirichletbc.py", line 107, in __init__
> if isinstance(args[2], cpp.mesh.SubDomain):
>
> IndexError: tuple index out of range