diff --git a/.idea/costs.iml b/.idea/costs.iml index 8b8c395..b6de3e9 100644 --- a/.idea/costs.iml +++ b/.idea/costs.iml @@ -2,7 +2,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 250142c..dc7953c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/costs/total_operational_costs.py b/costs/total_operational_costs.py index b3f97dd..269de9b 100644 --- a/costs/total_operational_costs.py +++ b/costs/total_operational_costs.py @@ -11,6 +11,48 @@ from costs.configuration import Configuration from costs.cost_base import CostBase +def Peak_load(building): + array = [None] * 12 + heating = 0 + cooling = 0 + for system in building.energy_systems: + for demand_type in system.demand_types: + if demand_type == cte.HEATING: + heating = 1 + if demand_type == cte.COOLING: + cooling = 1 + if cte.MONTH in building.heating_peak_load.keys() and cte.MONTH in building.cooling_peak_load.keys(): + peak_lighting = 0 + peak_appliances = 0 + for thermal_zone in building.internal_zones[0].thermal_zones: + lighting = thermal_zone.lighting + for schedule in lighting.schedules: + for value in schedule.values: + if value * lighting.density * thermal_zone.total_floor_area > peak_lighting: + peak_lighting = value * lighting.density * thermal_zone.total_floor_area + appliances = thermal_zone.appliances + for schedule in appliances.schedules: + for value in schedule.values: + if value * appliances.density * thermal_zone.total_floor_area > peak_appliances: + peak_appliances = value * appliances.density * thermal_zone.total_floor_area + + monthly_electricity_peak = [0.9 * peak_lighting + 0.7 * peak_appliances] * 12 + conditioning_peak = [] + for i, value in enumerate(building.heating_peak_load[cte.MONTH]): + if cooling * building.cooling_peak_load[cte.MONTH][i] > heating * value: + conditioning_peak.append(cooling * building.cooling_peak_load[cte.MONTH][i]) + else: + conditioning_peak.append(heating * value) + monthly_electricity_peak[i] += 0.8 * conditioning_peak[i] + + electricity_peak_load_results = pd.DataFrame(monthly_electricity_peak + , columns=[f'{building.name} electricity peak load W']) + else: + electricity_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} electricity peak load W']) + + return electricity_peak_load_results + + class TotalOperationalCosts(CostBase): """ End of life costs class @@ -29,6 +71,7 @@ class TotalOperationalCosts(CostBase): dtype='float' ) + def calculate(self) -> pd.DataFrame: """ Calculate total operational costs @@ -63,7 +106,9 @@ class TotalOperationalCosts(CostBase): ) # todo: change when peak electricity demand is coded. Careful with factor residential - peak_electricity_demand = 100 # self._peak_electricity_demand + peak_electricity_load = Peak_load(building) + peak_load_value = peak_electricity_load.max(axis=1) + peak_electricity_demand = peak_load_value[1]/1000 # self._peak_electricity_demand adapted to kW variable_electricity_cost_year_0 = total_electricity_consumption * archetype.operational_cost.fuels[0].variable[0] peak_electricity_cost_year_0 = peak_electricity_demand * archetype.operational_cost.fuels[0].fixed_power * 12 monthly_electricity_cost_year_0 = archetype.operational_cost.fuels[0].fixed_monthly * 12 * factor_residential diff --git a/tests/unit_tests.py b/tests/unit_tests.py index 3677651..5c4bbdc 100644 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -20,8 +20,8 @@ from costs.constants import SKIN_RETROFIT, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND class UnitTests(unittest.TestCase): def setUp(self) -> None: - city_file = Path("./tests/data/test.geojson").resolve() - output_path = Path('./tests/output/').resolve() + city_file = Path("./data/test.geojson").resolve() + output_path = Path('./output/').resolve() city = GeometryFactory('geojson', city_file, height_field='citygml_me', @@ -32,7 +32,7 @@ class UnitTests(unittest.TestCase): UsageFactory('nrcan', city).enrich() ExportsFactory('sra', city, output_path).export() sra_file = str((output_path / f'{city.name}_sra.xml').resolve()) - subprocess.run(['/usr/local/bin/sra', sra_file]) + subprocess.run(['sra', sra_file]) ResultFactory('sra', city, output_path).enrich() for building in city.buildings: