Guest User

Beam Reactions

a guest
Aug 23rd, 2015
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.82 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """ Cantilever Timoshenko beam problem solved using
  3. continuous-displacement/constant-shear finite element
  4. method. Cantilever type boundary conditions with point
  5. load applied.
  6.  
  7. Author: Jack S. Hale 2014
  8.  
  9. FE discretisation: Jack S. Hale PhD p. 114
  10. Beam problem: Jack S. Hale PhD p. 124
  11. Analytical solution: Jack S. Hale PhD p.125
  12. """
  13.  
  14. import numpy as np
  15. from dolfin import *
  16. # from dolfin_error_norms import relative_error, l2, h1
  17.  
  18.  
  19. parameters['form_compiler']['representation'] = 'quadrature'
  20. parameters['form_compiler']['quadrature_degree'] = 2
  21.  
  22.  
  23.  
  24. def main(nx=24, degree=2, epsilon=0.0001):
  25.     mesh = UnitIntervalMesh(nx)
  26.  
  27.     R = FunctionSpace(mesh, "CG", degree)
  28.     V_3 = FunctionSpace(mesh, "CG", degree)
  29.     S = FunctionSpace(mesh, "DG", degree - 1)
  30.  
  31.     # the method works with no locking
  32.     L = 1.0
  33.     p_tilde = 3.0
  34.  
  35.     # Inverse of shear constant
  36.     C_m = Constant(epsilon**2.0)
  37.     # Bending constants
  38.     C_b = Constant(L**2.0)
  39.  
  40.     # Rotation, Displacement, Shear Stress
  41.     U = MixedFunctionSpace([R, V_3, S])
  42.     R, V_3, S = U.split()
  43.  
  44.     # Rotation, Displacement, Shear Stress test functions
  45.     theta, z_3, gamma = TrialFunctions(U)
  46.     # Rotation, Displacement, Shear Stress trial functions
  47.     eta, y_3, psi = TestFunctions(U)
  48.  
  49.     # bilinear form Jack S. Hale PhD p.110
  50.     A = C_b*inner(grad(theta), grad(eta))*dx  + \
  51.         inner(gamma, y_3.dx(0) - eta)*dx + \
  52.         inner(z_3.dx(0) - theta, psi)*dx - \
  53.         C_m*inner(gamma, psi)*dx
  54.  
  55.     # linear form
  56.     L = Constant(0.0)*y_3*dx
  57.  
  58.     # Fixed (built-in) support on left
  59.     def left_boundary(x, on_boundary):
  60.         tol = 1E-14
  61.         return on_boundary and np.abs(x[0]) < tol
  62.  
  63.     zero = Constant(0.0)
  64.     bc1 = DirichletBC(V_3, zero, left_boundary)
  65.     bc2 = DirichletBC(R, zero, left_boundary)
  66.     bcs = [bc1, bc2]
  67.  
  68.     # point load on right
  69.     end_point = Point(1.0)
  70.     f = PointSource(V_3, end_point, p_tilde)
  71.  
  72.     # Not sure if it is possible to use the PointSource class
  73.     # and LinearVariationalProblem so assemble system manually
  74.     u_h = Function(U)
  75.     A_matrix = assemble(A)
  76.     b_vector = assemble(L)
  77.     for bc in bcs:
  78.         bc.apply(A_matrix)
  79.         bc.apply(b_vector)
  80.     # Apply point source to rhs vector
  81.     f.apply(b_vector)
  82.  
  83.     # solve
  84.     solver = LUSolver(A_matrix)
  85.     solver.solve(u_h.vector(), b_vector)
  86.  
  87.     theta_h, z_3h, gamma_h = u_h.split()
  88.  
  89.     # Jack S. Hale PhD p.125
  90.     z_3 = Expression('0.5*(2.0 - 3.0*(1.0 - x[0]) + pow((1.0 - x[0]), 3) + 6.0*pow(epsilon,2)*x[0])',
  91.                      epsilon=epsilon)
  92.     theta = Expression('1.5*(1.0 - pow((1.0 - x[0]),2))')
  93.  
  94.     V_e = FunctionSpace(mesh, "CG", 3)
  95.  
  96.     results = {}
  97.     results['z3_tip_error'] = z_3h(1.0)/z_3(1.0)
  98.     results['z3_tip'] = z_3h(1.0)
  99.     results['theta_tip_error'] = theta_h(1.0)/theta(1.0)
  100.     # results['z3_l2'] = relative_error(z_3, z_3h, V_e, norm=l2)
  101.     # results['z3_h1'] = relative_error(z_3, z_3h, V_e, norm=h1)
  102.     # results['theta_l2'] = relative_error(theta, theta_h, V_e, norm=l2)
  103.     # results['theta_h1'] = relative_error(theta, theta_h, V_e, norm=h1)
  104.     results['z_3h'] = z_3h
  105.     results['theta_h'] = theta
  106.     results['gamma_h'] = gamma_h
  107.     results['dofs'] = U.dim()
  108.  
  109.     reaction = Function(U)
  110.     reaction.vector()[:] = A_matrix * u_h.vector()
  111.     reaction_forces = reaction.split(deepcopy=True)[1]
  112.     plot(reaction_forces); interactive()
  113.     matrix = assemble(A)
  114.     reaction.vector()[:] = matrix * u_h.vector()
  115.     reaction_forces = reaction.split(deepcopy=True)[1]
  116.     plot(reaction_forces); interactive()
  117.     return results
  118.  
  119.  
  120. if __name__ == "__main__":
  121.     results = main(nx=20, degree=2)
  122.     print results
  123.  
  124.     # Uncomment these lines to plot results
  125.     # plot(results['z_3h'])
  126.     # interactive()
Advertisement
Add Comment
Please, Sign In to add comment