forked from NHERI-SimCenter/SimCenterBackendApplications
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCapacityModels.py
More file actions
390 lines (337 loc) · 12.9 KB
/
Copy pathCapacityModels.py
File metadata and controls
390 lines (337 loc) · 12.9 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
# # noqa: D100, INP001
# Copyright (c) 2018 Leland Stanford Junior University
# Copyright (c) 2018 The Regents of the University of California
#
# This file is part of the SimCenter Backend Applications
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# You should have received a copy of the BSD 3-Clause License along with
# this file. If not, see <http://www.opensource.org/licenses/>.
#
# Contributors:
# Jinyan Zhao
#
# References:
# 1. Cao, T., & Petersen, M. D. (2006). Uncertainty of earthquake losses due to
# model uncertainty of input ground motions in the Los Angeles area. Bulletin of
# the Seismological Society of America, 96(2), 365-376.
# 2. Steelman, J., & Hajjar, J. F. (2008). Systemic validation of consequence-based
# risk management for seismic regional losses.
# 3. Newmark, N. M., & Hall, W. J. (1982). Earthquake spectra and design.
# Engineering monographs on earthquake criteria.
# 4. FEMA (2022), HAZUS - Multi-hazard Loss Estimation Methodology 5.0,
# Earthquake Model Technical Manual, Federal Emergency Management Agency, Washington D.C.
import os
import sys
import time
import numpy as np
import pandas as pd
ap_DesignLevel = {1940: 'Pre-Code', 1975: 'Moderate-Code', 2100: 'High-Code'} # noqa: N816
# original:
# ap_DesignLevel = {1940: 'Pre-Code', 1940: 'Low-Code', 1975: 'Moderate-Code', 2100: 'High-Code'}
# Note that the duplicated key is ignored, and Python keeps the last
# entry.
ap_DesignLevel_W1 = {0: 'Moderate-Code', 1975: 'Moderate-Code', 2100: 'High-Code'} # noqa: N816
# original:
# ap_DesignLevel_W1 = {0: 'Pre-Code', 0: 'Low-Code', 1975: 'Moderate-Code', 2100: 'High-Code'}
# same thing applies
def convert_story_rise(structureType, stories): # noqa: N803
"""
Convert the story type and number of stories to rise attribute of archetype.
Parameters
----------
structureType : str
The type of the structure.
stories : int
The number of stories.
Returns
-------
rise : str or None
The rise attribute of the archetype.
"""
if structureType in ['W1', 'W2', 'S3', 'PC1', 'MH']:
# These archetypes have no rise information in their IDs
rise = None
else:
rise = None
# First, check if we have valid story information
try:
stories = int(stories)
except (ValueError, TypeError):
msg = (
'Missing "NumberOfStories" information, '
'cannot infer `rise` attribute of archetype'
)
raise ValueError( # noqa: B904
msg
)
if structureType == 'RM1':
if stories <= 3: # noqa: PLR2004
rise = 'L'
else:
rise = 'M'
elif structureType == 'URM':
if stories <= 2: # noqa: PLR2004
rise = 'L'
else:
rise = 'M'
elif structureType in [
'S1',
'S2',
'S4',
'S5',
'C1',
'C2',
'C3',
'PC2',
'RM2',
]:
if stories <= 3: # noqa: PLR2004
rise = 'L'
elif stories <= 7: # noqa: PLR2004
rise = 'M'
else:
rise = 'H'
return rise
def auto_populate_hazus(GI): # noqa: N803
"""
Auto-populate the HAZUS parameters based on the given building information.
Parameters
----------
GI : dict
The building information.
Returns
-------
LF : str
The load factor.
dl : str
The design level.
"""
# get the building parameters
bt = GI['StructureType'] # building type
# get the design level
dl = GI.get('DesignLevel', None)
if dl is None:
# If there is no DesignLevel provided, we assume that the YearBuilt is
# available
year_built = GI['YearBuilt']
if 'W1' in bt:
DesignL = ap_DesignLevel_W1 # noqa: N806
else:
DesignL = ap_DesignLevel # noqa: N806
for year in sorted(DesignL.keys()):
if year_built <= year:
dl = DesignL[year]
break
# get the number of stories / height
stories = GI.get('NumberOfStories', None)
# We assume that the structure type does not include height information
# and we append it here based on the number of story information
rise = convert_story_rise(bt, stories)
if rise is not None:
LF = f'{bt}{rise}' # noqa: N806
else:
LF = f'{bt}' # noqa: N806
return LF, dl
class capacity_model_base:
"""
A class to represent the base of capacity models.
Attributes
----------
Methods
-------
""" # noqa: D414
def __init__(self):
pass
def name(self): # noqa: D102
return 'capacity_model_base'
class cao_peterson_2006(capacity_model_base):
"""
A class to represent the capacity model in Cao and Peterson 2006.
Attributes
----------
Dy : float
Yield displacement. In the unit of (inch)
Ay : float
Yield acceleration. In the unit of (g)
Du : float
Ultimate displacement. In the unit of (inch)
Au : float
Ultimate acceleration. In the unit of (g)
Ax : float
Parameter in Eq. A5 of Cao and Peterson 2006. In the unit of (g)
B : float
Parameter in Eq. A5 of Cao and Peterson 2006. In the unit of (g)
C : float
Parameter in Eq. A5 of Cao and Peterson 2006. In the unit of (inch)
Methods
-------
""" # noqa: D414
def __init__(self, Dy, Ay, Du, Au, dD=0.001): # noqa: N803
# region between elastic and perfectly plastic
sd_elpl = np.arange(Dy, Du, dD)
# Eq. B3 in Steelman & Hajjar 2008
Ax = (Au**2 * Dy - Ay**2 * Du) / (2 * Au * Dy - Ay * Dy - Ay * Du) # noqa: N806
# Eq. B4 in Steelman & Hajjar 2008
B = Au - Ax # noqa: N806
# Eq. B5 in Steelman & Hajjar 2008
C = (Dy * B**2 * (Du - Dy) / (Ay * (Ay - Ax))) ** 0.5 # noqa: N806
# Eq. B1 in Steelman & Hajjar 2008
sa_elpl = Ax + B * (1 - ((sd_elpl - Du) / C) ** 2) ** 0.5
# elastic and perfectly plastic regions
sd_el = np.arange(0, Dy, dD)
sd_pl = np.arange(Du, 4 * Du, dD)
sa_el = sd_el * Ay / Dy
sa_pl = Au * np.ones(len(sd_pl))
self.sd = np.concatenate((sd_el, sd_elpl, sd_pl))
self.sa = np.concatenate((sa_el, sa_elpl, sa_pl))
self.Ax = Ax
self.B = B
self.C = C
self.Du = Du
self.Ay = Ay
self.Dy = Dy
def name(self): # noqa: D102
return 'cao_peterson_2006'
class HAZUS_cao_peterson_2006(capacity_model_base):
"""
A class to represent the capacity model in Cao and Peterson 2006.
Attributes
----------
Dy : float
Yield displacement. In the unit of (inch)
Ay : float
Yield acceleration. In the unit of (g)
Du : float
Ultimate displacement. In the unit of (inch)
Au : float
Ultimate acceleration. In the unit of (g)
Ax : float
Parameter in Eq. A5 of Cao and Peterson 2006. In the unit of (g)
B : float
Parameter in Eq. A5 of Cao and Peterson 2006. In the unit of (g)
C : float
Parameter in Eq. A5 of Cao and Peterson 2006. In the unit of (inch)
Methods
-------
""" # noqa: D414
def __init__(self, general_info, dD=0.001): # noqa: N803
# HAZUS capacity data: Table 5-7 to Table 5-10 in HAZUS 5.1
self.capacity_data = dict() # noqa: C408
self.capacity_data['Severe-Code'] = pd.read_csv(
os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH118, PTH120, RUF100
'SC_capacity_data.csv',
),
index_col=0,
).to_dict(orient='index')
self.capacity_data['Very High-Code'] = pd.read_csv(
os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH118, PTH120, RUF100
'VC_capacity_data.csv',
),
index_col=0,
).to_dict(orient='index')
self.capacity_data['High-Code'] = pd.read_csv(
os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH118, PTH120, RUF100
'HC_capacity_data.csv',
),
index_col=0,
).to_dict(orient='index')
self.capacity_data['Moderate-Code'] = pd.read_csv(
os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH118, PTH120, RUF100
'MC_capacity_data.csv',
),
index_col=0,
).to_dict(orient='index')
self.capacity_data['Low-Code'] = pd.read_csv(
os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH118, PTH120, RUF100
'LC_capacity_data.csv',
),
index_col=0,
).to_dict(orient='index')
self.capacity_data['Pre-Code'] = pd.read_csv(
os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH118, PTH120, RUF100
'PC_capacity_data.csv',
),
index_col=0,
).to_dict(orient='index')
self.capacity_data['alpha2'] = pd.read_csv(
os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH118, PTH120, RUF100
'hazus_capacity_alpha2.csv',
),
index_col=0,
).to_dict(orient='index')
self.capacity_data['roof_height'] = pd.read_csv(
os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH118, PTH120, RUF100
'hazus_typical_roof_height.csv',
),
index_col=0,
).to_dict(orient='index')
# auto populate to get the parameters
self.HAZUS_type, self.design_level = auto_populate_hazus(general_info)
try:
self.Du = self.capacity_data[self.design_level][self.HAZUS_type]['Du']
self.Au = self.capacity_data[self.design_level][self.HAZUS_type]['Au']
self.Dy = self.capacity_data[self.design_level][self.HAZUS_type]['Dy']
self.Ay = self.capacity_data[self.design_level][self.HAZUS_type]['Ay']
except KeyError:
msg = f'No capacity data for build class {self.HAZUS_type} and design level {self.design_level}'
raise KeyError(msg) # noqa: B904
self.cao_peterson_2006 = cao_peterson_2006(
self.Dy, self.Ay, self.Du, self.Au, dD
)
self.Ax = self.cao_peterson_2006.Ax
self.B = self.cao_peterson_2006.B
self.C = self.cao_peterson_2006.C
def get_capacity_curve(self, sd_max): # noqa: D102
sd = self.cao_peterson_2006.sd
sa = self.cao_peterson_2006.sa
if sd_max > sd[-1]:
num_points = min(
500, int((sd_max - self.cao_peterson_2006.sd[-1]) / 0.001)
)
sd = np.concatenate(
(sd, np.linspace(self.cao_peterson_2006.sd[-1], sd_max, num_points))
)
sa = np.concatenate((sa, sa[-1] * np.ones(num_points)))
return sd, sa
# def get_capacity_curve(self):
# return self.cao_peterson_2006.sd, self.cao_peterson_2006.sa
def get_hazus_alpha2(self): # noqa: D102
return self.capacity_data['alpha2'][self.HAZUS_type]['alpha2']
def get_hazus_roof_height(self): # noqa: D102
return self.capacity_data['roof_height'][self.HAZUS_type]['roof_height_ft']
def name(self): # noqa: D102
return 'HAZUS_cao_peterson_2006'