From d7b24eba41133ccc0b89af71d694b20e353a771f Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 5 Jun 2020 12:24:03 -0400 Subject: [PATCH] move assumptions into configuration.ini --- city_model_structure/thermal_boundary.py | 6 +++--- city_model_structure/thermal_opening.py | 8 ++++---- config/configuration.ini | 7 +++++++ helpers/assumptions.py | 9 --------- helpers/configuration.py | 22 ++++++++++++++++++++++ tests/test_physics_factory.py | 19 ++++++++++++++++++- 6 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 config/configuration.ini delete mode 100644 helpers/assumptions.py create mode 100644 helpers/configuration.py diff --git a/city_model_structure/thermal_boundary.py b/city_model_structure/thermal_boundary.py index 2c7e62fc..552e664a 100644 --- a/city_model_structure/thermal_boundary.py +++ b/city_model_structure/thermal_boundary.py @@ -1,7 +1,7 @@ from city_model_structure.thermal_opening import ThermalOpening from city_model_structure.surface import Surface from city_model_structure.layer import Layer -import helpers.assumptions as assumptions +from helpers.configuration import Configuration from typing import List @@ -108,8 +108,8 @@ class ThermalBoundary: @property def u_value(self): if self._u_value is None: - h_i = assumptions.h_i - h_e = assumptions.h_e + h_i = Configuration().h_i + h_e = Configuration().h_e r_value = 1.0/h_i + 1.0/h_e try: for layer in self.layers: diff --git a/city_model_structure/thermal_opening.py b/city_model_structure/thermal_opening.py index f4072afc..159aee9d 100644 --- a/city_model_structure/thermal_opening.py +++ b/city_model_structure/thermal_opening.py @@ -1,4 +1,4 @@ -import helpers.assumptions as assumptions +from helpers.configuration import Configuration class ThermalOpening: @@ -6,7 +6,7 @@ class ThermalOpening: self._area = None self._openable_ratio = None self._conductivity_w_mk = None - self._frame_ratio = assumptions.frame_ratio + self._frame_ratio = Configuration().frame_ratio self._g_value = None self._thickness_m = None self._inside_reflectance = None @@ -81,8 +81,8 @@ class ThermalOpening: def u_value(self): if self._u_value is None: try: - h_i = assumptions.h_i - h_e = assumptions.h_e + h_i = Configuration().h_i + h_e = Configuration().h_e r_value = 1 / h_i + 1 / h_e + float(self.conductivity_w_mk) / float(self.thickness_m) self._u_value = 1 / r_value except TypeError: diff --git a/config/configuration.ini b/config/configuration.ini new file mode 100644 index 00000000..dc0e7b11 --- /dev/null +++ b/config/configuration.ini @@ -0,0 +1,7 @@ +# These values are intended as configurable assumptions +[convective_fluxes] +h_i = 10 # W/m2K +h_e = 25 # W/m2K + +[windows] +frame_ratio = 0 diff --git a/helpers/assumptions.py b/helpers/assumptions.py deleted file mode 100644 index 13115d60..00000000 --- a/helpers/assumptions.py +++ /dev/null @@ -1,9 +0,0 @@ -# These values are intended as configurable assumptions -# ToDo: these values need to be changed into configurable parameters - -# convective fluxes -h_i = 10 # W/m2K -h_e = 25 # W/m2K - -# windows' default values -frame_ratio = 0 diff --git a/helpers/configuration.py b/helpers/configuration.py new file mode 100644 index 00000000..0c971460 --- /dev/null +++ b/helpers/configuration.py @@ -0,0 +1,22 @@ +import configparser +from pathlib import Path + + +class Configuration: + def __init__(self): + base_path = Path().resolve().parent + config_file = Path(base_path / 'config/configuration.ini').resolve() + self._config = configparser.ConfigParser() + self._config.read(config_file) + + @property + def h_i(self): + return self._config.getfloat('convective_fluxes', 'h_i') + + @property + def h_e(self): + return self._config.getfloat('convective_fluxes', 'h_e') + + @property + def frame_ratio(self): + return self._config.getint('windows', 'frame_ratio') diff --git a/tests/test_physics_factory.py b/tests/test_physics_factory.py index 889d6690..116ad42b 100644 --- a/tests/test_physics_factory.py +++ b/tests/test_physics_factory.py @@ -24,4 +24,21 @@ class TestPhysicsFactory(TestCase): return self._nyc_with_physics def test_city_with_physics(self): - city = self.get_city_with_physics() \ No newline at end of file + city = self.get_city_with_physics() + for city_object in city.city_objects: + self.assertIsNotNone(city_object.average_storey_height, 'average_storey_height is none') + self.assertIsNotNone(city_object.storeys_above_ground, 'storeys_above_ground is none') + for thermal_zone in city_object.thermal_zones: + self.assertIsNotNone(thermal_zone.effective_thermal_capacity, 'effective_thermal_capacity is none') + self.assertIsNotNone(thermal_zone.additional_thermal_bridge_u_value, + 'additional_thermal_bridge_u_value is none') + self.assertIsNotNone(thermal_zone.indirectly_heated_area_ratio, 'indirectly_heated_area_ratio is none') + self.assertIsNotNone(thermal_zone.infiltration_rate_system_on, 'infiltration_rate_system_on is none') + self.assertIsNotNone(thermal_zone.infiltration_rate_system_off, 'infiltration_rate_system_off is none') + self.assertIsNotNone(thermal_zone.bounded, 'bounded is none') + for thermal_boundary in thermal_zone.bounded: + self.assertIsNotNone(thermal_boundary.outside_solar_absorptance, 'outside_solar_absorptance is none') + self.assertIsNotNone(thermal_boundary.outside_thermal_absorptance, 'outside_thermal_absorptance is none') + self.assertIsNotNone(thermal_boundary.outside_visible_absorptance, 'outside_visible_absorptance is none') + self.assertIsNotNone(thermal_boundary.window_ratio, 'window_ratio is none') + self.assertIsNotNone(thermal_boundary.layers, 'layers is none')