-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathload_cases.py
294 lines (263 loc) · 11.8 KB
/
load_cases.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
from typing import Iterable, Tuple, Union, List
from numpy import int16
class LoadCases:
def __init__(
self,
etabs=None,
):
self.etabs = etabs
self.SapModel = etabs.SapModel
def get_load_cases(self):
load_case_names = self.SapModel.LoadCases.GetNameList(0, [])[1]
return [text for text in load_case_names if not text.startswith('~')]
def select_all_load_cases(self):
load_case_names = self.get_load_cases()
self.SapModel.DatabaseTables.SetLoadCombinationsSelectedForDisplay('')
self.SapModel.DatabaseTables.SetLoadCasesSelectedForDisplay(load_case_names)
def select_load_cases(self, names):
self.SapModel.DatabaseTables.SetLoadCombinationsSelectedForDisplay('')
self.SapModel.DatabaseTables.SetLoadCasesSelectedForDisplay(names)
def add_response_spectrum_loadcases(self,
names: List[str],
eccentricity: float=0.05,
):
for name in names:
self.etabs.SapModel.LoadCases.ResponseSpectrum.SetCase(name)
if eccentricity > 0:
self.etabs.SapModel.LoadCases.ResponseSpectrum.SetEccentricity(name, eccentricity)
def get_loadcase_withtype(self, n) -> list:
'''
return load cases that match load case type number:
1 : LinearStatic
2 : NonlinearStatic
3 : Modal
4 : ResponseSpectrum
'''
load_cases = self.get_load_cases()
ret = []
for lc in load_cases:
if self.SapModel.LoadCases.GetTypeOAPI(lc)[0] == n:
ret.append(lc)
return ret
def get_modal_loadcase_name(self):
load_cases = self.get_load_cases()
for lc in load_cases:
if self.SapModel.LoadCases.GetTypeOAPI(lc)[0] == 3:
return lc
return None
def get_response_spectrum_loadcase_name(self):
load_cases = self.get_load_cases()
names = []
for lc in load_cases:
if self.SapModel.LoadCases.GetTypeOAPI(lc)[0] == 4:
names.append(lc)
return names
def get_response_spectrum_loadcase_with_dir_angle(self, direction, angle):
specs = self.get_response_spectrum_loadcase_name()
for name in specs:
n, dirs, _, _, _, angles, _ = self.SapModel.LoadCases.ResponseSpectrum.GetLoads(name)
if n == 1 and dirs[0] == direction and float(angles[0]) == angle:
return name
return None
def get_response_spectrum_xy_loadcase_name(self):
sx = self.get_response_spectrum_loadcase_with_dir_angle('U1', 0)
if sx is None:
sx = self.get_response_spectrum_loadcase_with_dir_angle('U2', 90)
sy = self.get_response_spectrum_loadcase_with_dir_angle('U2', 0)
if sy is None:
sy = self.get_response_spectrum_loadcase_with_dir_angle('U1', 90)
return sx, sy
def get_response_spectrum_xy_loadcases_names(self):
x_names = []
y_names = []
specs = self.get_response_spectrum_loadcase_name()
for name in specs:
n, dirs, _, _, _, angles, _ = self.SapModel.LoadCases.ResponseSpectrum.GetLoads(name)
if n == 1:
if dirs[0] == 'U1':
if float(angles[0]) == 0:
x_names.append(name)
elif float(angles[0]) == 90:
y_names.append(name)
elif dirs[0] == 'U2':
if float(angles[0]) == 90:
x_names.append(name)
elif float(angles[0]) == 0:
y_names.append(name)
return x_names, y_names
def get_response_spectrum_sxye_loadcases_names(self):
sx = set()
sy = set()
sxe = set()
sye = set()
table_key = 'Load Case Definitions - Response Spectrum'
df = self.etabs.database.read(table_key, to_dataframe=True)
if df is not None:
df['EccenRatio'] = df['EccenRatio'].astype(float)
filt_not_ecc = df['EccenRatio'] == 0
ecc_names = set(df.loc[~filt_not_ecc].Name)
for name in df.Name.unique():
try:
n, dirs, _, _, _, angles, _ = self.SapModel.LoadCases.ResponseSpectrum.GetLoads(name)
except:
continue
if n == 1:
if (dirs[0] == 'U1' and float(angles[0]) == 0) or (dirs[0] == 'U2' and float(angles[0]) == 90):
if name in ecc_names:
sxe.add(name)
else:
sx.add(name)
elif (dirs[0] == 'U2' and float(angles[0]) == 0) or (dirs[0] == 'U1' and float(angles[0]) == 90):
if name in ecc_names:
sye.add(name)
else:
sy.add(name)
return sx, sxe, sy, sye
def multiply_response_spectrum_scale_factor(self,
name : str,
scale : float,
scale_min : Union[float, bool] = 1.0,
all : bool = False,
):
self.etabs.unlock_model()
if scale_min is not None:
scale = max(scale, scale_min)
ret = self.SapModel.LoadCases.ResponseSpectrum.GetLoads(name)
if all:
scales = (i * scale for i in ret[3])
scales = tuple(scales)
else:
scales = (ret[3][0] * scale,) + tuple(ret[3][1:])
ret[3] = scales
self.SapModel.LoadCases.ResponseSpectrum.SetLoads(name, *ret[:-1])
return scales
def get_spectral_with_angles(self,
angles : Union[Iterable, bool] = None,
specs : Iterable = None,
) -> dict:
'''
return angles and Response spectrum loadcase
{0: spec}
'''
table_key = 'Load Case Definitions - Response Spectrum'
df = self.etabs.database.read(table_key, to_dataframe=True)
if df is None:
return {}
df = df.dropna(subset=['Angle'])
df['Angle'] = df['Angle'].astype(int16)
if specs is not None:
df = df[df['Name'].isin(specs)]
angles_specs = dict()
if df is not None:
for name in df.Name.unique():
try:
n, dirs, _, _, _, angles, _ = self.SapModel.LoadCases.ResponseSpectrum.GetLoads(name)
except:
continue
if n == 1:
angle = angles[0]
if dirs[0] == 'U2':
angle = 90 - angle
if angles is None or angle in angles:
angles_specs[angle] = name
return angles_specs
def reset_scales_for_response_spectrums(self,
scale : float = 1,
loadcases : Union[list, bool] = None,
length_unit : str = 'mm', # 'cm', 'm'
) -> None:
self.etabs.unlock_model()
self.etabs.set_current_unit('N', length_unit)
if loadcases is None:
loadcases = self.get_loadcase_withtype(4)
for name in loadcases:
ret = self.SapModel.LoadCases.ResponseSpectrum.GetLoads(name)
scales = (scale,) + tuple(ret[3][1:])
ret[3] = scales
self.SapModel.LoadCases.ResponseSpectrum.SetLoads(name, *ret[:-1])
return None
def get_seismic_load_cases(
self,
):
'''
Search for Response spectrum load case and load cases that have at least one seismic load pattern
'''
seismic_load_cases = []
for lc in self.get_load_cases():
load_case_type = self.SapModel.LoadCases.GetTypeOAPI(lc)[0]
if load_case_type == 1: # Static Linear
for lp in self.SapModel.LoadCases.StaticLinear.GetLoads(lc)[2]:
if self.SapModel.LoadPatterns.GetLoadType(lp)[0] == 5: # seismic load pattern
seismic_load_cases.append(lc)
break
elif load_case_type == 4: # Adding Response Spectrum load cases
seismic_load_cases.append(lc)
return seismic_load_cases
def get_seismic_drift_load_cases(
self,
):
'''
Search for load cases that have at least one seismic drift load pattern
'''
seismic_drift_load_cases = []
for lc in self.get_load_cases():
load_case_type = self.SapModel.LoadCases.GetTypeOAPI(lc)[0]
if load_case_type == 1: # Static Linear
for lp in self.SapModel.LoadCases.StaticLinear.GetLoads(lc)[2]:
if self.SapModel.LoadPatterns.GetLoadType(lp)[0] == self.etabs.seismic_drift_load_type: # seismic load pattern
seismic_drift_load_cases.append(lc)
break
return seismic_drift_load_cases
def get_xy_seismic_load_cases(
self,
):
'''
Search for load cases that all load patterns are in x or y direction
'''
x_seismic_load_cases = []
y_seismic_load_cases = []
x_names, y_names = self.etabs.load_patterns.get_load_patterns_in_XYdirection()
for lc in self.get_load_cases():
load_case_type = self.SapModel.LoadCases.GetTypeOAPI(lc)[0]
if load_case_type == 1: # Static Linear
dir_set = set()
for lp in self.SapModel.LoadCases.StaticLinear.GetLoads(lc)[2]:
if lp in x_names:
dir_set.add('x')
elif lp in y_names:
dir_set.add('y')
if dir_set == {'x'}:
x_seismic_load_cases.append(lc)
elif dir_set == {'y'}:
y_seismic_load_cases.append(lc)
return x_seismic_load_cases, y_seismic_load_cases
def get_angular_response_spectrum_with_section_cuts(self) -> tuple:
'''
return angles, section_cuts, specs and all_response_spectrums
'''
all_response_spectrums = self.etabs.load_cases.get_response_spectrum_loadcase_name()
section_cuts_angles = self.etabs.database.get_section_cuts_angle()
angles = list(section_cuts_angles.values())
angles_spectral = self.get_spectral_with_angles(angles)
section_cuts = []
specs = []
angles = []
for angle, spec in angles_spectral.items():
for sec_cut, ang in section_cuts_angles.items():
if int(angle) == int(ang):
specs.append(spec)
section_cuts.append(sec_cut)
angles.append(ang)
break
return angles, section_cuts, specs, all_response_spectrums
def add_angular_load_cases(self,
func: str,
angles: Iterable=range(0, 180, 10),
prefix: str= 'SPEC',
ecc: float=0.05,
):
for angle in angles:
name = f"{prefix}{angle}"
self.etabs.load_cases.add_response_spectrum_loadcases([name], ecc)
args = [1, ('U1',), (func,), (1,), ('Global',), (angle,)]
self.etabs.SapModel.LoadCases.ResponseSpectrum.SetLoads(name, *args)