Note
Go to the end to download the full example code.
Homog3#
Conduct full-field homogenization.
inclusions: dy = -1.658
non hom: dy = -0.929
hom: dy = -1.960
12 from EasyFEA import (
13 Display,
14 Models,
15 plt,
16 np,
17 Geoms,
18 ElemType,
19 Simulations,
20 )
21 from EasyFEA.fem import FeArray
22
23 from Homog1 import Compute_ukl
24
25 if __name__ == "__main__":
26 Display.Clear()
27
28 # ----------------------------------------------
29 # Configuration
30 # ----------------------------------------------
31 # use Periodic boundary conditions ?
32 usePER = True
33
34 # geom
35 L = 120 # mm
36 h = 13
37 b = 13
38
39 # inclusions
40 nL = 40 # number of inclusions following x
41 nH = 4 # number of inclusions following y
42 cL = L / (2 * nL)
43 cH = h / (2 * nH)
44 isHollow = True # hollow inclusions
45
46 # model
47 E = 210000
48 v = 0.3
49
50 # load
51 load = 800
52
53 # ----------------------------------------------
54 # Mesh
55 # ----------------------------------------------
56 elemType = ElemType.TRI6
57 meshSize = h / 10
58
59 pt1 = Geoms.Point()
60 pt2 = Geoms.Point(L, 0)
61 pt3 = Geoms.Point(L, h)
62 pt4 = Geoms.Point(0, h)
63
64 domain = Geoms.Domain(pt1, pt2, meshSize)
65
66 inclusions = []
67 for i in range(nL):
68 x = cL + cL * (2 * i)
69 for j in range(nH):
70 y = cH + cH * (2 * j)
71
72 ptd1 = Geoms.Point(x - cL / 2, y - cH / 2)
73 ptd2 = Geoms.Point(x + cL / 2, y + cH / 2)
74
75 inclusion = Geoms.Domain(ptd1, ptd2, meshSize, isHollow)
76
77 inclusions.append(inclusion)
78
79 inclusion = Geoms.Domain(ptd1, ptd2, meshSize)
80 area_inclusion = inclusion.Mesh_2D().area
81
82 points = Geoms.Points([pt1, pt2, pt3, pt4], meshSize)
83
84 # mesh with inclusions
85 mesh_inclusions = points.Mesh_2D(inclusions, elemType)
86
87 # mesh without inclusions
88 mesh = points.Mesh_2D([], elemType)
89
90 ptI1 = Geoms.Point(-cL, -cH)
91 ptI2 = Geoms.Point(cL, -cH)
92 ptI3 = Geoms.Point(cL, cH)
93 ptI4 = Geoms.Point(-cL, cH)
94
95 pointsI = Geoms.Points([ptI1, ptI2, ptI3, ptI4], meshSize / 4)
96
97 mesh_RVE = pointsI.Mesh_2D(
98 [
99 Geoms.Domain(
100 Geoms.Point(-cL / 2, -cH / 2),
101 Geoms.Point(cL / 2, cH / 2),
102 meshSize / 4,
103 isHollow,
104 )
105 ],
106 elemType,
107 )
108
109 Display.Plot_Mesh(mesh_inclusions, title="non hom")
110 Display.Plot_Mesh(mesh_RVE, title="RVE")
111 Display.Plot_Mesh(mesh, title="hom")
112
113 # ----------------------------------------------
114 # Material
115 # ----------------------------------------------
116
117 # elastic behavior of the beam
118 material_inclsuion = Models.ElasIsot(2, E=E, v=v, planeStress=True, thickness=b)
119 CMandel = material_inclsuion.C
120
121 material = Models.ElasAnisot(2, CMandel, False)
122 testC = np.linalg.norm(material_inclsuion.C - material.C) / np.linalg.norm(
123 material_inclsuion.C
124 )
125 assert testC < 1e-12, "the matrices are different"
126
127 # ----------------------------------------------
128 # Homogenization
129 # ----------------------------------------------
130 simu_inclusions = Simulations.ElasticSimu(mesh_inclusions, material_inclsuion)
131 simu_VER = Simulations.ElasticSimu(mesh_RVE, material_inclsuion)
132 simu = Simulations.ElasticSimu(mesh, material)
133
134 r2 = np.sqrt(2)
135 E11 = np.array([[1, 0], [0, 0]])
136 E22 = np.array([[0, 0], [0, 1]])
137 E12 = np.array([[0, 1 / r2], [1 / r2, 0]])
138
139 if usePER:
140 nodes_border = mesh_RVE.Nodes_Tags(["P0", "P1", "P2", "P3"])
141 paired_nodes = mesh_RVE.Get_Paired_Nodes(nodes_border, True)
142 else:
143 nodes_border = mesh_RVE.Nodes_Tags(["L0", "L1", "L2", "L3"])
144 paired_nodes = None
145
146 u11 = Compute_ukl(simu_VER, nodes_border, E11, paired_nodes)
147 u22 = Compute_ukl(simu_VER, nodes_border, E22, paired_nodes)
148 u12 = Compute_ukl(simu_VER, nodes_border, E12, paired_nodes, True)
149
150 u11_e = mesh_RVE.Locates_sol_e(u11, asFeArray=True)
151 u22_e = mesh_RVE.Locates_sol_e(u22, asFeArray=True)
152 u12_e = mesh_RVE.Locates_sol_e(u12, asFeArray=True)
153
154 U_e = FeArray.zeros(*u11_e.shape, 3)
155
156 U_e[..., 0] = u11_e
157 U_e[..., 1] = u22_e
158 U_e[..., 2] = u12_e
159
160 matrixType = "rigi"
161 wJ_e_pg = mesh_RVE.Get_weightedJacobian_e_pg(matrixType)
162 B_e_pg = mesh_RVE.Get_B_e_pg(matrixType)
163
164 C_hom = (wJ_e_pg * CMandel @ B_e_pg @ U_e).sum((0, 1)) / mesh_RVE.area
165
166 if isHollow:
167 coef = 1 - area_inclusion / mesh_RVE.area
168 C_hom *= coef
169
170 # print(np.linalg.eigvals(C_hom))
171
172 # ----------------------------------------------
173 # Comparison
174 # ----------------------------------------------
175 def Simulation(simu: Simulations._Simu, title=""):
176 simu.Bc_Init()
177
178 simu.add_dirichlet(simu.mesh.Nodes_Tags(["L3"]), [0, 0], ["x", "y"])
179 simu.add_surfLoad(simu.mesh.Nodes_Tags(["L1"]), [-load / (b * h)], ["y"])
180
181 simu.Solve()
182
183 # Display.Plot_BoundaryConditions(simu)
184 Display.Plot_Result(simu, "uy", title=f"{title} uy")
185 # Display.Plot_Result(simu, "Eyy")
186
187 print(
188 f"{title}: dy = {np.max(simu.Result('uy')[simu.mesh.Nodes_Point(Geoms.Point(L, 0))]):.3f}"
189 )
190
191 Simulation(simu_inclusions, "inclusions")
192 Simulation(simu, "non hom")
193
194 testSym = np.linalg.norm(C_hom.T - C_hom) / np.linalg.norm(C_hom)
195
196 if testSym >= 1e-12 and testSym <= 1e-3:
197 C_hom = 1 / 2 * (C_hom.T + C_hom)
198
199 material.Set_C(C_hom, False)
200 Simulation(simu, "hom")
201
202 # ax = Display.Plot_Result(simu, "uy")
203 # Display.Plot_Result(simuInclusions, "uy", ax=ax)
204
205 plt.show()
Total running time of the script: (0 minutes 2.320 seconds)











