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











