From fa4371a1bd37cf3f34ab79aa2b3f8286d7699548 Mon Sep 17 00:00:00 2001 From: David Paul Jansen Date: Tue, 14 Jan 2025 16:29:42 +0100 Subject: [PATCH 1/2] fix default parameters for calc_building_parameter class and add tests for it --- teaser/logic/buildingobjects/building.py | 36 +++++++--- tests/test_data.py | 85 ++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 11 deletions(-) diff --git a/teaser/logic/buildingobjects/building.py b/teaser/logic/buildingobjects/building.py index 9bc04ed7d..9ec1625a0 100644 --- a/teaser/logic/buildingobjects/building.py +++ b/teaser/logic/buildingobjects/building.py @@ -368,7 +368,10 @@ def fill_window_area_dict(self): self.window_area[key] = self.get_window_area(key) def calc_building_parameter( - self, number_of_elements=2, merge_windows=False, used_library="AixLib" + self, + number_of_elements=None, + merge_windows=None, + used_library=None ): """calc all building parameters @@ -378,19 +381,30 @@ def calc_building_parameter( Parameters ---------- - number_of_elements : int + number_of_elements : int, optional defines the number of elements, that area aggregated, between 1 - and 4, default is 2 - merge_windows : bool + and 4. If None, uses existing class property + merge_windows : bool, optional True for merging the windows into the outer walls, False for - separate resistance for window, default is False - used_library : str - used library (AixLib and IBPSA are supported) + separate resistance for window. If None, uses existing class + property + used_library : str, optional + used library (AixLib and IBPSA are supported). If None, uses + existing class property """ - - self._number_of_elements_calc = number_of_elements - self._merge_windows_calc = merge_windows - self._used_library_calc = used_library + # Use provided values or fall back to existing class properties + number_of_elements = ( + number_of_elements if number_of_elements is not None + else self._number_of_elements_calc) + merge_windows = (merge_windows if merge_windows is not None + else self._merge_windows_calc) + used_library = used_library if used_library is not None else ( + self._used_library_calc) + + # Update class properties with the values being used + self.number_of_elements_calc = number_of_elements + self.merge_windows_calc = merge_windows + self.used_library_calc = used_library self.area_rt = 0 self.area_gf = 0 diff --git a/tests/test_data.py b/tests/test_data.py index 7329e2ac6..9cc6b73dc 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -4,6 +4,9 @@ @author: TEASER 4 Development Team """ from teaser.logic import utilities +from teaser.logic.buildingobjects.calculation.four_element import FourElement +from teaser.logic.buildingobjects.calculation.three_element import ThreeElement +from teaser.logic.buildingobjects.calculation.two_element import TwoElement from teaser.project import Project from teaser.data.utilities import ConstructionData from teaser.data.dataclass import DataClass @@ -15,10 +18,12 @@ prj = Project(False) prj.data = DataClass(construction_data=ConstructionData.iwu_heavy) + class Test_teaser(object): """Unit Tests for TEASER""" global prj + def test_calc_vdi_room1(self): """Parameter Verification for rouvel room1""" import teaser.examples.verification.verification_VDI_6007_room1 as room1 @@ -625,6 +630,86 @@ def test_calc_all_buildings(self): prj.used_library_calc = "AixLib" prj.calc_all_buildings(raise_errors=True) + def test_number_of_elements_propagation(self): + """Tests propagation of changes in number_of_elements_calc""" + + helptest.building_test2(prj) + prj.number_of_elements_calc = 2 + prj.merge_windows_calc = False + prj.used_library_calc = "AixLib" + prj.calc_all_buildings(raise_errors=True) + + assert prj.number_of_elements_calc == 2 + bldg = prj.buildings[-1] + assert bldg.number_of_elements_calc == 2 + tz = bldg.thermal_zones[0] + assert isinstance(tz.model_attr, TwoElement) + assert not hasattr(tz.model_attr, 'area_gf') + assert not hasattr(tz.model_attr, 'area_rt') + + prj.number_of_elements_calc = 3 + prj.calc_all_buildings(raise_errors=True) + + assert prj.number_of_elements_calc == 3 + bldg = prj.buildings[-1] + assert bldg.number_of_elements_calc == 3 + tz = bldg.thermal_zones[0] + assert isinstance(tz.model_attr, ThreeElement) + assert tz.model_attr.area_gf == 140.0 + assert not hasattr(tz.model_attr, 'area_rt') + + prj.number_of_elements_calc = 4 + prj.calc_all_buildings(raise_errors=True) + + assert prj.number_of_elements_calc == 4 + bldg = prj.buildings[-1] + assert bldg.number_of_elements_calc == 4 + tz = bldg.thermal_zones[0] + assert isinstance(tz.model_attr, FourElement) + assert tz.model_attr.area_rt == 140.0 + assert tz.model_attr.area_gf == 140.0 + + def test_calc_building_parameter(self): + """Check that calc_building_parameter() not overwrites prj settings""" + helptest.building_test2(prj) + prj.number_of_elements_calc = 2 + prj.merge_windows_calc = False + prj.used_library_calc = "AixLib" + prj.calc_all_buildings(raise_errors=True) + + assert prj.number_of_elements_calc == 2 + bldg = prj.buildings[-1] + assert bldg.number_of_elements_calc == 2 + bldg.calc_building_parameter() + tz = bldg.thermal_zones[0] + assert isinstance(tz.model_attr, TwoElement) + assert not hasattr(tz.model_attr, 'area_gf') + assert not hasattr(tz.model_attr, 'area_rt') + + prj.number_of_elements_calc = 3 + prj.calc_all_buildings(raise_errors=True) + + assert prj.number_of_elements_calc == 3 + bldg = prj.buildings[-1] + assert bldg.number_of_elements_calc == 3 + bldg.calc_building_parameter() + tz = bldg.thermal_zones[0] + assert isinstance(tz.model_attr, ThreeElement) + assert tz.model_attr.area_gf == 140.0 + assert not hasattr(tz.model_attr, 'area_rt') + + prj.number_of_elements_calc = 4 + prj.calc_all_buildings(raise_errors=True) + + assert prj.number_of_elements_calc == 4 + bldg = prj.buildings[-1] + assert bldg.number_of_elements_calc == 4 + bldg.calc_building_parameter() + tz = bldg.thermal_zones[0] + assert isinstance(tz.model_attr, FourElement) + assert tz.model_attr.area_rt == 140.0 + assert tz.model_attr.area_gf == 140.0 + def test_retrofit_all_buildings(self): """test of retrofit_all_buildings, no calculation verification""" prj.add_residential( From 473fdf452bb70d895c95dea82a82e34ba80e4732 Mon Sep 17 00:00:00 2001 From: David Paul Jansen Date: Tue, 14 Jan 2025 17:04:28 +0100 Subject: [PATCH 2/2] raise version due to hotfix --- teaser/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/teaser/__init__.py b/teaser/__init__.py index 44a0fb927..b5d9c4a85 100644 --- a/teaser/__init__.py +++ b/teaser/__init__.py @@ -7,7 +7,7 @@ import sys import os -__version__ = "1.1.1" +__version__ = "1.1.2" new_path = os.path.join(os.path.expanduser('~'), ("TEASEROutput"))