-
Notifications
You must be signed in to change notification settings - Fork 0
/
beamcalc.py
121 lines (96 loc) · 3.27 KB
/
beamcalc.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
from elements import *
import matplotlib
import matplotlib.pyplot as plt
import io
import base64
matplotlib.use('agg')
def generate_graphs(input):
ss = SystemElements(EA=15000, EI=5000)
variables = []
variables.append(float(input['BeamLen']))
for each in input['Pin']:
variables.append(float(each))
for each in input['Roller']:
variables.append(float(each))
for each in input['Fixed']:
if each == 'Left':
variables.append(float(0))
else:
variables.append(float(input['BeamLen']))
for each in input['PL']:
variables.append(float(each['location']))
for each in input['Mom']:
variables.append(float(each['location']))
for each in input['UDL']:
variables.append(float(each['start']))
variables.append(float(each['end']))
variables.sort()
nodes = list(set(variables))
nodes.sort()
if nodes[0] != 0:
nodes.insert(0,float(0))
for each in nodes:
if each > 0:
ss.add_element([each, 0])
print("add element")
print(each)
for each in input['Pin']:
nodePin = int(nodes.index(float(each)) + 1)
ss.add_support_hinged([nodePin])
for each in input['Fixed']:
if each == 'Left':
nodeFixed = int(nodes.index(float(0)) + 1)
else:
nodeFixed = int(nodes.index(float(input['BeamLen'])) + 1)
ss.add_support_fixed([nodeFixed])
for each in input['Roller']:
nodeRoller = int(nodes.index(float(each)) + 1)
ss.add_support_roll(nodeRoller, direction='x')
for each in input['PL']:
locPL = float(each['location'])
nodePL = int(nodes.index(locPL) + 1)
loadPL = -1 * float(each['load'])
ss.point_load(nodePL, Fx=0, Fy = loadPL)
for each in input['Mom']:
locMom = float(each['location'])
nodeMom = int(nodes.index(locMom) + 1)
loadMom = float(each['load'])
ss.moment_load(nodeMom, Ty= loadMom)
for each in input['UDL']:
startUDL = float(each['start'])
endUDL = float(each['end'])
nodeStart = int(nodes.index(startUDL) + 1)
nodeEnd = int(nodes.index(endUDL) + 1)
for i in range(nodeStart, nodeEnd):
ss.q_load(-1 * float(each['load']),[i])
ss.solve()
x ,y = ss.show_bending_moment(show = False, values_only = True, factor = 1)
neg = -1
y = neg * np.array(y)
maxbm = float(max(y))
plt.axhline(linewidth=1, color='k')
plt.plot(x,y)
plt.title('Bending Moment')
plt.xlabel('Length (m)')
plt.ylabel('Bending Moment (Nm)')
img = io.BytesIO()
plt.savefig(img, format='png')
img.seek(0)
bm = base64.b64encode(img.getvalue()).decode('utf8')
plt.figure()
x ,y = ss.show_shear_force(show = False, values_only = True, factor = 1)
neg = -1
y = neg * np.array(y)
maxshear = float(max(y))
plt.axhline(linewidth=1, color='k')
plt.plot(x,y)
plt.title('Shear Force')
plt.xlabel('Length (m)')
plt.ylabel('Shear Force (N)')
imgShear = io.BytesIO()
plt.savefig(imgShear, format='png')
imgShear.seek(0)
shear = base64.b64encode(imgShear.getvalue()).decode('utf8')
plt.figure()
graphs = [bm, shear, maxbm, maxshear]
return graphs