dynamic_building_simulation/main.py

126 lines
4.5 KiB
Python
Raw Normal View History

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
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
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'
function_format = 'hft'
construction_format = 'nrel'
usage_format = 'comnet'
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-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()
tmp_path = (example_path / 'tests' / 'tmp').resolve()
weather_path = (Path(__file__).parent.parent / 'libs' / 'data' / 'weather').resolve()
keep_sra_file = True
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
pickle_file = 'tests/tests_data/one_building_in_kelowna.pickle'
2020-05-01 18:33:06 -04:00
# Load geometry
if not pickle_geometry:
city = GeometryFactory('citygml', full_path_gml).city
city.save(pickle_file)
else:
city = City.load(pickle_file)
2021-05-26 16:28:39 -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
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()
# calculate radiation on external surfaces
path = (example_path / 'tests').resolve()
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)
# to save only the targeted building
radius = 10
city = city.region(building.centroid, radius)
city.save(pickle_file)
else:
city = City.load(pickle_file)
# Enrich target building in the city with construction, usage and schedules
if not pickle_construction or not pickle_usage or not pickle_schedules:
for building in city.buildings:
2021-12-03 10:07:39 -05:00
building.function = 'residential'
building.year_of_construction = 2010
if function_format == 'hft':
building.function = GeometryHelper.hft_to_function[building.function]
elif function_format == 'pluto':
building.function = GeometryHelper.pluto_to_function[building.function]
city = EnrichCity(city).enriched_city(construction_format, usage_format, schedules_format,
pickle_construction, pickle_usage, pickle_schedules)
city.save(pickle_file)
2020-05-19 11:22:15 -04:00
else:
city = City.load(pickle_file)
# Assign user defined parameters
for building in city.buildings:
building.heated = True
building.cooled = True
building.attic_heated = 2
building.basement_heated = 0
2020-05-01 18:33:06 -04:00
# Demand calculation (one model per building)
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()
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
insel_file_name = building.name + '.insel'
2020-05-19 17:00:15 -04:00
try:
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)
insel = Insel(example_path, insel_file_name, content, mode=2, keep_files=keep_insel_file).results
break
except ValueError:
2020-05-19 17:00:15 -04:00
print(sys.exc_info()[1])
print('Building ' + building.name + ' could not be processed')
2020-05-19 17:00:15 -04:00
continue