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 = 'LoD1_EVBuilding.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 = False 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 path = (example_path / 'tests').resolve() radius = 80 building = city.city_object('97d96d14-82a7-4bf7-9147-d3b304700b4c') # 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: building.function = 'large office' 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 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