From e6d290385d60371903095dc8cbff310375f7d58e Mon Sep 17 00:00:00 2001 From: Pilar Date: Thu, 12 Aug 2021 11:08:28 -0400 Subject: [PATCH] Added a parameter in building.py to specifically decide whether dividing the building in storeys or not. By default, False. --- .../thermal_demand_dynamic_simulation.py | 63 +++++++++---------- main.py | 49 ++++----------- 2 files changed, 42 insertions(+), 70 deletions(-) diff --git a/insel/templates/thermal_demand_dynamic_simulation.py b/insel/templates/thermal_demand_dynamic_simulation.py index 09e9f7c..642f878 100644 --- a/insel/templates/thermal_demand_dynamic_simulation.py +++ b/insel/templates/thermal_demand_dynamic_simulation.py @@ -3,7 +3,9 @@ from insel.insel import Insel class ThermalDemandDynamicSimulation: @staticmethod - def generate_thermal_dynamic_template(city_object, outputs_paths, weather_path, ig_path, simulation_period): + def generate_thermal_dynamic_template(building, outputs_paths, weather_path, ig_path, simulation_period): + number_usage_zones = len(building.usage_zones) + file = "" file += "%Thermal Demand Dynamic Calculation\r\n" file += "%by Pilar Monsalvete Alvarez de Uribarri\r\n" @@ -57,7 +59,8 @@ class ThermalDemandDynamicSimulation: # weather blocks i_block += 1 n_weather = i_block - # todo: n_records is the number of columns to be read in the weather file + # todo: n_records is the number of columns to be read in the weather file -> + # it should be = number of external surfaces n_records = 1000 inputs = [str(n_hoy) + ".1"] parameters = [str(n_records) + " %[Nrec]", @@ -69,7 +72,7 @@ class ThermalDemandDynamicSimulation: # internal gains and control blocks i_block += 1 n_ig = i_block - n_records = len(city_object.usage_zones) * 5 + n_records = number_usage_zones * 5 inputs = [str(n_hoy) + ".1"] parameters = [str(n_records) + " %[Nrec]", str(n_records * 12) + " %[RecLen]", @@ -84,16 +87,14 @@ class ThermalDemandDynamicSimulation: str(n_clock) + ".3", str(n_clock) + ".4"] headline = '' - for i in range(0, len(city_object.usage_zones)): + for i in range(0, number_usage_zones): inputs.append(str(i_block+2) + "." + str(i*2+2)) inputs.append(str(i_block+2) + "." + str(i*2+3)) headline += "CoolingTZ_" + str(i+1) + " (Wh); " + "HeatingTZ_" + str(i+1) + " (Wh); " parameters = ["1 %[Mode]", - "0 %[Suppress FNQ inputs]", - #"2 %[Semicolon sep]", "'" + str(outputs_paths) + "_demand.out' %[FileName]", - "'*' %[FileFormat]"] - #"'Year; month; day; hour; " + headline + "' %[Headline]"] + "'*' %[FileFormat]", + f"'Year; month; day; hour; {headline}' %[Headline]"] file = Insel.add_block(file, i_block, 'WRITE', inputs, parameters) i_block += 1 @@ -102,41 +103,39 @@ class ThermalDemandDynamicSimulation: str(n_clock) + ".3", str(n_clock) + ".4"] headline = '' - for i in range(0, len(city_object.usage_zones)): + for i in range(0, number_usage_zones): inputs.append(str(i_block+2) + "." + str(i+2)) headline += "TempTZ_" + str(i+1) + " (C); " parameters = ["1 %[Mode]", - "0 %[Suppress FNQ inputs]", - #"2 %[Semicolon sep]", "'" + str(outputs_paths) + "_temp.out' %[FileName]", - "'*' %[FileFormat]"] - #"'Year; month; day; hour; " + headline + "' %[Headline]"] + "'*' %[FileFormat]", + f"'Year; month; day; hour; {headline}' %[Headline]"] file = Insel.add_block(file, i_block, 'WRITE', inputs, parameters) # todo: NDelayRoom[usage_zone] = NDelayRoom[usage_zone-1] + 2/(10 surfaces) being surface = any wall or window + 2/window - NDelayRoom = [1] + NDelayRoom = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] i_block += 1 inputs = [str(n_hoy) + ".1"] - for i in range(0, len(city_object.usage_zones)): - inputs.append(str(i * 7 + NDelayRoom[i] + n_ig + 8 + 2*len(city_object.usage_zones)) + ".2") - inputs.append(str(i * 7 + NDelayRoom[i] + n_ig + 8 + 2*len(city_object.usage_zones)) + ".3") + for i in range(0, number_usage_zones): + inputs.append(str(i * 7 + NDelayRoom[i] + n_ig + 8 + 2 * number_usage_zones) + ".2") + inputs.append(str(i * 7 + NDelayRoom[i] + n_ig + 8 + 2 * number_usage_zones) + ".3") file = Insel.add_block(file, i_block, 'AVEC', inputs) i_block += 1 inputs = [str(n_hoy) + ".1"] - for i in range(0, len(city_object.usage_zones)): - inputs.append(str(i * 7 + NDelayRoom[i] + n_ig + 8 + 2 * len(city_object.usage_zones)) + ".1") + for i in range(0, number_usage_zones): + inputs.append(str(i * 7 + NDelayRoom[i] + n_ig + 8 + 2 * number_usage_zones) + ".1") file = Insel.add_block(file, i_block, 'AVEC', inputs) i_block += 1 n_cumc = i_block inputs = [str(n_clock) + ".2"] - for i in range(0, len(city_object.usage_zones)): + for i in range(0, number_usage_zones): inputs.append(str(i_block - 2) + "." + str(2*i+2)) inputs.append(str(i_block - 2) + "." + str(2*i+3)) file = Insel.add_block(file, i_block, 'CUMC', inputs) - for i in range(0, len(city_object.usage_zones)): + for i in range(0, number_usage_zones): i_block += 1 inputs = [str(n_cumc) + "." + str(2*i+2), str(i_block - 2) + "." + str(2*i+3)] @@ -150,30 +149,25 @@ class ThermalDemandDynamicSimulation: i_block += 1 inputs = [str(n_clock) + ".1", str(n_clock) + ".2"] - headline = '' - for i in range(0, len(city_object.usage_zones)): - inputs.append(str(i_block-2*len(city_object.usage_zones)+2*i+1) + ".1") - headline += "CoolingTZ_" + str(i + 1) + " (Wh); " + "HeatingTZ_" + str(i + 1) + " (Wh); " + for i in range(0, number_usage_zones): + inputs.append(str(i_block - 2 * number_usage_zones + 2 * i + 1) + ".1") parameters = ["1 %[Mode]", - "0 %[Suppress FNQ inputs]", - #"2 %[Semicolon sep]", "'" + str(outputs_paths) + "_month.out' %[FileName]", - "'*' %[FileFormat]"] - #"'Year; month; day; hour; " + headline + "' %[Headline]"] + "'*' %[FileFormat]", + f"'Total heated area: {building.floor_area} (m2)' %[Headline]"] file = Insel.add_block(file, i_block, 'WRITE', inputs, parameters) # Zero constant for different uses i_block += 1 n_zero = i_block parameters = ["0 %[ZeroConst]"] - file = Insel.add_block(file, i_block, 'WRITE', parameters=parameters) + file = Insel.add_block(file, i_block, 'CONST', parameters=parameters) - print(file) # Zones: n_start_zones = i_block n_zone = [] i_zone = 0 - for usage_zone in city_object.usage_zones: + for usage_zone in building.usage_zones: i_block += 1 n_zone.append(i_block) inputs = [str(n_gain_moy) + ".1", @@ -187,7 +181,8 @@ class ThermalDemandDynamicSimulation: str(n_weather) + ".1", # ventilation temperature str(n_zone[i_zone] + 4) + ".1", # from chs ] - parameters = [usage_zone.gross_volume + " %[RoomAirVol]", + print('usage_zone has no sense here!!!') + parameters = [usage_zone.volume + " %[RoomAirVol]", usage_zone.initial_temperature + " %[Tini]", usage_zone.cooling_on + " %[CSOn]", usage_zone.cooling_maximum_power + " %[CPMax]", @@ -196,6 +191,7 @@ class ThermalDemandDynamicSimulation: usage_zone.thermal_bridges + " %[TBridges]", usage_zone.n_surfaces + " %[Nwalls+Nwindow]" ] + print('aaaaa') for surface in usage_zone.surfaces: parameters.append(str(surface.area) + " " + str(surface.interior_covective_coefficient) + " %[Area] + [ConvCoefi]") file = Insel.add_block(file, i_block, 'UBROOMV2', inputs, parameters) @@ -416,5 +412,6 @@ class ThermalDemandDynamicSimulation: # myInselModel.add(Integer.toString(numZero) + ".1"); //If there is no windows, conected to const = 0 # } # } + print(file) i_zone += 1 return file diff --git a/main.py b/main.py index dcc7791..f52e227 100644 --- a/main.py +++ b/main.py @@ -10,9 +10,6 @@ import helpers.constants as cte from imports.geometry_factory import GeometryFactory from imports.geometry.helpers.geometry_helper import GeometryHelper from city_model_structure.city import City -from city_model_structure.building import Building -from city_model_structure.attributes.polygon import Polygon -from city_model_structure.attributes.surface import Surface name_gml = 'one_building_in_kelowna.gml' function_format = 'hft' @@ -28,38 +25,17 @@ 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_files = False -pickle_created = False +pickle_created = True pickle_file = 'tests/tests_data/one_building_in_kelowna.pickle' -# todo: simplification of the data model - if not pickle_created: city = GeometryFactory('citygml', full_path_gml).city - # Building division by storey - for building in city.buildings: - building.average_storey_height = 1.5 - building.storeys_above_ground = 2 - storeys = building.storeys - - if len(storeys) != len(building.thermal_zones): - # todo:assign one thermal zone per storey - for storey in storeys: - surfaces = [] - for face in storey.faces: - # todo: review for obj with windows - points = [] - for vertex_index in face: - points.append(storey.vertices[vertex_index]) - solid_polygon = Polygon(points) - perimeter_polygon = solid_polygon - surface = Surface(solid_polygon, perimeter_polygon) - surfaces.append(surface) - 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() + for building in city.buildings: if cte.HOUR not in building.external_temperature: print('No external temperature found') @@ -82,13 +58,13 @@ if not pickle_created: else: sra.call_sra(weather_format, keep_files=keep_files) sra.set_irradiance_surfaces(city, mode=1) - # print(city.buildings[0].surfaces[1].global_irradiance['hour'].sra) for building in city.buildings: 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) city.save(pickle_file) @@ -97,19 +73,18 @@ else: # todo: when the enrichment step goes after SRA, check whether srw has changed # after reading the construction library or not -quit() - # Demand calculation (one model per building) -for city_object in city.city_objects: - full_path_out = (outputs_path / city_object.name).resolve() - full_path_wea = (tmp_path / (city_object.name + '.weather')).resolve() - full_path_ig = (tmp_path / (city_object.name + '.ig')).resolve() +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() - insel_file_name = city_object.name + '.insel' + insel_file_name = building.name + '.insel' try: - content = Templates.generate_thermal_dynamic_template(city_object, full_path_out, full_path_wea, full_path_ig, Sp) - insel = Insel(example_path, insel_file_name, content, mode=2, keep_files=keep_files).results + content = Templates.generate_thermal_dynamic_template(building, full_path_out, full_path_wea, full_path_ig, Sp) + print(content) + #insel = Insel(example_path, insel_file_name, content, mode=2, keep_files=keep_files).results except: print(sys.exc_info()[1]) - print('Building ' + city_object.name + ' could not be processed') + print('Building ' + building.name + ' could not be processed') continue