DamageCalculator#
DamageCalculator is the shared helper layer for damage probability
calculation. Use it when you need to inspect component-combination tables,
build per-component resistance vectors, or convert Monte Carlo damage-ratio
iterations into damage-state probabilities without running the full building
inventory workflow.
Inputs#
Constructor inputs are inherited from the base calculation class:
| Input | Type | Notes |
|---|---|---|
BuildingInventory |
cheersafe.inventory.BuildingInventory |
Inventory object; required by the dataclass even when only static helpers are used through an instance. |
Sampling |
cheersafe.tools.Sampling |
Sampling helper, used by subclasses. |
Covariance |
cheersafe.tools.Covariance |
Covariance helper, used by subclasses. |
Loaded file inputs are the shared damage-probability calculation files listed in the module overview. Component configuration IDs are 1-based in the JSON files. Helper methods convert selected values to zero-based NumPy indexing where needed.
Important array shapes:
| Value | Shape | Meaning |
|---|---|---|
iteration_result |
[w, f, iteration] |
Simulated damage ratios by wind-speed index, flood-depth index, and Monte Carlo iteration. |
damage_states |
[d, 2] |
Damage-state id and damage ratio threshold. |
| returned probability array | [w, f, d] |
Probability for each wind, flood, and damage-state bin. |
Outputs And Returns#
| Method | Returns | Side effects |
|---|---|---|
get_component_combination_hip() |
Hip component matrix with selected columns from ComponentCombination_Hip. |
None. |
get_component_combination_gable() |
Gable component matrix with selected columns from ComponentCombination_Gable. |
None. |
fn_damage_probability(iteration_result, damage_states) |
Damage-state probability array [w, f, d]. |
None. |
initialize_resistance_values(ComponentCombination_cIndex, resistance_array) |
Length-10 resistance vector by component row. | None. |
calculate_resistance_values(num_component_array, resistance_value_c_index) |
Expanded resistance vector for all individual components. | None. |
Configuration Behavior#
With Config.AUTO_LOAD_DATASETS=True, construction loads the shared JSON
datasets. With False, call the needed load_* methods before accessing
dataset-backed helpers.
Config.AUTO_EXECUTE_METHODS does not trigger any additional calculation in
DamageCalculator; helper methods are called directly.
Minimal Examples#
Automatic loading:
import numpy as np
from cheersafe.config import Config
from cheersafe.inventory import BuildingInventory
from cheersafe.tools import Sampling, Covariance
from cheersafe.damage_probability_calculation import DamageCalculator
Config.AUTO_LOAD_DATASETS = True
calc = DamageCalculator(BuildingInventory(), Sampling(), Covariance())
iteration_result = np.zeros((2, 3, Config.NUM_OF_ITERATIONS))
prob_ds = calc.fn_damage_probability(iteration_result, calc.DamageStates)
hip = calc.get_component_combination_hip()
Manual control:
from cheersafe.config import Config
from cheersafe.inventory import BuildingInventory
from cheersafe.tools import Sampling, Covariance
from cheersafe.damage_probability_calculation import DamageCalculator
Config.AUTO_LOAD_DATASETS = False
calc = DamageCalculator(BuildingInventory(), Sampling(), Covariance())
calc.load_damage_states()
calc.load_component_combinations()
gable = calc.get_component_combination_gable()
Related References#
- API: Damage Probability Calculation
- Planned notebook: Fragility Curve Calculation