import sys from insel.insel import Insel from pathlib import Path from helpers.enrich_city import EnrichCity 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 imports.geometry.helpers.geometry_helper import GeometryHelper from city_model_structure.city import City 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 / 'libs' / 'data' / 'weather').resolve() keep_sra_file = True keep_insel_file = True keep_weather_file = True keep_ig_file = True pickle_geometry = True pickle_weather = False pickle_construction = False pickle_usage = False pickle_schedules = False pickle_file = 'tests/tests_data/one_building_in_kelowna.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 = 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) 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