Note
Go to the end to download the full example code.
LinearElasticity1#
A cantilever beam undergoing bending deformation.
Note that this simulation is also performed in examples/Elastic/Elas1.py.
14 import matplotlib.pyplot as plt
15 import numpy as np
16
17 from EasyFEA import Display, ElemType, Models, Simulations
18 from EasyFEA.FEM import Field, BiLinearForm, FeArray, Sym_Grad, Trace
19 from EasyFEA.Geoms import Domain
20
21 if __name__ == "__main__":
22 Display.Clear()
23
24 # ----------------------------------------------
25 # Configuration
26 # ----------------------------------------------
27
28 dim = 2
29
30 # geom
31 L = 120 # mm
32 h = 13
33
34 # load
35 F = -800 # N
36
37 # model
38 E = 210000 # MPa
39 v = 0.3
40
41 elastic = Models.Elastic.Isotropic(dim, E, v, planeStress=True, thickness=h)
42 lmbda = elastic.get_lambda()
43 mu = elastic.get_mu()
44
45 # ----------------------------------------------
46 # Mesh
47 # ----------------------------------------------
48
49 contour = Domain((0, 0), (L, h), h / 3)
50
51 if dim == 2:
52 mesh = contour.Mesh_2D([], ElemType.QUAD9, isOrganised=True)
53 else:
54 mesh = contour.Mesh_Extrude(
55 [], [0, 0, h], [3], ElemType.HEXA27, isOrganised=True
56 )
57
58 nodesX0 = mesh.Nodes_Conditions(lambda x, y, z: x == 0)
59 nodesXL = mesh.Nodes_Conditions(lambda x, y, z: x == L)
60
61 # ----------------------------------------------
62 # Formulations
63 # ----------------------------------------------
64
65 field = Field(mesh.groupElem, dim)
66
67 def S(u: Field) -> FeArray:
68 Eps = Sym_Grad(u)
69 return 2 * mu * Eps + lmbda * Trace(Eps) * np.eye(dim)
70
71 @BiLinearForm
72 def ComputeK(u: Field, v: Field):
73 Sig = S(u)
74 Eps = Sym_Grad(v)
75 return Sig.ddot(Eps)
76
77 weakForms = Models.WeakForms(field, ComputeK)
78
79 # ----------------------------------------------
80 # Simulations
81 # ----------------------------------------------
82
83 simu = Simulations.WeakForms(mesh, weakForms)
84
85 simu.add_dirichlet(nodesX0, [0] * dim, simu.Get_unknowns())
86 simu.add_surfLoad(nodesXL, [F / h**2], ["y"])
87
88 simu.Solve()
89
90 # ----------------------------------------------
91 # Results
92 # ----------------------------------------------
93
94 Display.Plot_Result(simu, "uy", 10, plotMesh=True)
95
96 def von_mises_stress(u):
97 Stress = S(u)
98 if dim == 2:
99 xx = Stress[..., 0, 0]
100 yy = Stress[..., 1, 1]
101 xy = Stress[..., 0, 1]
102 return np.sqrt(xx**2 + yy**2 - xx * yy + 3 * xy**2)
103 else:
104 Stress_d = Stress - 1 / 3 * Trace(Stress) * np.eye(3)
105 return np.sqrt(3 / 2 * Stress_d.ddot(Stress_d))
106
107 Svm_e = field.Evaluate_e(von_mises_stress, simu.u)
108
109 Display.Plot_Result(simu, Svm_e, plotMesh=True, ncolors=11)
110
111 plt.show()
Total running time of the script: (0 minutes 0.433 seconds)

