2020-05-19 17:00:15 -04:00
|
|
|
import sys
|
|
|
|
from insel.insel import Insel
|
2020-05-01 13:59:09 -04:00
|
|
|
from pathlib import Path
|
2021-06-10 10:48:30 -04:00
|
|
|
from helpers.enrich_city import EnrichCity
|
2021-05-26 16:28:39 -04:00
|
|
|
from simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
|
|
|
|
from imports.weather_factory import WeatherFactory
|
2020-05-19 17:00:15 -04:00
|
|
|
from insel.templates.thermal_demand_dynamic_simulation import ThermalDemandDynamicSimulation as Templates
|
|
|
|
from helpers.simulation_parameters import SimulationParameters as Sp
|
2021-05-26 16:28:39 -04:00
|
|
|
import helpers.constants as cte
|
|
|
|
from imports.geometry_factory import GeometryFactory
|
2021-06-10 10:48:30 -04:00
|
|
|
from imports.geometry.helpers.geometry_helper import GeometryHelper
|
|
|
|
from city_model_structure.city import City
|
2020-05-01 13:59:09 -04:00
|
|
|
|
2021-05-26 16:28:39 -04:00
|
|
|
name_gml = 'one_building_in_kelowna.gml'
|
2021-05-27 18:23:38 -04:00
|
|
|
function_format = 'hft'
|
2021-08-26 09:36:09 -04:00
|
|
|
construction_format = 'nrel'
|
2021-05-27 18:23:38 -04:00
|
|
|
usage_format = 'hft'
|
|
|
|
schedules_format = 'comnet'
|
2021-05-28 11:53:22 -04:00
|
|
|
climate_reference_city = 'Summerland'
|
|
|
|
weather_file_name = 'CAN_BC_Summerland.717680_CWEC.epw'
|
2021-05-27 18:23:38 -04:00
|
|
|
|
2021-05-26 16:28:39 -04:00
|
|
|
example_path = Path(__file__).parent
|
|
|
|
full_path_gml = (example_path / 'tests' / 'tests_data' / name_gml).resolve()
|
|
|
|
outputs_path = (example_path / 'tests' / 'tests_outputs').resolve()
|
2021-05-28 11:53:22 -04:00
|
|
|
tmp_path = (example_path / 'tests' / 'tmp').resolve()
|
|
|
|
weather_path = (Path(__file__).parent.parent / 'libs' / 'data' / 'weather').resolve()
|
2021-08-31 12:17:41 -04:00
|
|
|
keep_files = True
|
2021-08-12 11:08:28 -04:00
|
|
|
pickle_created = True
|
2021-06-10 10:48:30 -04:00
|
|
|
pickle_file = 'tests/tests_data/one_building_in_kelowna.pickle'
|
2020-05-01 18:33:06 -04:00
|
|
|
|
2021-06-10 10:48:30 -04:00
|
|
|
if not pickle_created:
|
|
|
|
city = GeometryFactory('citygml', full_path_gml).city
|
2021-05-26 16:28:39 -04:00
|
|
|
|
2021-06-10 10:48:30 -04:00
|
|
|
weather_format = 'epw'
|
|
|
|
city.climate_reference_city = climate_reference_city
|
|
|
|
city.climate_file = (tmp_path / f'{climate_reference_city}.cli').resolve()
|
|
|
|
WeatherFactory(weather_format, city, base_path=weather_path, file_name=weather_file_name).enrich()
|
2021-08-12 11:08:28 -04:00
|
|
|
|
2021-06-10 10:48:30 -04:00
|
|
|
for building in city.buildings:
|
|
|
|
if cte.HOUR not in building.external_temperature:
|
|
|
|
print('No external temperature found')
|
|
|
|
sys.exit()
|
2021-05-26 16:28:39 -04:00
|
|
|
|
2021-06-10 10:48:30 -04:00
|
|
|
max_buildings_handled_by_sra = 500
|
2021-05-28 11:53:22 -04:00
|
|
|
for building in city.buildings:
|
2021-06-10 10:48:30 -04:00
|
|
|
for surface in building.surfaces:
|
|
|
|
surface.swr = 0.2
|
|
|
|
path = (example_path / 'tests').resolve()
|
|
|
|
sra = SimplifiedRadiosityAlgorithm(city, path, weather_file_name)
|
|
|
|
total_number_of_buildings = len(city.buildings)
|
|
|
|
if total_number_of_buildings > max_buildings_handled_by_sra:
|
|
|
|
radius = 80
|
|
|
|
for building in city.buildings:
|
|
|
|
new_city = city.region(building.centroid, radius)
|
|
|
|
sra_new = SimplifiedRadiosityAlgorithm(new_city, path, weather_file_name)
|
|
|
|
sra_new.call_sra(weather_format, keep_files=keep_files)
|
|
|
|
sra_new.set_irradiance_surfaces(city, building_name=building.name)
|
|
|
|
else:
|
|
|
|
sra.call_sra(weather_format, keep_files=keep_files)
|
|
|
|
sra.set_irradiance_surfaces(city, mode=1)
|
|
|
|
|
|
|
|
for building in city.buildings:
|
|
|
|
if function_format == 'hft':
|
|
|
|
building.function = GeometryHelper.hft_to_function[building.function]
|
|
|
|
elif function_format == 'pluto':
|
|
|
|
building.function = GeometryHelper.pluto_to_function[building.function]
|
2021-08-12 11:08:28 -04:00
|
|
|
|
2021-06-10 10:48:30 -04:00
|
|
|
city = EnrichCity(city).enriched_city(construction_format, usage_format, schedules_format)
|
|
|
|
|
|
|
|
city.save(pickle_file)
|
2020-05-19 11:22:15 -04:00
|
|
|
else:
|
2021-06-10 10:48:30 -04:00
|
|
|
city = City.load(pickle_file)
|
|
|
|
|
|
|
|
# todo: when the enrichment step goes after SRA, check whether srw has changed
|
|
|
|
# after reading the construction library or not
|
2021-08-26 09:36:09 -04:00
|
|
|
# Assign user defined parameters
|
2021-08-27 14:23:22 -04:00
|
|
|
if not pickle_created:
|
|
|
|
for building in city.buildings:
|
2021-08-27 17:48:07 -04:00
|
|
|
print(len(building.storeys))
|
|
|
|
print(building.storeys[0].thermal_boundaries)
|
|
|
|
print(building.storeys[0].thermal_zone)
|
2021-08-27 14:23:22 -04:00
|
|
|
print('number of thermal boundaries', len(building.thermal_boundaries))
|
|
|
|
for i_tb, thermal_boundary in enumerate(building.thermal_boundaries):
|
|
|
|
print(i_tb, thermal_boundary.type)
|
2021-08-27 17:48:07 -04:00
|
|
|
for thermal_zone in thermal_boundary.thermal_zones:
|
2021-08-27 14:23:22 -04:00
|
|
|
print(thermal_zone.id)
|
|
|
|
quit()
|
|
|
|
for thermal_zone in building.thermal_zones:
|
|
|
|
print('volume', thermal_zone.volume)
|
|
|
|
for thermal_boundary in thermal_zone.thermal_boundaries:
|
|
|
|
print('type', thermal_boundary.surface.type)
|
|
|
|
print('id', thermal_boundary.surface.id)
|
|
|
|
print('area tb', thermal_boundary.area)
|
2021-08-27 17:48:07 -04:00
|
|
|
for tz in thermal_boundary.thermal_zones:
|
2021-08-27 14:23:22 -04:00
|
|
|
print('delimits', tz.id)
|
|
|
|
print('window ratio', thermal_boundary.window_ratio)
|
|
|
|
for thermal_opening in thermal_boundary.thermal_openings:
|
|
|
|
print('area window', thermal_opening.area)
|
|
|
|
print('frame', thermal_opening.frame_ratio)
|
|
|
|
quit()
|
|
|
|
|
2021-08-26 09:36:09 -04:00
|
|
|
for building in city.buildings:
|
|
|
|
building.heated = True
|
2021-08-31 12:17:41 -04:00
|
|
|
building.cooled = True
|
2021-08-26 09:36:09 -04:00
|
|
|
building.attic_heated = 2
|
|
|
|
building.basement_heated = 0
|
|
|
|
|
2020-05-01 18:33:06 -04:00
|
|
|
# Demand calculation (one model per building)
|
2021-08-12 11:08:28 -04:00
|
|
|
for building in city.buildings:
|
|
|
|
full_path_out = (outputs_path / building.name).resolve()
|
|
|
|
full_path_wea = (tmp_path / (building.name + '.weather')).resolve()
|
|
|
|
full_path_ig = (tmp_path / (building.name + '.ig')).resolve()
|
2021-08-31 12:17:41 -04:00
|
|
|
full_paths_fij = []
|
|
|
|
for i_tz in range(0, len(building.thermal_zones)):
|
|
|
|
full_paths_fij.append((tmp_path / (building.name + '_' + str(i_tz) + '.fij')).resolve())
|
2020-05-19 17:23:29 -04:00
|
|
|
|
2021-08-12 11:08:28 -04:00
|
|
|
insel_file_name = building.name + '.insel'
|
2020-05-19 17:00:15 -04:00
|
|
|
try:
|
2021-08-31 12:17:41 -04:00
|
|
|
template = Templates(building, full_path_out, full_path_wea, full_path_ig,
|
|
|
|
full_paths_fij, Sp)
|
|
|
|
content = template.generate_thermal_dynamic_template()
|
|
|
|
template.generate_weather_file()
|
|
|
|
template.generate_ig_file()
|
|
|
|
template.generate_fij_files()
|
|
|
|
print(insel_file_name)
|
2021-08-26 09:36:09 -04:00
|
|
|
insel = Insel(example_path, insel_file_name, content, mode=2, keep_files=keep_files).results
|
2021-08-31 12:17:41 -04:00
|
|
|
|
2020-05-19 17:00:15 -04:00
|
|
|
except:
|
|
|
|
print(sys.exc_info()[1])
|
2021-08-12 11:08:28 -04:00
|
|
|
print('Building ' + building.name + ' could not be processed')
|
2020-05-19 17:00:15 -04:00
|
|
|
continue
|