1
# This demo program solves the equations of static
2
# linear elasticity for a gear clamped at two of its
3
# ends and twisted 30 degrees.
5
# Original implementation: ../cpp/main.cpp by Johan Jansson and Anders Logg
7
__author__ = "Kristian B. Oelgaard (k.b.oelgaard@tudelft.nl)"
8
__date__ = "2007-11-14 -- 2007-12-03"
9
__copyright__ = "Copyright (C) 2007 Kristian B. Oelgaard"
10
__license__ = "GNU LGPL Version 2.1"
14
# Load mesh and create finite element
15
mesh = Mesh("../../../../../data/meshes/gear.xml.gz")
16
element = VectorElement("Lagrange", "tetrahedron", 1)
18
# Dirichlet boundary condition for clamp at left end
19
class Clamp(Function):
20
def __init__(self, element, mesh):
21
Function.__init__(self, element, mesh)
23
def eval(self, values, x):
34
# Sub domain for clamp at left end
35
class Left(SubDomain):
36
def inside(self, x, on_boundary):
37
return bool(x[0] < 0.5 and on_boundary)
39
# Dirichlet boundary condition for rotation at right end
40
class Rotation(Function):
41
def __init__(self, element, mesh):
42
Function.__init__(self, element, mesh)
44
def eval(self, values, x):
49
# Angle of rotation (30 degrees)
53
y = y0 + (x[1] - y0)*cos(theta) - (x[2] - z0)*sin(theta)
54
z = z0 + (x[1] - y0)*sin(theta) + (x[2] - z0)*cos(theta)
67
# Sub domain for rotation at right end
68
class Right(SubDomain):
69
def inside(self, x, on_boundary):
70
return bool(x[0] > 0.9 and on_boundary)
72
# Initialise source function
73
f = Function(element, mesh, 0.0)
75
# Define variational problem
76
# Test and trial functions
77
v = TestFunction(element)
78
u = TrialFunction(element)
84
lmbda = E*nu / ((1 + nu)*(1 - 2*nu))
87
return 0.5*(grad(v) + transp(grad(v)))
90
return 2.0*mu*epsilon(v) + lmbda*mult(trace(epsilon(v)), Identity(len(v)))
92
a = dot(grad(v), sigma(u))*dx
95
# Set up boundary condition at left end
96
c = Clamp(element, mesh)
98
bcl = DirichletBC(c, mesh, left)
100
# Set up boundary condition at right end
101
r = Rotation(element, mesh)
103
bcr = DirichletBC(r, mesh, right)
105
# Set up boundary conditions
108
# Set up PDE and solve
109
pde = LinearPDE(a, L, mesh, bcs)
113
plot(sol, mode="displacement")
115
# Save solution to VTK format
116
vtk_file = File("elasticity.pvd")
119
# Save solution to XML format
120
xml_file = File("elasticity.xml")