point_load.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """Apply a vector-valued point load
  2. to a corner of a linear-elastic cube.
  3. """
  4. # Credit https://fenicsproject.discourse.group/t/
  5. #applying-pointsource-at-two-different-vectors/1459/2
  6. from dolfin import *
  7. from vedo.dolfin import plot
  8. BULK_MOD = 1.0
  9. SHEAR_MOD = 1.0
  10. mesh = UnitCubeMesh(10, 10, 10)
  11. VE = VectorElement("Lagrange", mesh.ufl_cell(), 1)
  12. V = FunctionSpace(mesh, VE)
  13. # Constrain normal displacement on two sides:
  14. def boundary1(x, on_boundary):
  15. return on_boundary and near(x[1], 0.0)
  16. bc1 = DirichletBC(V.sub(1), Constant(0.0), boundary1)
  17. def boundary2(x, on_boundary):
  18. return on_boundary and near(x[0], 0.0)
  19. bc2 = DirichletBC(V.sub(0), Constant(0.0), boundary2)
  20. # Solve linear elasticity with point load at upper-right corner:
  21. u = TrialFunction(V)
  22. v = TestFunction(V)
  23. eps = 0.5 * (grad(u) + grad(u).T)
  24. I = Identity(3)
  25. sigma = BULK_MOD*tr(eps)*I + 2*SHEAR_MOD*(eps-tr(eps)*I/3)
  26. a = inner(sigma, grad(v)) * dx
  27. L = inner(Constant((0,0,0)), v) * dx
  28. # Assemble:
  29. A = assemble(a)
  30. B = assemble(L)
  31. # Apply point sources:
  32. ptSrcLocation = Point(1-DOLFIN_EPS, 1-DOLFIN_EPS)
  33. # Vectorial point load:
  34. f = [0.01, 0.02]
  35. # Distinct point sources for x- and y-components
  36. ptSrc_x = PointSource(V.sub(0), ptSrcLocation, f[0])
  37. ptSrc_y = PointSource(V.sub(1), ptSrcLocation, f[1])
  38. ptSrcs = [ptSrc_x, ptSrc_y]
  39. # Apply to RHS of linear system:
  40. for ptSrc in ptSrcs:
  41. ptSrc.apply(B)
  42. # Apply BCs:
  43. for bc in [bc1, bc2]:
  44. bc.apply(A)
  45. bc.apply(B)
  46. # Solve:
  47. u = Function(V)
  48. solve(A, u.vector(), B)
  49. plot(u, mode='displacement')