ANYstructure 5.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. anystruct/ANYstructure_documentation.pdf +0 -0
  2. anystruct/SN_curve_parameters.py +35 -0
  3. anystruct/__init__.py +0 -0
  4. anystruct/__main__.py +24 -0
  5. anystruct/api.py +772 -0
  6. anystruct/buckling_calc_external.py +120 -0
  7. anystruct/bulb_anglebar_tbar_flatbar.csv +677 -0
  8. anystruct/calc_loads.py +526 -0
  9. anystruct/calc_structure.py +4838 -0
  10. anystruct/compartment_window.py +176 -0
  11. anystruct/example_data.py +532 -0
  12. anystruct/example_data_puls.py +46 -0
  13. anystruct/excel_inteface.py +244 -0
  14. anystruct/fatigue_window.py +352 -0
  15. anystruct/grid_window.py +307 -0
  16. anystruct/gui.py +24 -0
  17. anystruct/helper.py +623 -0
  18. anystruct/images/ANYstructure_logo.jpg +0 -0
  19. anystruct/images/Buckling_Strength_of_Shells.png +0 -0
  20. anystruct/images/Panel_geometry_definitions.png +0 -0
  21. anystruct/images/current_comps_NONE.png +0 -0
  22. anystruct/images/fls_button.gif +0 -0
  23. anystruct/images/img_T_L_FB.gif +0 -0
  24. anystruct/images/img_axial_stresses.gif +0 -0
  25. anystruct/images/img_ext_pressure_button.gif +0 -0
  26. anystruct/images/img_ext_pressure_button_def.gif +0 -0
  27. anystruct/images/img_fixation_parameters.gif +0 -0
  28. anystruct/images/img_generate_report.gif +0 -0
  29. anystruct/images/img_int_pressure_button.gif +0 -0
  30. anystruct/images/img_int_pressure_button_search.gif +0 -0
  31. anystruct/images/img_multi_opt.gif +0 -0
  32. anystruct/images/img_optimize.gif +0 -0
  33. anystruct/images/img_plate_and_stiffener.gif +0 -0
  34. anystruct/images/img_stf_button.gif +0 -0
  35. anystruct/images/img_stiffener.gif +0 -0
  36. anystruct/images/img_stress_button.gif +0 -0
  37. anystruct/images/img_title.gif +0 -0
  38. anystruct/images/img_transverse_stress.gif +0 -0
  39. anystruct/load_factor_window.py +166 -0
  40. anystruct/load_window.py +721 -0
  41. anystruct/main_application.py +7918 -0
  42. anystruct/make_grid_numpy.py +506 -0
  43. anystruct/make_queue.py +52 -0
  44. anystruct/make_stack.py +52 -0
  45. anystruct/ml_files/CL_CSR-Tank_req_cl_predictor.pickle +0 -0
  46. anystruct/ml_files/CL_CSR-Tank_req_cl_scaler.pickle +0 -0
  47. anystruct/ml_files/CL_CSR_plate_cl,_CSR_web_cl,_CSR_web_flange_cl,_CSR_flange_cl_predictor.pickle +0 -0
  48. anystruct/ml_files/CL_CSR_plate_cl,_CSR_web_cl,_CSR_web_flange_cl,_CSR_flange_cl_scaler.pickle +0 -0
  49. anystruct/ml_files/CL_output_cl_str_buc_110_predictor_In-plane_support_cl_1_SP.pickle +0 -0
  50. anystruct/ml_files/CL_output_cl_str_buc_110_predictor_In-plane_support_cl_1_UP.pickle +0 -0
  51. anystruct/ml_files/CL_output_cl_str_buc_110_predictor_In-plane_support_cl_2,_3_SP.pickle +0 -0
  52. anystruct/ml_files/CL_output_cl_str_buc_110_predictor_In-plane_support_cl_2,_3_UP.pickle +0 -0
  53. anystruct/ml_files/CL_output_cl_str_buc_110_scaler_In-plane_support_cl_1_SP.pickle +0 -0
  54. anystruct/ml_files/CL_output_cl_str_buc_110_scaler_In-plane_support_cl_1_UP.pickle +0 -0
  55. anystruct/ml_files/CL_output_cl_str_buc_110_scaler_In-plane_support_cl_2,_3_SP.pickle +0 -0
  56. anystruct/ml_files/CL_output_cl_str_buc_110_scaler_In-plane_support_cl_2,_3_UP.pickle +0 -0
  57. anystruct/ml_files/CL_output_cl_str_buc_115_predictor_In-plane_support_cl_1_SP.pickle +0 -0
  58. anystruct/ml_files/CL_output_cl_str_buc_115_predictor_In-plane_support_cl_1_UP.pickle +0 -0
  59. anystruct/ml_files/CL_output_cl_str_buc_115_predictor_In-plane_support_cl_2,_3_SP.pickle +0 -0
  60. anystruct/ml_files/CL_output_cl_str_buc_115_predictor_In-plane_support_cl_2,_3_UP.pickle +0 -0
  61. anystruct/ml_files/CL_output_cl_str_buc_115_scaler_In-plane_support_cl_1_SP.pickle +0 -0
  62. anystruct/ml_files/CL_output_cl_str_buc_115_scaler_In-plane_support_cl_1_UP.pickle +0 -0
  63. anystruct/ml_files/CL_output_cl_str_buc_115_scaler_In-plane_support_cl_2,_3_SP.pickle +0 -0
  64. anystruct/ml_files/CL_output_cl_str_buc_115_scaler_In-plane_support_cl_2,_3_UP.pickle +0 -0
  65. anystruct/ml_files/CL_output_cl_str_ult_110_predictor_In-plane_support_cl_1_SP.pickle +0 -0
  66. anystruct/ml_files/CL_output_cl_str_ult_110_predictor_In-plane_support_cl_1_UP.pickle +0 -0
  67. anystruct/ml_files/CL_output_cl_str_ult_110_predictor_In-plane_support_cl_2,_3_SP.pickle +0 -0
  68. anystruct/ml_files/CL_output_cl_str_ult_110_predictor_In-plane_support_cl_2,_3_UP.pickle +0 -0
  69. anystruct/ml_files/CL_output_cl_str_ult_110_scaler_In-plane_support_cl_1_SP.pickle +0 -0
  70. anystruct/ml_files/CL_output_cl_str_ult_110_scaler_In-plane_support_cl_1_UP.pickle +0 -0
  71. anystruct/ml_files/CL_output_cl_str_ult_110_scaler_In-plane_support_cl_2,_3_SP.pickle +0 -0
  72. anystruct/ml_files/CL_output_cl_str_ult_110_scaler_In-plane_support_cl_2,_3_UP.pickle +0 -0
  73. anystruct/ml_files/CL_output_cl_str_ult_115_predictor_In-plane_support_cl_1_SP.pickle +0 -0
  74. anystruct/ml_files/CL_output_cl_str_ult_115_predictor_In-plane_support_cl_1_UP.pickle +0 -0
  75. anystruct/ml_files/CL_output_cl_str_ult_115_predictor_In-plane_support_cl_2,_3_SP.pickle +0 -0
  76. anystruct/ml_files/CL_output_cl_str_ult_115_predictor_In-plane_support_cl_2,_3_UP.pickle +0 -0
  77. anystruct/ml_files/CL_output_cl_str_ult_115_scaler_In-plane_support_cl_1_SP.pickle +0 -0
  78. anystruct/ml_files/CL_output_cl_str_ult_115_scaler_In-plane_support_cl_1_UP.pickle +0 -0
  79. anystruct/ml_files/CL_output_cl_str_ult_115_scaler_In-plane_support_cl_2,_3_SP.pickle +0 -0
  80. anystruct/ml_files/CL_output_cl_str_ult_115_scaler_In-plane_support_cl_2,_3_UP.pickle +0 -0
  81. anystruct/opt_problem.py +31 -0
  82. anystruct/optimize.py +1680 -0
  83. anystruct/optimize_cylinder.py +898 -0
  84. anystruct/optimize_geometry.py +1708 -0
  85. anystruct/optimize_multiple_window.py +1507 -0
  86. anystruct/optimize_window.py +1117 -0
  87. anystruct/pl_stf_window.py +572 -0
  88. anystruct/report_generator.py +912 -0
  89. anystruct/sections.csv +202 -0
  90. anystruct/sesam_interface.py +115 -0
  91. anystruct/ship_section_example.txt +1 -0
  92. anystruct/stresses_window.py +269 -0
  93. anystruct/testCalc.py +118 -0
  94. anystructure-5.2.0.dist-info/METADATA +86 -0
  95. anystructure-5.2.0.dist-info/RECORD +99 -0
  96. anystructure-5.2.0.dist-info/WHEEL +5 -0
  97. anystructure-5.2.0.dist-info/entry_points.txt +2 -0
  98. anystructure-5.2.0.dist-info/licenses/LICENSE +21 -0
  99. anystructure-5.2.0.dist-info/top_level.txt +1 -0
anystruct/optimize.py ADDED
@@ -0,0 +1,1680 @@
1
+ #Optimize structure
2
+ import numpy as np
3
+
4
+ import itertools as it
5
+ import time
6
+ import random
7
+ import copy
8
+ from multiprocessing import Pool, cpu_count
9
+ import math
10
+ from math import floor
11
+ from matplotlib import pyplot as plt
12
+ from tkinter.filedialog import asksaveasfilename
13
+ import csv
14
+
15
+ try:
16
+ import anystruct.calc_structure as calc
17
+ import anystruct.helper as hlp
18
+ except ModuleNotFoundError:
19
+ import ANYstructure.anystruct.calc_structure as calc
20
+ import ANYstructure.anystruct.helper as hlp
21
+
22
+
23
+ def run_optmizataion(initial_structure_obj=None, min_var=None, max_var=None, lateral_pressure=None,
24
+ deltas=None, algorithm='anysmart', trials=30000, side='p',
25
+ const_chk = (True,True,True,True,True,True, True, False, False, False),
26
+ pso_options = (100,0.5,0.5,0.5,100,1e-8,1e-8), is_geometric=False, fatigue_obj = None ,
27
+ fat_press_ext_int = None,
28
+ min_max_span = (2,6), tot_len = None, frame_height = 2.5, frame_distance = None,
29
+ slamming_press = 0, predefined_stiffener_iter = None, processes = None, use_weight_filter = True,
30
+ load_pre = False, opt_girder_prop = None, puls_sheet = None, puls_acceptance = 0.87,
31
+ fdwn = 1, fup = 0.5, ml_algo = None, cylinder = False):
32
+ '''
33
+ The optimazation is initiated here. It is called from optimize_window.
34
+ :param initial_structure_obj:
35
+ :param min_var:
36
+ :param max_var:
37
+ :param lateral_pressure:
38
+ :param deltas:
39
+ :param algorithm:
40
+ :param init_weigth:
41
+ :param pso_options:
42
+ :return:
43
+ '''
44
+ init_filter_weight = float('inf')
45
+
46
+ if is_geometric:
47
+ fat_dict = [None if this_fat is None else this_fat.get_fatigue_properties() for this_fat in fatigue_obj]
48
+ else:
49
+ fat_dict = None if fatigue_obj is None else fatigue_obj.get_fatigue_properties()
50
+
51
+ if use_weight_filter and not cylinder:
52
+
53
+ if is_geometric or algorithm == 'pso':
54
+ init_filter_weight = float('inf')
55
+ else:
56
+ predefined_stiffener_iter = None if predefined_stiffener_iter is None else predefined_stiffener_iter
57
+
58
+ init_filter_weight = get_initial_weight(obj=initial_structure_obj,
59
+ lat_press=lateral_pressure,
60
+ min_var=min_var, max_var=max_var, deltas=deltas,
61
+ trials= 30000 if predefined_stiffener_iter is None else
62
+ len(predefined_stiffener_iter),
63
+ fat_dict=fat_dict,
64
+ fat_press=None if fat_press_ext_int is None else fat_press_ext_int,
65
+ predefined_stiffener_iter = predefined_stiffener_iter,
66
+ slamming_press=slamming_press, fdwn = fdwn, fup = fup,
67
+ ml_algo = ml_algo)
68
+
69
+ if cylinder:
70
+ to_return = any_smart_loop_cylinder(min_var=min_var, max_var=max_var, deltas=deltas,
71
+ initial_structure_obj=initial_structure_obj,
72
+ use_weight_filter = use_weight_filter,
73
+ predefiened_stiffener_iter=predefined_stiffener_iter)
74
+ return to_return
75
+
76
+ elif algorithm == 'anysmart' and not is_geometric:
77
+ to_return = any_smart_loop(min_var, max_var, deltas, initial_structure_obj, lateral_pressure,
78
+ init_filter_weight, side=side, const_chk=const_chk, fat_dict=fat_dict,
79
+ fat_press=fat_press_ext_int,slamming_press=slamming_press,
80
+ predefiened_stiffener_iter=predefined_stiffener_iter, puls_sheet = puls_sheet,
81
+ puls_acceptance = puls_acceptance, fdwn = fdwn, fup = fup, ml_algo=ml_algo)
82
+ return to_return
83
+ elif algorithm == 'anysmart' and is_geometric:
84
+ return geometric_summary_search(min_var= min_var, max_var=max_var, deltas= deltas,
85
+ initial_structure_obj= initial_structure_obj, lateral_pressure=lateral_pressure,
86
+ init_filter= init_filter_weight, side= side, const_chk= const_chk,
87
+ fat_obj= fatigue_obj, fat_press= fat_press_ext_int, min_max_span= min_max_span,
88
+ tot_len= tot_len, frame_distance = frame_distance,
89
+ algorithm= 'anysmart', predefiened_stiffener_iter=predefined_stiffener_iter,
90
+ slamming_press = slamming_press, load_pre = load_pre,
91
+ opt_girder_prop = opt_girder_prop, ml_algo=ml_algo)
92
+ elif algorithm == 'anydetail' and not is_geometric:
93
+ return any_optimize_loop(min_var, max_var, deltas, initial_structure_obj, lateral_pressure,init_filter_weight,
94
+ side=side, const_chk=const_chk, fat_dict=fat_dict, fat_press=fat_press_ext_int,
95
+ slamming_press=slamming_press)
96
+ elif algorithm == 'random' and not is_geometric:
97
+ return get_random_result(initial_structure_obj,lateral_pressure,min_var,max_var,deltas,trials=trials,
98
+ side=side, const_chk=const_chk, fat_dict=fat_dict,fat_press=fat_press_ext_int)
99
+ elif algorithm == 'random_no_delta' and not is_geometric:
100
+ return get_random_result_no_bounds(initial_structure_obj, lateral_pressure, min_var, max_var, trials=trials,
101
+ side=side, const_chk=const_chk)
102
+
103
+ # elif algorithm == 'pso' and is_geometric:
104
+ # return geometric_summary_search(min_var,max_var,deltas, initial_structure_obj,lateral_pressure,
105
+ # init_filter_weight,side,const_chk,pso_options,fatigue_obj,fat_press_ext_int,
106
+ # min_max_span,tot_len,frame_height,frame_cross_a, 'pso')
107
+ else:
108
+ return None
109
+
110
+ def any_optimize_loop(min_var,max_var,deltas,initial_structure_obj,lateral_pressure, init_filter = float('inf'),
111
+ side='p',const_chk=(True,True,True,True,True,False), fat_dict = None, fat_press = None,
112
+ slamming_press = 0):
113
+ '''
114
+ Calulating initial values.
115
+ :param min:
116
+ :param max:
117
+ :return:
118
+ '''
119
+ ass_var = []
120
+ plot_x,plot_y = [],[]
121
+ plt.xlabel('#')
122
+ plt.ylabel('weigth [kg]')
123
+ plt.title('ANYdetail brute force results')
124
+ plt.grid(True)
125
+ plt.draw()
126
+ iter_count = 0
127
+ min_weight = init_filter
128
+ main_fail = list()
129
+ for spacing in np.arange(min_var[0],max_var[0]+deltas[0],deltas[0]):
130
+ for plate_thk in np.arange(min_var[1],max_var[1]+deltas[1],deltas[1]):
131
+ for stf_web_h in np.arange(min_var[2],max_var[2]+deltas[2],deltas[2]):
132
+ for stf_web_thk in np.arange(min_var[3],max_var[3]+deltas[3],deltas[3]):
133
+ for stf_flange_width in np.arange(min_var[4],max_var[4]+deltas[4],deltas[4]):
134
+ for stf_flange_thk in np.arange(min_var[5],max_var[5]+deltas[5],deltas[5]):
135
+ var_x = np.array([spacing, plate_thk, stf_web_h, stf_web_thk, stf_flange_width,
136
+ stf_flange_thk,min_var[6],min_var[7]])
137
+ check = any_constraints_all(var_x,initial_structure_obj,lat_press=lateral_pressure,
138
+ init_weight=min_weight,side=side,chk=const_chk,
139
+ fat_dict = fat_dict, fat_press = fat_press,
140
+ slamming_press=slamming_press)
141
+ if check[0] is not False:
142
+ current_weight = calc_weight(var_x)
143
+ if current_weight <= min_weight:
144
+ iter_count+=1
145
+ min_weight = current_weight
146
+ ass_var = var_x
147
+ main_fail.append(check)
148
+ else:
149
+ main_fail.append(check)
150
+ if ass_var is None:
151
+ return None, None, None, False, main_fail
152
+
153
+ new_struc_obj = create_new_structure_obj(initial_structure_obj,[item for item in ass_var])
154
+ new_calc_obj = create_new_calc_obj(initial_structure_obj,[item for item in ass_var])[0]
155
+
156
+ return new_struc_obj, new_calc_obj, fat_dict, True, main_fail
157
+
158
+ def any_smart_loop(min_var,max_var,deltas,initial_structure_obj,lateral_pressure, init_filter = float('inf'),
159
+ side='p',const_chk=(True,True,True,True,True,True,True, False, False,False), fat_dict = None,
160
+ fat_press = None,
161
+ slamming_press = 0, predefiened_stiffener_iter = None, processes = None,
162
+ puls_sheet = None, puls_acceptance = 0.87, fdwn = 1, fup = 0.5, ml_algo = None):
163
+ '''
164
+ Trying to be smart
165
+ :param min_var:
166
+ :param max_var:
167
+ :param initial_structure:
168
+ :return:
169
+ '''
170
+ initial_structure_obj.lat_press = lateral_pressure
171
+
172
+ if predefiened_stiffener_iter is None:
173
+ structure_to_check = any_get_all_combs(min_var, max_var, deltas)
174
+ else:
175
+ structure_to_check = any_get_all_combs(min_var, max_var, deltas,predef_stiffeners=[item.get_tuple() for item
176
+ in predefiened_stiffener_iter])
177
+
178
+ main_result = get_filtered_results(structure_to_check, initial_structure_obj,lateral_pressure,
179
+ init_filter_weight=init_filter, side=side,chk=const_chk, fat_dict=fat_dict,
180
+ fat_press=fat_press, slamming_press=slamming_press, processes=processes,
181
+ puls_sheet = puls_sheet, puls_acceptance = puls_acceptance, ml_algo=ml_algo)
182
+
183
+ main_iter = main_result[0]
184
+ main_fail = main_result[1]
185
+
186
+ ass_var=None
187
+ current_weight = float('inf')
188
+ for item in main_iter:
189
+ main_fail.append(item)
190
+ item_weight = calc_weight(item[2])
191
+ if item_weight < current_weight:
192
+ ass_var = item[2]
193
+ current_weight = item_weight
194
+
195
+ if ass_var == None:
196
+ return None, None, None, False, main_fail
197
+
198
+ if len(ass_var) == 8:
199
+ ass_var = [round(item, 10) for item in ass_var[0:8]]
200
+ else:
201
+ ass_var = [round(item, 10) for item in ass_var[0:8]] + [ass_var[8]]
202
+
203
+ # initial_structure_obj.Plate = create_new_structure_obj(initial_structure_obj.Plate, ass_var,
204
+ # fdwn = fdwn, fup = fup)
205
+ # initial_structure_obj.Stiffener = create_new_structure_obj(initial_structure_obj.Stiffener, ass_var,
206
+ # fdwn=fdwn, fup=fup)
207
+
208
+ calc_object_stf = None if initial_structure_obj.Stiffener is None \
209
+ else create_new_calc_obj(initial_structure_obj.Stiffener, ass_var,
210
+ fat_dict, fdwn=fdwn, fup=fup)
211
+ calc_object_pl = create_new_calc_obj(initial_structure_obj.Plate, ass_var, fat_dict,
212
+ fdwn=fdwn, fup=fup)
213
+ calc_object = calc.AllStructure(Plate=calc_object_pl[0],
214
+ Stiffener=None if initial_structure_obj.Stiffener is None else calc_object_stf[0],
215
+ Girder=None,
216
+ main_dict=initial_structure_obj.get_main_properties()['main dict'])
217
+ calc_object.lat_press = lateral_pressure
218
+
219
+ return calc_object, fat_dict, True, main_fail
220
+
221
+ def any_smart_loop_cylinder(min_var,max_var,deltas,initial_structure_obj,lateral_pressure = None,
222
+ init_filter = float('inf'),
223
+ side='p',const_chk=(True,True,True,True,True,True,True, False, False,False), fat_dict = None,
224
+ fat_press = None, slamming_press = 0, predefiened_stiffener_iter = None, processes = None,
225
+ fdwn = 1, fup = 0.5, ml_algo = None, use_weight_filter = True):
226
+
227
+ combs = list()
228
+ # TODO first optmize for long then ring components. Find the overall smallest weight.
229
+ # Creating the individual combinations for Shell, LongStf, RingStf and RingFrame
230
+ for idx, str_type in enumerate(range(len(min_var))):
231
+ if sum(min_var[idx]) == 0:
232
+ structure_to_check = [(0, 0, 0, 0, 0, 0, 0, 0),]
233
+ else:
234
+ if any([predefiened_stiffener_iter is None, idx == 0]):
235
+ initial_structure_obj.LongStfObj.stiffener_type = 'T'
236
+ structure_to_check = any_get_all_combs(min_var[idx], max_var[idx], deltas[idx])
237
+
238
+ else:
239
+ structure_to_check = any_get_all_combs(min_var[idx], max_var[idx], deltas[idx],
240
+ predef_stiffeners= [item.get_tuple() for item in
241
+ predefiened_stiffener_iter])
242
+ # TODO add stifffener type
243
+
244
+ # [list(item).append('T') for item in structure_to_check]
245
+ # [tuple(item) for item in structure_to_check]
246
+ combs.append(structure_to_check)
247
+
248
+ # Combining the individual components.
249
+ final_comb, iter_vals = list(), list()
250
+ for shell in combs[0]:
251
+ for long in combs[1]:
252
+ for ring_stf in combs[2]:
253
+ for ring_frame in combs[3]:
254
+ final_comb.append([[shell, long, ring_stf, ring_frame], initial_structure_obj])
255
+ # print('All combs', len(combs[0]),len(combs[1]),len(combs[2]),len(combs[3]),len(final_comb))
256
+ # quit()
257
+ # Weight filter
258
+ min_weight = float('inf')
259
+ if use_weight_filter:
260
+ to_check = [random.choice(final_comb) + [float('inf')] for dummy in range(10000)]
261
+ with Pool(processes=max(cpu_count() - 1, 1)) as my_process:
262
+ res_pre = my_process.starmap(any_constraints_cylinder, to_check)
263
+ for chk_res in res_pre :
264
+ if chk_res[0]:
265
+ current_weight = calc_weight_cylinder(chk_res[2])
266
+ if current_weight < min_weight:
267
+ min_weight = current_weight
268
+ else:
269
+ min_weight = False
270
+
271
+ final_comb_inc_weight = list()
272
+ for val in final_comb:
273
+ final_comb_inc_weight.append(val + [min_weight])
274
+
275
+ t1 = time.time()
276
+ with Pool(processes = max(cpu_count()-1,1)) as my_process:
277
+ res_pre = my_process.starmap(any_constraints_cylinder, final_comb_inc_weight)
278
+
279
+ check_ok, check_not_ok = list(), list()
280
+ for item in res_pre:
281
+ if item[0] is False:
282
+ check_not_ok.append(item)
283
+ else:
284
+ check_ok.append(item)
285
+
286
+ main_iter = check_ok
287
+ main_fail = check_not_ok
288
+
289
+ ass_var = None
290
+ current_weight = float('inf')
291
+ for item in main_iter:
292
+ main_fail.append(item)
293
+ item_weight = calc_weight_cylinder(item[2])
294
+ if item_weight < current_weight:
295
+ ass_var = item[2]
296
+ current_weight = item_weight
297
+
298
+ if ass_var == None:
299
+ return None, None, None, False, main_fail
300
+
301
+ new_cylinder_obj = create_new_cylinder_obj(initial_structure_obj, ass_var)
302
+
303
+ # Checking ring stiffeners and frames
304
+
305
+ #return new_struc_obj, new_calc_obj, fat_dict, True, main_fail
306
+ return new_cylinder_obj, main_fail
307
+
308
+
309
+ def any_smart_loop_geometric(min_var,max_var,deltas,initial_structure_obj,lateral_pressure, init_filter = float('inf'),
310
+ side='p',const_chk=(True,True,True,True,True,True), fat_obj = None, fat_press = None,
311
+ slamming_press = None, predefiened_stiffener_iter=None, processes = None, ml_algo = None):
312
+ ''' Searching multiple sections using the smart loop. '''
313
+
314
+ all_obj = []
315
+ idx = 0
316
+ for struc_obj, lat_press, fatigue_obj, fatigue_press, slam_press in zip(initial_structure_obj, lateral_pressure,
317
+ fat_obj, fat_press, slamming_press):
318
+ #print(predefiened_stiffener_iter)
319
+ if predefiened_stiffener_iter is not None:
320
+ this_predefiened_objects = hlp.helper_read_section_file(predefiened_stiffener_iter, struc_obj)
321
+ else:
322
+ this_predefiened_objects = None
323
+
324
+ opt_obj = any_smart_loop(min_var = min_var,max_var = max_var,deltas = deltas,initial_structure_obj = struc_obj,
325
+ lateral_pressure = lat_press, init_filter = init_filter, side=side,
326
+ const_chk=const_chk,
327
+ fat_dict = None if fatigue_obj is None else fatigue_obj.get_fatigue_properties(),
328
+ fat_press = None if fatigue_press is None else fatigue_press,
329
+ slamming_press = 0 if slam_press is None else slam_press,
330
+ predefiened_stiffener_iter=this_predefiened_objects, processes=processes,
331
+ ml_algo=ml_algo)
332
+
333
+ all_obj.append(opt_obj)
334
+ idx += 1
335
+
336
+ return all_obj
337
+
338
+ def geometric_summary_search(min_var=None,max_var=None,deltas = None, initial_structure_obj=None,lateral_pressure=None,
339
+ init_filter = float('inf'),side='p',const_chk=(True,True,True,True, True, True),
340
+ pso_options=(100,0.5,0.5,0.5,100,1e-8,1e-8), fat_obj = None, fat_press = None,
341
+ min_max_span = (2,6), tot_len = None, frame_distance = None,
342
+ algorithm = 'anysmart', predefiened_stiffener_iter=None, reiterate = True,
343
+ processes = None, slamming_press = None, load_pre = False, opt_girder_prop = None,
344
+ ml_algo = None):
345
+
346
+ '''Geometric optimization of all relevant sections. '''
347
+ # Checking the number of initial objects and adding if number of fraction is to be changed.
348
+ # print('Min/max span is', min_max_span)
349
+ found_max, found_min = False, False
350
+ for frames in range(1,100):
351
+ frame_count = frames
352
+ if tot_len/frames <= min_max_span[1] and found_min is False:
353
+ min_frame_count = frame_count - 1
354
+ found_min = True
355
+ if tot_len/frames <= min_max_span[0] and found_max is False:
356
+ max_frame_count = frame_count - 1
357
+ found_max = True
358
+ if found_min and found_max:
359
+ break
360
+
361
+ results = {}
362
+ # print('Frame count min/max: ', min_frame_count, max_frame_count)
363
+ # print('Initial objects: ', [print(type(obj)) for obj in initial_structure_obj])
364
+ # print('Initial lateral: ', lateral_pressure)
365
+ working_objects = {}
366
+ working_lateral = {}
367
+ working_fatigue = {}
368
+ working_fatigue_press = {}
369
+ working_slamming = {}
370
+
371
+ for no_of_fractions in range(min_frame_count+1, max_frame_count+1):
372
+ # Create fraction varables
373
+ frac_var,min_frac,max_frac = [], [], []
374
+
375
+ for var in range(no_of_fractions):
376
+ # Frame height is a interpolation between height at start and end.
377
+ frac_var.append(1/no_of_fractions)
378
+ working_objects[no_of_fractions] = list(initial_structure_obj)
379
+ working_lateral[no_of_fractions] = list(lateral_pressure)
380
+ working_fatigue[no_of_fractions] = list(fat_obj)
381
+ working_fatigue_press[no_of_fractions] = list(fat_press)
382
+ working_slamming[no_of_fractions] = list(slamming_press)
383
+ similar_count = len(working_objects[no_of_fractions])
384
+ tick_tock = True
385
+
386
+ while similar_count != no_of_fractions*2:
387
+
388
+ if similar_count > no_of_fractions*2:
389
+ for var_dict in [working_objects, working_lateral, working_fatigue,
390
+ working_fatigue_press, working_slamming]:
391
+ if tick_tock:
392
+ lower_idx = 0
393
+ upper_idx = int(floor(len(working_objects[no_of_fractions]) / 2))
394
+ tick_tock = False
395
+ else:
396
+ lower_idx = int(len(working_objects[no_of_fractions]) / 2) - 1
397
+ upper_idx = -1
398
+ tick_tock = True
399
+
400
+ var_dict[no_of_fractions].pop(lower_idx)
401
+ var_dict[no_of_fractions].pop(upper_idx)
402
+ similar_count -= 2
403
+ else:
404
+ if tick_tock:
405
+ lower_idx = 0
406
+ upper_idx = int(len(working_objects[no_of_fractions])/2)
407
+ tick_tock = False
408
+ else:
409
+ lower_idx = int(len(working_objects[no_of_fractions])/2) - 1
410
+ upper_idx = -1
411
+ tick_tock = True
412
+ #print(no_of_fractions, int(ceil(len(working_objects[no_of_fractions])/2)))
413
+
414
+ obj_start, obj_stop = copy.deepcopy(working_objects[no_of_fractions][lower_idx]),\
415
+ copy.deepcopy(working_objects[no_of_fractions][upper_idx])
416
+
417
+ fat_obj_start, fat_obj_stop = copy.deepcopy(working_fatigue[no_of_fractions][lower_idx]), \
418
+ copy.deepcopy(working_fatigue[no_of_fractions][upper_idx])
419
+ lat_start, lat_stop = working_lateral[no_of_fractions][lower_idx], \
420
+ working_lateral[no_of_fractions][upper_idx]
421
+ fat_press_start, fat_press_stop = working_fatigue_press[no_of_fractions][lower_idx], \
422
+ working_fatigue_press[no_of_fractions][upper_idx]
423
+ slam_start, slam_stop = working_slamming[no_of_fractions][lower_idx], \
424
+ working_slamming[no_of_fractions][upper_idx]
425
+ # if no_of_fractions == 11:
426
+ # print('Tick/tock', tick_tock, 'lower/opper idx', lower_idx, upper_idx)
427
+
428
+ for work, work_input in zip([working_objects[no_of_fractions], working_lateral[no_of_fractions],
429
+ working_fatigue[no_of_fractions],
430
+ working_fatigue_press[no_of_fractions],
431
+ working_slamming[no_of_fractions]],
432
+ [(obj_start, obj_stop), (lat_start, lat_stop),
433
+ (fat_obj_start, fat_obj_stop), (fat_press_start, fat_press_stop),
434
+ (slam_start, slam_stop)]):
435
+ # First iteration tick_tock true, second tick_tock false
436
+ if not tick_tock:
437
+ lower_idx = lower_idx
438
+ upper_idx = upper_idx + 1
439
+ else:
440
+ lower_idx = lower_idx + 1
441
+ upper_idx = -1
442
+ work.insert(lower_idx, work_input[0])
443
+ work.insert(upper_idx, work_input[1])
444
+ similar_count += 2
445
+ # if no_of_fractions == 11:
446
+ # [print(item.get_structure_type()) for item in working_objects[no_of_fractions]]
447
+ # print('')
448
+ for no_of_fractions, struc_objects in working_objects.items():
449
+ for struc_obj in struc_objects:
450
+ struc_obj.Plate.set_span(tot_len/no_of_fractions)
451
+ struc_obj.Stiffener.set_span(tot_len / no_of_fractions)
452
+
453
+ solution_found, iterations = False, 0
454
+
455
+ while not solution_found:
456
+ iterations += 1
457
+ if iterations != 1:
458
+ min_var[0:6] += deltas/2
459
+ max_var[0:6] -= deltas/2
460
+
461
+ if algorithm == 'anysmart':
462
+ if load_pre:
463
+ import pickle
464
+ with open('geo_opt_2.pickle', 'rb') as file:
465
+ opt_objects = pickle.load(file)[no_of_fractions][1]
466
+ else:
467
+
468
+ opt_objects = any_smart_loop_geometric(min_var=min_var,max_var=max_var,deltas=deltas,
469
+ initial_structure_obj=working_objects[no_of_fractions],
470
+ lateral_pressure=working_lateral[no_of_fractions],
471
+ init_filter = init_filter,side=side,const_chk=const_chk,
472
+ fat_obj = working_fatigue[no_of_fractions],
473
+ slamming_press = working_slamming[no_of_fractions],
474
+ fat_press=working_fatigue_press[no_of_fractions],
475
+ predefiened_stiffener_iter = predefiened_stiffener_iter,
476
+ ml_algo=ml_algo)
477
+
478
+
479
+ # Finding weight of this solution.
480
+
481
+ tot_weight, frame_spacings, valid, width, weight_details = 0, [None for dummy in range(len(opt_objects))], \
482
+ True, 10, {'frames': list(), 'objects': list(),
483
+ 'scales': list()}
484
+
485
+ #print('Weight for', no_of_fractions)
486
+ for count, opt in enumerate(opt_objects):
487
+ obj = opt[0]
488
+
489
+ if opt[3]:
490
+ weigth_to_add = calc_weight((obj.Plate.get_s(),obj.Plate.get_pl_thk(),obj.Stiffener.get_web_h(),
491
+ obj.Stiffener.get_web_thk(),
492
+ obj.Stiffener.get_fl_w(),obj.Stiffener.get_fl_thk(),
493
+ obj.Plate.span,width), prt=False)
494
+ tot_weight += weigth_to_add
495
+ weight_details['objects'].append(weigth_to_add)
496
+ if frame_spacings[count // 2] is None:
497
+ frame_spacings[count // 2] = obj.Plate.get_s()
498
+ #print('added normal weight', weigth_to_add)
499
+
500
+ else:
501
+ # In this case there are no applicable solutions found in the specified dimension ranges.
502
+ tot_weight += float('inf')
503
+ valid = False
504
+ if valid:
505
+ #print(frame_distance)
506
+ for frame in range(no_of_fractions-1):
507
+ frame_height = 2.5 if frame_distance is None else frame_distance['start_dist'] + \
508
+ (frame_distance['stop_dist']-
509
+ frame_distance['start_dist']) * \
510
+ ((frame+1)/no_of_fractions)
511
+
512
+ #pl_area, stf_area = 0.018 * width, 0.25 * 0.015 * (width//frame_spacings[frame])
513
+ this_x = (frame_spacings[frame], opt_girder_prop[0], opt_girder_prop[1], opt_girder_prop[2],
514
+ opt_girder_prop[3], opt_girder_prop[4], None, width)
515
+ this_weight = sum(get_field_tot_area(this_x))* frame_height * 7850
516
+ scale_max, scale_min = opt_girder_prop[5], opt_girder_prop[6]
517
+
518
+ this_scale = scale_min + (scale_max-scale_min) * (abs((max_frame_count-(count+1)/2))/
519
+ (max_frame_count-min_frame_count))
520
+ #print('Number of fractions', no_of_fractions, 'Scale', this_scale)
521
+ tot_weight += this_weight * this_scale
522
+ solution_found = True
523
+ #print('added frame weight', this_weight * this_scale)
524
+ weight_details['frames'].append(this_weight * this_scale)
525
+ weight_details['scales'].append(this_scale)
526
+ elif iterations == 2:
527
+ solution_found = True # Only iterate once.
528
+
529
+ if predefiened_stiffener_iter is not None or not reiterate:
530
+ solution_found = True # Noe solution may be found, but in this case no more iteations.
531
+
532
+ results[no_of_fractions] = tot_weight, opt_objects, weight_details
533
+ # for key, val in results.items():
534
+ # print(key)
535
+ # print(val)
536
+ return results
537
+
538
+ def any_find_min_weight_var(var):
539
+ '''
540
+ Find the minimum weight of the inpu
541
+ :param min:
542
+ :param max:
543
+ :return:
544
+ '''
545
+
546
+ return min(map(calc_weight))
547
+
548
+ def any_constraints_cylinder(x,obj: calc.CylinderAndCurvedPlate,init_weight, lat_press = None,side='p',
549
+ chk=(True,True,True,True, True, True, True, False, False, False),
550
+ fat_dict = None, fat_press = None, slamming_press = 0,fdwn = 1, fup = 0.5,
551
+ ml_results = None):
552
+ '''
553
+ Checking all constraints defined.
554
+
555
+ iter_var = ((item,init_stuc_obj,lat_press,init_filter_weight,side,chk,fat_dict,fat_press,slamming_press, PULSrun)
556
+ for item in iterable_all)
557
+ :param x:
558
+ :return:
559
+ '''
560
+
561
+ all_checks = [0,0,0,0,0,0,0,0]
562
+ check_map = {'weight': 0, 'UF unstiffened': 1, 'Column stability': 2, 'UF longitudinal stiffeners':3,
563
+ 'Stiffener check': 4, 'UF ring stiffeners':5, 'UF ring frame': 6, 'Check OK': 7}
564
+
565
+ calc_obj = create_new_cylinder_obj(obj, x)
566
+
567
+ optimizing = True if any([calc_obj.RingStfObj is None, calc_obj.RingFrameObj is None]) else False
568
+ # Weigth
569
+ if init_weight != False:
570
+ this_weight = calc_weight_cylinder(x)
571
+ if this_weight > init_weight:
572
+ results = calc_obj.get_utilization_factors(optimizing=optimizing, empty_result_dict = True)
573
+ results['Weight'] = this_weight
574
+ all_checks[0] += 1
575
+ return False, 'Weight filter', x, all_checks, calc_obj
576
+
577
+ if chk[0]:
578
+ results = calc_obj.get_utilization_factors(optimizing = optimizing)
579
+ if results[0]:
580
+ all_checks[check_map[results[1]]] += 1
581
+ return True, results[1], x, all_checks, calc_obj
582
+ else:
583
+ all_checks[check_map[results[1]]] += 1
584
+ return False, results[1], x, all_checks, calc_obj
585
+
586
+
587
+ def any_constraints_all(x,obj,lat_press,init_weight,side='p',chk=(True,True,True,True, True, True, True, False,
588
+ False, False),
589
+ fat_dict = None, fat_press = None, slamming_press = 0, PULSrun: calc.PULSpanel = None,
590
+ print_result = False, fdwn = 1, fup = 0.5, ml_results = None, random_result_return = False):
591
+ '''
592
+ Checking all constraints defined.
593
+
594
+ iter_var = ((item,init_stuc_obj,lat_press,init_filter_weight,side,chk,fat_dict,fat_press,slamming_press, PULSrun)
595
+ for item in iterable_all)
596
+ :param x:
597
+ :return:
598
+ '''
599
+ if random_result_return:
600
+ # Skip all calculations
601
+ if random.choice([True,False,False,False,False,False,False]):
602
+ return True, 'Check OK', x, [0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]
603
+ else:
604
+ return False, 'Random result', x, [1.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]
605
+ all_checks = [0,0,0,0,0,0,0,0,0,0,0]
606
+ print_result = False
607
+ calc_object_stf = None if obj.Stiffener is None else create_new_calc_obj(obj.Stiffener, x, fat_dict, fdwn = fdwn, fup = fup)
608
+ calc_object_pl = create_new_calc_obj(obj.Plate, x, fat_dict, fdwn=fdwn, fup=fup)
609
+ calc_object = [calc.AllStructure(Plate=calc_object_pl[0],
610
+ Stiffener=None if obj.Stiffener is None else calc_object_stf[0], Girder=None,
611
+ main_dict=obj.get_main_properties()['main dict']), calc_object_pl[1]]
612
+ calc_object[0].lat_press = lat_press
613
+
614
+ # PULS buckling check
615
+ if chk[7] and PULSrun is not None:
616
+ x_id = x_to_string(x)
617
+ if calc_object[0].Plate.get_puls_method() == 'buckling':
618
+ puls_uf = PULSrun.get_puls_line_results(x_id)["Buckling strength"]["Actual usage Factor"][0]
619
+ elif calc_object[0].Plate.get_puls_method() == 'ultimate':
620
+ puls_uf = PULSrun.get_puls_line_results(x_id)["Ultimate capacity"]["Actual usage Factor"][0]
621
+ if type(puls_uf) == str or puls_uf is None:
622
+ return False, 'PULS', x, all_checks
623
+ all_checks[8] = puls_uf/PULSrun.puls_acceptance
624
+ if puls_uf/PULSrun.puls_acceptance >= 1:
625
+ if print_result:
626
+ print('PULS', calc_object[0].get_one_line_string(), False)
627
+ return False, 'PULS', x, all_checks
628
+
629
+ # Buckling ml-cl
630
+ if chk[8]:
631
+ if any([calc_object[0].Plate.get_puls_method() == 'buckling' and ml_results[0] != 9,
632
+ calc_object[0].Plate.get_puls_method() == 'ultimate' and ml_results[1] != 9]):
633
+ if print_result:
634
+ print('Buckling ML-CL', calc_object[0].Stiffener.get_one_line_string(), False)
635
+ return False, 'Buckling ML-CL', x, all_checks
636
+
637
+ # Buckling ml-reg
638
+ if chk[9]:
639
+ pass
640
+
641
+ this_weight = calc_weight(x)
642
+
643
+ if this_weight > init_weight:
644
+ weigt_frac = this_weight / init_weight
645
+ if print_result:
646
+ pass
647
+ # print('Weights', calc_weight(x), ' > ', init_weight,
648
+ # calc_object[0].get_one_line_string(), init_weight, False)
649
+ all_checks[0] = weigt_frac
650
+ return False, 'Weight filter', x, all_checks
651
+
652
+ # Section modulus
653
+ if chk[0] and calc_object[0].Stiffener is not None:
654
+ section_modulus = min(calc_object[0].Stiffener.get_section_modulus())
655
+ min_section_modulus = calc_object[0].Stiffener.get_dnv_min_section_modulus(lat_press*1000)
656
+ section_frac = section_modulus / min_section_modulus
657
+ #print(section_modulus, min_section_modulus, section_frac, lat_press)
658
+ all_checks[1] = section_frac
659
+ if not section_modulus > min_section_modulus :
660
+ if print_result:
661
+ print('Section modulus',calc_object[0].get_one_line_string(), False)
662
+ return False, 'Section modulus', x, all_checks
663
+
664
+
665
+ # Local stiffener buckling
666
+ if chk[6] and calc_object[0].Stiffener is not None:
667
+ buckling_local = calc_object[0].local_buckling(optimizing=True)
668
+ check = all([buckling_local['Stiffener'][0] < calc_object[0].Stiffener.hw,
669
+ buckling_local['Stiffener'][1] < calc_object[0].Stiffener.b])
670
+ all_checks[2] = max([0 if buckling_local['Stiffener'][0] == 0 else
671
+ calc_object[0].Stiffener.hw/buckling_local['Stiffener'][0],
672
+ 0 if buckling_local['Stiffener'][1] == 0 else
673
+ calc_object[0].Stiffener.b/buckling_local['Stiffener'][1]])
674
+ if not check:
675
+ if print_result:
676
+ print('Local stiffener buckling',calc_object[0].get_one_line_string(), False)
677
+ return False, 'Local stiffener buckling', x, all_checks
678
+
679
+ # Buckling
680
+ if chk[3]:
681
+ '''
682
+ {'Plate': {'Plate buckling': up_buckling}, 'Stiffener': {'Overpressure plate side': stf_buckling_pl_side,
683
+ 'Overpressure stiffener side': stf_buckling_stf_side,
684
+ 'Resistance between stiffeners': stf_plate_resistance,
685
+ 'Shear capacity': stf_shear_capacity},
686
+ 'Girder': {'Overpressure plate side': girder_buckling_pl_side,
687
+ 'Overpressure girder side': girder_buckling_girder_side,
688
+ 'Shear capacity': girder_shear_capacity},
689
+ 'Local buckling': local_buckling}
690
+ '''
691
+ buckling_results = calc_object[0].plate_buckling(optimizing=True)
692
+ res = [buckling_results['Plate']['Plate buckling'],]
693
+ for val in buckling_results['Stiffener'].values():
694
+ res.append(val)
695
+ # for val in buckling_results['Girder'].values():
696
+ # res.append(val)
697
+ buckling_results = res
698
+ # print(buckling_results)
699
+ all_checks[3] = max(buckling_results)
700
+ if not all([uf<=1 for uf in buckling_results]):
701
+ if print_result:
702
+ print('Buckling',calc_object[0].get_one_line_string(), False)
703
+ return False, 'Buckling', x, all_checks
704
+
705
+
706
+ # Minimum plate thickness
707
+ if chk[1]:
708
+ act_pl_thk = calc_object[0].Plate.get_pl_thk()
709
+ min_pl_thk = calc_object[0].Plate.get_dnv_min_thickness(lat_press*1000)/1000
710
+ plate_frac = min_pl_thk / act_pl_thk
711
+ all_checks[4] = plate_frac
712
+ if not act_pl_thk > min_pl_thk:
713
+ if print_result:
714
+ print('Minimum plate thickeness',calc_object[0].get_one_line_string(), False)
715
+ return False, 'Minimum plate thickness', x, all_checks
716
+
717
+ # Shear area
718
+ if chk[2]:
719
+ pass
720
+ # calc_shear_area = calc_object[0].Stiffener.get_shear_area()
721
+ # min_shear_area = calc_object[0].Stiffener.get_minimum_shear_area(lat_press)
722
+ # shear_frac = min_shear_area / calc_shear_area
723
+ # all_checks[5] = shear_frac
724
+ # if not calc_shear_area > min_shear_area:
725
+ # if print_result:
726
+ # print('Shear area',calc_object[0].Stiffener.get_one_line_string(), False)
727
+ # return False, 'Shear area', x, all_checks
728
+
729
+ # Fatigue
730
+ if chk[4] and fat_dict is not None and fat_press is not None:
731
+
732
+ fatigue_uf = calc_object[1].get_total_damage(ext_press=fat_press[0],
733
+ int_press=fat_press[1])*calc_object[1].get_dff()
734
+ all_checks[6] = fatigue_uf
735
+ if fatigue_uf > 1:
736
+ if print_result:
737
+ print('Fatigue',calc_object[0].Stiffener.get_one_line_string(), False)
738
+ return False, 'Fatigue', x, all_checks
739
+
740
+ # Slamming
741
+
742
+ if chk[5] and slamming_press != 0 and calc_object[0].Stiffener is not None:
743
+ slam_check = calc_object[0].Stiffener.check_all_slamming(slamming_press)
744
+ all_checks[7] = slam_check[1]
745
+ if slam_check[0] is False:
746
+ if print_result:
747
+ print('Slamming',calc_object[0].Stiffener.get_one_line_string(), False)
748
+ return False, 'Slamming', x, all_checks
749
+
750
+ if print_result:
751
+ print('OK Section', calc_object[0].Stiffener.get_one_line_string(), True)
752
+
753
+ return True, 'Check OK', x, all_checks
754
+
755
+ def constraint_geometric(fractions, *args):
756
+ return sum(fractions) == 1
757
+
758
+ def pso_constraint_geometric(x,*args):
759
+ ''' The sum of the fractions must be 1.'''
760
+ return 1-sum(x)
761
+
762
+ def create_new_cylinder_obj(init_obj, x_new):
763
+ '''
764
+ shell (0.02, 2.5, 5, 5, 10, nan, nan, nan),
765
+ long (0.875, nan, 0.3, 0.01, 0.1, 0.01, nan, nan),
766
+ ring (nan, nan, 0.3, 0.01, 0.1, 0.01, nan, nan),
767
+ ring (nan, nan, 0.7, 0.02, 0.2, 0.02, nan, nan)]
768
+ '''
769
+
770
+ stress_press = [init_obj.sasd, init_obj.smsd, init_obj.tTsd, init_obj.tQsd, init_obj.shsd]
771
+ shell_obj = init_obj.ShellObj
772
+ long_obj = init_obj.LongStfObj
773
+ '''
774
+ t1, r1, s1, hw1, tw1, b1, tf1 = x1
775
+ t1, r1, s2, hw2, tw2, b2, tf2 = x2
776
+ '''
777
+
778
+ x_old = shell_obj.thk, shell_obj.radius, \
779
+ init_obj.panel_spacing if long_obj is None else long_obj.s/1000, \
780
+ 0 if long_obj is None else long_obj.hw/1000, \
781
+ 0 if long_obj is None else long_obj.tw/1000,\
782
+ 0 if long_obj is None else long_obj.b/1000,\
783
+ 0 if long_obj is None else long_obj.tf/1000,
784
+
785
+ x_new_stress_scaling = x_new[0][0] if not np.isnan(x_new[0][0]) else shell_obj.thk, \
786
+ x_new[0][1] if not np.isnan(x_new[0][1]) else shell_obj.radius,\
787
+ x_new[0][5] if long_obj is None else x_new[1][0], \
788
+ 0 if long_obj is None else x_new[1][2], \
789
+ 0 if long_obj is None else x_new[1][3],\
790
+ 0 if long_obj is None else x_new[1][4],\
791
+ 0 if long_obj is None else x_new[1][5]
792
+
793
+ new_stresses = stress_scaling_cylinder(x_old, x_new_stress_scaling, stress_press)
794
+ new_obj = copy.deepcopy(init_obj)
795
+ new_obj.sasd, new_obj.smsd, new_obj.tTsd, new_obj.tQsd, new_obj.shsd = new_stresses
796
+ new_obj.ShellObj.radius = x_new[0][1]
797
+ new_obj.ShellObj.thk = x_new[0][0]
798
+ if long_obj is None:
799
+ new_obj.panel_spacing = x_new[0][5]
800
+ else:
801
+ new_obj.LongStfObj.s = x_new[1][0]*1000
802
+ new_obj.LongStfObj.hw = x_new[1][2]*1000
803
+ new_obj.LongStfObj.tw = x_new[1][3]*1000
804
+ new_obj.LongStfObj.b = x_new[1][4]*1000
805
+ new_obj.LongStfObj.tf = x_new[1][5]*1000
806
+
807
+ #new_obj.LongStfObj.stiffener_type = x_new[1][7] # TODO should be 8
808
+
809
+ return new_obj
810
+
811
+ def create_new_calc_obj(init_obj,x, fat_dict=None, fdwn = 1, fup = 0.5):
812
+ '''
813
+ Returns a new calculation object to be used in optimization
814
+ :param init_obj:
815
+ :return:
816
+ '''
817
+
818
+ if type(init_obj) == calc.AllStructure:
819
+
820
+ if init_obj.Stiffener is not None:
821
+ plate = init_obj.Plate
822
+ stiffener = init_obj.Stiffener
823
+ girder = init_obj.Girder
824
+ x_old = (plate.get_s(), plate.get_pl_thk(), stiffener.get_web_h(), stiffener.get_web_thk(),
825
+ stiffener.get_fl_w(),
826
+ stiffener.get_fl_thk(), plate.span, stiffener.girder_lg if girder is None else
827
+ girder.girder_lg, stiffener.stiffener_type)
828
+ else:
829
+ x_old = init_obj.Plate.get_tuple()
830
+
831
+ sigma_y1_new = stress_scaling(init_obj.Plate.sigma_y1, init_obj.Plate.get_pl_thk(), x[1], fdwn = fdwn, fup = fup)
832
+ sigma_y2_new = stress_scaling(init_obj.Plate.sigma_y2, init_obj.Plate.get_pl_thk(), x[1], fdwn = fdwn, fup = fup)
833
+ tau_xy_new = stress_scaling(init_obj.Plate.tau_xy, init_obj.Plate.get_pl_thk(), x[1], fdwn = fdwn, fup = fup)
834
+ sigma_x1_new = stress_scaling_area(init_obj.Plate.sigma_x1,
835
+ sum(get_field_tot_area(x_old)),
836
+ sum(get_field_tot_area(x)), fdwn = fdwn, fup = fup)
837
+ sigma_x2_new = stress_scaling_area(init_obj.Plate.sigma_x2,
838
+ sum(get_field_tot_area(x_old)),
839
+ sum(get_field_tot_area(x)), fdwn = fdwn, fup = fup)
840
+ try:
841
+ stf_type = x[8]
842
+ except IndexError:
843
+ stf_type = init_obj.plate.get_stiffener_type()
844
+
845
+ main_dict = {'mat_yield': [init_obj.Plate.get_fy(), 'Pa'],'mat_factor': [init_obj.Plate.mat_factor, ''],
846
+ 'span': [init_obj.Plate.span, 'm'],
847
+ 'spacing': [x[0], 'm'],'plate_thk': [x[1], 'm'],'stf_web_height':[ x[2], 'm'],
848
+ 'stf_web_thk': [x[3], 'm'],'stf_flange_width': [x[4], 'm'],
849
+ 'stf_flange_thk': [x[5], 'm'],'structure_type': [init_obj.Plate.get_structure_type(), ''],
850
+ 'stf_type': [stf_type, ''],'sigma_y1': [sigma_y1_new, 'MPa'],
851
+ 'sigma_y2': [sigma_y2_new, 'MPa'],'sigma_x1': [sigma_x1_new, 'MPa'],'sigma_x2': [sigma_x2_new, 'MPa'],
852
+ 'tau_xy': [tau_xy_new, 'MPa'],'plate_kpp': [init_obj.Plate.get_kpp(), ''],
853
+ 'stf_kps': [init_obj.Plate.get_kps(), ''],'stf_km1': [init_obj.Plate.get_km1(), ''],
854
+ 'stf_km2': [init_obj.Plate.get_km2(), ''],'stf_km3': [init_obj.Plate.get_km3(), ''],
855
+ 'structure_types':[init_obj.Plate.get_structure_types(), ''],
856
+ 'zstar_optimization': [init_obj.Plate.get_z_opt(), ''],
857
+ 'puls buckling method':[init_obj.Plate.get_puls_method(),''],
858
+ 'puls boundary':[init_obj.Plate.get_puls_boundary(),''],
859
+ 'puls stiffener end':[init_obj.Plate.get_puls_stf_end(),''],
860
+ 'puls sp or up':[init_obj.Plate.get_puls_sp_or_up(),''],
861
+ 'puls up boundary':[init_obj.Plate.get_puls_up_boundary(),''],
862
+ 'panel or shell': [init_obj.Plate.panel_or_shell, '']}
863
+ all_dict = init_obj.get_main_properties()
864
+ all_dict['Plate'] = main_dict
865
+ all_dict['Stiffener'] = None if init_obj.Stiffener is None else main_dict
866
+ all_dict['Girder'] = None if init_obj.Girder is None else main_dict
867
+
868
+ if fat_dict == None:
869
+ return calc.AllStructure(Plate=None if all_dict['Plate'] is None
870
+ else calc.CalcScantlings(all_dict['Plate']),
871
+ Stiffener=None if all_dict['Stiffener'] is None
872
+ else calc.CalcScantlings(all_dict['Stiffener']),
873
+ Girder=None if all_dict['Girder'] is None
874
+ else calc.CalcScantlings(all_dict['Girder']),
875
+ main_dict=all_dict['main dict']), None
876
+ else:
877
+ return calc.AllStructure(Plate=None if all_dict['Plate'] is None
878
+ else calc.CalcScantlings(all_dict['Plate']),
879
+ Stiffener=None if all_dict['Stiffener'] is None
880
+ else calc.CalcScantlings(all_dict['Stiffener']),
881
+ Girder=None if all_dict['Girder'] is None
882
+ else calc.CalcScantlings(all_dict['Girder']),
883
+ main_dict=all_dict['main dict']), \
884
+ calc.CalcFatigue(main_dict, fat_dict)
885
+ else:
886
+ x_old = [init_obj.get_s(), init_obj.get_pl_thk(), init_obj.get_web_h() , init_obj.get_web_thk(),
887
+ init_obj.get_fl_w(),init_obj.get_fl_thk(), init_obj.span, init_obj.girder_lg]
888
+
889
+ sigma_y1_new = stress_scaling(init_obj.sigma_y1, init_obj.get_pl_thk(), x[1], fdwn = fdwn, fup = fup)
890
+ sigma_y2_new = stress_scaling(init_obj.sigma_y2, init_obj.get_pl_thk(), x[1], fdwn = fdwn, fup = fup)
891
+ tau_xy_new = stress_scaling(init_obj.tau_xy, init_obj.get_pl_thk(), x[1], fdwn = fdwn, fup = fup)
892
+ sigma_x1_new = stress_scaling_area(init_obj.sigma_x1,
893
+ sum(get_field_tot_area(x_old)),
894
+ sum(get_field_tot_area(x)), fdwn = fdwn, fup = fup)
895
+ sigma_x2_new = stress_scaling_area(init_obj.sigma_x2,
896
+ sum(get_field_tot_area(x_old)),
897
+ sum(get_field_tot_area(x)), fdwn = fdwn, fup = fup)
898
+ try:
899
+ stf_type = x[8]
900
+ except IndexError:
901
+ stf_type = init_obj.get_stiffener_type()
902
+
903
+ main_dict = {'mat_yield': [init_obj.get_fy(), 'Pa'],'mat_factor': [init_obj.mat_factor, ''],
904
+ 'span': [init_obj.span, 'm'],
905
+ 'spacing': [x[0], 'm'],'plate_thk': [x[1], 'm'],'stf_web_height':[ x[2], 'm'],
906
+ 'stf_web_thk': [x[3], 'm'],'stf_flange_width': [x[4], 'm'],
907
+ 'stf_flange_thk': [x[5], 'm'],'structure_type': [init_obj.get_structure_type(), ''],
908
+ 'stf_type': [stf_type, ''],'sigma_y1': [sigma_y1_new, 'MPa'],
909
+ 'sigma_y2': [sigma_y2_new, 'MPa'],'sigma_x1': [sigma_x1_new, 'MPa'],'sigma_x2': [sigma_x2_new, 'MPa'],
910
+ 'tau_xy': [tau_xy_new, 'MPa'],'plate_kpp': [init_obj.get_kpp(), ''],
911
+ 'stf_kps': [init_obj.get_kps(), ''],'stf_km1': [init_obj.get_km1(), ''],
912
+ 'stf_km2': [init_obj.get_km2(), ''],'stf_km3': [init_obj.get_km3(), ''],
913
+ 'structure_types':[init_obj.get_structure_types(), ''],
914
+ 'zstar_optimization': [init_obj.get_z_opt(), ''],
915
+ 'puls buckling method':[init_obj.get_puls_method(),''],
916
+ 'puls boundary':[init_obj.get_puls_boundary(),''],
917
+ 'puls stiffener end':[init_obj.get_puls_stf_end(),''],
918
+ 'puls sp or up':[init_obj.get_puls_sp_or_up(),''],
919
+ 'puls up boundary':[init_obj.get_puls_up_boundary(),''],
920
+ 'panel or shell': [init_obj.panel_or_shell, '']}
921
+ if fat_dict == None:
922
+ return calc.CalcScantlings(main_dict), None
923
+ else:
924
+ return calc.CalcScantlings(main_dict), calc.CalcFatigue(main_dict, fat_dict)
925
+
926
+ def create_new_structure_obj(init_obj, x, fat_dict=None, fdwn = 1, fup = 0.5):
927
+ '''
928
+ Returns a new calculation object to be used in optimization
929
+ :param init_obj:
930
+ :return:
931
+ '''
932
+ x_old = [init_obj.get_s(), init_obj.get_pl_thk(), init_obj.get_web_h() , init_obj.get_web_thk(),
933
+ init_obj.get_fl_w() ,init_obj.get_fl_thk(), init_obj.span, init_obj.girder_lg]
934
+
935
+ sigma_y1_new = stress_scaling(init_obj.sigma_y1, init_obj.get_pl_thk(), x[1], fdwn = fdwn, fup = fup)
936
+ sigma_y2_new = stress_scaling(init_obj.sigma_y2, init_obj.get_pl_thk(), x[1], fdwn = fdwn, fup = fup)
937
+ tau_xy_new = stress_scaling(init_obj.tau_xy, init_obj.get_pl_thk(), x[1],fdwn = fdwn, fup = fup)
938
+ sigma_x1_new = stress_scaling_area(init_obj.sigma_x1,sum(get_field_tot_area(x_old)),sum(get_field_tot_area(x)),
939
+ fdwn = fdwn, fup = fup)
940
+ sigma_x2_new = stress_scaling_area(init_obj.sigma_x2,sum(get_field_tot_area(x_old)),sum(get_field_tot_area(x)),
941
+ fdwn = fdwn, fup = fup)
942
+
943
+ try:
944
+ stf_type = x[8]
945
+ except IndexError:
946
+ stf_type = init_obj.get_stiffener_type()
947
+
948
+ main_dict = {'mat_yield': [init_obj.get_fy(), 'Pa'], 'span': [init_obj.span, 'm'],
949
+ 'mat_factor': [init_obj.Plate.mat_factor, ''],
950
+ 'spacing': [x[0], 'm'], 'plate_thk': [x[1], 'm'], 'stf_web_height': [x[2], 'm'],
951
+ 'stf_web_thk': [x[3], 'm'], 'stf_flange_width': [x[4], 'm'],
952
+ 'stf_flange_thk': [x[5], 'm'], 'structure_type': [init_obj.get_structure_type(), ''],
953
+ 'stf_type': [stf_type, ''], 'sigma_y1': [sigma_y1_new, 'MPa'],
954
+ 'sigma_y2': [sigma_y2_new, 'MPa'], 'sigma_x1': [sigma_x1_new, 'MPa'],'sigma_x2': [sigma_x2_new, 'MPa'],
955
+ 'tau_xy': [tau_xy_new, 'MPa'], 'plate_kpp': [init_obj.get_kpp(), ''],
956
+ 'stf_kps': [init_obj.get_kps(), ''], 'stf_km1': [init_obj.get_km1(), ''],
957
+ 'stf_km2': [init_obj.get_km2(), ''], 'stf_km3': [init_obj.get_km3(), ''],
958
+ 'structure_types': [init_obj.get_structure_types(), ''],
959
+ 'zstar_optimization': [init_obj.get_z_opt(), ''],
960
+ 'puls buckling method': [init_obj.get_puls_method(), ''],
961
+ 'puls boundary': [init_obj.get_puls_boundary(), ''],
962
+ 'puls stiffener end': [init_obj.get_puls_stf_end(), ''],
963
+ 'puls sp or up': [init_obj.get_puls_sp_or_up(), ''],
964
+ 'puls up boundary': [init_obj.get_puls_up_boundary(), ''],
965
+ }
966
+
967
+ #if fat_dict == None:
968
+ return calc.Structure(main_dict)
969
+
970
+ def get_field_tot_area(x):
971
+ ''' Total area of a plate field. '''
972
+
973
+ if len(x) == 6:
974
+ width = 10
975
+ else:
976
+ width = x[7]
977
+ plate_area = width*x[1]
978
+ stiff_area = (x[2] * x[3]+ x[4] * x[5]) * (width//x[0])
979
+
980
+ return plate_area, stiff_area
981
+
982
+ def calc_weight(x, prt = False):
983
+ '''
984
+ Calculating the current weight
985
+ :param current_dict:
986
+ :return:
987
+ '''
988
+ span = x[6]
989
+ plate_area, stiff_area = get_field_tot_area(x)
990
+
991
+ if prt:
992
+ print('x is', x, 'plate area', plate_area, 'stiff area', stiff_area, 'weight',
993
+ span * 7850 * (plate_area + stiff_area))
994
+ return span * 7850 * (plate_area + stiff_area)
995
+
996
+ def calc_weight_pso(x,*args):
997
+ '''
998
+ Calculating the current weight
999
+ :param current_dict:
1000
+ :return:
1001
+ '''
1002
+
1003
+ width = args[5]
1004
+ span = args[6]
1005
+
1006
+ plate_area = width*x[1]
1007
+ stiff_area = (x[2] * x[3]+ x[4] * x[5]) * (width//x[0])
1008
+ return span * 7850 * (plate_area + stiff_area)
1009
+
1010
+ def calc_weight_pso_section(x,*args):
1011
+ '''
1012
+ Calculating the weight of a complete section.
1013
+ :param x:
1014
+ :param args:
1015
+ :return:
1016
+ '''
1017
+ stru_objects = args[1]
1018
+ tot_length = args[2]
1019
+ frame_height = args[3]
1020
+ frame_section_area = args[4]
1021
+
1022
+ tot_weight = 0
1023
+
1024
+ for dummy_i in range(len(stru_objects)):
1025
+ tot_weight += frame_section_area*frame_height*7850
1026
+
1027
+ count = 0
1028
+ for stru_object in stru_objects:
1029
+ span = tot_length*x[count]
1030
+ stru_object.Plate.set_span(span)
1031
+ stru_object.Stiffener.set_span(span)
1032
+ tot_weight += stru_object.Stiffener.get_weight_width_lg()
1033
+
1034
+ return tot_weight
1035
+
1036
+ def calc_weight_cylinder(x):
1037
+ '''
1038
+ Calculation of total weigth.
1039
+
1040
+ shell (0.02, 2.5, 5, 5, 10, nan, nan, nan),
1041
+ long (0.875, nan, 0.3, 0.01, 0.1, 0.01, nan, nan),
1042
+ ring (nan, nan, 0.3, 0.01, 0.1, 0.01, nan, nan),
1043
+ ring (nan, nan, 0.7, 0.02, 0.2, 0.02, nan, nan)]
1044
+ '''
1045
+ if sum(x[1][0:8]) != 0:
1046
+ num_long_stf = 2*math.pi*x[0][1]/x[1][0]
1047
+ long_stf_area = x[1][2]*x[1][3]+x[1][4]*x[1][5]
1048
+ long_stf_volume = long_stf_area * x[0][4] * num_long_stf
1049
+ else:
1050
+ long_stf_volume = 0
1051
+ if sum(x[2][0:8]) != 0:
1052
+ num_ring_stf = x[0][4] / x[0][2]
1053
+ ring_stf_volume = math.pi*(math.pow(x[0][1],2)-math.pow(x[0][1]-x[2][2],2))*x[2][3] + \
1054
+ 2*math.pi*(x[0][1]-x[2][2]) * x[2][4] * x[2][5]
1055
+ ring_stf_tot_vol = ring_stf_volume * num_ring_stf
1056
+ else:
1057
+ ring_stf_tot_vol = 0
1058
+ if sum(x[3][0:8]) != 0:
1059
+ num_ring_girder = x[0][4] / x[0][3]
1060
+ ring_frame_volume = math.pi*(math.pow(x[0][1],2)-math.pow(x[0][1]-x[3][2],2))*x[3][3] + \
1061
+ 2*math.pi*(x[0][1]-x[3][2])*x[3][4]*x[3][5]
1062
+ tot_ring_frame_vol = ring_frame_volume*num_ring_girder
1063
+ else:
1064
+ tot_ring_frame_vol = 0
1065
+
1066
+ shell_volume = 2 * math.pi * x[0][1] * x[0][0] * x[0][4]
1067
+
1068
+ return (long_stf_volume+ring_stf_tot_vol+tot_ring_frame_vol+shell_volume)*7850
1069
+
1070
+ def stress_scaling_cylinder(x1, x2, stress1):
1071
+ '''
1072
+ Scale stresses of a stiffened cylinder.
1073
+
1074
+ To scale:
1075
+
1076
+ Design axial stress, sa,sd =
1077
+ Design bending stress, sm,sd =
1078
+ Design torsional stress, tT,sd=
1079
+ Design shear stress, tQ,sd=
1080
+ Additional hoop stress, sh,sd =
1081
+
1082
+ '''
1083
+
1084
+ t1, r1, s1, hw1, tw1, b1, tf1 = x1
1085
+ t2, r2, s2, hw2, tw2, b2, tf2 = x2
1086
+
1087
+ sasd1, smsd1, tTsd1, tQsd1, shsd1 = stress1
1088
+
1089
+ A1 = hw1 * tw1 + b1 * tf1
1090
+ A2 = hw2 * tw2 + b2 * tf2
1091
+ # Axial stress changes by equivalent thickness
1092
+
1093
+ thk_eq1 = t1 + 0 if s1 == 0 else A1 / s1
1094
+ thk_eq2 = t2 + 0 if s2 == 0 else A2 / s2
1095
+
1096
+ # Moment stress changes by difference in moment of inertia
1097
+
1098
+ Itot1 = calc.CylinderAndCurvedPlate.get_Itot(hw=hw1, tw=tw1, b=b1, tf=tf1, r=r1, s=s1, t=t1)
1099
+ Itot2 = calc.CylinderAndCurvedPlate.get_Itot(hw=hw2, tw=tw2, b=b2, tf=tf2, r=r2, s=s2, t=t2)
1100
+
1101
+ # Torsional, shear and hoop changes by cylinder thickness.
1102
+
1103
+ return sasd1*(thk_eq1/thk_eq2), smsd1*(Itot1/Itot2), tTsd1*(t1/t2), tQsd1*(t1/t2), shsd1*(t1/t2)
1104
+
1105
+ def stress_scaling(sigma_old,t_old,t_new, fdwn = 1, fup = 0.5):
1106
+
1107
+ if t_new <= t_old: #decreasing the thickness
1108
+ sigma_new = sigma_old*(t_old/(t_old-fdwn*abs((t_old-t_new))))
1109
+ # assert sigma_new >= sigma_old, 'ERROR no stress increase: \n' \
1110
+ # 't_old '+str(t_old)+' sigma_old '+str(sigma_old)+ \
1111
+ # '\nt_new '+str(t_new)+' sigma_new '+str(sigma_new)
1112
+
1113
+ else: #increasing the thickness
1114
+
1115
+ sigma_new = sigma_old*(t_old/(t_old+fup*abs((t_old-t_new))))
1116
+ # assert sigma_new <= sigma_old, 'ERROR no stress reduction: \n' \
1117
+ # 't_old '+str(t_old)+' sigma_old '+str(sigma_old)+ \
1118
+ # '\nt_new '+str(t_new)+' sigma_new '+str(sigma_new)
1119
+ return sigma_new
1120
+
1121
+ def stress_scaling_area(sigma_old,a_old,a_new, fdwn = 1, fup = 0.5):
1122
+ ''' Scale stresses using input area '''
1123
+
1124
+ if a_new <= a_old: #decreasing the thickness
1125
+ sigma_new = sigma_old*(a_old/(a_old-fdwn*abs((a_old-a_new))))
1126
+ # assert sigma_new >= sigma_old, 'ERROR no stress increase: \n' \
1127
+ # 't_old '+str(a_old)+' sigma_old '+str(sigma_old)+ \
1128
+ # '\nt_new '+str(a_new)+' sigma_new '+str(sigma_new)
1129
+ else: #increasing the thickness
1130
+ sigma_new = sigma_old*(a_old/(a_old+fup*abs((a_old-a_new))))
1131
+ # assert sigma_new <= sigma_old, 'ERROR no stress reduction: \n' \
1132
+ # 't_old '+str(a_old)+' sigma_old '+str(sigma_old)+ \
1133
+ # '\nt_new '+str(a_new)+' sigma_new '+str(sigma_new)
1134
+ #print('a_old', a_old, 'sigma_old', sigma_old, '|', 'a_new', a_new, 'sigma_new',sigma_new)
1135
+ return sigma_new
1136
+
1137
+ def x_to_string(x):
1138
+ ret = ''
1139
+ for val in x:
1140
+ ret += str(val) + '_'
1141
+ return ret
1142
+
1143
+ def get_filtered_results(iterable_all,init_stuc_obj,lat_press,init_filter_weight,side='p',
1144
+ chk=(True,True,True,True,True,True,True, False),fat_dict = None, fat_press = None,
1145
+ slamming_press=None, processes = None, puls_sheet = None, puls_acceptance = 0.87,
1146
+ fdwn = 1, fup = 0.5, ml_algo = None):
1147
+ '''
1148
+ Using multiprocessing to return list of applicable results.
1149
+
1150
+ :param iterable_all:
1151
+ :param init_stuc_obj:
1152
+ :param lat_press:
1153
+ :param init_filter_weight:
1154
+ :param side:
1155
+ :param chk:
1156
+ :return:
1157
+ '''
1158
+ #print('Init filter weight', init_filter_weight)
1159
+ '''
1160
+ x,obj,lat_press,init_weight,side='p',chk=(True,True,True,True, True, True, True, False),
1161
+ fat_dict = None, fat_press = None, slamming_press = 0, , puls_results = None, print_result = False
1162
+ '''
1163
+
1164
+ if chk[7]:
1165
+ # PULS to be used.
1166
+ #calc.PULSpanel
1167
+ '''
1168
+ dict_to_run[line_given] = self._line_to_struc[line_given][1].get_puls_input()
1169
+ dict_to_run[line_given]['Identification'] = line_given
1170
+ dict_to_run[line_given]['Pressure (fixed)'] = self.get_highest_pressure(line_given)['normal'] / 1e6
1171
+ '''
1172
+
1173
+ dict_to_run = {}
1174
+ for x in iterable_all:
1175
+ x_id = x_to_string(x)
1176
+ # calc_object = create_new_calc_obj(init_stuc_obj, x, fat_dict, fdwn = fdwn, fup = fup)
1177
+
1178
+ calc_object_stf = None if init_stuc_obj.Stiffener is None else create_new_calc_obj(init_stuc_obj.Stiffener,
1179
+ x, fat_dict,
1180
+ fdwn=fdwn, fup=fup)
1181
+ calc_object_pl = create_new_calc_obj(init_stuc_obj.Plate, x, fat_dict, fdwn=fdwn, fup=fup)
1182
+ calc_object = [calc.AllStructure(Plate=calc_object_pl[0],
1183
+ Stiffener=None if init_stuc_obj.Stiffener is None else calc_object_stf[0],
1184
+ Girder=None,
1185
+ main_dict=init_stuc_obj.get_main_properties()['main dict']),
1186
+ calc_object_pl[1]]
1187
+
1188
+ dict_to_run[x_id] = calc_object[0].Plate.get_puls_input()
1189
+ dict_to_run[x_id]['Identification'] = x_id
1190
+ dict_to_run[x_id]['Pressure (fixed)'] = lat_press # PULS sheet to have pressure in MPa
1191
+
1192
+ PULSrun = calc.PULSpanel(dict_to_run, puls_sheet_location=puls_sheet, puls_acceptance=puls_acceptance)
1193
+ PULSrun.run_all()
1194
+ sort_again = None
1195
+ elif chk[8]:
1196
+
1197
+ # ML-CL to be used.
1198
+ # Buckling ml-cl
1199
+ sp_int, sp_gl_gt, up_int, up_gl_gt, \
1200
+ sp_int_idx, sp_gl_gt_idx, up_int_idx, up_gl_gt_idx = \
1201
+ list(), list(), list(),list(),list(), list(), list(),list()
1202
+
1203
+ # Create iterator
1204
+ idx_count = 0
1205
+ for idx, x in enumerate(iterable_all):
1206
+ idx_count += 1
1207
+ # calc_object = create_new_calc_obj(init_stuc_obj, x, fat_dict, fdwn=fdwn, fup=fup)
1208
+
1209
+ calc_object_stf = None if init_stuc_obj.Stiffener is None else create_new_calc_obj(init_stuc_obj.Stiffener,
1210
+ x, fat_dict,
1211
+ fdwn=fdwn, fup=fup)
1212
+ calc_object_pl = create_new_calc_obj(init_stuc_obj.Plate, x, fat_dict, fdwn=fdwn, fup=fup)
1213
+ calc_object = [calc.AllStructure(Plate=calc_object_pl[0],
1214
+ Stiffener=None if init_stuc_obj.Stiffener is None else calc_object_stf[0],
1215
+ Girder=None,
1216
+ main_dict=init_stuc_obj.get_main_properties()['main dict']), calc_object_pl[1]]
1217
+
1218
+ if calc_object[0].Plate.get_puls_sp_or_up() == 'UP':
1219
+ if calc_object[0].Plate.get_puls_boundary() == 'Int':
1220
+ up_int.append(calc_object[0].Plate.get_buckling_ml_input(lat_press, alone = False))
1221
+ up_int_idx.append(idx)
1222
+ else:
1223
+ up_gl_gt.append(calc_object[0].Plate.get_buckling_ml_input(lat_press, alone = False))
1224
+ up_gl_gt_idx.append(idx)
1225
+ else:
1226
+ if calc_object[0].Plate.get_puls_boundary() == 'Int':
1227
+ sp_int.append(calc_object[0].Plate.get_buckling_ml_input(lat_press, alone = False))
1228
+ sp_int_idx.append(idx)
1229
+ else:
1230
+ sp_gl_gt.append(calc_object[0].Plate.get_buckling_ml_input(lat_press, alone = False))
1231
+ sp_gl_gt_idx.append(idx)
1232
+
1233
+ # Predict
1234
+ sort_again = np.zeros([len(iterable_all),2])
1235
+
1236
+ if len(sp_int) != 0:
1237
+ sp_int_res = [ml_algo['cl SP buc int predictor'].predict(ml_algo['cl SP buc int scaler']
1238
+ .transform(sp_int)),
1239
+ ml_algo['cl SP ult int predictor'].predict(ml_algo['cl SP buc int scaler']
1240
+ .transform(sp_int))]
1241
+ for idx, res_buc, res_ult in zip(sp_int_idx, sp_int_res[0],sp_int_res[1]):
1242
+ sort_again[idx] = [res_buc, res_ult]
1243
+
1244
+ if len(sp_gl_gt) != 0:
1245
+ sp_gl_gt_res = [ml_algo['cl SP buc GLGT predictor'].predict(ml_algo['cl SP buc GLGT scaler']
1246
+ .transform(sp_gl_gt)),
1247
+ ml_algo['cl SP buc GLGT predictor'].predict(ml_algo['cl SP buc GLGT scaler']
1248
+ .transform(sp_gl_gt))]
1249
+ for idx, res_buc, res_ult in zip(sp_gl_gt_idx, sp_gl_gt_res[0],sp_gl_gt_res[1]):
1250
+ sort_again[idx] = [res_buc, res_ult]
1251
+ if len(up_int) != 0:
1252
+ up_int_res = [ml_algo['cl UP buc int predictor'].predict(ml_algo['cl UP buc int scaler']
1253
+ .transform(up_int)),
1254
+ ml_algo['cl UP ult int predictor'].predict(ml_algo['cl UP buc int scaler']
1255
+ .transform(up_int))]
1256
+ for idx, res_buc, res_ult in zip(up_int_idx, up_int_res[0],up_int_res[1]):
1257
+ sort_again[idx] = [res_buc, res_ult]
1258
+ if len(up_gl_gt) != 0:
1259
+ up_gl_gt_res =[ml_algo['cl UP buc GLGT predictor'].predict(ml_algo['cl UP buc GLGT scaler']
1260
+ .transform(up_gl_gt)),
1261
+ ml_algo['cl UP buc GLGT predictor'].predict(ml_algo['cl UP buc GLGT scaler']
1262
+ .transform(up_gl_gt))]
1263
+ for idx, res_buc, res_ult in zip(up_gl_gt_idx, up_gl_gt_res[0],up_gl_gt_res[1]):
1264
+ sort_again[idx] = [res_buc, res_ult]
1265
+ PULSrun = None
1266
+ else:
1267
+ PULSrun = None
1268
+ idx_count = 0
1269
+ for x in iterable_all:
1270
+ idx_count += 1
1271
+ sort_again = None
1272
+
1273
+ iter_var = list()
1274
+ for idx,item in enumerate(iterable_all):
1275
+ iter_var.append((item,init_stuc_obj,lat_press,init_filter_weight,side,chk,fat_dict,fat_press,slamming_press,
1276
+ PULSrun, False,fdwn, fup, sort_again[idx] if chk[8] == True else None))
1277
+
1278
+ iter_var = tuple(iter_var)
1279
+
1280
+ #res_pre = it.starmap(any_constraints_all, iter_var)
1281
+ if processes is None:
1282
+ processes = max(cpu_count()-1,1)
1283
+
1284
+ with Pool(processes) as my_process:
1285
+ # res_pre = m
1286
+ # y_process.starmap_async(any_constraints_all, iter_var).get()
1287
+ # print('Done calculating')
1288
+ res_pre = my_process.starmap(any_constraints_all, iter_var)
1289
+
1290
+ check_ok, check_not_ok = list(), list()
1291
+ for item in res_pre:
1292
+ if item[0] is False:
1293
+ check_not_ok.append(item)
1294
+ else:
1295
+ check_ok.append(item)
1296
+
1297
+ return check_ok, check_not_ok
1298
+
1299
+ def any_get_all_combs(min_var, max_var,deltas, init_weight = float('inf'), predef_stiffeners = None, stf_type = None):
1300
+ '''
1301
+ Calulating initial values.
1302
+ :param min:
1303
+ :param max:
1304
+ :return:
1305
+ '''
1306
+ '''
1307
+ shell_upper_bounds = np.array( [0.03, 2.5, 5, 0.8, 6, 6])
1308
+ shell_deltas = np.array( [0.01, 2.5, 1, 0.1, 1, 1])
1309
+ shell_lower_bounds = np.array( [0.02, 2.5, 5, 0.6, 4, 4])
1310
+
1311
+ long_upper_bounds = np.array( [0.875, None, 0.5, 0.018, 0.2, 0.03])
1312
+ long_deltas = np.array( [0.025, None, 0.1, 0.004, 0.05, 0.005])
1313
+ long_lower_bounds = np.array( [0.875, None, 0.3, 0.010, 0.1, 0.010])
1314
+
1315
+ ring_stf_upper_bounds = np.array( [None, None, 0.5, 0.018, 0.2, 0.03])
1316
+ ring_stf_deltas = np.array( [None, None, 0.1, 0.004, 0.05, 0.005])
1317
+ ring_stf_lower_bounds = np.array( [None, None, 0.3, 0.010, 0.1, 0.010])
1318
+
1319
+ ring_frame_upper_bounds = np.array( [None, None, 0.9, 0.04, 0.3, 0.04])
1320
+ ring_frame_deltas = np.array( [None, None, 0.2, 0.01, 0.1, 0.01])
1321
+ ring_frame_lower_bounds = np.array( [None, None, 0.5, 0.02, 0.2, 0.020])
1322
+ '''
1323
+ if min_var[0] is not None:
1324
+ spacing_array = (np.arange(min_var[0], max_var[0]+ deltas[0], deltas[0])) if min_var[0] != max_var[0] \
1325
+ else np.array([min_var[0]])
1326
+ spacing_array = spacing_array[spacing_array <= max_var[0]]
1327
+ else:
1328
+ spacing_array = np.array([np.nan])
1329
+
1330
+ if min_var[1] is not None:
1331
+ pl_thk_array = (np.arange(min_var[1], max_var[1]+ deltas[1], deltas[1])) if min_var[1] != max_var[1] \
1332
+ else np.array([min_var[1]])
1333
+ pl_thk_array = pl_thk_array[pl_thk_array <= max_var[1]]
1334
+ else:
1335
+ pl_thk_array = np.array([np.nan])
1336
+
1337
+ if predef_stiffeners is not None:
1338
+ predef_iterable = list()
1339
+ for pre_str in predef_stiffeners:
1340
+ for spacing in spacing_array:
1341
+
1342
+ for pl_thk in pl_thk_array:
1343
+ new_field = list(pre_str)
1344
+ new_field[0] = spacing
1345
+ new_field[1] = pl_thk
1346
+ predef_iterable.append(tuple(new_field))
1347
+
1348
+ return predef_iterable
1349
+
1350
+
1351
+ web_h_array = (np.arange(min_var[2], max_var[2]+ deltas[2], deltas[2])) if min_var[2] != max_var[2] \
1352
+ else np.array([min_var[2]])
1353
+ web_h_array = web_h_array[web_h_array <= max_var[2]]
1354
+
1355
+ web_thk_array = (np.arange(min_var[3], max_var[3]+ deltas[3], deltas[3])) if min_var[3] != max_var[3] \
1356
+ else np.array([min_var[3]])
1357
+ web_thk_array = web_thk_array[web_thk_array <= max_var[3]]
1358
+
1359
+ flange_w_array = (np.arange(min_var[4], max_var[4]+ deltas[4], deltas[4])) if min_var[4] != max_var[4] \
1360
+ else np.array([min_var[4]])
1361
+ flange_w_array = flange_w_array[flange_w_array <= max_var[4]]
1362
+
1363
+ if min_var[5] is not None:
1364
+ flange_thk_array = (np.arange(min_var[5], max_var[5]+ deltas[5], deltas[5])) if min_var[5] != max_var[5] \
1365
+ else np.array([min_var[5]])
1366
+ flange_thk_array = flange_thk_array[flange_thk_array <= max_var[5]]
1367
+ else:
1368
+ flange_thk_array = np.array([np.nan])
1369
+
1370
+ if min_var[6] is not None:
1371
+ span_array = (np.arange(min_var[6], max_var[6], deltas[4])) if min_var[6] != max_var[6] \
1372
+ else np.array([min_var[6]])
1373
+ else:
1374
+ span_array = np.array([np.nan])
1375
+
1376
+ if min_var[7] is not None:
1377
+ girder_array = (np.arange(min_var[7], max_var[7], deltas[7])) if min_var[7] != max_var[7] \
1378
+ else np.array([min_var[7]])
1379
+ else:
1380
+ girder_array = np.array([np.nan])
1381
+
1382
+ comb = it.product(spacing_array, pl_thk_array, web_h_array, web_thk_array, flange_w_array, flange_thk_array,
1383
+ span_array,girder_array)
1384
+
1385
+ return list(comb)
1386
+
1387
+ def get_initial_weight(obj,lat_press,min_var,max_var,deltas,trials,fat_dict,fat_press, predefined_stiffener_iter,
1388
+ slamming_press, fdwn = 1, fup = 0.5, ml_algo = None):
1389
+ '''
1390
+ Return a guess of the initial weight used to filter the constraints.
1391
+ Only aim is to reduce running time of the algorithm.
1392
+ '''
1393
+
1394
+ min_weight = float('inf')
1395
+ if predefined_stiffener_iter is None:
1396
+ combs = any_get_all_combs(min_var, max_var, deltas)
1397
+ else:
1398
+ combs = any_get_all_combs(min_var, max_var, deltas,predef_stiffeners=[item.get_tuple() for item in
1399
+ predefined_stiffener_iter])
1400
+
1401
+ trial_selection = random_product(combs, repeat=trials)
1402
+ obj.lat_press = lat_press
1403
+ for x in trial_selection:
1404
+ if any_constraints_all(x=x,obj=obj,lat_press=lat_press,init_weight=min_weight,
1405
+ fat_dict=fat_dict,fat_press = fat_press,slamming_press=slamming_press,
1406
+ fdwn = fdwn, fup = fup)[0]:
1407
+ current_weight = calc_weight(x)
1408
+ if current_weight < min_weight:
1409
+ min_weight = current_weight
1410
+ return min_weight
1411
+
1412
+ def get_random_result(obj,lat_press,min_var,max_var,deltas,trials=10000,side='p',const_chk=(True,True,True,True,True),
1413
+ fat_dict=None, fat_press=None):
1414
+ '''
1415
+ Return random results
1416
+ '''
1417
+ min_weight = float('inf')
1418
+ ass_var = None
1419
+ combs = any_get_all_combs(min_var, max_var, deltas)
1420
+ trial_selection = random_product(combs,repeat=trials)
1421
+ for x in trial_selection:
1422
+ if any_constraints_all(x=x,obj=obj,lat_press=lat_press,init_weight=min_weight,side=side,chk=const_chk,
1423
+ fat_dict = fat_dict, fat_press = fat_press)[0] is not False:
1424
+ current_weight = calc_weight(x)
1425
+ if current_weight < min_weight:
1426
+ min_weight = current_weight
1427
+ ass_var = x
1428
+ if ass_var == None:
1429
+ return ass_var
1430
+ return create_new_structure_obj(obj, [round(item, 5) for item in ass_var]), \
1431
+ create_new_calc_obj(obj, [round(item, 5) for item in ass_var])[0]
1432
+
1433
+ def get_random_result_no_bounds(obj,lat_press,min_var,max_var,trials=10000,side='p',const_chk=(True,True,True,True,True)
1434
+ , fat_dict=None, fat_press=None):
1435
+ '''
1436
+ Return random results, ignoring the deltas
1437
+ '''
1438
+ min_weight = float('inf')
1439
+ ass_var = None
1440
+ for trial in range(trials):
1441
+ spacing = random.randrange(int(min_var[0]*1000),int(max_var[0]*1000),1)/1000
1442
+ pl_thk = random.randrange(int(min_var[1]*1000),int(max_var[1]*1000),1)/1000
1443
+ web_h = random.randrange(int(min_var[2]*1000),int(max_var[2]*1000),1)/1000
1444
+ web_thk = random.randrange(int(min_var[3]*1000),int(max_var[3]*1000),1)/1000
1445
+ fl_w = random.randrange(int(min_var[4]*1000),int(max_var[4]*1000),1)/1000
1446
+ fl_thk = random.randrange(int(min_var[5]*1000),int(max_var[5]*1000),1)/1000
1447
+ x = (spacing,pl_thk,web_h,web_thk,fl_w,fl_thk,min_var[6],min_var[7])
1448
+ if any_constraints_all(x=x,obj=obj,lat_press=lat_press,init_weight=min_weight,side=side,chk=const_chk,
1449
+ fat_dict = fat_dict, fat_press = fat_press)[0]:
1450
+ current_weight = calc_weight(x)
1451
+ if current_weight < min_weight:
1452
+ min_weight = current_weight
1453
+ ass_var = x
1454
+ if ass_var == None:
1455
+ return ass_var
1456
+ return create_new_structure_obj(obj, [round(item, 5) for item in ass_var]), \
1457
+ create_new_calc_obj(obj, [round(item, 5) for item in ass_var])[0]
1458
+
1459
+ def random_product(*args, repeat=1):
1460
+ "Random selection from itertools.product(*args, **kwds)"
1461
+ pools = [tuple(pool) for pool in args] * repeat
1462
+ return tuple(random.choice(pool) for pool in pools)
1463
+
1464
+ def product_any(*args, repeat=1,weight=float('inf')):
1465
+ # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
1466
+ # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
1467
+ pools = [tuple(pool) for pool in args] * repeat
1468
+ result = [[]]
1469
+ for pool in pools:
1470
+ result = [x+[y] for x in result for y in pool]
1471
+ for prod in result:
1472
+ if calc_weight(prod) < weight:
1473
+ yield tuple(prod)
1474
+
1475
+ def plot_optimization_results(results, multiple = False):
1476
+
1477
+ check_ok_array, check_array, section_array = list(), list(), list()
1478
+ save_to_csv = asksaveasfilename()
1479
+
1480
+ if save_to_csv != '':
1481
+ csv_file = open(save_to_csv,'w', newline='')
1482
+ csv_writer = csv.writer(csv_file)
1483
+ csv_writer.writerow(['Is OK', 'Check info', 'pl b', 'pl thk', 'web h', 'web thk', 'fl b', 'fl thk', 'span',
1484
+ 'girder width', 'stiffener type', 'uf weight', 'uf sec mod', 'uf loc stf buc',
1485
+ 'uf buckling', 'uf min pl', 'uf shear', 'uf fatigue', 'uf slamming'])
1486
+
1487
+ for check_ok, check, section, ufres in results[3]:
1488
+ check_ok_array.append(check_ok)
1489
+ check_array.append(check)
1490
+ section_array.append(section)
1491
+ if save_to_csv != '':
1492
+ to_write = list()
1493
+ to_write.append(check_ok)
1494
+ to_write.append(check)
1495
+ [to_write.append(item) for item in section]
1496
+ if(len(section) == 8):
1497
+ to_write.append('T')
1498
+ [to_write.append(item) for item in ufres]
1499
+ csv_writer.writerow(to_write)
1500
+
1501
+ if save_to_csv != '':
1502
+ csv_file.close()
1503
+
1504
+ check_ok_array, check_array, section_array = np.array(check_ok_array), \
1505
+ np.array(check_array), \
1506
+ np.array(section_array)
1507
+
1508
+ x_label = np.unique(check_array)
1509
+ y = [np.count_nonzero(check_array == item) for item in np.unique(check_array)]
1510
+
1511
+ fig, axs = plt.subplots(2, 1)
1512
+ clust_data = np.append(np.array(x_label).reshape(len(x_label), 1), np.array(y).reshape(len(y), 1), axis=1)
1513
+ collabel = ('Check fail type or OK', 'Number of occurences')
1514
+ axs[0].axis('tight')
1515
+ axs[0].axis('off')
1516
+ the_table = axs[0].table(cellText=clust_data, colLabels=collabel, loc='center')
1517
+ axs[1].pie(y, labels=x_label, autopct='%1.1f%%', explode=[0.1 for dummy in range(len(x_label))])
1518
+
1519
+ plt.show()
1520
+
1521
+ if __name__ == '__main__':
1522
+ import example_data as ex
1523
+ from calc_structure import CylinderAndCurvedPlate, Structure, Shell
1524
+
1525
+ shell_main_dict = ex.shell_main_dict
1526
+ shell_main_dict['geometry'] = [7, '']
1527
+ #Structure(ex.obj_dict_cyl_ring)
1528
+ #Structure(ex.obj_dict_cyl_heavy_ring)
1529
+ # my_cyl = CylinderAndCurvedPlate(main_dict = ex.shell_main_dict, shell= Shell(ex.shell_dict),
1530
+ # long_stf= Structure(ex.obj_dict_cyl_long2),
1531
+ # ring_stf = Structure(ex.obj_dict_cyl_ring2),
1532
+ # ring_frame= Structure(ex.obj_dict_cyl_heavy_ring2))
1533
+ my_cyl = CylinderAndCurvedPlate(main_dict = ex.shell_main_dict, shell= Shell(ex.shell_dict),
1534
+ long_stf= Structure(ex.obj_dict_cyl_long2),
1535
+ ring_stf = None,# Structure(ex.obj_dict_cyl_ring2),
1536
+ ring_frame= None)#Structure(ex.obj_dict_cyl_heavy_ring2))
1537
+
1538
+ shell_upper_bounds = np.array( [0.03, 5, 5, 5, 10, None, None, None])
1539
+ shell_deltas = np.array( [0.005, 0.5, 1, 0.1,1, None, None, None])
1540
+ shell_lower_bounds = np.array( [0.02, 5, 5, 5, 10, None, None, None])
1541
+
1542
+ long_upper_bounds = np.array( [0.8, None, 0.5, 0.02, 0.2, 0.03, None, None])
1543
+ long_deltas = np.array( [0.1, None, 0.1, 0.01, 0.1, 0.01, None, None])
1544
+ long_lower_bounds = np.array( [0.7, None, 0.3, 0.01, 0.1, 0.01, None, None])
1545
+
1546
+ ring_stf_upper_bounds = np.array( [None, None, 0.5, 0.018, 0.2, 0.03, None, None])
1547
+ ring_stf_deltas = np.array( [None, None, 0.1, 0.004, 0.1, 0.01, None, None])
1548
+ ring_stf_lower_bounds = np.array( [None, None, 0.3, 0.010, 0.1, 0.010, None, None])
1549
+
1550
+ ring_frame_upper_bounds = np.array( [None, None, 0.9, 0.04, 0.3, 0.04, None, None])
1551
+ ring_frame_deltas = np.array( [None, None, 0.2, 0.01, 0.1, 0.01, None, None])
1552
+ ring_frame_lower_bounds = np.array( [None, None, 0.7, 0.02, 0.2, 0.02, None, None])
1553
+
1554
+ max_var = [shell_upper_bounds, long_upper_bounds, ring_stf_upper_bounds, ring_frame_upper_bounds]
1555
+ deltas = [shell_deltas, long_deltas, ring_stf_deltas, ring_frame_deltas]
1556
+ min_var = [shell_lower_bounds, long_lower_bounds, ring_stf_lower_bounds, ring_frame_lower_bounds]
1557
+
1558
+ results = run_optmizataion(initial_structure_obj=my_cyl, min_var=min_var, max_var=max_var, deltas=deltas,
1559
+ cylinder=True, use_weight_filter=True)
1560
+ shell = ['Shell thk. [mm]', 'Shell radius [mm]' , 'l rings [mm]', 'L shell [mm]', 'L tot. [mm]', 'N/A - future', 'N/A - future', 'N/A - future']
1561
+ stf_long = ['Spacing [mm]', 'Plate thk. [mm]', 'Web height [mm]', 'Web thk. [mm]', 'Flange width [mm]', 'Flange thk. [mm]', 'N/A - future', 'N/A - future']
1562
+ stf_ring = ['N/A', 'Plate thk. [mm]', 'Web height [mm]', 'Web thk. [mm]', 'Flange width [mm]', 'Flange thk. [mm]', 'N/A - future', 'N/A - future']
1563
+
1564
+ # obj_dict = ex.obj_dict_sec_error
1565
+ # fat_obj = ex.get_fatigue_object_problematic()
1566
+ # fp = ex.get_fatigue_pressures_problematic()
1567
+ # fat_press = ((fp['p_ext']['loaded'],fp['p_ext']['ballast'],fp['p_ext']['part']),
1568
+ # (fp['p_int']['loaded'],fp['p_int']['ballast'],fp['p_int']['part']))
1569
+ # x0 = [obj_dict['spacing'][0], obj_dict['plate_thk'][0], obj_dict['stf_web_height'][0], obj_dict['stf_web_thk'][0],
1570
+ # obj_dict['stf_flange_width'][0], obj_dict['stf_flange_thk'][0], obj_dict['span'][0], 10]
1571
+ #
1572
+ # obj = calc.Structure(obj_dict)
1573
+ # lat_press = 427.235
1574
+ # calc_object = calc.CalcScantlings(obj_dict)
1575
+ # lower_bounds = np.array([0.875, 0.012, 0.3, 0.012, 0.1, 0.012, 3.5, 10])
1576
+ # upper_bounds = np.array([0.875, 0.025, 0.5, 0.018, 0.2, 0.03, 3.5, 10])
1577
+ # deltas = np.array([0.025, 0.001, 0.01, 0.001, 0.01, 0.001])
1578
+ #
1579
+ #
1580
+ # t1 = time.time()
1581
+ # #
1582
+ # results = run_optmizataion(obj, lower_bounds,upper_bounds, lat_press, deltas, algorithm='anysmart',
1583
+ # fatigue_obj=fat_obj, fat_press_ext_int=fat_press, use_weight_filter=True)
1584
+ #
1585
+ # print(results[1])
1586
+ # print(results[1].get_dnv_min_section_modulus(lat_press))
1587
+ # print(min([round(results[1].get_section_modulus()[0], 5), round(results[1].get_section_modulus()[1], 5)]))
1588
+
1589
+ # t1 = time.time()
1590
+ # check_ok_array, check_array, section_array = list(), list(), list()
1591
+ #
1592
+ # for check_ok, check, section in results[4]:
1593
+ # check_ok_array.append(check_ok)
1594
+ # check_array.append(check)
1595
+ # section_array.append(section)
1596
+ # check_ok_array, check_array, section_array = np.array(check_ok_array),\
1597
+ # np.array(check_array),\
1598
+ # np.array(section_array)
1599
+ #
1600
+ # x_label = np.unique(check_array)
1601
+ # y = [np.count_nonzero(check_array == item) for item in np.unique(check_array)]
1602
+ #
1603
+ # fig, axs = plt.subplots(2, 1)
1604
+ # clust_data = np.append(np.array(x_label).reshape(len(x_label),1), np.array(y).reshape(len(y),1), axis=1)
1605
+ # collabel = ('Check fail type or OK', 'Number of occurences')
1606
+ # axs[0].axis('tight')
1607
+ # axs[0].axis('off')
1608
+ # the_table = axs[0].table(cellText=clust_data, colLabels=collabel, loc='center')
1609
+ # axs[1].pie(y, labels = x_label, autopct='%1.1f%%', explode=[0.1 for dummy in range(len(x_label))])
1610
+ # plt.show()
1611
+ #
1612
+ # cmap = plt.cm.get_cmap(plt.cm.viridis, len(x_label))
1613
+ #
1614
+
1615
+ # Create data
1616
+ # N = 60
1617
+ # x = section_array[:,0] * section_array[:,1]
1618
+ # y = section_array[:,2] * section_array[:,3]
1619
+ # z = section_array[:,4] * section_array[:,5]
1620
+ #
1621
+ # #data = (g1, g2, g3)
1622
+ #
1623
+ # groups = x_label
1624
+ # colors = "bgrcmykw"
1625
+ # color_dict = dict()
1626
+ # for idx, group in enumerate(groups):
1627
+ # color_dict[group] = colors[idx]
1628
+ #
1629
+ # # Create plot
1630
+ # fig = plt.figure()
1631
+ # #ax = fig.add_subplot(1, 1, 1)
1632
+ # ax = fig.gca(projection='3d')
1633
+ #
1634
+ # for xdata, ydata, zdata, group in zip(x, y, z, groups):
1635
+ # if group == 'Check OK':
1636
+ # ax.scatter(x, y, z, alpha= 0.6 if group != 'Weight filter' else 0.2,
1637
+ # c=color_dict[group], edgecolors='none', s=5, label=group)
1638
+ #
1639
+ # plt.title('Matplot 3d scatter plot')
1640
+ # plt.legend(loc=2)
1641
+ # plt.show()
1642
+
1643
+
1644
+
1645
+ # for swarm_size in [100, 1000, 10000, 100000, 1000000]:
1646
+ # t1 = time.time()
1647
+ #
1648
+ # pso_options = (swarm_size, 0.5, 0.5, 0.5, 100, 1e-8, 1e-8)
1649
+ # results = run_optmizataion(obj, upper_bounds, lower_bounds, lat_press, deltas, algorithm='anysmart',
1650
+ # fatigue_obj=fat_obj, fat_press_ext_int=fat_press, pso_options=pso_options)[0]
1651
+ # print('Swarm size', swarm_size, 'running time', time.time()-t1, results.get_one_line_string())
1652
+ # fat_press_ext_int = list()
1653
+ # for pressure in ex.get_geo_opt_fat_press():
1654
+ # fat_press_ext_int.append(((pressure['p_ext']['loaded'], pressure['p_ext']['ballast'],
1655
+ # pressure['p_ext']['part']),
1656
+ # (pressure['p_int']['loaded'], pressure['p_int']['ballast'],
1657
+ # pressure['p_int']['part'])))
1658
+ #
1659
+ # opt_girder_prop = (0.018, 0.25,0.015, 0,0, 1.1,0.9)
1660
+ #
1661
+ # results = run_optmizataion(ex.get_geo_opt_object(), lower_bounds, upper_bounds, ex.get_geo_opt_presure(), deltas,
1662
+ # is_geometric=True, fatigue_obj=ex.get_geo_opt_fatigue(),
1663
+ # fat_press_ext_int=fat_press_ext_int,
1664
+ # slamming_press=ex.get_geo_opt_slamming_none(), load_pre=False,
1665
+ # opt_girder_prop= opt_girder_prop,
1666
+ # min_max_span=(1,12), tot_len=12)
1667
+
1668
+ # import pickle
1669
+ # with open('geo_opt_2.pickle', 'rb') as file:
1670
+ # geo_results = pickle.load(file)
1671
+ #
1672
+ # print(geo_results.keys())
1673
+ # print(geo_results[1][0])
1674
+ # for val in range(6):
1675
+ # plot_optimization_results(geo_results[3][1][val])
1676
+
1677
+
1678
+
1679
+
1680
+