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











