From ffc956b2d0ce4cee8a06e60ced15d49f57d271ec Mon Sep 17 00:00:00 2001 From: Pilar Date: Tue, 7 Mar 2023 15:03:24 -0500 Subject: [PATCH] a bug in usage -> division by 0 --- .../building_demand/thermal_zone.py | 10 +++++++--- hub/city_model_structure/building_demand/usage.py | 10 +++++++--- .../building_demand/usage_zone.py | 10 +++++++--- hub/exports/building_energy/idf.py | 10 ++++++---- .../insel/insel_monthly_energy_balance.py | 4 +++- hub/imports/usage/comnet_usage_parameters.py | 13 +++++++++---- 6 files changed, 39 insertions(+), 18 deletions(-) diff --git a/hub/city_model_structure/building_demand/thermal_zone.py b/hub/city_model_structure/building_demand/thermal_zone.py index db873ce4..beb26045 100644 --- a/hub/city_model_structure/building_demand/thermal_zone.py +++ b/hub/city_model_structure/building_demand/thermal_zone.py @@ -510,10 +510,14 @@ class ThermalZone: _schedule.values = values[:day] _schedules.append(_schedule) - _internal_gain.convective_fraction = _convective_fraction / _average_internal_gain - _internal_gain.radiative_fraction = _radiative_fraction / _average_internal_gain - _internal_gain.latent_fraction = _latent_fraction / _average_internal_gain _internal_gain.average_internal_gain = _average_internal_gain + _internal_gain.convective_fraction = 0 + _internal_gain.radiative_fraction = 0 + _internal_gain.latent_fraction = 0 + if _average_internal_gain != 0: + _internal_gain.convective_fraction = _convective_fraction / _average_internal_gain + _internal_gain.radiative_fraction = _radiative_fraction / _average_internal_gain + _internal_gain.latent_fraction = _latent_fraction / _average_internal_gain _internal_gain.type = 'mean_value' _internal_gain.schedules = _schedules self._internal_gains = [_internal_gain] diff --git a/hub/city_model_structure/building_demand/usage.py b/hub/city_model_structure/building_demand/usage.py index f623ee91..36240038 100644 --- a/hub/city_model_structure/building_demand/usage.py +++ b/hub/city_model_structure/building_demand/usage.py @@ -91,9 +91,13 @@ class Usage: + 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.latent_fraction = 0 + _internal_gain.radiative_fraction = 0 + _internal_gain.convective_fraction = 0 + if _total_heat_gain != 0: + _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: diff --git a/hub/city_model_structure/building_demand/usage_zone.py b/hub/city_model_structure/building_demand/usage_zone.py index 43a69c20..6357cff8 100644 --- a/hub/city_model_structure/building_demand/usage_zone.py +++ b/hub/city_model_structure/building_demand/usage_zone.py @@ -91,9 +91,13 @@ class UsageZone: + 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.latent_fraction = 0 + _internal_gain.radiative_fraction = 0 + _internal_gain.convective_fraction = 0 + if _total_heat_gain != 0: + _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: diff --git a/hub/exports/building_energy/idf.py b/hub/exports/building_energy/idf.py index e33a6d34..330fc20b 100644 --- a/hub/exports/building_energy/idf.py +++ b/hub/exports/building_energy/idf.py @@ -323,9 +323,12 @@ class Idf: def _add_occupancy(self, thermal_zone, zone_name): number_of_people = thermal_zone.occupancy.occupancy_density * thermal_zone.total_floor_area - fraction_radiant = thermal_zone.occupancy.sensible_radiative_internal_gain / \ - (thermal_zone.occupancy.sensible_radiative_internal_gain + - thermal_zone.occupancy.sensible_convective_internal_gain) + fraction_radiant = 0 + total_sensible = thermal_zone.occupancy.sensible_radiative_internal_gain + \ + thermal_zone.occupancy.sensible_convective_internal_gain + if total_sensible != 0: + fraction_radiant = thermal_zone.occupancy.sensible_radiative_internal_gain / total_sensible + self._idf.newidfobject(self._PEOPLE, Name=f'{zone_name}_occupancy', Zone_or_ZoneList_Name=zone_name, @@ -377,7 +380,6 @@ class Idf: self._rename_building(self._city.name) self._lod = self._city.level_of_detail.geometry for building in self._city.buildings: - for internal_zone in building.internal_zones: for thermal_zone in internal_zone.thermal_zones: for thermal_boundary in thermal_zone.thermal_boundaries: diff --git a/hub/exports/building_energy/insel/insel_monthly_energy_balance.py b/hub/exports/building_energy/insel/insel_monthly_energy_balance.py index f136509a..0bc18c1a 100644 --- a/hub/exports/building_energy/insel/insel_monthly_energy_balance.py +++ b/hub/exports/building_energy/insel/insel_monthly_energy_balance.py @@ -112,7 +112,9 @@ class InselMonthlyEnergyBalance(Insel): for thermal_boundary in thermal_zone.thermal_boundaries: type_code = _CONSTRUCTION_CODE[thermal_boundary.type] - window_area = thermal_boundary.opaque_area * thermal_boundary.window_ratio / (1 - thermal_boundary.window_ratio) + window_area = 0 + if thermal_boundary.window_ratio < 1: + window_area = thermal_boundary.opaque_area * thermal_boundary.window_ratio / (1 - thermal_boundary.window_ratio) parameters.append(type_code) if thermal_boundary.type != cte.GROUND: diff --git a/hub/imports/usage/comnet_usage_parameters.py b/hub/imports/usage/comnet_usage_parameters.py index 7c6c137e..6dcab450 100644 --- a/hub/imports/usage/comnet_usage_parameters.py +++ b/hub/imports/usage/comnet_usage_parameters.py @@ -189,10 +189,15 @@ class ComnetUsageParameters: _schedule_values[v, day] += value * archetype.appliances.density _sum += value * archetype.appliances.density * _number_of_days_per_type[day] - _latent_fraction = _latent_heat_gain / _total_heat_gain - _radiative_fraction = _radiative_heat_gain / _total_heat_gain - _convective_fraction = _convective_heat_gain / _total_heat_gain - _average_internal_gain = _sum / _total_heat_gain + _latent_fraction = 0 + _radiative_fraction = 0 + _convective_fraction = 0 + _average_internal_gain = 0 + if _total_heat_gain != 0: + _latent_fraction = _latent_heat_gain / _total_heat_gain + _radiative_fraction = _radiative_heat_gain / _total_heat_gain + _convective_fraction = _convective_heat_gain / _total_heat_gain + _average_internal_gain = _sum / _total_heat_gain _schedules = [] for day in range(0, len(_DAYS)):