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











