Skip to content

Commit fb3f1ff

Browse files
committed
Division by zero fixes.
1 parent eded756 commit fb3f1ff

File tree

4 files changed

+52
-28
lines changed

4 files changed

+52
-28
lines changed

ANYstructure_local/helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ def helper_tank_test(line_name_obj, coord, defined_loads, load_condition,
251251

252252
def helper_manual(line_name, comb_name,load_factors_all):
253253
calc_load, load_print = [], ['',]
254-
254+
if (comb_name, line_name[0], 'manual') not in load_factors_all.keys():
255+
return [0, 'Manual pressure: 0']
255256
load_factors = load_factors_all[(comb_name, line_name[0], 'manual')]
256257
man_press = load_factors[0].get() * load_factors[1].get() * load_factors[2].get()
257258
if print_it:

ANYstructure_local/load_window.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ class CreateLoadWindow():
88
'''
99
This class defines the external pressures on the hull (static and dynamic).
1010
'''
11+
@staticmethod
12+
def return_dummy_manual(line):
13+
load = 'manual'
14+
combination = 'manual'
15+
load_comb_dict = {}
16+
load_comb_dict[(combination, line, load)] = [tk.DoubleVar(), tk.DoubleVar(), tk.IntVar()]
17+
load_comb_dict[(combination, line, load)][0].set(0)
18+
load_comb_dict[(combination, line, load)][1].set(1)
19+
load_comb_dict[(combination, line, load)][2].set(1)
20+
return load_comb_dict
21+
1122
def __init__(self, master,app=None):
1223

1324
super(CreateLoadWindow, self).__init__()
@@ -498,6 +509,7 @@ def save_and_close(self):
498509
for line in self.app._line_dict.keys():
499510
self.make_load_comb_dict(line,'manual')
500511
if self._load_objects is not None:
512+
501513
self.app.on_close_load_window(self._load_objects, self._load_count, self._load_comb_dict)
502514
self._frame.destroy()
503515

ANYstructure_local/main_application.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ def __init__(self, parent):
177177
# 'line1':[Structure,CalcScantlings,Fatigue,Load,Combinations]
178178
self._tank_dict = {} # Main tank dictionary (created when BFS search is executed for the grid) (comp# : TankObj)
179179
self._load_dict = {} # Main load dictionary (created in separate load window (load# : [LoadObj, lines])
180-
self._new_load_comb_dict = {} # Load combination dict.(comb,line,load) : [DoubleVar(), DoubleVar], IntVar()]
180+
self._new_load_comb_dict = {} # Load combination dict.(comb,line,load) : [DoubleVar(), DoubleVar(), IntVar()]
181+
# Example ('dnva', 'line25', 'comp3'), ('dnvb', 'line14', 'comp4'),
182+
# ('manual', 'line74', 'manual'), ('tanktest', 'line76', 'comp3')
181183
self._sections = list() # A list containing section property objects.
182184
#
183185
# -------------------------------------------------------------------------------------------------------------
@@ -1406,25 +1408,29 @@ def gui_load_combinations(self,event):
14061408
self._manual_created[3].place(relx=lc_x + 7 * lc_x_delta, rely=lc_y)
14071409

14081410
#printing the results
1409-
try:
1410-
results = self.calculate_all_load_combinations_for_line(self._active_line)
1411-
self._result_label_dnva.config(text = 'DNV a [Pa]: ' + str(results['dnva']),
1412-
font = self._text_size['Text 8'])
1413-
self._result_label_dnvb.config(text = 'DNV b [Pa]: ' + str(results['dnvb']),
1411+
1412+
#try:
1413+
# TODO the reason manual does not show is because it others do noe exist in line_comb_dict. FIX.
1414+
results = self.calculate_all_load_combinations_for_line(self._active_line)
1415+
1416+
self._result_label_dnva.config(text = 'DNV a [Pa]: ' + str(results['dnva']),
1417+
font = self._text_size['Text 8'])
1418+
self._result_label_dnvb.config(text = 'DNV b [Pa]: ' + str(results['dnvb']),
1419+
font = self._text_size['Text 8'])
1420+
self._result_label_tanktest.config(text = 'TT [Pa]: ' + str(results['tanktest']),
14141421
font = self._text_size['Text 8'])
1415-
self._result_label_tanktest.config(text = 'TT [Pa]: ' + str(results['tanktest']),
1416-
font = self._text_size['Text 8'])
14171422

1418-
self._result_label_manual.config(text = 'Manual [Pa]: ' + str(results['manual']))
1423+
self._result_label_manual.config(text = 'Manual [Pa]: ' + str(results['manual']))
14191424

1420-
lc_y = self.results_gui_start+0.018518519
1421-
self._result_label_dnva.place(relx = lc_x+0*lc_x_delta, rely = lc_y+lc_y_delta*1.5)
1422-
self._result_label_dnvb.place(relx=lc_x+4*lc_x_delta, rely=lc_y+lc_y_delta*1.5)
1423-
self._result_label_tanktest.place(relx=lc_x+0*lc_x_delta, rely=lc_y+2.4*lc_y_delta)
1425+
lc_y = self.results_gui_start+0.018518519
1426+
self._result_label_dnva.place(relx = lc_x+0*lc_x_delta, rely = lc_y+lc_y_delta*1.5)
1427+
self._result_label_dnvb.place(relx=lc_x+4*lc_x_delta, rely=lc_y+lc_y_delta*1.5)
1428+
self._result_label_tanktest.place(relx=lc_x+0*lc_x_delta, rely=lc_y+2.4*lc_y_delta)
1429+
1430+
self._result_label_manual.place(relx=lc_x+4*lc_x_delta, rely=lc_y+2.4*lc_y_delta)
1431+
# except KeyError:
1432+
# pass
14241433

1425-
self._result_label_manual.place(relx=lc_x+4*lc_x_delta, rely=lc_y+2.4*lc_y_delta)
1426-
except KeyError:
1427-
pass
14281434

14291435
def slider_used(self, event):
14301436
'''
@@ -1575,15 +1581,15 @@ def add_to_combinations_dict(self,line):
15751581
self._new_load_comb_dict[name][0].set(self._load_factors_dict[combination][1])
15761582
self._new_load_comb_dict[name][1].set(self._load_factors_dict[combination][2])
15771583
self._new_load_comb_dict[name][2].set(1)
1578-
1579-
name = ('manual', line,'manual')
1580-
self._new_load_comb_dict[name] = [tk.DoubleVar(), tk.DoubleVar(), tk.IntVar()]
1581-
self._new_load_comb_dict[name][0].set(0)
1582-
self._new_load_comb_dict[name][1].set(0)
1583-
self._new_load_comb_dict[name][2].set(0)
15841584
else:
15851585
pass
15861586

1587+
name = ('manual', line, 'manual')
1588+
self._new_load_comb_dict[name] = [tk.DoubleVar(), tk.DoubleVar(), tk.IntVar()]
1589+
self._new_load_comb_dict[name][0].set(0)
1590+
self._new_load_comb_dict[name][1].set(0)
1591+
self._new_load_comb_dict[name][2].set(0)
1592+
15871593
def trace_acceptance_change(self, *args):
15881594
try:
15891595
self.update_frame()
@@ -2162,7 +2168,8 @@ def color_code_text(self, state):
21622168
anchor="nw")
21632169
self._main_canvas.create_text(10, start_text+20*idx, text=str(str(press) + ' Pa'),
21642170
font=self._text_size["Text 10 bold"],
2165-
fill=matplotlib.colors.rgb2hex(cmap_sections(press/highest_pressure)),
2171+
fill=matplotlib.colors.rgb2hex(cmap_sections(0 if highest_pressure == 0
2172+
else press/highest_pressure)),
21662173
anchor="nw")
21672174

21682175
elif all([self._new_colorcode_utilization.get() == True,
@@ -2385,15 +2392,15 @@ def color_code_line(self, state, line, coord1, vector):
23852392
color = 'blue' if state['color code']['lines'][line]['PULS method'] == 'ultimate' else 'red'
23862393
if self._new_label_color_coding.get():
23872394
self._main_canvas.create_text(coord1[0] + vector[0] / 2 + 5, coord1[1] + vector[1] / 2 - 10,
2388-
text=round(state['color code']['lines'][line]['PULS method'], 2))
2395+
text=state['color code']['lines'][line]['PULS method'])
23892396
elif self._new_colorcode_puls_sp_or_up.get():
23902397
if state['color code']['lines'][line]['PULS sp or up'] == None:
23912398
color = 'black'
23922399
else:
23932400
color = 'blue' if state['color code']['lines'][line]['PULS sp or up'] == 'SP' else 'red'
23942401
if self._new_label_color_coding.get():
23952402
self._main_canvas.create_text(coord1[0] + vector[0] / 2 + 5, coord1[1] + vector[1] / 2 - 10,
2396-
text=round(state['color code']['lines'][line]['PULS sp or up'], 2))
2403+
text=state['color code']['lines'][line]['PULS sp or up'])
23972404
else:
23982405
color = 'black'
23992406

@@ -3074,6 +3081,8 @@ def calculate_all_load_combinations_for_line(self, line, limit_state = 'ULS', ge
30743081
results = {} #dict - dnva/dnvb/tanktest/manual
30753082
load_info = []
30763083
# calculating for DNV a and DNV b
3084+
3085+
30773086
for dnv_ab in ['dnva', 'dnvb']: #, load_factors in self._load_factors_dict.items():
30783087
results[dnv_ab] = []
30793088
for load_condition in self._load_conditions[0:2]:
@@ -3088,6 +3097,7 @@ def calculate_all_load_combinations_for_line(self, line, limit_state = 'ULS', ge
30883097
results['tanktest'].append(res_val[0])
30893098
[load_info.append(val) for val in res_val[1]]
30903099

3100+
30913101
# calculating for manual condition
30923102
results['manual'] = []
30933103
res_val = self.calculate_one_load_combination(line, 'manual', 'manual')
@@ -4339,6 +4349,7 @@ def on_close_load_window(self, returned_loads, counter, load_comb_dict):
43394349
Setting properties created in load window.
43404350
:return:
43414351
'''
4352+
43424353
try:
43434354
img_file_name = 'img_ext_pressure_button.gif'
43444355
if os.path.isfile('images/' + img_file_name):

ANYstructure_local/tests/gui_automatic_run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def run_cc_chks():
5656
my_dict['_new_line_p1'].set(3)
5757
my_dict['_new_line_p2'].set(4)
5858

59-
my_app.new_line()
60-
6159
print(my_dict['_line_dict'])
6260

61+
my_app.gui_load_combinations(None)
62+
6363
my_app.grid_find_tanks()
6464
my_app.grid_display_tanks()
6565
run_cc_chks()

0 commit comments

Comments
 (0)