From ab42ea4ac42f3cbe32c018a7ddc887e217836909 Mon Sep 17 00:00:00 2001 From: Guille Date: Wed, 21 Oct 2020 15:23:06 -0400 Subject: [PATCH] Add idf base class corrections and test files --- city_model_structure/building.py | 1 + helpers/{IDF.py => idf.py} | 27 +++++++++++-------- tests/test_idf.py | 46 ++++++++++++++++++++++++++++++++ tests_data/buildings.gml | 8 +----- 4 files changed, 64 insertions(+), 18 deletions(-) rename helpers/{IDF.py => idf.py} (66%) create mode 100644 tests/test_idf.py diff --git a/city_model_structure/building.py b/city_model_structure/building.py index f2f751ff..b942fcbd 100644 --- a/city_model_structure/building.py +++ b/city_model_structure/building.py @@ -20,6 +20,7 @@ from city_model_structure.city_object import CityObject from city_model_structure.building_unit import BuildingUnit from city_model_structure.schedule_value import ScheduleValue + class Building(CityObject): """ Building(CityObject) class diff --git a/helpers/IDF.py b/helpers/idf.py similarity index 66% rename from helpers/IDF.py rename to helpers/idf.py index 5c2d71b8..a73ff238 100644 --- a/helpers/IDF.py +++ b/helpers/idf.py @@ -1,37 +1,42 @@ +""" +TestOccupancyFactory test and validate the city model structure occupancy parameters +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2020 Project Author Sourush .... +""" from geomeppy import IDF -import matplotlib.pyplot as plt import esoreader +from pathlib import Path -class IDF: +class Idf: def __init__(self, idf_file_path, idd_file_path, epw_file_path, eso_file_path): self._idd_file_path = str(idd_file_path) self._idf_file_path = str(idf_file_path) self._epw_file_path = str(epw_file_path) self._eso_file_path = str(eso_file_path) - self._idf=IDF(idf_file_path) - self._IDF.setiddname(idd_file_path) - self._idf.epw=epw_file_path + IDF.setiddname(idd_file_path) + self._idf = IDF(idf_file_path) + self._idf.epw = epw_file_path self._eso_file_path = str((Path.cwd() / 'eplusout.eso').resolve()) - def add_zone(self, building_name): - self._idf.newidfobject('ZONE', Name=building_name, Ceiling_Height='autocalculate', Volume='autocalculate',Floor_Area='autocalculate',Part_of_Total_Floor_Area='yes',) - + IDF.newidfobject('ZONE', Name=building_name, Ceiling_Height='autocalculate', Volume='autocalculate', + Floor_Area='autocalculate', Part_of_Total_Floor_Area='yes',) def add_surface(self, surface, building_name): - self._idf.newidfobject('BUILDINGSURFACE:DETAILED', Name=surface.name, Surface_Type = surface.type, Zone_Name=building_name,) + self._idf.newidfobject('BUILDINGSURFACE:DETAILED', Name=surface.name, Surface_Type = surface.type, + Zone_Name=building_name,) self.wall.setcoords(surface.points_list.toList()) - def run(self,window_ratio=0.35): + def run(self, window_ratio=0.35): self._idf.set_default_constructions() self._idf.intersect_match() self._idf.set_wwr(window_ratio) self._idf.translate_to_origin() self._idf.view_model() self._idf.newidfobject("HVACTEMPLATE:THERMOSTAT", Name="Zone Stat", Constant_Heating_Setpoint=20, Constant_Cooling_Setpoint=24,) - for zone in idf.idfobjects["ZONE"]: + for zone in self._idf.idfobjects["ZONE"]: self._idf.newidfobject("HVACTEMPLATE:ZONE:IDEALLOADSAIRSYSTEM", Zone_Name=zone.Name, Template_Thermostat_Name=stat.Name, Outdoor_Air_Method="DetailedSpecification",) # Run self._idf.run() diff --git a/tests/test_idf.py b/tests/test_idf.py new file mode 100644 index 00000000..dbd68197 --- /dev/null +++ b/tests/test_idf.py @@ -0,0 +1,46 @@ +""" +TestOccupancyFactory test and validate the city model structure occupancy parameters +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca +""" +import os +from pathlib import Path +from unittest import TestCase + +from geometry.geometry_factory import GeometryFactory +from helpers.idf import Idf + + +class TestIdf(TestCase): + """ + Test IDF Class + """ + + def setUp(self) -> None: + """ + Test setup + :return: None + """ + self._city_gml = None + self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve() + + def _get_citygml(self): + if self._city_gml is None: + file_path = (self._example_path / 'buildings.gml').resolve() + self._city_gml = GeometryFactory('citygml', file_path).city + self.assertIsNotNone(self._city_gml, 'city is none') + return self._city_gml + + def test_idf_run(self): + idd_file_path = (self._example_path / 'energy+.idd').resolve() + idf_file_path = (self._example_path / 'minimal.idf').resolve() + epw_file_path = (self._example_path / 'montreal.epw').resolve() + _idf = Idf(idf_file_path, idd_file_path, epw_file_path, self._example_path) + city = self._get_citygml() + for building in city.buildings: + _idf.add_zone(building.name) + for surface in building.surfaces: + _idf.add_surface(surface, building.name) + + _idf.run() + diff --git a/tests_data/buildings.gml b/tests_data/buildings.gml index c6097031..76dbe975 100644 --- a/tests_data/buildings.gml +++ b/tests_data/buildings.gml @@ -425,12 +425,6 @@ - - 2045 - - - C1 - @@ -620,7 +614,7 @@ 2045 - I1 + C1