-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdesign.py
More file actions
492 lines (466 loc) · 19.7 KB
/
design.py
File metadata and controls
492 lines (466 loc) · 19.7 KB
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
'''
Design Module
'''
from pathlib import Path
import sys
from typing import Union
import pandas as pd
pd.options.mode.chained_assignment = None
from python_functions import change_unit
__all__ = ['Design']
class Design:
def __init__(
self,
etabs=None,
):
self.etabs = etabs
self.SapModel = etabs.SapModel
def get_code(self,
type_ : str = 'Concrete', # 'Steel'
):
if type_ == 'Concrete':
return self.SapModel.DesignConcrete.getCode()[0]
elif type_ == 'Steel':
return self.SapModel.DesignSteel.getCode()[0]
def get_code_string(self,
type_: str = 'Concrete', # 'Steel'
code : Union[str, None] = None,
):
'''
get code of design in format 'ACI 318-14' and return 'ACI318_14'
'''
if code is None:
code = self.get_code(type_=type_)
code = code.replace(" ", "")
i = code.find('-')
code = code[:i] + '_' + code[i + 1:]
if 'ACI318_08' in code:
code += '_IBC2009'
return code
def set_overwrite(self,
name: str,
item: int,
value: float,
type_: str = 'Concrete', # 'Steel'
code: Union[str, bool] = None,
):
if code is None:
code = self.get_code_string(type_)
exec(f"self.SapModel.Design{type_}.{code}.SetOverwrite('{name}',{item}, {value})")
def set_concrete_framing_type(self,
type_: str = 2,
beams: bool = True,
columns: bool = True,
):
'''
type_:
0 = Program Default
1 = Sway special
2 = Sway Intermediate
3 = Sway Ordinary
4 = Non-sway
'''
beam_names, column_names = self.etabs.frame_obj.get_beams_columns(type_=2)
if columns:
for name in column_names:
self.set_overwrite(
name = name,
item = 1, # Framing Type
value = type_, # Sway special
)
if beams:
for name in beam_names:
self.set_overwrite(
name = name,
item = 1, # Framing Type
value = type_, # Sway special
)
def set_preference(self,
item: int,
value,
type_: str = 'Concrete', # 'Steel'
code: Union[str, bool] = None,
):
if code is None:
code = self.get_code_string(type_)
exec(f"self.SapModel.Design{type_}.{code}.SetPreference({item}, {value})")
def model_designed(self,
type_: str='Concrete',
):
all_table = self.SapModel.DatabaseTables.GetAvailableTables()[1]
import python_functions
if (
type_ == 'Concrete' and
python_functions.is_text_in_list_elements(all_table, 'Concrete Beam Design Summary')
) or (
type_ == 'Steel' and
python_functions.is_text_in_list_elements(all_table, 'Steel Frame Design Summary')
):
return True
return False
def set_phi_joint_shear(self,
value=0.75,
code=None,
):
if code is None:
code = self.get_code_string('Concrete')
item = 15
if '11' in code:
item = 14
elif '08' in code:
item = 10
self.set_preference(item, value, code=code)
def get_rho_of_beams(
self,
names: "list[str]",
distances: "list[Union[float, str], float, str]"='middle', # start, end
locations: "Union[list[str], str]" = 'top',
torsion_areas: "Union[list[float], bool]" = None,
frame_areas: "Union[list[float], bool]" = None,
covers: "list[float]"= [6],
additionals_rebars: "Union[list[float], float]"=0,
widths: "Union[list[float], None]" = None,
heights: "Union[list[float], None]" = None,
) -> "tuple(list, list)":
from scipy.interpolate import interp1d
rhos = []
texts = []
units = self.etabs.get_current_unit()
self.etabs.set_current_unit('N', 'cm')
self.etabs.run_analysis()
self.etabs.frame_obj.set_frame_obj_selected(names)
self.etabs.start_design(check_designed=True)
if torsion_areas is None:
torsion_areas = len(names) * [None]
if frame_areas is None:
frame_areas = len(names) * [None]
if widths is None:
widths = len(names) * [None]
if heights is None:
heights = len(names) * [None]
if isinstance(covers, (int, float)):
covers = len(names) * [covers]
if isinstance(distances, (float, int, str)):
distances = len(names) * [distances]
if isinstance(locations, (float, int, str)):
locations = len(names) * [locations]
if isinstance(additionals_rebars, (int, float)):
additionals_rebars = len(names) * [additionals_rebars]
for i, name in enumerate(names):
location = locations[i]
distance = distances[i]
torsion_area = torsion_areas[i]
frame_area = frame_areas[i]
width = widths[i]
height = heights[i]
cover = covers[i]
additional_rebars = additionals_rebars[i]
text = ''
print(f'{name=}\n')
beam_rebars = self.SapModel.DesignConcrete.GetSummaryResultsBeam(name)
if location == 'top':
areas = beam_rebars[4]
elif location == 'bot':
areas = beam_rebars[6]
first_dist = beam_rebars[2][0]
last_dist = beam_rebars[2][-1]
text += f'The Calculated area of main rebar of beam name {name} at {location} in '
if isinstance(distance, str):
text += f'{distance} of beam = '
if distance == 'start':
distance = first_dist
elif distance == 'end':
distance = last_dist
elif distance == 'middle':
distance = (last_dist - first_dist) / 2
else:
text += f'{distance:.1f} cm = '
torsion_percent = 3 / 8
total_torsion_area = None
if distance < first_dist:
area = areas[0]
if torsion_area is None:
total_torsion_area = beam_rebars[10][0]
elif distance > last_dist:
area = areas[-1]
if torsion_area is None:
total_torsion_area = beam_rebars[10][-1]
else:
f = interp1d(beam_rebars[2], areas)
area = f(distance)
if torsion_area is None:
f = interp1d(beam_rebars[2], beam_rebars[10])
total_torsion_area = f(distance)
text += f'{area:.1f} Cm2\n'
if torsion_area is None:
torsion_area = total_torsion_area * torsion_percent
if total_torsion_area is not None:
text += f'Total torsion area = {total_torsion_area:0.1f} Cm2, Assume 3/8 for {location} ==> '
text += f'Torsion Area = {torsion_area:0.1f} Cm2\n'
text += f'As = bending + torsion + added rebar = {area:0.1f} + {torsion_area:0.1f} + {additional_rebars:0.1f}'
area += torsion_area
area += additional_rebars
text += f' = {area:0.1f} Cm2\n'
if frame_area is None:
frame_area = self.etabs.frame_obj.get_area(name, cover=cover)
rho = area / frame_area
if width is not None:
text += f'b = {int(width)}, d = {int(height)} - {cover} = {height - cover} ==> '
text += f'b x d = {frame_area:.1f} Cm2\n'
text += f'rho = As / b x d = {area:.1f} / {frame_area:.1f} = {rho:.4f}\n'
rhos.append(rho)
texts.append(text)
self.etabs.set_current_unit(*units)
return rhos, texts
def get_deflection_of_beams(self,
dead: list,
supper_dead: list,
lives: list,
beam_names: "Union[list[str], pd.DataFrame]",
distances_for_calculate_rho: "list[Union[float, str], float, str]"='middle', # start, end
locations: "Union[list[str], str]" = 'top',
torsion_areas: "Union[list[float], bool]" = None,
frame_areas: "Union[list[float], bool]" = None,
covers: "Union[list[float, int], float, int]"= 6,
lives_percentage: float = 0.25,
filename: str='',
points_for_get_deflection: "Union[list[str], bool]" = None,
is_consoles: "Union[list[bool], bool]"=False,
rhos: "Union[list[float, bool], bool]" = None,
additionals_rebars: "Union[list[float, int], int, float]"=0,
):
'''
dead: a list of Dead loads
supper_dead: a list of supper Dead loads
lives: a list of live loads
beam_name: The name of beam for calculating deflection
distance_for_calculate_rho: A string or float length for calculating rho, string can be 'middle', 'start' and 'end'
location: location for getting rebar area, 'top' and 'bot'
torsion_area: area of torsion rebars, if it None, automatically 1/2 of torsion area added to flextural rebar area
frame_area: The area of concrete section, when it is None, obtain automatically
cover: cover of beam
lives_percentage: live load percentage for considering to calculate short term cracking deflection
filename: The etabs file name for creating deflection model
point_for_get_deflection: The name of the point for calculate deflection on it, if it is None, for console it is 'start'
and for contiues beam it is 'middle'
is_console: If beam is console
rho: As / bd
additional_rebars: Add this to rebar area for calculating rho
'''
# prepare inputs for calculate deflections
texts = ['' for i in range(len(beam_names))]
if isinstance(beam_names, pd.DataFrame):
def add_beam_prop_to_df(row):
torsion_rebar = 'Torsion Rebar'
if row[torsion_rebar]:
row[torsion_rebar] = None
else:
row[torsion_rebar] = 0
if row['Console']:
row['location'] = 'bot'
row['distance_for_calculate_rho'] = 'start'
else:
row['location'] = 'top'
row['distance_for_calculate_rho'] = 'middle'
cover = row['Cover']
b = row['Width']
h = row['Height']
row['d'] = h - cover
row['frame_area'] = b * row['d']
return row
df = beam_names.apply(add_beam_prop_to_df, axis=1)
beam_names = df['Name']
torsion_areas = df['Torsion Rebar']
is_consoles = df['Console']
locations = df['location']
distances = df['distance_for_calculate_rho']
covers = df['Cover']
widths = df['Width']
heights = df['Height']
frame_areas = df['frame_area']
additionals_rebars = df['Add Rebar']
else:
if isinstance(distances_for_calculate_rho, (float, int, str)):
distances = len(beam_names) * [distances_for_calculate_rho]
else:
distances = distances_for_calculate_rho
if isinstance(is_consoles, bool):
is_consoles = len(beam_names) * [is_consoles]
if points_for_get_deflection is None:
points_for_get_deflection = len(beam_names) * [None]
# Get rhos of beams
if rhos is None:
rhos, texts = self.get_rho_of_beams(
beam_names,
distances=distances,
locations=locations,
torsion_areas=torsion_areas,
frame_areas=frame_areas,
covers = covers,
additionals_rebars=additionals_rebars,
widths = widths,
heights = heights,
)
units = self.etabs.get_current_unit()
self.etabs.set_current_unit('N', 'cm')
# Save As etabs model with filename
if not filename:
filename = 'deflection_beams_' + '_'.join(beam_names) + '.EDB'
print(f'Save file as {filename} ...')
file_path = self.etabs.get_filepath()
deflection_path = file_path / 'deflections'
if not deflection_path.exists():
import os
os.mkdir(str(deflection_path))
self.SapModel.File.Save(str(deflection_path / filename))
# Set frame stiffness modifiers
print("Set frame stiffness modifiers ...")
beams, columns = self.etabs.frame_obj.get_beams_columns()
self.etabs.frame_obj.assign_frame_modifiers(
frame_names=beams + columns,
area=1,
as2=1,
as3=1,
# torsion=1,
i22=1,
i33=1,
)
# Multiply j of beams and columns with 1.4
print("Multiply j of beams and columns with 1.4")
self.etabs.frame_obj.multiply_modifiers(
mult=[1, 1, 1, 1.4, 1, 1, 1, 1],
frame_names=beams + columns,
)
print("Set Slab stiffness modifiers ...")
self.etabs.area.assign_slab_modifiers(m11=1, m22=1, m12=1, reset=True)
print("Set floor cracking for beams and floors ...")
self.etabs.database.set_floor_cracking(type_='Frame')
self.etabs.database.set_floor_cracking(type_='Area')
print("Create nonlinear load cases ...")
lc1, lc2, lc3 = self.etabs.database.create_nonlinear_loadcases(
dead=dead,
supper_dead=supper_dead,
lives=lives,
lives_percentage=lives_percentage,
)
print("Create deflection load combinations ...")
self.SapModel.RespCombo.Add('deflection1', 0)
self.SapModel.RespCombo.SetCaseList('deflection1', 0, lc2, 1)
self.SapModel.RespCombo.SetCaseList('deflection1', 0, lc1, -1)
if supper_dead:
self.etabs.analyze.set_load_cases_to_analyze((lc1, lc2, lc3))
else:
self.etabs.analyze.set_load_cases_to_analyze((lc1, lc2))
new_points_for_get_deflection = []
beams_points = []
for i, beam_name in enumerate(beam_names):
print(20 * '=' + '\n')
print(f'Calculating Deflection for {beam_name=}\n')
point_for_get_deflection = points_for_get_deflection[i]
is_console = is_consoles[i]
distance = distances[i]
rho = rhos[i]
landa = 2 / (1 + 50 * rho)
texts[i] += f'lambda = 2 / (1 + 50 x rho) = 2 / (1 + 50 x {rho:.4f}) = {landa:.2f}'
print(f'\n{rho=}\n{landa=}')
p1_name, p2_name, _ = self.SapModel.FrameObj.GetPoints(beam_name)
beams_points.append([p1_name, p2_name])
if (
point_for_get_deflection is None and \
not is_console and \
isinstance(distance, str)
):
point_for_get_deflection = self.etabs.points.add_point_on_beam(
name=beam_name,
distance=distance,
unlock_model=False,
)
if (
point_for_get_deflection is None and \
is_console
):
point_for_get_deflection = p2_name
new_points_for_get_deflection.append(point_for_get_deflection)
print("Create deflection load combinations ...")
self.SapModel.RespCombo.Add(f'deflection2_beam{beam_name}', 0)
self.SapModel.RespCombo.SetCaseList(f'deflection2_beam{beam_name}', 0, lc2, 1)
self.SapModel.RespCombo.SetCaseList(f'deflection2_beam{beam_name}', 0, lc1, landa - 1)
if supper_dead:
# scale factor set to 0.5 due to xi for 3 month equal to 1.0
self.SapModel.RespCombo.SetCaseList(f'deflection2_beam{beam_name}', 0, lc3, -0.5)
self.etabs.run_analysis()
import python_functions
pts = python_functions.flatten_list(beams_points) + new_points_for_get_deflection
combos = ['deflection1'] + [f'deflection2_beam{beam_name}' for beam_name in beam_names]
pts_displacements = self.etabs.results.get_points_min_max_displacements(points=pts, load_combinations=combos)
deflections1 = []
deflections2 = []
for i, beam_name in enumerate(beam_names):
p1_name, p2_name = beams_points[i]
p1_def1 = pts_displacements.loc[(p1_name, 'deflection1'), ('Uz', 'min')]
p2_def1 = pts_displacements.loc[(p2_name, 'deflection1'), ('Uz', 'min')]
p1_def2 = pts_displacements.loc[(p1_name, f'deflection2_beam{beam_name}'), ('Uz', 'min')]
p2_def2 = pts_displacements.loc[(p2_name, f'deflection2_beam{beam_name}'), ('Uz', 'min')]
print(f'\n{p1_def1=}, {p1_def2=}, {p2_def1=}, {p2_def2=}')
if is_consoles[i]:
def1 = p2_def1 - p1_def1
def2 = p2_def2 - p1_def2
else:
def_def1 = pts_displacements.loc[(new_points_for_get_deflection[i], 'deflection1'), ('Uz', 'min')]
def_def2 = pts_displacements.loc[(new_points_for_get_deflection[i], f'deflection2_beam{beam_name}'), ('Uz', 'min')]
print(f'\n{def_def1=}, {def_def2=}')
def1 = def_def1 - (p1_def1 + p2_def1) / 2
def2 = def_def2 - (p1_def2 + p2_def2) / 2
print(f'\n{def1=}, {def2=}')
deflections1.append(abs(def1))
deflections2.append(abs(def2))
self.etabs.set_current_unit(*units)
return deflections1, deflections2, texts
@change_unit('kgf', 'm')
def get_concrete_columns_pmm_table(self,
columns: Union[list, None]=['Story', 'Label', 'UniqueName', 'DesignSect', 'PMMRatio', 'PMMCombo', 'Station']
):
self.etabs.start_design(type_ = 'Concrete')
table_key = self.etabs.database.table_name_that_containe("Concrete Column Design Summary")
if table_key is None:
return None
if columns is not None:
df = self.etabs.database.read(table_key, to_dataframe=True, cols=columns)
else:
df = self.etabs.database.read(table_key, to_dataframe=True)
cols = ['PMMRatio', 'Station']
df[cols] = df[cols].astype(float).round(2)
return df
def get_deflection_check_result(
def1: float,
def2: float,
ln: float,
short_term: float=360,
long_term: float=480,
):
allow_def1 = ln / short_term
allow_def2 = ln / long_term
ret = f'Ln = {ln:.0f} Cm\n'
ret += 20 * '-'
ret += f'\ncombo1 deflection = {def1:.3f} Cm '
if def1 <= allow_def1:
ret += f'< Ln / {short_term} = {allow_def1:.2f} Cm ==> OK'
else:
ret += f'> Ln / {short_term} = {allow_def1:.2f} Cm ==> Not OK'
# combo 2
ret += f'\ncombo2 deflection = {def2:.3f} Cm '
if def2 <= allow_def2:
ret += f'< Ln / {long_term} = {allow_def2:.2f} Cm ==> OK\n'
else:
ret += f'> Ln / {long_term} = {allow_def2:.2f} Cm ==> Not OK\n'
ret += 20 * '-'
return ret
if __name__ == '__main__':
from pathlib import Path
current_path = Path(__file__).parent
import sys
sys.path.insert(0, str(current_path))
from etabs_obj import EtabsModel
etabs = EtabsModel(backup=False)
etabs.design.get_code()
print('Wow')