mirror of
https://rs-loy-gitlab.concordia.ca/PMAU/DynamicBuildingSimulation.git
synced 2024-11-14 15:00:29 -05:00
151 lines
5.7 KiB
Python
151 lines
5.7 KiB
Python
import sys
|
|
from insel.insel import Insel
|
|
from pathlib import Path
|
|
from simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
|
|
from imports.weather_factory import WeatherFactory
|
|
from insel.templates.thermal_demand_dynamic_simulation import ThermalDemandDynamicSimulation as Templates
|
|
from helpers.simulation_parameters import SimulationParameters as Sp
|
|
from imports.geometry_factory import GeometryFactory
|
|
from city_model_structure.city import City
|
|
from imports.construction_factory import ConstructionFactory
|
|
from imports.usage_factory import UsageFactory
|
|
from helpers.dictionaries import Dictionaries
|
|
|
|
name_gml = 'one_building_in_kelowna.gml'
|
|
function_format = 'hft'
|
|
construction_format = 'nrel'
|
|
usage_format = 'comnet'
|
|
schedules_format = 'comnet'
|
|
climate_reference_city = 'Montreal'
|
|
weather_file_name = 'CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw'
|
|
|
|
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 / 'hub' / 'data' / 'weather').resolve()
|
|
keep_sra_file = True
|
|
keep_insel_file = True
|
|
keep_weather_file = True
|
|
keep_ig_file = True
|
|
|
|
pickle_geometry = False
|
|
pickle_weather = False
|
|
pickle_construction = False
|
|
pickle_usage = False
|
|
pickle_schedules = False
|
|
pickle_file = 'tests/tests_data/dompark.pickle'
|
|
|
|
# Load geometry
|
|
if not pickle_geometry:
|
|
city = GeometryFactory('citygml', full_path_gml).city
|
|
city.save(pickle_file)
|
|
else:
|
|
city = City.load(pickle_file)
|
|
|
|
# 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
|
|
max_buildings_handled_by_sra = 100
|
|
path = (example_path / 'tests').resolve()
|
|
total_number_of_buildings = len(city.buildings)
|
|
if total_number_of_buildings > max_buildings_handled_by_sra:
|
|
sys.stderr.write(f'{max_buildings_handled_by_sra} buildings are too many buildings to be simulated. '
|
|
'The workflow does not handle more that 100 at a time')
|
|
else:
|
|
sra = SimplifiedRadiosityAlgorithm(city, path, weather_file_name)
|
|
sra.call_sra(weather_format, keep_files=keep_sra_file)
|
|
sra.set_irradiance_surfaces(city)
|
|
sra.set_irradiance_surfaces(city, mode=1)
|
|
|
|
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:
|
|
building.function = 'residential'
|
|
building.year_of_construction = 2010
|
|
|
|
if function_format == 'hft':
|
|
building.function = Dictionaries().hft_function_to_hub_function[building.function]
|
|
elif function_format == 'pluto':
|
|
building.function = Dictionaries().pluto_function_to_hub_function[building.function]
|
|
ConstructionFactory(construction_format, city).enrich()
|
|
UsageFactory(usage_format, city).enrich()
|
|
|
|
city.save(pickle_file)
|
|
else:
|
|
city = City.load(pickle_file)
|
|
|
|
# Assign user defined parameters
|
|
if not pickle_geometry:
|
|
for building in city.buildings:
|
|
print(len(building.storeys))
|
|
print(building.storeys[0].thermal_boundaries)
|
|
print(building.storeys[0].thermal_zone)
|
|
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)
|
|
for thermal_zone in thermal_boundary.thermal_zones:
|
|
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)
|
|
for tz in thermal_boundary.thermal_zones:
|
|
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()
|
|
|
|
for building in city.buildings:
|
|
building.heated = True
|
|
building.cooled = True
|
|
building.attic_heated = 2
|
|
building.basement_heated = 0
|
|
|
|
# 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())
|
|
|
|
insel_file_name = building.name + '.insel'
|
|
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:
|
|
print(sys.exc_info()[1])
|
|
print('Building ' + building.name + ' could not be processed')
|
|
continue
|