2023-05-04 10:39:23 -04:00
|
|
|
"""
|
|
|
|
TestSystemsFactory
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2023 Concordia CERC group
|
|
|
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
|
|
"""
|
|
|
|
|
2023-05-12 09:27:29 -04:00
|
|
|
import subprocess
|
2023-05-04 10:39:23 -04:00
|
|
|
from pathlib import Path
|
|
|
|
from unittest import TestCase
|
2023-05-15 11:03:54 -04:00
|
|
|
import copy
|
2023-10-13 13:31:46 -04:00
|
|
|
from typing import cast
|
2023-05-04 10:39:23 -04:00
|
|
|
|
2023-05-12 09:27:29 -04:00
|
|
|
import hub.helpers.constants as cte
|
|
|
|
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
|
|
|
from hub.exports.exports_factory import ExportsFactory
|
|
|
|
from hub.helpers.dictionaries import Dictionaries
|
2023-05-04 10:39:23 -04:00
|
|
|
from hub.imports.construction_factory import ConstructionFactory
|
2023-05-12 09:27:29 -04:00
|
|
|
from hub.imports.geometry_factory import GeometryFactory
|
2023-06-05 13:42:15 -04:00
|
|
|
from hub.imports.weather_factory import WeatherFactory
|
2023-05-12 09:27:29 -04:00
|
|
|
from hub.imports.results_factory import ResultFactory
|
2023-05-04 10:39:23 -04:00
|
|
|
from hub.imports.usage_factory import UsageFactory
|
|
|
|
from hub.imports.energy_systems_factory import EnergySystemsFactory
|
2023-05-15 11:03:54 -04:00
|
|
|
from hub.city_model_structure.energy_systems.energy_system import EnergySystem
|
|
|
|
from hub.city_model_structure.energy_systems.generation_system import GenerationSystem
|
|
|
|
from hub.city_model_structure.energy_systems.distribution_system import DistributionSystem
|
|
|
|
from hub.city_model_structure.energy_systems.emission_system import EmissionSystem
|
2023-10-02 13:19:58 -04:00
|
|
|
from hub.city_model_structure.energy_systems.thermal_storage_system import ThermalStorageSystem
|
2023-10-13 13:31:46 -04:00
|
|
|
from hub.city_model_structure.energy_systems.non_pv_generation_system import NonPvGenerationSystem
|
|
|
|
|
2023-05-04 10:39:23 -04:00
|
|
|
|
|
|
|
class TestSystemsFactory(TestCase):
|
|
|
|
"""
|
|
|
|
TestSystemsFactory TestCase
|
|
|
|
"""
|
|
|
|
def setUp(self) -> None:
|
|
|
|
"""
|
2023-05-12 09:27:29 -04:00
|
|
|
Test setup
|
|
|
|
:return: None
|
2023-05-04 10:39:23 -04:00
|
|
|
"""
|
|
|
|
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
2023-05-12 09:27:29 -04:00
|
|
|
self._output_path = (Path(__file__).parent / 'tests_outputs').resolve()
|
2023-07-13 15:53:20 -04:00
|
|
|
file = 'test.geojson'
|
|
|
|
file_path = (self._example_path / file).resolve()
|
|
|
|
self._city = GeometryFactory('geojson',
|
|
|
|
path=file_path,
|
|
|
|
height_field='citygml_me',
|
|
|
|
year_of_construction_field='ANNEE_CONS',
|
|
|
|
function_field='CODE_UTILI',
|
|
|
|
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
2023-05-04 10:39:23 -04:00
|
|
|
|
|
|
|
def test_montreal_custom_system_factory(self):
|
|
|
|
"""
|
|
|
|
Enrich the city with the construction information and verify it
|
|
|
|
"""
|
2023-05-12 09:27:29 -04:00
|
|
|
for building in self._city.buildings:
|
2023-05-04 10:39:23 -04:00
|
|
|
building.energy_systems_archetype_name = 'system 1 gas'
|
|
|
|
|
2023-05-12 09:27:29 -04:00
|
|
|
EnergySystemsFactory('montreal_custom', self._city).enrich()
|
2023-10-06 04:54:20 -04:00
|
|
|
self.assertEqual(1, len(self._city.generic_energy_systems))
|
2023-05-04 10:39:23 -04:00
|
|
|
|
|
|
|
def test_montreal_custom_system_results(self):
|
|
|
|
"""
|
|
|
|
Enrich the city with the construction information and verify it
|
|
|
|
"""
|
2023-05-12 09:27:29 -04:00
|
|
|
ConstructionFactory('nrcan', self._city).enrich()
|
|
|
|
UsageFactory('nrcan', self._city).enrich()
|
2023-06-06 13:32:37 -04:00
|
|
|
WeatherFactory('epw', self._city).enrich()
|
2023-06-05 13:42:15 -04:00
|
|
|
ExportsFactory('sra', self._city, self._output_path).export()
|
2023-05-12 09:27:29 -04:00
|
|
|
sra_path = (self._output_path / f'{self._city.name}_sra.xml').resolve()
|
|
|
|
subprocess.run(['sra', str(sra_path)])
|
|
|
|
ResultFactory('sra', self._city, self._output_path).enrich()
|
|
|
|
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', self._city, self._output_path).export()
|
|
|
|
for building in self._city.buildings:
|
|
|
|
insel_path = (self._output_path / f'{building.name}.insel')
|
|
|
|
subprocess.run(['insel', str(insel_path)])
|
|
|
|
ResultFactory('insel_monthly_energy_balance', self._city, self._output_path).enrich()
|
|
|
|
|
|
|
|
for building in self._city.buildings:
|
2024-12-13 06:19:24 -05:00
|
|
|
building.energy_systems_archetype_name = 'northern community system'
|
2023-05-12 09:27:29 -04:00
|
|
|
EnergySystemsFactory('montreal_custom', self._city).enrich()
|
2023-05-15 11:03:54 -04:00
|
|
|
# Need to assign energy systems to buildings:
|
|
|
|
for building in self._city.buildings:
|
|
|
|
_building_energy_systems = []
|
2023-10-13 13:31:46 -04:00
|
|
|
for energy_system in building.energy_systems:
|
|
|
|
if cte.HEATING in energy_system.demand_types:
|
|
|
|
_generation_system = cast(NonPvGenerationSystem, energy_system.generation_systems[0])
|
|
|
|
_generation_system.heat_power = building.heating_peak_load[cte.YEAR][0]
|
|
|
|
if cte.COOLING in energy_system.demand_types:
|
|
|
|
_generation_system = cast(NonPvGenerationSystem, energy_system.generation_systems[0])
|
|
|
|
_generation_system.cooling_power = building.cooling_peak_load[cte.YEAR][0]
|
2023-05-12 09:27:29 -04:00
|
|
|
|
|
|
|
for building in self._city.buildings:
|
|
|
|
self.assertLess(0, building.heating_consumption[cte.YEAR][0])
|
2024-12-13 06:19:24 -05:00
|
|
|
self.assertLessEqual(0, building.cooling_consumption[cte.YEAR][0])
|
2023-05-12 09:27:29 -04:00
|
|
|
self.assertLess(0, building.domestic_hot_water_consumption[cte.YEAR][0])
|
2023-08-07 16:56:01 -04:00
|
|
|
self.assertLess(0, building.onsite_electrical_production[cte.YEAR][0])
|
2023-10-02 13:19:58 -04:00
|
|
|
|
2024-02-07 18:54:09 -05:00
|
|
|
def test_montreal_future_system_results(self):
|
|
|
|
"""
|
|
|
|
Enrich the city with the construction information and verify it
|
|
|
|
"""
|
|
|
|
ConstructionFactory('nrcan', self._city).enrich()
|
|
|
|
UsageFactory('nrcan', self._city).enrich()
|
|
|
|
WeatherFactory('epw', self._city).enrich()
|
|
|
|
ExportsFactory('sra', self._city, self._output_path).export()
|
|
|
|
sra_path = (self._output_path / f'{self._city.name}_sra.xml').resolve()
|
|
|
|
subprocess.run(['sra', str(sra_path)])
|
|
|
|
ResultFactory('sra', self._city, self._output_path).enrich()
|
|
|
|
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', self._city, self._output_path).export()
|
|
|
|
for building in self._city.buildings:
|
|
|
|
insel_path = (self._output_path / f'{building.name}.insel')
|
|
|
|
subprocess.run(['insel', str(insel_path)])
|
|
|
|
ResultFactory('insel_monthly_energy_balance', self._city, self._output_path).enrich()
|
|
|
|
|
|
|
|
for building in self._city.buildings:
|
2024-11-15 07:58:11 -05:00
|
|
|
building.energy_systems_archetype_name = ('Central Hydronic Air and Gas Source Heating System with Unitary Split '
|
2024-11-17 09:29:19 -05:00
|
|
|
'Cooling and Air Source HP DHW and Grid Tied PV')
|
2024-02-07 18:54:09 -05:00
|
|
|
EnergySystemsFactory('montreal_future', self._city).enrich()
|
|
|
|
# Need to assign energy systems to buildings:
|
|
|
|
for building in self._city.buildings:
|
|
|
|
_building_energy_systems = []
|
|
|
|
for energy_system in building.energy_systems:
|
|
|
|
if cte.HEATING in energy_system.demand_types:
|
|
|
|
_generation_system = cast(NonPvGenerationSystem, energy_system.generation_systems[0])
|
2024-06-27 16:32:44 -04:00
|
|
|
_generation_system.nominal_heat_output = building.heating_peak_load[cte.YEAR][0]
|
2024-02-07 18:54:09 -05:00
|
|
|
if cte.COOLING in energy_system.demand_types:
|
|
|
|
_generation_system = cast(NonPvGenerationSystem, energy_system.generation_systems[0])
|
2024-06-27 16:32:44 -04:00
|
|
|
_generation_system.nominal_cooling_output = building.cooling_peak_load[cte.YEAR][0]
|
2024-02-07 18:54:09 -05:00
|
|
|
|
2024-10-29 06:36:47 -04:00
|
|
|
for building in self._city.buildings:
|
|
|
|
self.assertLess(0, building.heating_consumption[cte.YEAR][0])
|
|
|
|
self.assertLess(0, building.cooling_consumption[cte.YEAR][0])
|
|
|
|
self.assertLess(0, building.domestic_hot_water_consumption[cte.YEAR][0])
|
2024-11-17 09:29:19 -05:00
|
|
|
if 'PV' in building.energy_systems_archetype_name:
|
|
|
|
self.assertLess(0, building.onsite_electrical_production[cte.YEAR][0])
|
2024-10-29 06:36:47 -04:00
|
|
|
|
|
|
|
def test_palma_system_results(self):
|
|
|
|
"""
|
|
|
|
Enrich the city with the construction information and verify it
|
|
|
|
"""
|
|
|
|
ConstructionFactory('nrcan', self._city).enrich()
|
|
|
|
UsageFactory('nrcan', self._city).enrich()
|
|
|
|
WeatherFactory('epw', self._city).enrich()
|
|
|
|
ExportsFactory('sra', self._city, self._output_path).export()
|
|
|
|
sra_path = (self._output_path / f'{self._city.name}_sra.xml').resolve()
|
|
|
|
subprocess.run(['sra', str(sra_path)])
|
|
|
|
ResultFactory('sra', self._city, self._output_path).enrich()
|
|
|
|
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', self._city, self._output_path).export()
|
|
|
|
for building in self._city.buildings:
|
|
|
|
insel_path = (self._output_path / f'{building.name}.insel')
|
|
|
|
subprocess.run(['insel', str(insel_path)])
|
|
|
|
ResultFactory('insel_monthly_energy_balance', self._city, self._output_path).enrich()
|
|
|
|
|
|
|
|
for building in self._city.buildings:
|
|
|
|
building.energy_systems_archetype_name = 'PV and heat pump'
|
|
|
|
EnergySystemsFactory('palma', self._city).enrich()
|
|
|
|
# Need to assign energy systems to buildings:
|
|
|
|
for building in self._city.buildings:
|
|
|
|
_building_energy_systems = []
|
|
|
|
for energy_system in building.energy_systems:
|
|
|
|
if cte.HEATING in energy_system.demand_types:
|
|
|
|
_generation_system = cast(NonPvGenerationSystem, energy_system.generation_systems[0])
|
|
|
|
_generation_system.nominal_heat_output = building.heating_peak_load[cte.YEAR][0]
|
|
|
|
if cte.COOLING in energy_system.demand_types:
|
|
|
|
_generation_system = cast(NonPvGenerationSystem, energy_system.generation_systems[0])
|
|
|
|
_generation_system.nominal_cooling_output = building.cooling_peak_load[cte.YEAR][0]
|
|
|
|
|
2024-02-07 18:54:09 -05:00
|
|
|
for building in self._city.buildings:
|
|
|
|
self.assertLess(0, building.heating_consumption[cte.YEAR][0])
|
|
|
|
self.assertLess(0, building.cooling_consumption[cte.YEAR][0])
|
|
|
|
self.assertLess(0, building.domestic_hot_water_consumption[cte.YEAR][0])
|
2024-06-27 16:32:44 -04:00
|
|
|
self.assertLess(0, building.onsite_electrical_production[cte.YEAR][0])
|