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
|
|
|
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-11-18 13:07:48 -05: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-11-11 17:29:17 -05:00
|
|
|
usage_format = 'comnet'
|
2021-05-27 18:23:38 -04:00
|
|
|
schedules_format = 'comnet'
|
2021-12-03 10:07:39 -05: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-09-02 12:30:37 -04:00
|
|
|
keep_sra_file = True
|
2021-11-11 17:29:17 -05:00
|
|
|
keep_insel_file = True
|
|
|
|
keep_weather_file = True
|
|
|
|
keep_ig_file = True
|
|
|
|
|
2021-12-03 10:07:39 -05:00
|
|
|
pickle_geometry = False
|
|
|
|
pickle_weather = False
|
|
|
|
pickle_construction = False
|
|
|
|
pickle_usage = False
|
|
|
|
pickle_schedules = False
|
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-08-31 16:16:22 -04:00
|
|
|
# Load geometry
|
|
|
|
if not pickle_geometry:
|
2021-06-10 10:48:30 -04:00
|
|
|
city = GeometryFactory('citygml', full_path_gml).city
|
2021-08-31 16:16:22 -04:00
|
|
|
city.save(pickle_file)
|
|
|
|
else:
|
|
|
|
city = City.load(pickle_file)
|
2021-05-26 16:28:39 -04:00
|
|
|
|
2021-08-31 16:16:22 -04:00
|
|
|
# Load weather and calculate radiation
|
|
|
|
if not pickle_weather:
|
|
|
|
# user configurable parameters
|
|
|
|
for building in city.buildings:
|
|
|
|
for surface in building.surfaces:
|
|
|
|
surface.swr = 0.2
|
|
|
|
|
|
|
|
# load weather
|
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-08-31 16:16:22 -04:00
|
|
|
# calculate radiation on external surfaces
|
2021-06-10 10:48:30 -04:00
|
|
|
path = (example_path / 'tests').resolve()
|
2021-11-11 17:29:17 -05:00
|
|
|
radius = 80
|
|
|
|
building = city.city_object('BLD109438')
|
|
|
|
# building = city.city_object('1066157')
|
|
|
|
new_city = city.region(building.centroid, radius)
|
|
|
|
sra = SimplifiedRadiosityAlgorithm(new_city, path, weather_file_name)
|
|
|
|
sra.call_sra(weather_format, keep_files=keep_sra_file, selected_buildings=[building])
|
|
|
|
sra.set_irradiance_surfaces(city, mode=1, building_name=building.name)
|
2021-06-10 10:48:30 -04:00
|
|
|
|
2021-11-11 17:29:17 -05:00
|
|
|
# to save only the targeted building
|
|
|
|
radius = 10
|
|
|
|
city = city.region(building.centroid, radius)
|
2021-08-31 16:16:22 -04:00
|
|
|
city.save(pickle_file)
|
|
|
|
else:
|
|
|
|
city = City.load(pickle_file)
|
|
|
|
|
2021-11-11 17:29:17 -05:00
|
|
|
# Enrich target building in the city with construction, usage and schedules
|
2021-08-31 16:16:22 -04:00
|
|
|
if not pickle_construction or not pickle_usage or not pickle_schedules:
|
2021-11-11 17:29:17 -05:00
|
|
|
|
2021-06-10 10:48:30 -04:00
|
|
|
for building in city.buildings:
|
2021-12-03 10:07:39 -05:00
|
|
|
building.function = 'residential'
|
2021-11-11 17:29:17 -05:00
|
|
|
building.year_of_construction = 2010
|
|
|
|
|
2021-06-10 10:48:30 -04:00
|
|
|
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-31 16:16:22 -04:00
|
|
|
city = EnrichCity(city).enriched_city(construction_format, usage_format, schedules_format,
|
|
|
|
pickle_construction, pickle_usage, pickle_schedules)
|
2021-11-11 17:29:17 -05:00
|
|
|
|
2021-06-10 10:48:30 -04:00
|
|
|
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)
|
|
|
|
|
2021-08-26 09:36:09 -04:00
|
|
|
# Assign user defined parameters
|
|
|
|
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-31 16:16:22 -04:00
|
|
|
insel = Insel(example_path, insel_file_name, content, mode=2, keep_files=keep_insel_file).results
|
2021-11-11 17:29:17 -05:00
|
|
|
break
|
2021-08-31 12:17:41 -04:00
|
|
|
|
2021-11-11 17:29:17 -05:00
|
|
|
except ValueError:
|
2020-05-19 17:00:15 -04:00
|
|
|
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
|