def __init__(self, structures, SA, periods, magnitudes, csm_use_variability, csm_standard_deviation, csm_params=None): """Class to determine the damage and economic loss. structures a Structures instance - But what is actually needed from it? SA array of Spectral Acceleration, in g, with axis; sites, pseudo_events, atten_periods the site axis usually has a size of 1 periods array, 1 axis magnitudes array, 1 axis csm_params capacity spectrum method params One Damage_model instance is created for each site, in calc_total_loss(). The structures value will be different for each site. """ self.structures = structures self.periods = periods self.magnitudes = magnitudes self.SA = SA self.csm_use_variability = csm_use_variability self.csm_standard_deviation = csm_standard_deviation if csm_params is None: csm_params = { 'csm_damping_regimes': CSM_DAMPING_REGIMES_USE_ALL, 'csm_damping_modify_Tav': CSM_DAMPING_MODIFY_TAV, 'csm_damping_use_smoothing': CSM_DAMPING_USE_SMOOTHING, 'rtol': 0.01, 'csm_damping_max_iterations': 7, 'sdtcap': 0.3, 'csm_use_variability': False, 'csm_variability_method': None, 'csm_hysteretic_damping': 'trapezoidal', 'atten_override_RSA_shape': None, 'atten_cutoff_max_spectral_displacement': False, 'loss_min_pga': 0.0 } csm_params['periods'] = periods csm_params['building_parameters'] = structures.building_parameters csm_params['magnitudes'] = magnitudes self.capacity_spectrum_model = Capacity_spectrum_model(**csm_params)
def __init__( self, structures, SA, periods, magnitudes, csm_use_variability, csm_standard_deviation, csm_params=None): """Class to determine the damage and economic loss. structures a Structures instance - But what is actually needed from it? SA array of Spectral Acceleration, in g, with axis; sites, pseudo_events, atten_periods the site axis usually has a size of 1 periods array, 1 axis magnitudes array, 1 axis csm_params capacity spectrum method params One Damage_model instance is created for each site, in calc_total_loss(). The structures value will be different for each site. """ self.structures = structures self.periods = periods self.magnitudes = magnitudes self.SA = SA self.csm_use_variability = csm_use_variability self.csm_standard_deviation = csm_standard_deviation if csm_params is None: csm_params = {'csm_damping_regimes': CSM_DAMPING_REGIMES_USE_ALL, 'csm_damping_modify_Tav': CSM_DAMPING_MODIFY_TAV, 'csm_damping_use_smoothing': CSM_DAMPING_USE_SMOOTHING, 'rtol': 0.01, 'csm_damping_max_iterations': 7, 'sdtcap': 0.3, 'csm_use_variability': False, 'csm_variability_method': None, 'csm_hysteretic_damping': 'trapezoidal', 'atten_override_RSA_shape': None, 'atten_cutoff_max_spectral_displacement': False, 'loss_min_pga': 0.0} csm_params['periods'] = periods csm_params['building_parameters'] = structures.building_parameters csm_params['magnitudes'] = magnitudes self.capacity_spectrum_model = Capacity_spectrum_model(**csm_params)
class Damage_model(object): """ attributes: structure_state: only created after get_building_states is called. Axis of sites, model_generated_psudo_events, 4 (# of damage states) """ def __init__( self, structures, SA, periods, magnitudes, csm_use_variability, csm_standard_deviation, csm_params=None): """Class to determine the damage and economic loss. structures a Structures instance - But what is actually needed from it? SA array of Spectral Acceleration, in g, with axis; sites, pseudo_events, atten_periods the site axis usually has a size of 1 periods array, 1 axis magnitudes array, 1 axis csm_params capacity spectrum method params One Damage_model instance is created for each site, in calc_total_loss(). The structures value will be different for each site. """ self.structures = structures self.periods = periods self.magnitudes = magnitudes self.SA = SA self.csm_use_variability = csm_use_variability self.csm_standard_deviation = csm_standard_deviation if csm_params is None: csm_params = {'csm_damping_regimes': CSM_DAMPING_REGIMES_USE_ALL, 'csm_damping_modify_Tav': CSM_DAMPING_MODIFY_TAV, 'csm_damping_use_smoothing': CSM_DAMPING_USE_SMOOTHING, 'rtol': 0.01, 'csm_damping_max_iterations': 7, 'sdtcap': 0.3, 'csm_use_variability': False, 'csm_variability_method': None, 'csm_hysteretic_damping': 'trapezoidal', 'atten_override_RSA_shape': None, 'atten_cutoff_max_spectral_displacement': False, 'loss_min_pga': 0.0} csm_params['periods'] = periods csm_params['building_parameters'] = structures.building_parameters csm_params['magnitudes'] = magnitudes self.capacity_spectrum_model = Capacity_spectrum_model(**csm_params) def get_building_states(self): """ Determine the cumulative probability of a building being in or exceeding a given damage state for 3 types of damage; structure, non_structural, acceleration_sensitive. """ csm_use_variability = self.csm_use_variability csm_standard_deviation = self.csm_standard_deviation beta_th_sd = 0.4 beta_th_nsd_d = 0.5 beta_th_nsd_a = 0.6 beta_bridge = 0.6 if (csm_use_variability is False): # incorporate buiding cap variability into the beta # (may not be correct!) beta_sd = ( beta_th_sd ** 2 + csm_standard_deviation ** 2) ** (0.5) beta_nsd_d = ( beta_th_nsd_d ** 2 + csm_standard_deviation ** 2) ** (0.5) beta_nsd_a = ( beta_th_nsd_a ** 2 + csm_standard_deviation ** 2) ** (0.5) elif (csm_use_variability is True): # normal case: beta_sd = beta_th_sd # This does nothing beta_nsd_d = beta_th_nsd_d beta_nsd_a = beta_th_nsd_a # warning: this option will cause divide by zero warnings in make_fragility.m else: msg = ('ERROR in prep_build_vun: ' 'csm_use_variability not properly defined') raise RuntimeError(msg) (SA, SD) = self.get_building_displacement() SA = SA.round(4) SD = SD.round(4) building_parameters = self.structures.building_parameters threshold = building_parameters['structural_damage_threshold'] # reshape threshold so it is [sites,magnitudes,damage_states] threshold = threshold[:, newaxis, :] assert len(threshold.shape) == 3 # threshold is [sites,1,damage_states] # SA = SA[:, :, newaxis] SD = SD[:, :, newaxis] assert len(SA.shape) == 3 assert len(SD.shape) == 3 structure_state = state_probability(threshold, beta_th_sd, SD) # The above could be a typo. Is this what we want? # It will change scenario results. # Is it beta_sd or beta_th_sd that we want? threshold = building_parameters['drift_threshold'] threshold = threshold[:, newaxis, :] non_structural_state = state_probability(threshold, beta_nsd_d, SD) threshold = building_parameters['acceleration_threshold'] threshold = threshold[:, newaxis, :] acceleration_sensitive_state = state_probability(threshold, beta_nsd_a, SA) self.structure_state = structure_state # for writing to file return (structure_state, non_structural_state, acceleration_sensitive_state) def get_building_displacement(self): point = self.capacity_spectrum_model.building_response(self.SA) return point def building_loss(self, ci=None, loss_aus_contents=0): damage_states = self.get_building_states() total_costs = self.structures.cost_breakdown(ci=ci) (structure_state, non_structural_state, acceleration_sensitive_state) = damage_states (structure_cost, non_structural_cost, acceleration_cost, contents_cost) = total_costs # hardwired loss for each damage state f1 = array((0.02, 0.1, 0.5, 1.0))[newaxis, newaxis, :] f2 = array((0.02, 0.1, 0.5, 1.0))[newaxis, newaxis, :] f3 = array((0.02, 0.1, 0.3, 1.0))[newaxis, newaxis, :] f4 = array((0.01, 0.05, 0.25, 0.5))[newaxis, newaxis, :] if loss_aus_contents == 1: f4 = f4 * 2 # 100% contents loss if building collapses structure_ratio = (f1 * structure_state) # .sum(axis=-1) nsd_ratio = (f2 * non_structural_state) # .sum(axis=-1) accel_ratio = (f3 * acceleration_sensitive_state) # .sum(axis=-1) contents_ratio = (f4 * acceleration_sensitive_state) # .sum(axis=-1) loss_ratio = (structure_ratio, nsd_ratio, accel_ratio, contents_ratio) structure_loss = structure_ratio * structure_cost[:, newaxis, newaxis] nsd_loss = nsd_ratio * non_structural_cost[:, newaxis, newaxis] accel_loss = accel_ratio * acceleration_cost[:, newaxis, newaxis] contents_loss = contents_ratio * contents_cost[:, newaxis, newaxis] total_loss = (structure_loss, nsd_loss, accel_loss, contents_loss) return (loss_ratio, total_loss) def aggregated_building_loss(self, ci=None, loss_aus_contents=0): (loss_ratio, total_loss) = \ self.building_loss(ci=ci, loss_aus_contents=loss_aus_contents) total_loss = tuple([loss.sum(axis=-1) for loss in total_loss]) return total_loss def annualised_loss(self, event_activity): event_activity = event_activity[:, newaxis] building_loss = self.aggregated_building_loss() raise NotImplementedError('Annualised Loss is not implemented')
def test_building_response(self): #Test that building response is the same as matlab periods=array([0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3]) SA = array([0.017553049, 0.028380350, 0.036142210, 0.037701113, 0.039325398, 0.038083417, 0.036880517, 0.036190107, 0.035512489, 0.035088679, 0.034669917, 0.033162774, 0.030871523, 0.027841184, 0.025094836, 0.022850476, 0.021322256, 0.019895084, 0.018562342, 0.017317833, 0.016160874, 0.015195155, 0.014287144, 0.013433394, 0.012630662, 0.011875899, 0.011166239, 0.010498986, 0.009871606, 0.009281717, 0.008727078, 0.008140645, 0.007593619, 0.007083352, 0.006607374, 0.006163380]) SA = SA[newaxis, newaxis, :] magnitudes = array([6.5]) Btype = 'RM2L' eqrm_dir = determine_eqrm_path() default_input_dir = join(eqrm_dir, 'resources', 'data', '') building_parameters = \ building_params_from_csv(building_classification_tag = '', damage_extent_tag = '', default_input_dir=default_input_dir) # Pull the parameters out: b_index = where([(bt == Btype) for bt in building_parameters['structure_classification']]) new_bp = {} for key in building_parameters: try: new_bp[key] = building_parameters[key][b_index] except: new_bp[key] = building_parameters[key] structures = Structures(latitude=[-31], longitude=[150], building_parameters=new_bp, #bridge_parameters={}, FCB_USAGE=array([111]), STRUCTURE_CLASSIFICATION=array([Btype]), STRUCTURE_CATEGORY=array(['BUILDING'])) building_parameters = structures.building_parameters # All the same for this type anyway csm_use_variability = None csm_standard_deviation = None damage_model = Damage_model(structures, SA, periods, magnitudes, csm_use_variability, csm_standard_deviation) # set up the capacity model capacity_spectrum_model = Capacity_spectrum_model(periods, magnitudes, building_parameters) capacity_spectrum_model.smooth_damping = True capacity_spectrum_model.use_displacement_corner_period = True capacity_spectrum_model.damp_corner_periods = True capacity_spectrum_model.use_exact_area = True capacity_spectrum_model.rtol = 0.01 capacity_spectrum_model.csm_damping_max_iterations = 7 ########################################################### damage_model.capacity_spectrum_model = capacity_spectrum_model # Warning, point is not used point = damage_model.get_building_displacement() # matlab values SAcr = 0.032208873 SDcr = 0.97944026 assert allclose(point[0], SAcr) assert allclose(point[1], SDcr) assert allclose(point, [[[SAcr]], [[SDcr]]])
def test_capacity_method(self): #in (Ay, Dy, Au, Du) =(0.13417, 2.9975, 0.26833, 41.964) (aa, bb, cc, kappa) =(-0.3647, 0.33362, 0.26833, 0.001) capacity_parameters = (Dy, Ay, Du, Au, aa, bb, cc) SA_Regolith = array([0.342012967618843, 0.763365709250557, 0.653837319165796, 0.530630921234538, 0.442943423800148, 0.383969335597378, 0.344524949645552, 0.321240620786007, 0.302941865445212, 0.27664105478319, 0.248309353527187, 0.15957588550857, 0.110047888697209, 0.0801793140567643, 0.0550935180421332, 0.0397236036505722, 0.0291049436633207, 0.0214091242649845, 0.0157482043977009]) SA_Regolith.shape = (1, 1, -1) params = (0.069, 13, 0.3, 0.9, 0.7, 1.75, 2, 7) dparams = (0.001, 0.001, 0.001, 0.08) (C, height, T, a1, a2, y, h, u) =params magnitudes = array([7.2]) (damping_s, damping_m, damping_l, initial_damping) = dparams periods = array([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]) building_parameters = {} building_parameters['design_strength'] = array([C]) building_parameters['natural_elastic_period'] = array([T]) building_parameters['fraction_in_first_mode'] = array([a1]) building_parameters['height_to_displacement'] = array([a2]) building_parameters['yield_to_design'] = array([y]) building_parameters['ultimate_to_yield'] = array([h]) building_parameters['ductility'] = array([u]) building_parameters['damping_s'] = array([damping_s]) building_parameters['damping_m'] = array([damping_m]) building_parameters['damping_l'] = array([damping_l]) building_parameters['damping_Be'] = array([initial_damping]) building_parameters['structure_classification'] = ['test_blg'] csm = Capacity_spectrum_model(periods, magnitudes, building_parameters) csm.rtol = 0.01 csm.csm_damping_max_iterations = 7 csm.use_displacement_corner_period = True csm.use_exact_area = True csm.damp_corner_periods = True point = csm.building_response(SA_Regolith) #final SDnew = [0, 1.6012, 5.486, 10.017, 15.022, 20.783, 27.144, 34.449, 42.431, 49.04, 54.342, 78.577, 96.336, 109.67, 108.51, 106.5, 101.91, 94.879, 86.162] SAnew = [0, 1.6012, 5.486, 10.017, 15.022, 20.783, 27.144, 34.449, 42.431, 49.04, 54.342, 78.577, 96.336, 109.67, 108.51, 106.5, 101.91, 94.879, 86.162] SDcr = 41.810644943005 SAcr = 0.26833301410569 assert allclose(SAcr, point[0]) assert allclose(SDcr, point[1])
def test_OS_bug_search(self): """ Used to trackdown ticket #98 """ SA =array([[[ 0.14210731, 0.29123634 , 0.23670422 , 0.13234554, 0.08648546 ,0.06338455, 0.04945741, 0.04140068 , 0.03497466 , 0.02969136, 0.02525473 ,0.02151188, 0.018371 , 0.01571802 , 0.01344816 , 0.01148438, 0.00980236 ,0.00836594, 0.00714065, 0.00609482], [ 0.2093217 , 0.30976405 , 0.16232743 , 0.06989206, 0.03216174 ,0.01945677, 0.01347719, 0.00987403 , 0.00799221 , 0.00660128, 0.00547129 ,0.0045463, 0.0042072 , 0.00418348 , 0.0041599 , 0.00413222, 0.00410333 ,0.00407463, 0.00404614, 0.00401785], [ 0.01450217, 0.02750284 , 0.02231209 , 0.01127933, 0.00793098 ,0.00621618, 0.0051103 , 0.00430777 , 0.00364714 , 0.0031542, 0.00279411 ,0.00247654, 0.0022153 , 0.001994 , 0.0017948 , 0.00161223, 0.00144737 ,0.00129929, 0.00117312, 0.00105988]]]) csm_params = { 'building_parameters': { 'residential_drift_threshold': array([[ 21.9456, 43.8912, 109.728 , 164.592 ]]), 'design_strength': array([ 0.033]), 'height': array([ 7315.2]), 'ultimate_to_yield': array([ 3.]), 'structure_class':array(['BUILDING'],dtype='|S8'), 'non_residential_drift_threshold': array([[ 5.4864, 43.8912, 82.296 , 137.16 ]]) , 'damping_Be': array([ 0.1]), 'fraction_in_first_mode': array([ 0.8]), 'nsd_a_ratio': array([ 0.7254902]), 'acceleration_threshold': array([[ 0.2, 0.4, 0.8, 1.6]]), 'nsd_d_ratio': array([ 0.11764706]), 'structure_ratio': array([ 0.15686275]), 'structural_damage_threshold': array([[ 26.33472, 41.69664, 88.87968, 219.456 ]]), 'natural_elastic_period': array([ 0.5]), 'damping_s': array([ 0.4]), 'drift_threshold': array([[ 5.4864, 43.8912, 82.296 , 137.16 ]]), 'yield_to_design': array([ 1.5]), 'structure_classification': array(['S1L'],dtype='|S13'), 'height_to_displacement': array([ 0.75]), 'ductility': array([ 5.]), 'damping_l': array([ 0.]), 'damping_m': array([ 0.2])}, 'loss_min_pga': 0.050000000000000003, 'csm_hysteretic_damping': 'trapezoidal', 'csm_use_variability': 1, 'sdtcap': 0.29999999999999999, 'csm_variability_method': 3, 'rtol': 0.01, 'csm_damping_regimes': CSM_DAMPING_REGIMES_USE_ALL, 'csm_damping_modify_Tav': CSM_DAMPING_MODIFY_TAV, 'csm_damping_use_smoothing': CSM_DAMPING_USE_SMOOTHING, 'magnitudes': array([ 6.0201519, 6.0201519, 6.0201519]), 'periods': array( [ 0. , 0.17544, 0.35088, 0.52632, 0.70175, 0.87719, 1.0526 , 1.2281 , 1.4035 , 1.5789 , 1.7544 , 1.9298 , 2.1053 , 2.2807 , 2.4561 , 2.6316 , 2.807 , 2.9825 , 3.1579 , 3.3333 ]), 'atten_override_RSA_shape': None, 'atten_cutoff_max_spectral_displacement': False, 'csm_damping_max_iterations': 7} reset_seed(True) capacity_spectrum_model=Capacity_spectrum_model(**csm_params) point=capacity_spectrum_model.building_response(SA) point_windows= (array([[ 0.11670333, 0.06428497, 0.]]), array([[ 7.35287023, 3.98947559, 0.]])) assert allclose(asarray(point),asarray(point_windows) )
def test_OS_bug_search(self): """ Used to trackdown ticket #98 """ SA = array([[[ 0.14210731, 0.29123634, 0.23670422, 0.13234554, 0.08648546, 0.06338455, 0.04945741, 0.04140068, 0.03497466, 0.02969136, 0.02525473, 0.02151188, 0.018371, 0.01571802, 0.01344816, 0.01148438, 0.00980236, 0.00836594, 0.00714065, 0.00609482 ], [ 0.2093217, 0.30976405, 0.16232743, 0.06989206, 0.03216174, 0.01945677, 0.01347719, 0.00987403, 0.00799221, 0.00660128, 0.00547129, 0.0045463, 0.0042072, 0.00418348, 0.0041599, 0.00413222, 0.00410333, 0.00407463, 0.00404614, 0.00401785 ], [ 0.01450217, 0.02750284, 0.02231209, 0.01127933, 0.00793098, 0.00621618, 0.0051103, 0.00430777, 0.00364714, 0.0031542, 0.00279411, 0.00247654, 0.0022153, 0.001994, 0.0017948, 0.00161223, 0.00144737, 0.00129929, 0.00117312, 0.00105988 ]]]) csm_params = { 'building_parameters': { 'residential_drift_threshold': array([[21.9456, 43.8912, 109.728, 164.592]]), 'design_strength': array([0.033]), 'height': array([7315.2]), 'ultimate_to_yield': array([3.]), 'structure_class': array(['BUILDING'], dtype='|S8'), 'non_residential_drift_threshold': array([[5.4864, 43.8912, 82.296, 137.16]]), 'damping_Be': array([0.1]), 'fraction_in_first_mode': array([0.8]), 'nsd_a_ratio': array([0.7254902]), 'acceleration_threshold': array([[0.2, 0.4, 0.8, 1.6]]), 'nsd_d_ratio': array([0.11764706]), 'structure_ratio': array([0.15686275]), 'structural_damage_threshold': array([[26.33472, 41.69664, 88.87968, 219.456]]), 'natural_elastic_period': array([0.5]), 'damping_s': array([0.4]), 'drift_threshold': array([[5.4864, 43.8912, 82.296, 137.16]]), 'yield_to_design': array([1.5]), 'structure_classification': array(['S1L'], dtype='|S13'), 'height_to_displacement': array([0.75]), 'ductility': array([5.]), 'damping_l': array([0.]), 'damping_m': array([0.2]) }, 'loss_min_pga': 0.050000000000000003, 'csm_hysteretic_damping': 'trapezoidal', 'csm_use_variability': 1, 'sdtcap': 0.29999999999999999, 'csm_variability_method': 3, 'rtol': 0.01, 'csm_damping_regimes': CSM_DAMPING_REGIMES_USE_ALL, 'csm_damping_modify_Tav': CSM_DAMPING_MODIFY_TAV, 'csm_damping_use_smoothing': CSM_DAMPING_USE_SMOOTHING, 'magnitudes': array([6.0201519, 6.0201519, 6.0201519]), 'periods': array([ 0., 0.17544, 0.35088, 0.52632, 0.70175, 0.87719, 1.0526, 1.2281, 1.4035, 1.5789, 1.7544, 1.9298, 2.1053, 2.2807, 2.4561, 2.6316, 2.807, 2.9825, 3.1579, 3.3333 ]), 'atten_override_RSA_shape': None, 'atten_cutoff_max_spectral_displacement': False, 'csm_damping_max_iterations': 7 } reset_seed(True) capacity_spectrum_model = Capacity_spectrum_model(**csm_params) point = capacity_spectrum_model.building_response(SA) point_windows = (array([[0.11670333, 0.06428497, 0.]]), array([[7.35287023, 3.98947559, 0.]])) assert allclose(asarray(point), asarray(point_windows))
class Damage_model(object): """ attributes: structure_state: only created after get_building_states is called. Axis of sites, model_generated_psudo_events, 4 (# of damage states) """ def __init__(self, structures, SA, periods, magnitudes, csm_use_variability, csm_standard_deviation, csm_params=None): """Class to determine the damage and economic loss. structures a Structures instance - But what is actually needed from it? SA array of Spectral Acceleration, in g, with axis; sites, pseudo_events, atten_periods the site axis usually has a size of 1 periods array, 1 axis magnitudes array, 1 axis csm_params capacity spectrum method params One Damage_model instance is created for each site, in calc_total_loss(). The structures value will be different for each site. """ self.structures = structures self.periods = periods self.magnitudes = magnitudes self.SA = SA self.csm_use_variability = csm_use_variability self.csm_standard_deviation = csm_standard_deviation if csm_params is None: csm_params = { 'csm_damping_regimes': CSM_DAMPING_REGIMES_USE_ALL, 'csm_damping_modify_Tav': CSM_DAMPING_MODIFY_TAV, 'csm_damping_use_smoothing': CSM_DAMPING_USE_SMOOTHING, 'rtol': 0.01, 'csm_damping_max_iterations': 7, 'sdtcap': 0.3, 'csm_use_variability': False, 'csm_variability_method': None, 'csm_hysteretic_damping': 'trapezoidal', 'atten_override_RSA_shape': None, 'atten_cutoff_max_spectral_displacement': False, 'loss_min_pga': 0.0 } csm_params['periods'] = periods csm_params['building_parameters'] = structures.building_parameters csm_params['magnitudes'] = magnitudes self.capacity_spectrum_model = Capacity_spectrum_model(**csm_params) def get_building_states(self): """ Determine the cumulative probability of a building being in or exceeding a given damage state for 3 types of damage; structure, non_structural, acceleration_sensitive. """ csm_use_variability = self.csm_use_variability csm_standard_deviation = self.csm_standard_deviation beta_th_sd = 0.4 beta_th_nsd_d = 0.5 beta_th_nsd_a = 0.6 beta_bridge = 0.6 if (csm_use_variability is False): # incorporate buiding cap variability into the beta # (may not be correct!) beta_sd = (beta_th_sd**2 + csm_standard_deviation**2)**(0.5) beta_nsd_d = (beta_th_nsd_d**2 + csm_standard_deviation**2)**(0.5) beta_nsd_a = (beta_th_nsd_a**2 + csm_standard_deviation**2)**(0.5) elif (csm_use_variability is True): # normal case: beta_sd = beta_th_sd # This does nothing beta_nsd_d = beta_th_nsd_d beta_nsd_a = beta_th_nsd_a # warning: this option will cause divide by zero warnings in make_fragility.m else: msg = ('ERROR in prep_build_vun: ' 'csm_use_variability not properly defined') raise RuntimeError(msg) (SA, SD) = self.get_building_displacement() SA = SA.round(4) SD = SD.round(4) building_parameters = self.structures.building_parameters threshold = building_parameters['structural_damage_threshold'] # reshape threshold so it is [sites,magnitudes,damage_states] threshold = threshold[:, newaxis, :] assert len(threshold.shape) == 3 # threshold is [sites,1,damage_states] # SA = SA[:, :, newaxis] SD = SD[:, :, newaxis] assert len(SA.shape) == 3 assert len(SD.shape) == 3 structure_state = state_probability(threshold, beta_th_sd, SD) # The above could be a typo. Is this what we want? # It will change scenario results. # Is it beta_sd or beta_th_sd that we want? threshold = building_parameters['drift_threshold'] threshold = threshold[:, newaxis, :] non_structural_state = state_probability(threshold, beta_nsd_d, SD) threshold = building_parameters['acceleration_threshold'] threshold = threshold[:, newaxis, :] acceleration_sensitive_state = state_probability( threshold, beta_nsd_a, SA) self.structure_state = structure_state # for writing to file return (structure_state, non_structural_state, acceleration_sensitive_state) def get_building_displacement(self): point = self.capacity_spectrum_model.building_response(self.SA) return point def building_loss(self, ci=None, loss_aus_contents=0): damage_states = self.get_building_states() total_costs = self.structures.cost_breakdown(ci=ci) (structure_state, non_structural_state, acceleration_sensitive_state) = damage_states (structure_cost, non_structural_cost, acceleration_cost, contents_cost) = total_costs # hardwired loss for each damage state f1 = array((0.02, 0.1, 0.5, 1.0))[newaxis, newaxis, :] f2 = array((0.02, 0.1, 0.5, 1.0))[newaxis, newaxis, :] f3 = array((0.02, 0.1, 0.3, 1.0))[newaxis, newaxis, :] f4 = array((0.01, 0.05, 0.25, 0.5))[newaxis, newaxis, :] if loss_aus_contents == 1: f4 = f4 * 2 # 100% contents loss if building collapses structure_ratio = (f1 * structure_state) # .sum(axis=-1) nsd_ratio = (f2 * non_structural_state) # .sum(axis=-1) accel_ratio = (f3 * acceleration_sensitive_state) # .sum(axis=-1) contents_ratio = (f4 * acceleration_sensitive_state) # .sum(axis=-1) loss_ratio = (structure_ratio, nsd_ratio, accel_ratio, contents_ratio) structure_loss = structure_ratio * structure_cost[:, newaxis, newaxis] nsd_loss = nsd_ratio * non_structural_cost[:, newaxis, newaxis] accel_loss = accel_ratio * acceleration_cost[:, newaxis, newaxis] contents_loss = contents_ratio * contents_cost[:, newaxis, newaxis] total_loss = (structure_loss, nsd_loss, accel_loss, contents_loss) return (loss_ratio, total_loss) def aggregated_building_loss(self, ci=None, loss_aus_contents=0): (loss_ratio, total_loss) = \ self.building_loss(ci=ci, loss_aus_contents=loss_aus_contents) total_loss = tuple([loss.sum(axis=-1) for loss in total_loss]) return total_loss def annualised_loss(self, event_activity): event_activity = event_activity[:, newaxis] building_loss = self.aggregated_building_loss() raise NotImplementedError('Annualised Loss is not implemented')
def BROKEN_test_find_intersection(self): # An error in the hysteresis area calc means the results # from Matlab are wrong. SA = array( [ 0.21604198097920, 0.49383398471879, 0.35207861448168, 0.28146561293471, 0.24663798021059, 0.18607106822206, 0.12461515892587, 0.08879073656528, 0.06464645061910, 0.04893110975922, 0.03794974804020, 0.02998618121319, 0.02404471425307, 0.01947448758241, 0.01577287001015, 0.01292966840312, 0.01064323885374, 0.00876012522030, 0.00721096310143, 0.00593573499178, ] ) SA.shape = 1, 1, -1 periods = array( [ 0, 0.17544, 0.35088, 0.52632, 0.70175, 0.87719, 1.0526, 1.2281, 1.4035, 1.5789, 1.7544, 1.9298, 2.1053, 2.2807, 2.4561, 2.6316, 2.807, 2.9825, 3.1579, 3.3333, ] ) magnitudes = array([5.6]) building_parameters = { "height": array([4572.0]), "ultimate_to_yield": array([2.0]), "design_strength": array([0.2]), "fraction_in_first_mode": array([0.75]), "natural_elastic_period": array([0.13]), "yield_to_design": array([1.5]), "height_to_displacement": array([0.75]), "ductility": array([2.0]), "damping_s": array([0.001]), "damping_m": array([0.001]), "damping_l": array([0.001]), "damping_Be": array([0.05]), } csm_hysteretic_damping = "curve" rtol = 1 / 100.0 csm_damping_max_iterations = 7 sdtcap = 0.3 csm_use_variability = False csm_variability_method = 3 csm_variability_method = 3 atten_override_RSA_shape = 0 capacity_spectrum_model = Capacity_spectrum_model( periods, magnitudes, building_parameters, csm_damping_regimes=CSM_DAMPING_REGIMES_USE_ALL, csm_damping_modify_Tav=CSM_DAMPING_MODIFY_TAV, csm_damping_use_smoothing=CSM_DAMPING_USE_SMOOTHING, csm_hysteretic_damping=csm_hysteretic_damping, rtol=rtol, csm_damping_max_iterations=csm_damping_max_iterations, sdtcap=sdtcap, csm_use_variability=csm_use_variability, atten_override_RSA_shape=atten_override_RSA_shape, csm_variability_method=csm_variability_method, ) SAcr, SDcr = capacity_spectrum_model.building_response(SA) # print SDcr # print SAcr assert allclose(1.99087165775938, SDcr[0, 0]) assert allclose(0.46802255489563, SAcr)
def BROKEN_test_find_intersection(self): # An error in the hysteresis area calc means the results # from Matlab are wrong. SA = array([ 0.21604198097920, 0.49383398471879, 0.35207861448168, 0.28146561293471, 0.24663798021059, 0.18607106822206, 0.12461515892587, 0.08879073656528, 0.06464645061910, 0.04893110975922, 0.03794974804020, 0.02998618121319, 0.02404471425307, 0.01947448758241, 0.01577287001015, 0.01292966840312, 0.01064323885374, 0.00876012522030, 0.00721096310143, 0.00593573499178 ]) SA.shape = 1, 1, -1 periods = array([ 0, 0.17544, 0.35088, 0.52632, 0.70175, 0.87719, 1.0526, 1.2281, 1.4035, 1.5789, 1.7544, 1.9298, 2.1053, 2.2807, 2.4561, 2.6316, 2.807, 2.9825, 3.1579, 3.3333 ]) magnitudes = array([5.6]) building_parameters = { 'height': array([4572.]), 'ultimate_to_yield': array([2.]), 'design_strength': array([0.2]), 'fraction_in_first_mode': array([0.75]), 'natural_elastic_period': array([0.13]), 'yield_to_design': array([1.5]), 'height_to_displacement': array([0.75]), 'ductility': array([2.]), 'damping_s': array([0.001]), 'damping_m': array([0.001]), 'damping_l': array([0.001]), 'damping_Be': array([0.05]) } csm_hysteretic_damping = 'curve' rtol = 1 / 100.0 csm_damping_max_iterations = 7 sdtcap = 0.3 csm_use_variability = False csm_variability_method = 3 csm_variability_method = 3 atten_override_RSA_shape = 0 capacity_spectrum_model = Capacity_spectrum_model( periods, magnitudes, building_parameters, csm_damping_regimes=CSM_DAMPING_REGIMES_USE_ALL, csm_damping_modify_Tav=CSM_DAMPING_MODIFY_TAV, csm_damping_use_smoothing=CSM_DAMPING_USE_SMOOTHING, csm_hysteretic_damping=csm_hysteretic_damping, rtol=rtol, csm_damping_max_iterations=csm_damping_max_iterations, sdtcap=sdtcap, csm_use_variability=csm_use_variability, atten_override_RSA_shape=atten_override_RSA_shape, csm_variability_method=csm_variability_method) SAcr, SDcr = capacity_spectrum_model.building_response(SA) #print SDcr #print SAcr assert allclose(1.99087165775938, SDcr[0, 0]) assert allclose(0.46802255489563, SAcr)