From 7772d807dcb262b936876ecba74e061e0ef7f7fa Mon Sep 17 00:00:00 2001 From: guille Date: Thu, 12 Aug 2021 11:58:24 -0400 Subject: [PATCH] correct idf factory --- exports/exports_factory.py | 11 +++- exports/formats/idf.py | 55 ++++++++++--------- imports/construction/ca_physics_parameters.py | 2 + imports/construction_factory.py | 7 +++ imports/geometry/citygml.py | 1 - non_functional_tests/tests_data/C40_Final.gml | 20 +++---- 6 files changed, 57 insertions(+), 39 deletions(-) diff --git a/exports/exports_factory.py b/exports/exports_factory.py index 0f386d37..205f087d 100644 --- a/exports/exports_factory.py +++ b/exports/exports_factory.py @@ -67,9 +67,8 @@ class ExportsFactory: Export the city to Energy+ idf format :return: """ - # todo: this need to be generalized - data_path = Path('../libs_Final/tests/tests_data').resolve() - return Idf(self._city, self._path, (data_path / f'minimal.idf').resolve(), (data_path / f'energy+.idd').resolve(), + data_path = (Path(__file__).parent / '../tests/tests_data/').resolve() + Idf(self._city, self._path, (data_path / f'minimal.idf').resolve(), (data_path / f'energy+.idd').resolve(), (data_path / f'montreal.epw').resolve()) @property @@ -83,3 +82,9 @@ class ExportsFactory: """ return getattr(self, self._export_type, lambda: None) + def _debug_export(self): + """ + Export the city model structure to the given export type + :return: None + """ + self._idf() diff --git a/exports/formats/idf.py b/exports/formats/idf.py index f4c40893..335d453c 100644 --- a/exports/formats/idf.py +++ b/exports/formats/idf.py @@ -5,6 +5,8 @@ Copyright © 2020 Project Author Soroush Samareh Abolhassani - soroush.samarehab """ from geomeppy import IDF from pathlib import Path + + class Idf: _THERMOSTAT = 'HVACTEMPLATE:THERMOSTAT' _IDEAL_LOAD_AIR_SYSTEM = 'HVACTEMPLATE:ZONE:IDEALLOADSAIRSYSTEM' @@ -32,10 +34,10 @@ class Idf: 'residential': 'residential_building' } - def __init__(self, city, output_path, idf_file_path, idd_file_path, epw_file_path): + def __init__(self, city, output_path, idf_file_path, idd_file_path, epw_file_path, export_type="Surfaces"): self._city = city self._output_path = str(output_path.resolve()) - print(self._output_path) + self._export_type = export_type self._idd_file_path = str(idd_file_path) self._idf_file_path = str(idf_file_path) self._epw_file_path = str(epw_file_path) @@ -43,21 +45,21 @@ class Idf: self._idf = IDF(self._idf_file_path, self._epw_file_path) self._export() - @staticmethod - def _matrix_to_list(points): - points_list = [] - for point in points: - point_tuple = (point[0], point[1], point[2]) - points_list.append(point_tuple) - return points_list + @staticmethod + def _matrix_to_list(points): + points_list = [] + for point in points: + point_tuple = (point[0], point[1], point[2]) + points_list.append(point_tuple) + return points_list - @staticmethod - def _matrix_to_2d_list(points): - points_list = [] - for point in points: - point_tuple = (point[0], point[1]) - points_list.append(point_tuple) - return points_list + @staticmethod + def _matrix_to_2d_list(points): + points_list = [] + for point in points: + point_tuple = (point[0], point[1]) + points_list.append(point_tuple) + return points_list def _add_material(self, layer): for material in self._idf.idfobjects[self._MATERIAL]: @@ -125,7 +127,12 @@ class Idf: for construction in self._idf.idfobjects[self._CONSTRUCTION]: if construction.Name == thermal_boundary.construction_name: return - + if thermal_boundary.layers is None: + for material in self._idf.idfobjects[self._MATERIAL]: + if material.Name == "DefaultMaterial": + return + self._idf.set_default_constructions() + return for layer in thermal_boundary.layers: self._add_material(layer) layers = thermal_boundary.layers @@ -194,28 +201,26 @@ class Idf: Velocity_Squared_Term_Coefficient=0.0000000E+00 # todo: change it from usage catalog ) - def _export(self, export_type="Surfaces"): + def _export(self): """ Export the idf file into the given path export type = "Surfaces|Block" """ - print("called") for building in self._city.buildings: - print('add building') for usage_zone in building.usage_zones: self._add_schedule(usage_zone, "Infiltration") self._add_schedule(usage_zone, "Lights") self._add_schedule(usage_zone, "Occupancy") self._add_zone(usage_zone) self._add_heating_system(usage_zone) - self._add_construction(usage_zone) - print('zone construction') - print('add surfaces') - if export_type == "Surfaces": + for thermal_zone in building.thermal_zones: + for thermal_boundary in thermal_zone.bounded: + self._add_construction(thermal_boundary) + + if self._export_type == "Surfaces": self._add_surfaces(building) else: self._add_block(building) - print(' =out path', str(self._output_path)) self._idf.saveas(str(self._output_path)) def _add_block(self, building): diff --git a/imports/construction/ca_physics_parameters.py b/imports/construction/ca_physics_parameters.py index de0d7db3..13cad8b7 100644 --- a/imports/construction/ca_physics_parameters.py +++ b/imports/construction/ca_physics_parameters.py @@ -7,6 +7,8 @@ import sys from imports.construction.nrel_physics_interface import NrelPhysicsInterface from imports.construction.helpers.construction_helper import ConstructionHelper +from city_model_structure.building_demand.layer import Layer +from city_model_structure.building_demand.material import Material class CaPhysicsParameters(NrelPhysicsInterface): diff --git a/imports/construction_factory.py b/imports/construction_factory.py index 33b769a7..186710ad 100644 --- a/imports/construction_factory.py +++ b/imports/construction_factory.py @@ -32,3 +32,10 @@ class ConstructionFactory: :return: None """ getattr(self, self._handler, lambda: None)() + + def _enrich_debug(self): + """ + Enrich the city with the construction information + :return: None + """ + self._nrcan() diff --git a/imports/geometry/citygml.py b/imports/geometry/citygml.py index f6d170bb..cbc23a6d 100644 --- a/imports/geometry/citygml.py +++ b/imports/geometry/citygml.py @@ -90,7 +90,6 @@ class CityGml: building_parts = [] for part in city_object['consistsOfBuildingPart']: building = self._create_building(part['BuildingPart']) - print(f'add city building part {building.name}') self._city.add_city_object(building) building_parts.append(building) return PartsConsistingBuilding(name, building_parts) diff --git a/non_functional_tests/tests_data/C40_Final.gml b/non_functional_tests/tests_data/C40_Final.gml index 8c992c3d..34126bd7 100644 --- a/non_functional_tests/tests_data/C40_Final.gml +++ b/non_functional_tests/tests_data/C40_Final.gml @@ -11,7 +11,7 @@ residential -2020 +1996 12.822875976562045 2 4.5 @@ -136,7 +136,7 @@ residential -2020 +1996 17.09716796875 2 6 @@ -261,7 +261,7 @@ residential -2020 +1996 6.411376953125 1 4.5 @@ -674,7 +674,7 @@ residential -2020 +1996 6.411376953125 1 4.5 @@ -943,7 +943,7 @@ residential -2020 +1996 6.411437988281023 1 4.5 @@ -1068,7 +1068,7 @@ residential -2020 +1996 6.411376953125 1 4.5 @@ -1197,7 +1197,7 @@ residential -2020 +1996 14.532531738281023 3 3.4 @@ -1880,7 +1880,7 @@ residential -2020 +1996 7.002624511718977 1 5 @@ -2081,7 +2081,7 @@ residential -2020 +1996 24.220886230468977 5 3.4 @@ -3106,7 +3106,7 @@ residential -2020 +1996 7.002685546875 1 5