-
Notifications
You must be signed in to change notification settings - Fork 0
/
TRUSS-ty-CALC_v1.3.4.py
2756 lines (2408 loc) · 139 KB
/
TRUSS-ty-CALC_v1.3.4.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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Copyright© 2023, Spencer Hiscox
All rights Reserved
"""
from time import perf_counter as pctime
from time import sleep
from math import sqrt, pi, sin, cos, tan
π = pi
from typing import Tuple
import re
from gc import collect
from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset
from copy import deepcopy
from numpy import arange
from inspect import currentframe
#CLASS DEFINITIONS
class truss:
def __init__(self, no_joists, angle, t_type):
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, "truss()"])
self.no_joists = no_joists
self.m_dimensions = {'angle': angle, 'Sj': _span / (no_joists + 1)}
self.m_dimensions['Diag'] = self.m_dimensions['Sj'] / angle[1]
self.m_dimensions['Vert'] = self.m_dimensions['Diag'] * angle[2]
self.m_weights = [[], [], [], [], []]
self.m_forces = [[], [], [], [], []]
self.m_sections = [[], [], [], [], []]
self.total_weight = 0
self.fsir = 0
self.typ = t_type
if self.typ == 3:
self.m_dimensions['Horz'] = self.m_dimensions['Sj'] * 2
self.m_dimensions['Bot'] = self.m_dimensions['Horz'] * 2
if self.typ == 2:
self.m_dimensions['Bot'] = self.m_dimensions['Sj'] * 2
if self.typ == 1:
self.m_dimensions['CenterBot'] = 2 * self.m_dimensions['Sj']
class diag_obj:
def __init__(self):
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, "diag_obj()"])
def forces(self, **kwargs)->None:
global t_count, t0, full_solve, dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, "diag_obj.forces()"])
sav_2iterF = full_solve
full_solve = False
n_upd = kwargs.get('no_update')
user_choice = []
print(f"{new_screen}Please note that force algorithm diagnostics does not currently support second\n"
"iteration calculations. Support for that feature will hopefully be implemented soon...")
user_choice.append(input(f"\nView graphs from the two algorithms' generated data [Y / N]? ").lower())
if user_choice[0] == 'y' or user_choice == 'yes':
user_choice[0] == True
else:
user_choice[0] = False
user_choice.append(input("Display Optimal Truss solution upon completion of optimization algorithms [Y / N]? ").lower())
if user_choice[1] == 'y' or user_choice == 'yes':
user_choice[1] = True
else:
user_choice[1] = False
t_count = 0
t0 = pctime()
optimize(disp_res=user_choice[1], disp_graphs=user_choice[0])
retainer = [weights_by_type, deepcopy(angle_matrix)]
input("Fast Optimization complete. Press <ENTER> to Continue...")
t_count = 0
t0 = pctime()
optimize(basic=True, disp_res=user_choice[1], disp_graphs=user_choice[0])
input("Hard-code calculation of forces complete. Press <ENTER> to compare algorithm results...")
print(f"{new_screen}\nVerifying all weights match, comparing by angle and truss type...\n\n")
sleep(3)
fail = False
truss_types = [f"{'Howe':>24}\t", f"{'Pratt':>24}\t", f"{'Warren with Verticals':>24}\t", f"{'Warren without Verticals':>24}\t"]
for truss_type in range(len(weights_by_type)):
row_no, row_change = 1, False
print(truss_types[truss_type], end="")
for angle_entry in range(len(weights_by_type[truss_type])):
if weights_by_type[truss_type][angle_entry] != retainer[0][truss_type][angle_entry]:
fail = True
if row_change:
print(f"{('False', 'True')[not fail]:>36}", end="\t")
row_change = False
else:
print(not fail, end="\t")
if angle_entry > (131 / 8) * row_no - 1:
row_no += 1
row_change = True
print()
sleep(0.1)
print()
if not fail:
if not n_upd:
update_truss_matrix(retainer[1])
print("\n\nALL CALCULATED VALUES MATCH. FAST ALGORITHM IS VERIFIED. DIAGNOSTICS COMPLETE.\n")
input("Press <ENTER> to Continue...")
else:
input("\n\nTEST FAILED. FAST ALGORITHM IS NON-FUNCTIONAL. PLEASE USE HARD-CODE (BASIC) ALGORITHM FOR FORCE CALCULATIONS.\n"
"(HARD-CODE OPTIMIZATION RESULTS WILL BE STORED IN MEMORY WHEN YOU EXIT THESE DIAGNOSTICS)\n"
"DIAGNOSTICS COMPLETE.\nPress <ENTER> to Continue...")
if not n_upd:
update_truss_matrix()
del retainer
collect();
full_solve = sav_2iterF
def iter2_dispC(self):
global number_joists, t_count, dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, "diag_obj.iter2_dispC()"])
def invalid_response(string: str)->str:
print(f"{string} is not a valid response.")
input("Press <ENTER> to continue.")
print(f"{new_screen}")
user_choice = []
while True:
print(f"{new_screen}\t1:\tHowe\n\t2:\tPratt\n\t3:\tWarren (with verticals)\n\t4:\tWarren (without verticals)\n\n")
user_choice.append(input("Select truss type from the menu options: ").lower())
try:
user_choice[0] = int(user_choice[0])
if (0 < user_choice[0] < 5):
user_choice[0] -= 1
break
else:
invalid_response(user_choice[0])
continue
except:
try:
if re.findall('how', user_choice[0]):
user_choice[0] = 0
elif re.findall('prat', user_choice[0]):
user_choice[0] = 1
elif re.findall('warr?en', user_choice[0]):
if re.findall('Ø', user_choice[0]) or re.findall('no', user_choice[0]) or \
re.findall('nv', user_choice[0]):
user_choice[0] = 3
else:
user_choice[0] = 2
else:
invalid_repsonse(user_choice[0])
continue
break
except:
invalid_response(user_choice[0])
continue
while True:
user_choice.append(input("\nEnter angle: ").lower())
if user_choice[1].isdigit():
user_choice[1] = int(user_choice[1])
if user_choice [1] >= 90 or user_choice[1] <= 0:
invalid_response(user_choice[1])
continue
break
else:
try:
user_choice[1] = float(user_choice[1])
if int(user_choice[1]) >= 90 or int(user_choice[1]) <= 0:
invalid_response(user_choice[1])
continue
break
except:
invalid_response(user_choice[1])
continue
angle = user_choice[1] * pi / 180
angle = [angle, sin(angle), cos(angle), tan(angle)]
truss_matrix[user_choice[0]][user_choice[1]] = dii_2iter(number_joists, angle, single=True, typ=user_choice[0], diag=True)
while True:
final_user_choice = input("\n\nDisplay calculated truss [Y / N]? ").lower()
if final_user_choice == 'y' or re.findall('yes', final_user_choice) or re.findall('display', final_user_choice):
display_truss(truss_matrix[user_choice[0]][user_choice[1]])
break
elif final_user_choice == 'n' or re.findall('no', user_choice):
break
else:
input(f"{final_user_choice} is not a valid response. Please enter <Y> or <N>.\nPress <ENTER> to Continue...")
def truss_soln_check_balance(self):
global full_solve, _P_f, _P_faj, new_screen, empty, optima, dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, "diag_obj.truss_soln_check_balance()"])
print(f"{new_screen}{'VERIFYING SYMMETRIC FORCE BALANCE FOR OPTIMAL TRUSSES, BY TRUSS TYPE':>82}\n{f'{empty:=<82}':>82}\n\n")
truss_type = ['HOWE TRUSS', 'PRATT TRUSS', 'WARREN TRUSS - (with verticals)', 'WARREN TRUSS - (withOUT verticals)']
pass_fail = []
for truss in range(len(optima)):
underline = f'{"":=>82}'
top_member = optima[truss].m_weights[0][-1] * 1.25 / 2
determinant = truss % 2
other_member, other_member_F = 0, ''
if determinant:
other_member = optima[truss].m_weights[3][-1] * 1.25 / 2
other_member_F = f"{optima[truss].m_forces[3][-1] * optima[truss].m_dimensions['angle'][2]:.3f}"
else:
other_member = optima[truss].m_weights[2][-1] * 1.25 / 2
other_member_F = f"{optima[truss].m_forces[2][-1]:.3f}"
factored_load = 0
total_force = 0
if full_solve:
factored_load = _P_faj
if truss == 1:
total_force = 2 * (other_member + top_member) + factored_load
pass_fail.append(abs(total_force - float(other_member_F) * 2) / total_force < 0.003)
elif truss == 3:
total_force = 2 * (top_member + factored_load) + other_member
pass_fail.append(abs(total_force - float(other_member_F)) / total_force < 0.003)
else:
total_force = other_member + 2 * top_member + factored_load
pass_fail.append(abs(total_force - float(other_member_F)) / total_force < 0.003)
else:
factored_load = _P_f
total_force = factored_load
if truss == 1:
pass_fail.append(abs(total_force - float(other_member_F) * 2) / total_force < 0.003)
elif truss == 3:
total_force *= 2
pass_fail.append(abs(total_force - float(other_member_F)) / total_force < 0.003)
else:
pass_fail.append(abs(total_force - float(other_member_F)) / total_force < 0.003)
differential = ("CENTER VERTICAL", "CENTERMOST INWARD LEANING DIAGONAL")[determinant]
space = ' '
print(f"{underline}\n{truss_type[truss]:^82}\n{underline}\n")
if truss == 1:
print("\tCENTER TOP MEMBER WEIGHT (LEFT & RIGHT OF JOINT):"
f"{f'{top_member:.3f} * 2 = {top_member * 2:.3f}':>25}\n"
f"\t{differential + ' WEIGHT:':>49}{f'{other_member:.3f} * 2 = {other_member * 2:.3f}':>25}\n"
f"\t{'FACTORED LOAD:':>49}{f'{factored_load:.3f}':>25}\n"
f"{f'{empty:=>32}':>82}\n"
f"\t{f'TOTAL: {total_force:.3f}':>74}\n"
f"\t{differential + ' FORCE:':>49}{f'{other_member_F} * 2 = {float(other_member_F) * 2:.3f}':>25}\n"
f"{f'{empty:=>32}':>82}\n"
f"{'PERCENT DIFFERENCE:':>67}{f'{abs(total_force - float(other_member_F) * 2) / float(total_force):.3f}%':>15}\n")
elif truss == 3 and full_solve:
print("\tCENTER TOP MEMBER WEIGHT (LEFT & RIGHT OF JOINT):"
f"{f'{top_member:.3f} * 2 = {top_member * 2:.3f}':>25}\n"
f"\t{differential + ' WEIGHT:':>49}{f'{other_member:.3f} * 2 = {other_member * 2:.3f}':>25}\n"
f"\t{'FACTORED LOAD:':>49}{f'{factored_load:.3f} * 2 = {factored_load * 2:.3f}':>25}\n"
f"{f'{empty:=>32}':>82}\n"
f"\t{f'TOTAL: {total_force:.3f}':>74}\n"
f"\t{differential + ' FORCE:':>49}{other_member_F:>25}\n"
f"{f'{empty:=>32}':>82}\n"
f"{'PERCENT DIFFERENCE:':>67}{f'{abs(total_force - float(other_member_F)) / float(total_force):.3f}%':>15}\n")
else:
print("\tCENTER TOP MEMBER WEIGHT (LEFT & RIGHT OF JOINT):"
f"{f'{top_member:.3f} * 2 = {top_member * 2:.3f}':>25}\n"
f"\t{differential + ' WEIGHT:':>49}{f'{other_member:.3f}':>25}\n"
f"\t{'FACTORED LOAD:':>49}{f'{factored_load:.3f}':>25}\n"
f"{f'{empty:=>32}':>82}\n"
f"\t{f'TOTAL: {total_force:.3f}':>74}\n"
f"\t{differential + ' FORCE:':>49}{other_member_F:>25}\n"
f"{f'{empty:=>32}':>82}\n"
f"{'PERCENT DIFFERENCE:':>67}{f'{abs(total_force - float(other_member_F)) / float(total_force):.3f}%':>15}\n")
if pass_fail[truss]:
print(f"\n{f'{empty:=>27}':>82}\n{'FORCE MATCH: TRUE':>82}\n{f'{empty:=>27}':>82}")
else:
print(f"\n{f'{empty:=>27}':>82}\n{'FORCE MATCH: FALSE':>82}\n{f'{empty:=>27}':>82}")
print("\n\n")
for entry in range(len(pass_fail)):
if not pass_fail[entry]:
break
if entry == 3:
print(f"\n{'':=>82}\n"
f"{'FORCE CALCULATIONS VERIFIED BALANCED. ALGORITHMS CONFIRMED.':^82}\n"
f"{'':=>82}\n\n"
f"\tFINAL RESULTS:\n ==============\n")
for entry in range(len(pass_fail)):
print(f"{truss_type[entry]:>35}:\t{('FAIL', 'PASS')[pass_fail[entry]]}")
input("\n\nPress <ENTER> to Continue...")
return
print(f"\n{'':=>82}\n"
f"{'FORCE CALCULATIONS <UNBALANCED>!! ALGORITHMS FAULTY.':^82}\n"
f"{'':=>82}\n\n"
f"\tFINAL RESULTS:\n ==============\n")
for entry in range(len(pass_fail)):
print(f"{truss_type[entry]:>35}:\t{('FAIL', 'PASS')[pass_fail[entry]]}")
input("\n\nPress <ENTER> to Continue...")
#GLOBAL FUNCTION DEFINITIONS
def disp_truss_menu()->None:
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
def invalid_response(string: str)->str:
print(f"{string} is not a valid response.")
input("Press <ENTER> to continue.")
print(f"{new_screen}")
if not truss_matrix[0]:
input(f"{new_screen}No Optimization results loaded into memory. Run optimization or load saved results from file.\n"
"Press <ENTER> to Continue...")
else:
user_choice = []
while True:
print(f"{new_screen}\t1:\tHowe\n\t2:\tPratt\n\t3:\tWarren (with verticals)\n\t4:\tWarren (without verticals)\n\n")
user_choice.append(input("Select truss type from the menu options: ").lower())
try:
user_choice[0] = int(user_choice[0])
if (0 < user_choice[0] < 5):
user_choice[0] -= 1
break
else:
invalid_response(user_choice[0])
continue
except:
try:
if re.findall('how', user_choice[0]):
user_choice[0] = 0
elif re.findall('prat', user_choice[0]):
user_choice[0] = 1
elif re.findall('warr?en', user_choice[0]):
if re.findall('Ø', user_choice[0]) or re.findall('no', user_choice[0]) or \
re.findall('nv', user_choice[0]):
user_choice[0] = 3
else:
user_choice[0] = 2
else:
invalid_repsonse(user_choice[0])
continue
break
except:
invalid_response(user_choice[0])
continue
while True:
user_choice.append(input("\nEnter angle: ").lower())
if user_choice[1].isdigit():
user_choice[1] = int(user_choice[1])
if user_choice [1] >= 90 or user_choice[1] <= 0:
invalid_response(user_choice[1])
continue
break
else:
try:
user_choice[1] = float(user_choice[1])
if int(user_choice[1]) >= 90 or int(user_choice[1]) <= 0:
invalid_response(user_choice[1])
continue
break
except:
invalid_response(user_choice[1])
continue
try:
display_truss(truss_matrix[user_choice[0]][user_choice[1]])
except:
angle = user_choice[1] * pi / 180
angle = [angle, sin(angle), cos(angle), tan(angle)]
truss_matrix[user_choice[0]][user_choice[1]] = ((fast_calculate_member_forces(number_joists, angle, single=True, typ=user_choice[0]),
calculate_member_forces(number_joists, angle, single=True, typ=user_choice[0]))[basic_force_algorithm],
dii_2iter(number_joists, angle, single=True, typ=user_choice[0]))[full_solve]
if not full_solve:
assign_HSS_sections(truss_matrix[user_choice[0]][user_choice[1]])
display_truss(truss_matrix[user_choice[0]][user_choice[1]])
def display_truss(obj: '__main__.truss')->None:
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
truss_names = ['Howe', 'Pratt', 'Warren\n\t\t(with vertical members)', 'Warren\n\t\t(without vertical members)']
bullet = '● '
horizontal_display = f'{obj.m_dimensions["Sj"]}\n'
if obj.typ > 1:
if obj.typ > 2:
horizontal_display = f'\n{"GENERAL HORIZONTALS:":>36}\t{obj.m_dimensions["Horz"]}' + f'\n{"BOTTOM CENTER:":>36}\t{obj.m_dimensions["Bot"]}\n'
elif obj.typ == 1:
horizontal_display = f'\n{"GENERAL HORIZONTALS:":>36}\t{obj.m_dimensions["Sj"]}' + f'\n{"BOTTOM CENTER:":>36}\t{obj.m_dimensions["CenterBot"]}\n'
else:
horizontal_display = '\n\t\t{"TOP MEMBERS:":>36}\t' + horizontal_display + f'\n\t\t{"BOTTOM MEMBERS:":>36}\t{obj.m_dimensions["Bot"]}\n'
row_headers = ['TOP MEMBERS', 'OUTWARD-LEANING DIAGONAL MEMBERS', 'VERTICAL MEMBERS', 'INWARD-LEANING DIAGONAL MEMBERS', 'BOTTOM MEMBERS']
if obj.total_weight == None:
print(f"{new_screen}TRUSS DESIGN / CONFIGURATION DISPLAY\n{'':=>36}\n")
print("< UNABLE TO RESOLVE TRUSS DESIGN: HSS SECTIONS AVAILABLE WILL FAIL UNDER OPERATIONAL LOADS >\n\n"
f'{"TYPE:":>9}\t{truss_names[obj.typ]}\n'
f'{"ANGLE*:":>9}\t{obj.m_dimensions["angle"][0] / pi * 180:.3f}\n'
f'WEIGHT**:\t{obj.total_weight}\n\n\n'
f'*ALL ANGLES ARE MEASURED TO THE NORMAL AND GIVEN IN DEGREES (°)\n**WEIGHT GIVEN IN KILONEWTONS (kN)\n{"":=>156}\n', sep="")
else:
print(f"{new_screen}TRUSS DESIGN / CONFIGURATION DISPLAY\n{'':=>36}\n")
print(("\n", (f"\t<OPTIMAL {truss_names[obj.typ]} TRUSS>\n\n", "\t<OPTIMAL DESIGN>\n\n")[obj == optimal_truss_design])[obj in optima] +
f'{"TYPE:":>9}\t{truss_names[obj.typ]}\n'
f'{"ANGLE*:":>9}\t{obj.m_dimensions["angle"][0] / pi * 180:.3f}\n'
f'WEIGHT**:\t{obj.total_weight}\n\n\n'
f'*ALL ANGLES ARE MEASURED TO THE NORMAL AND GIVEN IN DEGREES (°)\n**WEIGHT GIVEN IN KILONEWTONS (kN)\n{"":=>156}\n')
print(f'DIMENSIONS*:\n{"":=>11}\n\n'
f'\t VERTICAL MEMBERS:\t{obj.m_dimensions["Vert"]}\n'
f'\t DIAGONAL MEMBERS:\t{obj.m_dimensions["Diag"]}\n'
f'\tHORIZONTAL MEMBERS:\t{horizontal_display}\n\n'
f'*ALL DIMENSIONS ARE GIVEN IN METERS (m)\n')
print(f'NOTE:\n\t{bullet}THIS TRUSS DESIGN / CONFIGURATION IS PREDICATED ON A JOIST SPACING OF {obj.m_dimensions["Sj"]}m.\n'
f'\t{bullet}THIS JOIST SPACING ALLOWS FOR {obj.no_joists} JOISTS EVENLY DISTRIBUTED ACROSS A ROOF SPAN OF {_span}m\n\n{"":=>156}\n\n')
print(f'HSS SECTIONS, BY MEMBER*:\n{"":=>24}\n')
for i in range(len(obj.m_sections)):
print(f"{f'{row_headers[i]}':>32}\t", end="")
for entry in obj.m_sections[i]:
print(entry, end="\t")
print()
print(f"\n\n*HSS SECTIONS ARE LISTED BY MEMBER, IN ORDER FROM THE OUTERMOST MEMBER TO THE INNERMOST (CENTRAL) MEMBERS\nAS VIEWED, LEFT TO RIGHT IN THE ABOVE TABLE\n{'':=>156}\n\n")
print(f"INTERNAL MEMBER FORCES*, BY MEMBER:\n{'':=>34}\n")
for i in range(len(obj.m_forces)):
print(f"{f'{row_headers[i]}':>32}", end="")
for entry in obj.m_forces[i]:
print(f"{f'{entry:.3f}':>16}", end="")
print()
print("\n\n*ALL FORCES ARE GIVEN IN KILONEWTONS (kN)")
if disp_from_disp:
while True:
user_choice = input("\n[D]isplay another truss or Return to [M]ain Menu [D / M]? ").lower()
if user_choice == 'd' or re.findall('display', user_choice):
disp_truss_menu()
break
elif user_choice == 'm' or re.findall('main', user_choice) or re.findall('menu', user_choice):
break
else:
input("Invalid response. Please enter either <D> or <M> to make your selection.\n"
"Press <ENTER> to Continue...")
def c_round(num: float, precision: int = 0)->int:
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
if precision < 0:
precision = abs(precision)
subtraction = num % (10 ** precision)
tmp = int(subtraction / 10 ** (precision - 1))
return (int(num - subtraction), int(num - subtraction + 10 ** precision))[tmp > 4]
else:
tmp = int((num * 10 ** (precision + 1)) % 10)
if precision == 0:
return (int(num), int(num) + 1)[tmp > 4]
else:
return (int(num * 10 ** precision) / 10 ** precision, (int(num * 10 ** precision) + 1) / 10 ** precision)[tmp > 4]
def full_list(**kwargs)->None:
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
from_update = kwargs.get('f_update')
first_run = kwargs.get('first_rn')
def left_fmt(*args)->str:
if len(args) > 2:
raise ValueError("Function left_fmt() takes a maximum of 2 arguments.")
string, space = '', 75
if len(args) == 2:
if type(args[0]) == str and type(args[1]) == int:
string, space = args[0], args[1]
elif type(args[0]) == int and type(args[1]) == str:
string, space = args[1], args[0]
else:
raise ValueError("Function left_fmt() can take only one argument of "
"type string and one argument of type int.")
if len(args) == 1:
if type(args[0]) == str:
string = args[0]
elif type(args[0]) == int:
space = args[0]
else:
raise ValueError("Function left_fmt() can take only arguments of "
"type str or type int.")
space -= len(string)
space *= ' '
return f"{string}{space}"
headers = [f'{"F17 SPECIFIC VARIABLES:":<75}CONSTANTS:\n{"":=>27}{"":<48}{"":=>38}',
f'{"1st ITERATION VALUES:":<75}2nd ITERATION VALUES:\n{"":=<46}{"":<29}{"":=<46}']
f17_spec = [f"{'Roof (Truss) Span:':>27}{_span:>3} m", f"{'Truss Spacing:':>27}{_S_t:>3} m",
f"{'Thickness of Concrete Slab:':>27}{_T_s:>6} m", f"{'Snow Accumulation:':>27}{_h_s:>5} m"]
constants = [f"{'Unit Weight of Snow (NBCC):':>38}{_ɣ_s:>5} kN/m³",
f"{'Additional Weight of Wet Snow (NBCC):':>38}{_S_r:>5} kN/m²",
f"{'Weight of the Steel Deck:':>38}{_W_sd:>5} kN/m²",
f"{'Steel Deck Flute Height:':>38}{_h_d:>7} m",
f"{'Number of Trusses supporting the roof:':>38}{_ROOF_SUPPORTS:>3}",
f"{'Unit Weight of Concrete:':>38}{_ɣ_c:>3} kN/m³",
f"{'Weight of Built-up Roof:':>38}{_W_r:>6} kN/m²",
f"{'Joist Spacing:':>38}{_S_j:>5} m"]
first_iter = [f"{'Snow Load / Unit Area Roof:':>46}{f'{_S_s:.2f}':>7} kN/m²",
f"{'Total Snow Load:':>46}{f'{_S:.2f}':>7} kN/m²",
f"{'Roof Length*:':>46}{_ROOF_LENGTH:>4} m",
f"{'Weight of Concrete Cover:':>46}{f'{_W_cc:.3f}':>8} kN/m²",
f"{'Weight of Concrete between S.D. Flutes:':>46}{f'{_W_cf:.3f}':>8} kN/m²",
f"{'TOTAL Weight of Roof:':>46}{f'{_W_T:.3f}':>8} kN/m²",
f"{'Total Factored Load:':>46}{f'{_w_f:.4f}':>9} kN/m²",
f"{'Factored, Uniform Distributed Load (Joists):':>46}{f'{_UDL_fj:.5f}':>10} kN/m",
f"{'Factored Support Reaction (each end of joist):':>46}{f'{_P_fj:.6f}':>11} kN",
f"{'Factored Load at each joint on the main Truss:':>46}{f'{_P_f:.5f}':>10} kN"]
second_iter = [f"{'Open-web Steel Joist, self-weight Dead Load:':>46}{f'{_w_swj:.3f}':>8} kN/m",
f"{'Total Dead Load per Open-web Steel Joist:':>46}{f'{_D_j:.3f}':>8} kN",
f"{'Adjusted factored Load / joint on main Truss:':>46}{f'{_P_fa:.5f}':>10} kN"]
print(f'{new_screen}{"":=<133}\n{"CURRENT VARIABLE VALUES":^133}\n{"":=>133}\n\n')
print(headers[0])
max_length = max([len(constants), len(f17_spec)])
for i in range(max_length):
try:
print(left_fmt(f17_spec[i]), end="")
except:
print(left_fmt(), end="")
try:
print(constants[i])
except:
print()
print(f'\n\n{f"{empty:=>84}":^133}\n{"CALCULATED VALUES":^133}\n{f"{empty:=>84}":^133}')
print(headers[1])
max_length = max([len(first_iter), len(second_iter)])
for i in range(max_length):
try:
print(left_fmt(first_iter[i]), end="")
except:
print(left_fmt(), end="")
try:
print(second_iter[i])
except:
print()
print('\n*not accounting for non-zero width of truss section members\n\n')
if not first_run:
while True:
if from_update:
user_choice = 'u'
else:
user_choice = input('[U]pdate variable values(s) or Return to [M]ain Menu [U / M]? ').lower()
if user_choice == 'u' or user_choice == 'update':
if not update_variable_values(True):
break
elif user_choice == 'm' or re.findall('main', user_choice) or re.findall('menu', user_choice):
break
else:
input("Invalid response. Please enter either <U> or <M> to make your selection.\n"
"Press <ENTER> to Continue...")
def calculate_HSS_radii():
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
interm_vals = []
for section in sections:
interm_vals.append(re.findall('(?<=[HSS|X])\d*\.?\d*(?=X|$)', section))
sections[section]['out_rad'] = (
sections[section]['Area(mm²)'] - 2 * float(interm_vals[-1][2]) * (
float(interm_vals[-1][0]) + float(interm_vals[-1][1]) - π * float(interm_vals[-1][2]) / 2)) / (2 * float(interm_vals[-1][2]) * (π - 4))
sections[section]['in_rad'] = sections[section]['out_rad'] - float(interm_vals[-1][2])
def imp_lookup_table_HSS(filename)->None:
global sections, dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
sections = {}
headers, data = [], []
with open(filename) as file:
file.readline()
headers = file.readline().replace(" ", "").replace("\n", "").split(sep=",")
for line in file:
data.append(line.replace(" ", "").split(sep=","))
data[-1][-1].replace("\n", "")
for entry in data:
sections[entry[0]] = {}
for i in range(1, len(headers)):
sections[entry[0]][headers[i]] = float(entry[i])
for section in sections:
sections[section]['T_r'] = _φ * _σ_y * sections[section]['Area(mm²)'] / 1000
calculate_HSS_radii()
def imp_lookup_table_OWSJ(filename)->None:
global joists, dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
joists = {}
headers, data, i, j = [], [], 0, 0
with open(filename) as file:
for k in range(2):
file.readline()
for k in range(4):
headers.append(file.readline().strip().replace("\n", ""))
for line in file:
if j == 0:
j += 1
continue
if j == 1:
data.append([line.strip().replace("\n", "")])
j += 1
continue
data[i] += [line.strip().replace("\n", "")]
if j == 4:
j = 0
i += 1
continue
j += 1
for entry in data:
joists[data.index(entry)] = {}
for element in entry:
joists[data.index(entry)][headers[entry.index(element)]] = element
def calculate_total_mass(obj: '__main__.truss')->None:
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
obj.total_weight = 0
for member_type in obj.m_weights:
for member in member_type:
obj.total_weight += member
obj.total_weight *= 2
if len(obj.m_weights[2]):
obj.total_weight -= obj.m_weights[2][-1]
if obj.typ == 3:
obj.total_weight -= obj.m_weights[0][-1]
def calculate_member_mass(obj: '__main__.truss', member_length: list)->None:
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
obj.m_weights = [[], [], [], [], []]
for i in range(len(obj.m_sections)):
for j in range(len(obj.m_sections[i])):
if type(obj.m_sections[i][j]) == list:
obj.m_weights[i].append(sections[obj.m_sections[i][j][0]]['DeadLoad(kN/m)'] * member_length[i])
continue
obj.m_weights[i].append(sections[obj.m_sections[i][j]]['DeadLoad(kN/m)'] * member_length[i])
calculate_total_mass(obj)
def assign_HSS_sections(obj: '__main__.truss')->None:
global dx, dx_exec_list
if dx:
dx_exec_list = "\n".join([dx_exec_list, f"{currentframe().f_code.co_name}()"])
_SINE, _COSINE = obj.m_dimensions['angle'][1], obj.m_dimensions['angle'][2]
member_length = [0, obj.m_dimensions['Diag'], obj.m_dimensions['Vert'], obj.m_dimensions['Diag'], 0]
obj.m_sections = [[], [], [], [], []]
if obj.typ == 3:
member_length[0] = member_length[4] = obj.m_dimensions['Horz']
elif obj.typ == 2:
member_length[4] = obj.m_dimensions['Bot']
member_length[0] = obj.m_dimensions['Sj']
else:
member_length[0] = member_length[4] = obj.m_dimensions['Sj']
if obj.typ == 1:
for i in range(len(member_length)):
if i in [0, 3]:
for section in sections:
_σ_e = (π**2 * _E) / ((_K * member_length[i] / sections[section]['r(mm)'])**2)
λ = sqrt(_σ_y / _σ_e)
f = 1 / ((1 + λ**(2 * _n))**(1 / _n))
sections[section]['C_r'] = (sections[section]['T_r'] * f)
sections[section]['KLr'] = (_K * member_length[i] / sections[section]['r(mm)']) <= 200
for k in range(len(obj.m_forces[i])):
if obj.m_forces[i][k]:
candidates, c2, c3 = {}, {}, []
for section in sections:
if obj.m_forces[i][k] > sections[section]['C_r']:
continue
candidates[sections[section]['DeadLoad(kN/m)']] = section
c2[section] = sections[section]['DeadLoad(kN/m)']
op_sec = list(c2.values())
op_sec.sort()
j = 0
for item in c2.items():
if item[1] == op_sec[0]:
c3.append(item[0])
if len(c3) > 1:
ts1, ts2 = {}, {}
for entry in c3:
ts1[entry] = sections[entry]['C_r']
ts2[sections[entry]['C_r']] = entry
fc = list(ts1.values())
fc.sort()
if fc.count(fc[0]) > 1:
options = []
for item in ts1.items():
if item[1] == fc[0]:
options.append(item[0])
obj.m_sections[i].append(options)
continue
obj.m_sections[i].append(ts2[fc[-1]])
continue
if not candidates:
obj.total_weight = None
return
obj.m_sections[i].append(candidates[op_sec[0]])
continue
for k in range(len(obj.m_forces[i])):
if obj.m_forces[i][k]:
candidates, c2, c3 = {}, {}, []
for section in sections:
if obj.m_forces[i][k] > sections[section]['T_r']:
continue
candidates[sections[section]['DeadLoad(kN/m)']] = section
c2[section] = sections[section]['DeadLoad(kN/m)']
op_sec = list(c2.values())
op_sec.sort()
j = 0
for item in c2.items():
if item[1] == op_sec[0]:
c3.append(item[0])
if len(c3) > 1:
ts1, ts2 = {}, {}
for entry in c3:
ts1[entry] = sections[entry]['T_r']
ts2[sections[entry]['T_r']] = entry
fc = list(ts1.values())
fc.sort()
if fc.count(fc[0]) > 1:
options = []
for item in ts1.items():
if item[1] == fc[0]:
options.append(item[0])
obj.m_sections[i].append(options)
continue
obj.m_sections[i].append(ts2[fc[-1]])
continue
if not candidates:
obj.total_weight = None
return
obj.m_sections[i].append(candidates[op_sec[0]])
for section in sections:
_σ_e = (π**2 * _E) / ((_K * member_length[2] / sections[section]['r(mm)'])**2)
λ = sqrt(_σ_y / _σ_e)
f = 1 / ((1 + λ**(2 * _n))**(1 / _n))
sections[section]['C_r'] = (sections[section]['T_r'] * f)
sections[section]['KLr'] = (_K * member_length[2] / sections[section]['r(mm)']) <= 200
i = 2
for k in range(1):
if obj.m_forces[i][k]:
candidates, c2, c3 = {}, {}, []
for section in sections:
if obj.m_forces[i][k] > sections[section]['C_r']:
continue
candidates[sections[section]['DeadLoad(kN/m)']] = section
c2[section] = sections[section]['DeadLoad(kN/m)']
op_sec = list(c2.values())
op_sec.sort()
j = 0
for item in c2.items():
if item[1] == op_sec[0]:
c3.append(item[0])
if len(c3) > 1:
ts1, ts2 = {}, {}
for entry in c3:
ts1[entry] = sections[entry]['C_r']
ts2[sections[entry]['C_r']] = entry
fc = list(ts1.values())
fc.sort()
if fc.count(fc[0]) > 1:
options = []
for item in ts1.items():
if item[1] == fc[0]:
options.append(item[0])
obj.m_sections[i][0] = options
continue
obj.m_sections[i][0] = ts2[fc[-1]]
continue
if not candidates:
obj.total_weight = None
return
obj.m_sections[i][0] = candidates[op_sec[0]]
else:
for i in range(len(member_length)):
if i in [0, 2, 3]:
for section in sections:
_σ_e = (π**2 * _E) / ((_K * member_length[i] / sections[section]['r(mm)'])**2)
λ = sqrt(_σ_y / _σ_e)
f = 1 / ((1 + λ**(2 * _n))**(1 / _n))
sections[section]['C_r'] = (sections[section]['T_r'] * f)
sections[section]['KLr'] = (_K * member_length[i] / sections[section]['r(mm)']) <= 200
for k in range(len(obj.m_forces[i])):
if obj.m_forces[i][k]:
candidates, c2, c3 = {}, {}, []
for section in sections:
if obj.m_forces[i][k] > sections[section]['C_r']:
continue
candidates[sections[section]['DeadLoad(kN/m)']] = section
c2[section] = sections[section]['DeadLoad(kN/m)']
op_sec = list(c2.values())
op_sec.sort()
j = 0
for item in c2.items():
if item[1] == op_sec[0]:
c3.append(item[0])
if len(c3) > 1:
ts1, ts2 = {}, {}
for entry in c3:
ts1[entry] = sections[entry]['C_r']
ts2[sections[entry]['C_r']] = entry
fc = list(ts1.values())
fc.sort()
if fc.count(fc[0]) > 1:
options = []
for item in ts1.items():
if item[1] == fc[0]:
options.append(item[0])
obj.m_sections[i].append(options)
continue
obj.m_sections[i].append(ts2[fc[-1]])
continue
if not candidates:
obj.total_weight = None
return
obj.m_sections[i].append(candidates[op_sec[0]])
continue
for k in range(len(obj.m_forces[i])):
if obj.m_forces[i][k]:
candidates, c2, c3 = {}, {}, []
for section in sections:
if obj.m_forces[i][k] > sections[section]['T_r']:
continue
candidates[sections[section]['DeadLoad(kN/m)']] = section
c2[section] = sections[section]['DeadLoad(kN/m)']
op_sec = list(c2.values())
op_sec.sort()
j = 0
for item in c2.items():
if item[1] == op_sec[0]:
c3.append(item[0])
if len(c3) > 1:
ts1, ts2 = {}, {}
for entry in c3:
ts1[entry] = sections[entry]['T_r']
ts2[sections[entry]['T_r']] = entry
fc = list(ts1.values())
fc.sort()
if fc.count(fc[0]) > 1:
options = []
for item in ts1.items():
if item[1] == fc[0]:
options.append(item[0])
obj.m_sections[i].append(options)
continue
obj.m_sections[i].append(ts2[fc[-1]])
continue
if not candidates:
obj.total_weight = None
return
obj.m_sections[i].append(candidates[op_sec[0]])
calculate_member_mass(obj, member_length)
def fast_calculate_member_forces(no_joists, angle, **kwargs)->list:
global _P_faj, _SWJa_NEC, dx, dx_exec_list
curr_truss = kwargs.get('init_cond')
single = kwargs.get('single')
index, return_val = [], []
if not curr_truss:
if single:
if dx:
types = ["Howe", "Pratt", "WarrenV", "WarrenØ"]
path_name = ".".join([currentframe().f_code.co_name, "1st_iteration", f"{types[kwargs.get('typ')]}()"])
dx_exec_list = "\n".join([dx_exec_list, path_name])
truss_type = kwargs.get("typ")
return_val = [truss(no_joists, angle, truss_type)]
index = [0, 0, 0, 0]
else:
if dx:
path_name = ".".join([currentframe().f_code.co_name, "1st_iteration", "all_types()"])
dx_exec_list = "\n".join([dx_exec_list, path_name])
return_val = [truss(no_joists, angle, 0),
truss(no_joists, angle, 1),
truss(no_joists, angle, 2),
truss(no_joists, angle, 3)]
index = [0, 1, 2, 3]
else:
return_val = []
if single:
if dx:
types = ["Howe", "Pratt", "WarrenV", "WarrenØ"]
path_name = ".".join([currentframe().f_code.co_name, "2nd_iteration", f"{types[curr_truss.typ]}()"])
dx_exec_list = "\n".join([dx_exec_list, path_name])
return_val = [curr_truss]
truss_type = return_val[0].typ
index = [0, 0, 0, 0]
else:
if dx:
path_name = ".".join([currentframe().f_code.co_name, "2nd_iteration", "all_types()"])
dx_exec_list = "\n".join([dx_exec_list, path_name])
return_val = curr_truss
index = [0, 1, 2, 3]
if _SWJa_NEC:
adjust_Pf_OWSJ()
CS_Rn_Fs = adjust_CS_Rn_Forces(curr_truss)
_COSINE, _TANGENT = return_val[0].m_dimensions['angle'][2], return_val[0].m_dimensions['angle'][3]
determinant = no_joists // 2
#COMMON
common_Horizontals = 0.5 * _P_f * _TANGENT
common_Diagonals = _P_f / (2 * _COSINE)
common_top_bot = []
for i in range(determinant + 1):
common_top_bot.append((no_joists - i) * (i + 1) * common_Horizontals)
common_diags , common_verts = [], []