-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sympy_Laminate_Analysis.py
437 lines (380 loc) · 14.1 KB
/
Sympy_Laminate_Analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
"""
Package to perform laminate analysis symbolically
"""
import sympy as sp
import numpy as np
import math
__author__ = 'MNR'
__all__ = ["T_Matrix", "R_Matrix", "Poissons_Ratio", "get_Elastic_Constants",
"Material", "Iso_Material", "Ortho_Material", "Ply", "GSCS_Ply",
"Ortho_Ply", "Laminate"]
def T_Matrix(angle):
"""
Calculates the transformation matrix.
Parameters
----------
angle : 'Int', 'Float', or Variable
Angle in degress of desired transformation.
"""
if isinstance(angle, (int, float)):
theta = math.radians(angle)
else:
theta = angle
c, s = (sp.cos(theta), sp.sin(theta))
return sp.Matrix([[c ** 2, s ** 2, 2 * s * c],
[s ** 2, c ** 2, -2 * s * c],
[-s * c, s * c, c ** 2 - s ** 2]])
def R_Matrix():
"""
Returns R matrices for transformation of S and Q in engineering
strain_type.
"""
return sp.Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 2]])
def Poissons_Ratio(vij, Ei, Ej):
"""
Calculates other poissons ratio vji = vij*(Ej/Ei)
"""
return vij * Ej / Ei
def get_Elastic_Constants(S_Matrix, strain_type="Engineering"):
"""
Extracts elastic constants from stiffness matrix.
"""
if strain_type.lower().startswith('e'):
strain_multiplier = 1
else:
strain_multiplier = 2
E11 = 1 / S_Matrix[0, 0]
E22 = 1 / S_Matrix[1, 1]
G12 = 1 / (strain_multiplier * S_Matrix[2, 2])
v12 = -1 * S_Matrix[1, 0] * E11
v21 = -1 * S_Matrix[0, 1] * E22
return E11, E22, G12, v12, v21
class Material(object):
def __init__(self, E1, E2, G1, G2, v12, v21):
"""
Create Material instance with given elastic constants
Parameters
----------
E1 : 'Int' or 'Float'
Axial Young's Modulus.
E2 : 'Int' or 'Float'
Transverse Young's Modulus.
G1 : 'Int' or 'Float'
Axial Shear Modulus.
G1 : 'Int' or 'Float'
Transverse Shear Modulus.
v12 : 'Int' or 'Float'
Axial Poisson's Ratio.
v21 : 'Int' or 'Float'
Transverse Poisson's Ratio.
"""
self.E1 = E1
self.E2 = E2
self.G1 = G1
self.G2 = G2
self.v12 = v12
self.v21 = v21
class Iso_Material(Material):
def __init__(self, E, G=None, v=None):
"""
Calculates elastic constants for an isotropic material and passes them
to Material.
Parameters
----------
E : 'Int' or 'Float'
Young's Modulus.
G : 'Int' or 'Float'
Shear Modulus, G = E/(2(1 + v).
v : 'Int' or 'Float'
Poisson's Ratio, v = E/2*G - 1.
"""
assert v is not None or G is not None, "Must supply v and/or G"
E1 = E2 = E
if v is None:
v12 = v21 = E / (2 * G) - 1
else:
v12 = v21 = v
if G is None:
G1 = G2 = E / (2 * (1 + v))
else:
G1 = G2 = G
# call parent constructor with simplified arguments
Material.__init__(self, E1, E2, G1, G2, v12, v21)
class Ortho_Material(Material):
def __init__(self, E1, E2, G1, G2, v12=None, v21=None):
"""
Calculates elastic constants for transversely orthotropic material and
passes them to Material.
Parameters
----------
E1 : 'Int' or 'Float'
Axial Young's Modulus.
E2 : 'Int' or 'Float'
Transverse Young's Modulus.
G1 : 'Int' or 'Float'
Axial Shear Modulus.
G2 : 'Int' or 'Float'
Transverse Shear Modulus .
v12 : 'Int' or 'Float'
Axial Poisson's Ratio, v12 = v21(E1/E2).
v21 : 'Int' or 'Float'
Transverse Poisson's Ratio, v21 = v12(E2/E1).
"""
assert v12 is not None or v21 is not None, \
"Must supply v12 and/or v21."
if v12 is None:
v12 = Poissons_Ratio(v21, E2, E1)
if v21 is None:
v21 = Poissons_Ratio(v12, E1, E2)
# call parent constructor with simplified arguments
Material.__init__(self, E1, E2, G1, G2, v12, v21)
class Ply(object):
def __init__(self, E11, E22, G12, v12, v21):
"""
Create Ply instancd with given elastic constants
Parameters
----------
E11 : 'Int' or 'Float'
Axial Young's Modulus.
E22 : 'Int' or 'Float'
Transverse Young's Modulus.
G12 : 'Int' or 'Float'
Shear Modulus.
v12 : 'Int' or 'Float'
Axial Poisson's Ratio.
v21 : 'Int' or 'Float'
Transverse Poisson's Ratio.
"""
self.E11 = E11
self.E22 = E22
self.G12 = G12
self.v12 = v12
self.v21 = v21
def get_S(self, theta=0., strain_type="Engineering"):
"""
Calculates the compliance matrix for the ply oriented at angle theta
in the specified strain units
Parameters
----------
theta : 'Int' or 'Float'
Angle in degrees of ply orientation.
strain_type : 'String'
Specifies 'Engineering' or 'Tensorial' strain.
"""
if strain_type.lower().startswith('e'):
strain_multiplier = 1
else:
strain_multiplier = 2
compliance = sp.Matrix([[1 / self.E11, -self.v21 / self.E22, 0],
[-self.v12 / self.E11, 1 / self.E22, 0],
[0, 0, 1 / (strain_multiplier * self.G12)]])
if theta == 0.:
return compliance
else:
T = T_Matrix(theta)
if strain_type.lower().startswith('e'):
R = R_Matrix()
TI = sp.simplify(R * T.inv() * R.inv())
else:
TI = T.inv()
return sp.simplify(sp.N(TI * compliance * T, chop=1e-10))
def get_Q(self, theta=0., strain_type="Engineering"):
"""
Calculates the stiffness matrix (Q = S^-1) for the ply oriented at
angle theta in the specified strain units
Parameters
----------
theta : 'Int' or 'Float'
Angle in degrees of ply orientation.
strain_type : 'String'
Specifies 'Engineering' or 'Tensorial' strain.
"""
return sp.simplify(sp.N(self.get_S(theta, strain_type).inv(),
chop=1e-10))
def weave_Ply(self, orientation=(0, 90)):
"""
Calculates the elastic constants of a woven ply in the given
orientation
Parameters
----------
orientation : 'Tuple', 'len(orientation) == 2'
Orientation of the weave.
"""
assert len(orientation) == 2, "orientation should have 2 entries"
Q_weave = (self.get_Q(orientation[0]) + self.get_Q(orientation[1])) / 2
S_weave = sp.simplify(sp.N(Q_weave.inv(), chop=1e-10))
(self.E11,
self.E22,
self.G12,
self.v12,
self.v21) = get_Elastic_Constants(S_weave)
class GSCS_Ply(Ply):
def __init__(self, fiber, matrix, Vf):
"""
Calculates the elastic constants of a ply made up of fiber and matrix
components with fiber volume fraction Vf
using the Christensen GSCS approach.
Parameters
----------
fiber : 'Material'
Fiber instance of Material class.
matrix : 'Material'
Matrix instance of Material class.
Vf : 'Int' or 'Float'
Volume fraction of fiber material.
"""
self.Vf = Vf
# Fiber Properties
(Eaf,
Etf,
Gaf,
Gtf,
vaf,
vtf,
cf) = sp.symbols('Eaf Etf Gaf Gtf vaf vtf cf')
fiberSubs = list(zip((Eaf, Etf, Gaf, Gtf, vaf, vtf, cf),
(fiber.E1, fiber.E2, fiber.G1, fiber.G2, fiber.v12,
fiber.v21, Vf)))
kf = (Eaf * Etf / (2 * Eaf - 4 * Etf * vaf ** 2 -
2 * Eaf * vtf)).subs(fiberSubs)
etaf = (3 - 4 * 1 / 2 * (1 - Gtf / kf)).subs(fiberSubs)
# Matrix Properties
(Eam,
Etm,
Gam,
Gtm,
vam,
vtm,
cm) = sp.symbols('Eam Etm Gam Gtm vam vtm cm')
matrixSubs = list(zip((Eam, Etm, Gam, Gtm, vam, vtm, cm),
(matrix.E1, matrix.E2, matrix.G1, matrix.G2,
matrix.v12, matrix.v21, 1 - Vf)))
km = (Eam * Etm / (2 * Eam - 4 * Etm * vam ** 2 -
2 * Eam * vtm)).subs(matrixSubs)
# mm = (1 + 4 * km * vam ** 2 / Eam).subs(matrixSubs)
etam = (3 - 4 * 1 / 2 * (1 - Gtm / km)).subs(matrixSubs)
# Axial Ply Properties (Hashin)
Eac = (Eam * cm + Eaf * cf + 4 * (vaf - vam) ** 2 * cm * cf /
(cm / kf + cf / km + 1 / Gtm)).subs(matrixSubs + fiberSubs)
vac = (vam * cm + vaf * cf + (vaf - vam) * (1 / km - 1 / kf) * cm *
cf / (cm / kf + cf / km + 1 / Gtm)).subs(matrixSubs + fiberSubs)
Gac = (Gam * (Gam * cm + Gaf * (1 + cf)) / (Gam * (1 + cf) +
Gaf * cm)).subs(matrixSubs + fiberSubs)
kc = ((km * (kf + Gtm) * cm + kf * (km + Gtm) * cf) / ((kf + Gtm) *
cm + (km + Gtm) * cf)).subs(matrixSubs + fiberSubs)
Gtr = (Gtf / Gtm).subs(matrixSubs + fiberSubs)
mc = (1 + 4 * kc * vac ** 2 / Eac)
# Transverse Ply Properties (Hashin)
Achr = sp.simplify((3 * cf * cm**2 * (Gtr - 1) * (Gtr + etaf) +
(Gtr * etam + etaf * etam - (Gtr * etam - etaf) *
cf ** 3) * (cf * etam * (Gtr - 1) -
(Gtr * etam + 1))).subs(matrixSubs + fiberSubs))
Bchr = sp.simplify((-3 * cf * cm**2 * (Gtr - 1) * (Gtr + etaf) +
1 / 2 * (etam * Gtr + (Gtr - 1) * cf + 1) *
((etam - 1) * (Gtr + etaf) - 2 *
(Gtr * etam - etaf) * cf**3) + cf / 2 *
(etam + 1) * (Gtr - 1) * (Gtr + etaf +
(Gtr * etam - etaf) *
cf**3)).subs(matrixSubs + fiberSubs))
Cchr = sp.simplify((3 * cf * cm ** 2 * (Gtr - 1) * (Gtr + etaf) +
(etam * Gtr + (Gtr - 1) * cf + 1) *
(Gtr + etaf + (Gtr * etam - etaf) *
cf ** 3)).subs(matrixSubs + fiberSubs))
x = sp.Symbol('x')
sols = sp.solve(Achr * x ** 2 + 2 * Bchr * x + Cchr, x)
Gtc = sp.simplify((Gtm * sols[-1]).subs(matrixSubs))
vtc = sp.simplify((kc - mc * Gtc) / (kc + mc * Gtc))
Etc = sp.simplify(2 * (1 + vtc) * Gtc)
# call parent constructor with simplified arguments
Ply.__init__(self, Eac, Etc, Gac, vac, Poissons_Ratio(vac, Eac, Etc))
class Ortho_Ply(Ply):
def __init__(self, E11, E22, G12, v12=None, v21=None):
"""
Creates ply with given elastic constants
----------
E11 : 'Int' or 'Float'
Axial Young's Modulus.
E22 : 'Int' or 'Float'
Transverse Young's Modulus.
G12 : 'Int' or 'Float'
Shear Modulus.
v12 : 'Int' or 'Float'
Axial Poisson's Ratio, v12 = v21(E1/E2).
v21 : 'Int' or 'Float'
Transverse Poisson's Ratio, v21 = v12(E2/E1).
"""
assert v12 is not None or v21 is not None, \
"Must supply v12 and/or v21."
if v12 is None:
v12 = Poissons_Ratio(v21, E22, E11)
if v21 is None:
v21 = Poissons_Ratio(v12, E11, E22)
# call parent constructor with simplified arguments
Ply.__init__(self, E11, E22, G12, v12, v21)
class Laminate(object):
def __init__(self, Plies, Layup, t_Plies=None,
strain_type="Engineering"):
"""
Calculates the elastic constants and A, B, and D matrices for a
laminate with the given set of plies.
Parameters
----------
Plies : 'List' or 'Tuple',
List or Tuple of plies
Layup : 'List' or 'Tuple',
List or Tuple of angles in degrees corresponding to the
orientation of each ply in Plies
t_plies : 'List' or 'Tuple', default = None
List or Tuple of ply thicknesses for each ply in Plies
strain_type : 'String'
Specifies 'Engineering' or 'Tensorial' strain.
"""
if t_Plies is None:
assert len(Plies) == len(Layup), "Must supply the same number \
of Plies and angles."
else:
assert (len(Plies) == len(Layup) and
len(Plies) == len(t_Plies)), "Must supply the same \
number of Plies and angles."
self.Plies = Plies
self.Layup = Layup
if t_Plies is None:
t = 1
t_Plies = [t / len(self.Layup), ] * len(self.Layup)
else:
t = sum(t_Plies)
z = (np.hstack((np.zeros(1), np.cumsum(t_Plies))) - t / 2).tolist()
self.t = t
self.z = z
A = sp.zeros(3, 3)
B = sp.zeros(3, 3)
D = sp.zeros(3, 3)
for k, (ply, theta) in enumerate(list(zip(self.Plies, self.Layup))):
Ak = sp.zeros(3, 3)
Bk = sp.zeros(3, 3)
Dk = sp.zeros(3, 3)
Q_Bar = ply.get_Q(theta, strain_type=strain_type)
z_k = self.z[k]
z_k1 = self.z[k + 1]
for i in range(3):
for j in range(3):
Ak[i, j] = (z_k1 - z_k) * Q_Bar[i, j]
Bk[i, j] = (1 / 2) * (z_k1 ** 2 - z_k ** 2) * Q_Bar[i, j]
Dk[i, j] = (1 / 3) * (z_k1 ** 3 - z_k ** 3) * Q_Bar[i, j]
A += Ak
B += Bk
D += Dk
self.A = sp.simplify(sp.N(A, chop=1e-10))
self.B = sp.simplify(sp.N(B, chop=1e-10))
self.D = sp.simplify(sp.N(D, chop=1e-10))
(E11,
E22,
G12,
v12,
v21) = get_Elastic_Constants(sp.simplify(sp.N(A.inv() * self.t,
chop=1e-10)), strain_type=strain_type)
self.E11 = E11
self.E22 = E22
self.G12 = G12
self.v12 = v12
self.v21 = v21