-
Notifications
You must be signed in to change notification settings - Fork 0
/
solver.py
649 lines (448 loc) · 18.9 KB
/
solver.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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize as sopt
import scipy.integrate as sint
from plate import Plate
from loads import *
class Solver:
"""Generic plate solver class.
Parameters
----------
plate : Plate
Plate to solve the deflection for.
load : Load
Load applied.
m_max : int
Maximum m index for sine series.
n_max : int
Maximum n index for sine series.
"""
def __init__(self, plate, load, m_max, n_max=1):
# Initialize
self.plate = plate
self.load = load
self.m_max = m_max
self.n_max = n_max
def get_deflection_field(self, Nx, Ny):
# Returns the deflections across the plate
# Get deflections at various points
X = np.linspace(0.0, self.plate.a, Nx)
Y = np.linspace(0.0, self.plate.b, Ny)
w = np.zeros((Nx, Ny))
for i, xi in enumerate(X):
for j, yj in enumerate(Y):
w[i,j] = self.w(xi, yj)
return X, Y, w
def plot_field(self, X, Y, value, label=''):
# Plot deflection
fig, ax = plt.subplots()
contour_plot = ax.contourf(X, Y, value.T, 100)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.xaxis.tick_top()
ax.xaxis.set_label_position('top')
ax.set_aspect('equal')
ax.invert_yaxis()
cbar = fig.colorbar(contour_plot)
cbar.ax.set_title(label)
plt.show()
def plot_deflection_field(self, Nx=50, Ny=50):
X, Y, w = self.get_deflection_field(Nx, Ny)
self.plot_field(X, Y, w, 'Deflection')
def compare_to_analytic_sinusoidal_solution(self):
# Get deflections at various points
Nx = 50
Ny = 50
X = np.linspace(0.0, self.plate.a, Nx)
Y = np.linspace(0.0, self.plate.b, Ny)
w = np.zeros((Nx, Ny))
w_anl = np.zeros_like(w)
for i, xi in enumerate(X):
for j, yj in enumerate(Y):
w[i,j] = self.w(xi, yj)
w_anl[i,j] = self.load.p0*np.sin(np.pi*xi/self.plate.a)*np.sin(np.pi*yj/self.plate.b)
w_anl /= np.pi**4*self.plate.D*(self.plate.a**-2 + self.plate.b**-2)**2
# Plot deflection
fig, ax = plt.subplots()
contour_plot = ax.contourf(X, Y, w-w_anl, 100)
cbar = fig.colorbar(contour_plot)
plt.show()
def sigma_x(self, x, y, z):
# Returns the x bending stress at the given location
P = self.d2w_dx2(x, y) + self.plate.v*self.d2w_dy2(x, y)
return -self.plate.E*z/(1.0-self.plate.v**2)*P
def sigma_y(self, x, y, z):
# Returns the y bending stress at the given location
P = self.d2w_dy2(x, y) + self.plate.v*self.d2w_dx2(x, y)
return -self.plate.E*z/(1.0-self.plate.v**2)*P
def tau_xy(self, x, y, z):
# Returns the plane shear stress at the given location
return -self.plate.E*z/(1.0+self.plate.v)*self.d2w_dxdy(x, y)
def tau_xz(self, x, y, z):
# Returns the transverse shear stress (from equilibrium) at the given location
P = self.d3w_dx3(x, y) + self.d3w_dxdy2(x,y)
Z = 0.25*self.plate.h**2 - z**2
return self.plate.E*Z*P/(2.0*(1.0-self.plate.v**2))
def tau_yz(self, x, y, z):
# Returns the transverse shear stress (from equilibrium) at the given location
P = self.d3w_dx2dy(x, y) + self.d3w_dy3(x,y)
Z = 0.25*self.plate.h**2 - z**2
return self.plate.E*Z*P/(2.0*(1.0-self.plate.v**2))
def corner_reactions(self):
# Returns the average corner reaction force
# Integrate edge forces
def V_x(y):
return self.V_x(0.0, y)
F_x_edge = sint.quadrature(V_x, 0.0, self.plate.b)[0]
def V_y(x):
return self.V_y(x, 0.0)
F_y_edge = sint.quadrature(V_y, 0.0, self.plate.a)[0]
# Add
F_edges = -2.0*(F_x_edge + F_y_edge)
return -0.25*(F_edges + self.load.F_total())
def get_maximum_w(self):
# Returns the location of the maximum deflection and its value
def f(x):
return -self.w(x[0], x[1])
# Run optimizer
result = sopt.minimize(f, [0.501*self.plate.a, 0.501*self.plate.b], method='nelder-mead', bounds=((0.0, self.plate.a), (0.0, self.plate.b)))
return result.x[0], result.x[1], -result.fun
def _get_max_stress(self, stress_fun, x0):
# Returns the location of the maximum of the given stress function and its value
def f(x):
return -abs(stress_fun(x[0], x[1], x[2]))
# Run optimizer
result = sopt.minimize(f, x0, method='nelder-mead', bounds=((0.0, self.plate.a), (0.0, self.plate.b), (-0.5*self.plate.h, 0.5*self.plate.h)))
# Refine
#result = sopt.minimize(f, result.x, method='L-BFGS-B', bounds=((0.0, self.plate.a), (0.0, self.plate.b), (-0.5*self.plate.h, 0.5*self.plate.h)))
return result.x[0], result.x[1], result.x[2], stress_fun(result.x[0], result.x[1], result.x[2])
def get_maximum_sigma_x(self):
# Returns the location of the maximum sigma_x and its value
if isinstance(self, NavierSolver):
x0 = [0.5*self.plate.a, 0.5*self.plate.b, 0.5*self.plate.h]
elif self.BC == "SSSS":
x0 = [0.5*self.plate.a, 0.5*self.plate.b, 0.5*self.plate.h]
elif self.BC == "SCSC":
x0 = [0.5*self.plate.a, 0.5*self.plate.b, 0.5*self.plate.h]
elif self.BC == "SCSF":
x0 = [0.5*self.plate.a, 0.9*self.plate.b, 0.5*self.plate.h]
return self._get_max_stress(self.sigma_x, x0)
def get_maximum_sigma_y(self):
# Returns the location of the maximum sigma_y and its value
if isinstance(self, NavierSolver):
x0 = [0.5*self.plate.a, 0.5*self.plate.b, 0.5*self.plate.h]
elif self.BC == "SSSS":
x0 = [0.5*self.plate.a, 0.5*self.plate.b, 0.5*self.plate.h]
elif self.BC == "SCSC":
x0 = [0.99*self.plate.a, 0.01*self.plate.b, 0.5*self.plate.h]
elif self.BC == "SCSF":
x0 = [0.99*self.plate.a, 0.01*self.plate.b, 0.5*self.plate.h]
return self._get_max_stress(self.sigma_y, x0)
def get_maximum_tau_xz(self):
# Returns the location of the maximum tau_xz and its value
if isinstance(self, NavierSolver):
x0 = [0.9*self.plate.a, 0.1*self.plate.b, 0.0]
elif self.BC == "SSSS":
x0 = [0.9*self.plate.a, 0.1*self.plate.b, 0.0]
elif self.BC == "SCSC":
x0 = [0.9*self.plate.a, 0.9*self.plate.b, 0.0]
elif self.BC == "SCSF":
x0 = [0.9*self.plate.a, 0.1*self.plate.b, 0.0]
return self._get_max_stress(self.tau_xz, x0)
def get_maximum_tau_yz(self):
# Returns the location of the maximum tau_yz and its value
if isinstance(self, NavierSolver):
x0 = [0.9*self.plate.a, 0.1*self.plate.b, 0.0]
elif self.BC == "SSSS":
x0 = [0.9*self.plate.a, 0.1*self.plate.b, 0.0]
elif self.BC == "SCSC":
x0 = [0.9*self.plate.a, 0.1*self.plate.b, 0.0]
elif self.BC == "SCSF":
x0 = [0.9*self.plate.a, 0.1*self.plate.b, 0.0]
return self._get_max_stress(self.tau_yz, x0)
def V_x(self, x, y):
# Gives the x shear force at the given location
P = self.d3w_dx3(x, y) + (2.0-self.plate.v)*self.d3w_dxdy2(x, y)
return -self.plate.D*P
def V_y(self, x, y):
# Gives the y shear force at the given location
P = self.d3w_dy3(x, y) + (2.0-self.plate.v)*self.d3w_dx2dy(x, y)
return -self.plate.D*P
class NavierSolver(Solver):
"""Solves for the deflection using the Navier solution method.
Parameters
----------
plate : Plate
Plate to solve the deflection for.
load : Load
Load applied.
m_max : int
Maximum m index for sine series.
n_max : int
Maximum n index for sine series.
"""
def __init__(self, plate, load, m_max, n_max):
super().__init__(plate, load, m_max, n_max)
def W_mn(self, m, n):
# Returns the desired Fourier deflection coefficient
Pmn = self.load.Pmn(m, n)
return Pmn/(((m/self.plate.a)**2 + (n/self.plate.b)**2)**2 * (np.pi**4*self.plate.D))
def w(self, x, y):
# Returns the plate deflection at the given location
w = 0.0
for mi in self.load.m[:self.m_max]:
for ni in self.load.n[:self.n_max]:
Sx = np.sin(mi*np.pi*x/self.plate.a)
Sy = np.sin(ni*np.pi*y/self.plate.b)
w += self.W_mn(mi, ni)*Sx*Sy
return w
def d2w_dx2(self, x, y):
# Returns the second derivative of w wrt x
d2w_dx2 = 0.0
for mi in self.load.m[:self.m_max]:
for ni in self.load.n[:self.n_max]:
Sx = np.sin(mi*np.pi*x/self.plate.a)
Sy = np.sin(ni*np.pi*y/self.plate.b)
d2w_dx2 += -(mi*np.pi/self.plate.a)**2*self.W_mn(mi, ni)*Sx*Sy
return d2w_dx2
def d3w_dx3(self, x, y):
# Returns the third derivative of w wrt x
d3w_dx3 = 0.0
for mi in self.load.m[:self.m_max]:
for ni in self.load.n[:self.n_max]:
Cx = np.cos(mi*np.pi*x/self.plate.a)
Sy = np.sin(ni*np.pi*y/self.plate.b)
d3w_dx3 += -(mi*np.pi/self.plate.a)**3*self.W_mn(mi, ni)*Cx*Sy
return d3w_dx3
def d2w_dy2(self, x, y):
# Returns the second derivative of w wrt y
d2w_dy2 = 0.0
for mi in self.load.m[:self.m_max]:
for ni in self.load.n[:self.n_max]:
Sx = np.sin(mi*np.pi*x/self.plate.a)
Sy = np.sin(ni*np.pi*y/self.plate.b)
d2w_dy2 += -(ni*np.pi/self.plate.b)**2*self.W_mn(mi, ni)*Sx*Sy
return d2w_dy2
def d3w_dy3(self, x, y):
# Returns the third derivative of w wrt y
d3w_dy3 = 0.0
for mi in self.load.m[:self.m_max]:
for ni in self.load.n[:self.n_max]:
Sx = np.sin(mi*np.pi*x/self.plate.a)
Cy = np.cos(ni*np.pi*y/self.plate.b)
d3w_dy3 += -(ni*np.pi/self.plate.b)**3*self.W_mn(mi, ni)*Sx*Cy
return d3w_dy3
def d2w_dxdy(self, x, y):
# Returns the second mixed derivative of W
d2w_dxdy = 0.0
for mi in self.load.m[:self.m_max]:
for ni in self.load.n[:self.n_max]:
Cx = np.cos(mi*np.pi*x/self.plate.a)
Cy = np.cos(ni*np.pi*y/self.plate.b)
d2w_dxdy += (mi*np.pi/self.plate.a)*(ni*np.pi/self.plate.b)*self.W_mn(mi, ni)*Cx*Cy
return d2w_dxdy
def d3w_dx2dy(self, x, y):
# Returns the third derivative of w wrt x squared and y
d3w_dx2dy = 0.0
for mi in self.load.m[:self.m_max]:
for ni in self.load.n[:self.n_max]:
Sx = np.sin(mi*np.pi*x/self.plate.a)
Cy = np.cos(ni*np.pi*y/self.plate.b)
d3w_dx2dy += -(mi*np.pi/self.plate.a)**2*(ni*np.pi/self.plate.b)*self.W_mn(mi, ni)*Sx*Cy
return d3w_dx2dy
def d3w_dxdy2(self, x, y):
# Returns the third derivative of w wrt x and y squared
d3w_dxdy2 = 0.0
for mi in self.load.m[:self.m_max]:
for ni in self.load.n[:self.n_max]:
Cx = np.cos(mi*np.pi*x/self.plate.a)
Sy = np.sin(ni*np.pi*y/self.plate.b)
d3w_dxdy2 += -(mi*np.pi/self.plate.a)*(ni*np.pi/self.plate.b)**2*self.W_mn(mi, ni)*Cx*Sy
return d3w_dxdy2
class LevySolver(Solver):
"""Solves for the deflection using the Levy solution method.
Parameters
----------
plate : Plate
Plate to solve the deflection for.
load : Load
Load applied.
BC : str
Boundary conditions to be applied.
m_max : int
Maximum m index for sine series.
"""
def __init__(self, plate, load, BC, m_max):
super().__init__(plate, load, m_max)
self.BC = BC
self.symmetric = self.BC[1] == self.BC[3]
def w(self, x, y):
# Returns the deflection at the given location
if self.symmetric:
y -= 0.5*self.plate.b
w = 0.0
for m in self.load.m[:self.m_max]:
Am, Bm, Cm, Dm, km = self.coefs(m)
beta_m = m*np.pi/self.plate.a
Shy = np.sinh(beta_m*y)
Chy = np.cosh(beta_m*y)
yShy = y*np.sinh(beta_m*y)
yChy = y*np.cosh(beta_m*y)
Sx = np.sin(beta_m*x)
w += (Am*Shy + Bm*Chy + Cm*yShy + Dm*yChy + km)*Sx
return w
def km(self, m):
# Returns the km coefficient
return self.load.Pm(m)*(self.plate.a/(m*np.pi))**4/self.plate.D
def coefs(self, m):
# Returns Am, Bm, Cm, Dm, and km
# Get k and beta
km = self.km(m)
beta_m = m*np.pi/self.plate.a
# Get alpha based on symmetry
if self.symmetric:
alpha_m = 0.5*beta_m*self.plate.b
else:
alpha_m = beta_m*self.plate.b
# Get intermediate calcs
Tha = np.tanh(alpha_m)
Cha = np.cosh(alpha_m)
# Calculate coefs based on boundary conditions
# All simply-supported
if self.BC == "SSSS":
# Get coefficients
Am = 0.0
Bm = -km*(2.0+alpha_m*Tha)/(2.0*Cha)
Cm = km*beta_m/(2.0*Cha)
Dm = 0.0
# Clamped on y-faces
elif self.BC == "SCSC":
# Get coefficients
denom = Cha*(Tha + alpha_m*(1.0-Tha**2))
Am = 0.0
Bm = -km*(alpha_m+Tha)/denom
Cm = km*beta_m*Tha/denom
Dm = 0.0
# Clamped at y=0, free at y=b
elif self.BC == "SCSF":
# Get matrix elements
a11 = -beta_m*((1.0+self.plate.v)*Tha + alpha_m*(1.0-self.plate.v))
a12 = alpha_m*(1.0-self.plate.v)*Tha + 2.0
a21 = -beta_m*(2.0 + alpha_m*(self.plate.v-1.0)*Tha)
a22 = (1.0+self.plate.v)*Tha + alpha_m*(self.plate.v-1.0)
b1 = km*beta_m*(self.plate.v/Cha + 1.0 - self.plate.v)
b2 = km*beta_m*(self.plate.v-1.0)*Tha
# Get solution
denom = (a12*a21 - a11*a22)
Am = (b2*a12 - b1*a22)/denom
Bm = -km
Cm = (b1*a21 - b2*a11)/denom
Dm = -beta_m*Am
else:
IOError("{0} is not an allowable BC set for the Levy solution! Quitting...".format(self.BC))
return Am, Bm, Cm, Dm, km
def d2w_dx2(self, x, y):
# Returns the second derivative of w wrt x at the given location
if self.symmetric:
y -= 0.5*self.plate.b
d2w_dx2 = 0.0
for m in self.load.m[:self.m_max]:
Am, Bm, Cm, Dm, km = self.coefs(m)
beta_m = m*np.pi/self.plate.a
Shy = np.sinh(beta_m*y)
Chy = np.cosh(beta_m*y)
yShy = y*np.sinh(beta_m*y)
yChy = y*np.cosh(beta_m*y)
Sx = np.sin(beta_m*x)
d2w_dx2 -= (Am*Shy + Bm*Chy + Cm*yShy + Dm*yChy + km)*beta_m**2*Sx
return d2w_dx2
def d3w_dx3(self, x, y):
# Returns the third derivative of w wrt x at the given location
if self.symmetric:
y -= 0.5*self.plate.b
d3w_dx3 = 0.0
for m in self.load.m[:self.m_max]:
Am, Bm, Cm, Dm, km = self.coefs(m)
beta_m = m*np.pi/self.plate.a
Shy = np.sinh(beta_m*y)
Chy = np.cosh(beta_m*y)
yShy = y*np.sinh(beta_m*y)
yChy = y*np.cosh(beta_m*y)
Cx = np.cos(beta_m*x)
d3w_dx3 -= (Am*Shy + Bm*Chy + Cm*yShy + Dm*yChy + km)*beta_m**3*Cx
return d3w_dx3
def d2w_dxdy(self, x, y):
# Returns the second derivative of w wrt x and y at the given location
if self.symmetric:
y -= 0.5*self.plate.b
d2w_dxdy = 0.0
for m in self.load.m[:self.m_max]:
Am, Bm, Cm, Dm, km = self.coefs(m)
beta_m = m*np.pi/self.plate.a
Shy = np.sinh(beta_m*y)
Chy = np.cosh(beta_m*y)
yShy = y*np.sinh(beta_m*y)
yChy = y*np.cosh(beta_m*y)
Cx = np.cos(beta_m*x)
d2w_dxdy += (Am*beta_m*Chy + Bm*beta_m*Shy + Cm*(Shy + beta_m*yChy) + Dm*(Chy + beta_m*yShy))*beta_m*Cx
return d2w_dxdy
def d2w_dy2(self, x, y):
# Returns the second derivative of w wrt y at the given location
if self.symmetric:
y -= 0.5*self.plate.b
d2w_dy2 = 0.0
for m in self.load.m[:self.m_max]:
Am, Bm, Cm, Dm, km = self.coefs(m)
beta_m = m*np.pi/self.plate.a
Shy = np.sinh(beta_m*y)
Chy = np.cosh(beta_m*y)
yShy = y*np.sinh(beta_m*y)
yChy = y*np.cosh(beta_m*y)
Sx = np.sin(beta_m*x)
d2w_dy2 += (Am*beta_m**2*Shy + Bm*beta_m**2*Chy + Cm*(2.0*beta_m*Chy + beta_m**2*yShy) + Dm*(2.0*beta_m*Shy + beta_m**2*yChy))*Sx
return d2w_dy2
def d3w_dy3(self, x, y):
# Returns the third derivative of w wrt y at the given location
if self.symmetric:
y -= 0.5*self.plate.b
d3w_dy3 = 0.0
for m in self.load.m[:self.m_max]:
Am, Bm, Cm, Dm, km = self.coefs(m)
beta_m = m*np.pi/self.plate.a
Shy = np.sinh(beta_m*y)
Chy = np.cosh(beta_m*y)
yShy = y*np.sinh(beta_m*y)
yChy = y*np.cosh(beta_m*y)
Sx = np.sin(beta_m*x)
d3w_dy3 += (Am*beta_m**3*Chy + Bm*beta_m**3*Shy + Cm*(3.0*beta_m**2*Shy + beta_m**3*yChy) + Dm*(3.0*beta_m**2*Chy + beta_m**3*yShy))*Sx
return d3w_dy3
def d3w_dx2dy(self, x, y):
# Returns the third derivative of w wrt x squared and y at the given location
if self.symmetric:
y -= 0.5*self.plate.b
d3w_dx2dy = 0.0
for m in self.load.m[:self.m_max]:
Am, Bm, Cm, Dm, km = self.coefs(m)
beta_m = m*np.pi/self.plate.a
Shy = np.sinh(beta_m*y)
Chy = np.cosh(beta_m*y)
yShy = y*np.sinh(beta_m*y)
yChy = y*np.cosh(beta_m*y)
Sx = np.sin(beta_m*x)
d3w_dx2dy -= (Am*beta_m*Chy + Bm*beta_m*Shy + Cm*(Shy + beta_m*yChy) + Dm*(Chy + beta_m*yShy))*beta_m**2*Sx
return d3w_dx2dy
def d3w_dxdy2(self, x, y):
# Returns the third derivative of w wrt x and y squared at the given location
if self.symmetric:
y -= 0.5*self.plate.b
d3w_dxdy2 = 0.0
for m in self.load.m[:self.m_max]:
Am, Bm, Cm, Dm, km = self.coefs(m)
beta_m = m*np.pi/self.plate.a
Shy = np.sinh(beta_m*y)
Chy = np.cosh(beta_m*y)
yShy = y*np.sinh(beta_m*y)
yChy = y*np.cosh(beta_m*y)
Cx = np.cos(beta_m*x)
d3w_dxdy2 += (Am*beta_m**2*Shy + Bm*beta_m**2*Chy + Cm*(2.0*beta_m*Chy+beta_m**2*yShy) + Dm*(2.0*beta_m*Shy + beta_m**2*yChy))*beta_m*Cx
return d3w_dxdy2