-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (46 loc) · 1.77 KB
/
main.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
from flask import Flask, request, jsonify
from indeterminatebeam import Beam, Support, PointLoadV, DistributedLoadV
app = Flask(__name__)
# Initialize an empty beam object
beam = None
@app.route('/setup_beam', methods=['POST'])
def setup_beam():
global beam
data = request.get_json()
length = data['length']
E = data['E']
I = data['I']
# Create the beam instance
beam = Beam(length, E, I)
# Add supports
for support in data['supports']:
beam.add_supports(Support(support['coord'], tuple(support['fixed'])))
# Add loads
for load in data['loads']:
if load['type'] == 'point':
beam.add_loads(PointLoadV(load['magnitude'], load['location']))
elif load['type'] == 'distributed':
beam.add_loads(DistributedLoadV(load['magnitude'], tuple(load['range'])))
# Perform analysis
beam.analyse()
return jsonify({'message': 'Beam setup and analysis successful'})
@app.route('/get_shear_force', methods=['POST'])
def get_shear_force():
data = request.get_json()
x_positions = data['x_positions']
shear_forces = [beam.get_shear_force(x) for x in x_positions]
return jsonify({'shear_forces': shear_forces})
@app.route('/get_bending_moment', methods=['POST'])
def get_bending_moment():
data = request.get_json()
x_positions = data['x_positions']
bending_moments = [beam.get_bending_moment(x) for x in x_positions]
return jsonify({'bending_moments': bending_moments})
@app.route('/get_normal_force', methods=['POST'])
def get_normal_force():
data = request.get_json()
x_positions = data['x_positions']
normal_force = [beam.get_normal_force(x) for x in x_positions]
return jsonify({'normal_force': normal_force})
#if __name__ == '__main__':
#app.run(debug=True)