From 406e04ccf8e5894e3e73fb564f9c7e942d71315f Mon Sep 17 00:00:00 2001 From: Pilar Date: Mon, 7 Nov 2022 11:49:59 -0500 Subject: [PATCH] ca is not a usage library anymore, it has been erased from test internal gains are calculated from occupancy and so again for monthly energy balance calculations --- .../building_demand/thermal_zone.py | 3 ++ .../building_demand/usage_zone.py | 43 ++++++++++++++++++- unittests/test_enrichement.py | 8 ++-- unittests/test_exports.py | 2 +- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/city_model_structure/building_demand/thermal_zone.py b/city_model_structure/building_demand/thermal_zone.py index 87c74929..9fc434f1 100644 --- a/city_model_structure/building_demand/thermal_zone.py +++ b/city_model_structure/building_demand/thermal_zone.py @@ -483,6 +483,9 @@ class ThermalZone: * internal_gain.latent_fraction for usage_zone in self.usage_zones: for internal_gain in usage_zone.internal_gains: + if internal_gain.schedules is None: + _schedules_defined = False + break if len(internal_gain.schedules) == 0: _schedules_defined = False break diff --git a/city_model_structure/building_demand/usage_zone.py b/city_model_structure/building_demand/usage_zone.py index 781fbf0f..225f9cb2 100644 --- a/city_model_structure/building_demand/usage_zone.py +++ b/city_model_structure/building_demand/usage_zone.py @@ -7,6 +7,7 @@ Code contributors: Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ import uuid from typing import Union, List +import helpers.constants as cte from city_model_structure.building_demand.occupancy import Occupancy from city_model_structure.building_demand.lighting import Lighting from city_model_structure.building_demand.appliances import Appliances @@ -79,9 +80,47 @@ class UsageZone: @property def internal_gains(self) -> List[InternalGain]: """ - Get usage zone internal gains - :return: [InternalGain] + Calculates and returns the list of all internal gains defined + :return: InternalGains """ + if self._internal_gains is None: + if self.occupancy is not None: + if self.occupancy.latent_internal_gain is not None: + _internal_gain = InternalGain() + _internal_gain.type = cte.OCCUPANCY + _total_heat_gain = (self.occupancy.sensible_convective_internal_gain + + self.occupancy.sensible_radiative_internal_gain + + self.occupancy.latent_internal_gain) + _internal_gain.average_internal_gain = _total_heat_gain + _internal_gain.latent_fraction = self.occupancy.latent_internal_gain / _total_heat_gain + _internal_gain.radiative_fraction = self.occupancy.sensible_radiative_internal_gain / _total_heat_gain + _internal_gain.convective_fraction = self.occupancy.sensible_convective_internal_gain / _total_heat_gain + _internal_gain.schedules = self.occupancy.occupancy_schedules + self._internal_gains = [_internal_gain] + if self.lighting is not None: + _internal_gain = InternalGain() + _internal_gain.type = cte.LIGHTING + _internal_gain.average_internal_gain = self.lighting.density + _internal_gain.latent_fraction = self.lighting.latent_fraction + _internal_gain.radiative_fraction = self.lighting.radiative_fraction + _internal_gain.convective_fraction = self.lighting.convective_fraction + _internal_gain.schedules = self.lighting.schedules + if self._internal_gains is not None: + self._internal_gains.append(_internal_gain) + else: + self._internal_gains = [_internal_gain] + if self.appliances is not None: + _internal_gain = InternalGain() + _internal_gain.type = cte.APPLIANCES + _internal_gain.average_internal_gain = self.appliances.density + _internal_gain.latent_fraction = self.appliances.latent_fraction + _internal_gain.radiative_fraction = self.appliances.radiative_fraction + _internal_gain.convective_fraction = self.appliances.convective_fraction + _internal_gain.schedules = self.appliances.schedules + if self._internal_gains is not None: + self._internal_gains.append(_internal_gain) + else: + self._internal_gains = [_internal_gain] return self._internal_gains @internal_gains.setter diff --git a/unittests/test_enrichement.py b/unittests/test_enrichement.py index e6ec7c88..16831dea 100644 --- a/unittests/test_enrichement.py +++ b/unittests/test_enrichement.py @@ -47,8 +47,8 @@ class TestGeometryFactory(TestCase): for internal_zone in building.internal_zones: self.assertIsNotNone(internal_zone.usage_zones, 'usage zones are not defined') self.assertIsNotNone(internal_zone.thermal_zones, 'thermal zones are not defined') - self.assertIsNotNone(building.basement_heated, 'building basement_heated is none') - self.assertIsNotNone(building.attic_heated, 'building attic_heated is none') + self.assertIsNone(building.basement_heated, 'building basement_heated is not none') + self.assertIsNone(building.attic_heated, 'building attic_heated is not none') self.assertIsNotNone(building.average_storey_height, 'building average_storey_height is none') self.assertIsNotNone(building.storeys_above_ground, 'building storeys_above_ground is none') self.assertTrue(building.is_conditioned, 'building is_conditioned is not conditioned') @@ -91,9 +91,11 @@ class TestGeometryFactory(TestCase): def _test_hft(self, file): _construction_keys = ['nrel'] - _usage_keys = ['ca', 'comnet', 'hft'] + _usage_keys = ['comnet', 'hft'] for construction_key in _construction_keys: + print('construction key: ', construction_key) for usage_key in _usage_keys: + print('usage key: ', usage_key) # construction factory called first city = self._get_citygml(file) for building in city.buildings: diff --git a/unittests/test_exports.py b/unittests/test_exports.py index f27e167b..d2efea73 100644 --- a/unittests/test_exports.py +++ b/unittests/test_exports.py @@ -51,7 +51,7 @@ class TestExports(TestCase): building.year_of_construction = 2006 ConstructionFactory('nrel', self._complete_city).enrich() UsageFactory('ca', self._complete_city).enrich() - cli = 'C:\\Users\\Pilar\\PycharmProjects\\monthlyenergybalance\\tests_data\\weather\\inseldb_Summerland.cli' + cli = (self._example_path / 'weather' / 'inseldb_Summerland.cli').resolve() self._complete_city.climate_file = Path(cli) self._complete_city.climate_reference_city = 'Summerland' dummy_measures = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]