now schedules are re-calculated on change

This commit is contained in:
Guille Gutierrez 2022-06-08 12:55:37 -04:00
parent 2799de760d
commit 3bf674d107

View File

@ -244,7 +244,7 @@ class ThermalZone:
return None return None
self._usage = '' self._usage = ''
for usage_zone in self._parent_internal_zone.usage_zones: for usage_zone in self._parent_internal_zone.usage_zones:
self._usage += str(round(usage_zone.percentage) * 100) + '-' + usage_zone.usage + '_' self._usage += str(round(usage_zone.percentage*100)) + '-' + usage_zone.usage + '_'
self._usage = self._usage[:-1] self._usage = self._usage[:-1]
return self._usage return self._usage
@ -308,39 +308,39 @@ class ThermalZone:
""" """
if self.usage_zones is None: if self.usage_zones is None:
return None return None
if self._occupancy is None:
self._occupancy = Occupancy()
_occupancy_density = 0
_convective_part = 0
_radiative_part = 0
_latent_part = 0
for usage_zone in self.usage_zones:
if usage_zone.occupancy is None:
return None
_occupancy_density += usage_zone.percentage * usage_zone.occupancy.occupancy_density
if usage_zone.occupancy.sensible_convective_internal_gain is not None:
_convective_part += usage_zone.percentage * usage_zone.occupancy.sensible_convective_internal_gain
_radiative_part += usage_zone.percentage * usage_zone.occupancy.sensible_radiative_internal_gain
_latent_part += usage_zone.percentage * usage_zone.occupancy.latent_internal_gain
self._occupancy.occupancy_density = _occupancy_density
self._occupancy.sensible_convective_internal_gain = _convective_part
self._occupancy.sensible_radiative_internal_gain = _radiative_part
self._occupancy.latent_internal_gain = _latent_part
_occupancy_reference = self.usage_zones[0].occupancy self._occupancy = Occupancy()
if _occupancy_reference.occupancy_schedules is not None: _occupancy_density = 0
_schedules = [] _convective_part = 0
for i_schedule in range(0, len(_occupancy_reference.occupancy_schedules)): _radiative_part = 0
schedule = copy.deepcopy(_occupancy_reference.occupancy_schedules[i_schedule]) _latent_part = 0
new_values = [] for usage_zone in self.usage_zones:
for i_value in range(0, len(_occupancy_reference.occupancy_schedules[i_schedule].values)): if usage_zone.occupancy is None:
_new_value = 0 return None
for usage_zone in self.usage_zones: _occupancy_density += usage_zone.percentage * usage_zone.occupancy.occupancy_density
_new_value += usage_zone.percentage * usage_zone.occupancy.occupancy_schedules[i_schedule].values[i_value] if usage_zone.occupancy.sensible_convective_internal_gain is not None:
new_values.append(_new_value) _convective_part += usage_zone.percentage * usage_zone.occupancy.sensible_convective_internal_gain
schedule.values = new_values _radiative_part += usage_zone.percentage * usage_zone.occupancy.sensible_radiative_internal_gain
_schedules.append(schedule) _latent_part += usage_zone.percentage * usage_zone.occupancy.latent_internal_gain
self._occupancy.occupancy_schedules = _schedules self._occupancy.occupancy_density = _occupancy_density
self._occupancy.sensible_convective_internal_gain = _convective_part
self._occupancy.sensible_radiative_internal_gain = _radiative_part
self._occupancy.latent_internal_gain = _latent_part
_occupancy_reference = self.usage_zones[0].occupancy
if _occupancy_reference.occupancy_schedules is not None:
_schedules = []
for i_schedule in range(0, len(_occupancy_reference.occupancy_schedules)):
schedule = copy.deepcopy(_occupancy_reference.occupancy_schedules[i_schedule])
new_values = []
for i_value in range(0, len(_occupancy_reference.occupancy_schedules[i_schedule].values)):
_new_value = 0
for usage_zone in self.usage_zones:
_new_value += usage_zone.percentage * usage_zone.occupancy.occupancy_schedules[i_schedule].values[i_value]
new_values.append(_new_value)
schedule.values = new_values
_schedules.append(schedule)
self._occupancy.occupancy_schedules = _schedules
return self._occupancy return self._occupancy
@property @property
@ -351,47 +351,47 @@ class ThermalZone:
""" """
if self.usage_zones is None: if self.usage_zones is None:
return None return None
if self._lighting is None:
self._lighting = Lighting()
_lighting_density = 0
_convective_part = 0
_radiative_part = 0
_latent_part = 0
for usage_zone in self.usage_zones:
if usage_zone.lighting is None:
return None
_lighting_density += usage_zone.percentage * usage_zone.lighting.density
if usage_zone.lighting.convective_fraction is not None:
_convective_part += usage_zone.percentage * usage_zone.lighting.density \
* usage_zone.lighting.convective_fraction
_radiative_part += usage_zone.percentage * usage_zone.lighting.density \
* usage_zone.lighting.radiative_fraction
_latent_part += usage_zone.percentage * usage_zone.lighting.density \
* usage_zone.lighting.latent_fraction
self._lighting.density = _lighting_density
if _lighting_density > 0:
self._lighting.convective_fraction = _convective_part / _lighting_density
self._lighting.radiative_fraction = _radiative_part / _lighting_density
self._lighting.latent_fraction = _latent_part / _lighting_density
else:
self._lighting.convective_fraction = 0
self._lighting.radiative_fraction = 0
self._lighting.latent_fraction = 0
_lighting_reference = self.usage_zones[0].lighting self._lighting = Lighting()
if _lighting_reference.schedules is not None: _lighting_density = 0
_schedules = [] _convective_part = 0
for i_schedule in range(0, len(_lighting_reference.schedules)): _radiative_part = 0
schedule = copy.deepcopy(_lighting_reference.schedules[i_schedule]) _latent_part = 0
new_values = [] for usage_zone in self.usage_zones:
for i_value in range(0, len(_lighting_reference.schedules[i_schedule].values)): if usage_zone.lighting is None:
_new_value = 0 return None
for usage_zone in self.usage_zones: _lighting_density += usage_zone.percentage * usage_zone.lighting.density
_new_value += usage_zone.percentage * usage_zone.lighting.schedules[i_schedule].values[i_value] if usage_zone.lighting.convective_fraction is not None:
new_values.append(_new_value) _convective_part += usage_zone.percentage * usage_zone.lighting.density \
schedule.values = new_values * usage_zone.lighting.convective_fraction
_schedules.append(schedule) _radiative_part += usage_zone.percentage * usage_zone.lighting.density \
self._lighting.schedules = _schedules * usage_zone.lighting.radiative_fraction
_latent_part += usage_zone.percentage * usage_zone.lighting.density \
* usage_zone.lighting.latent_fraction
self._lighting.density = _lighting_density
if _lighting_density > 0:
self._lighting.convective_fraction = _convective_part / _lighting_density
self._lighting.radiative_fraction = _radiative_part / _lighting_density
self._lighting.latent_fraction = _latent_part / _lighting_density
else:
self._lighting.convective_fraction = 0
self._lighting.radiative_fraction = 0
self._lighting.latent_fraction = 0
_lighting_reference = self.usage_zones[0].lighting
if _lighting_reference.schedules is not None:
_schedules = []
for i_schedule in range(0, len(_lighting_reference.schedules)):
schedule = copy.deepcopy(_lighting_reference.schedules[i_schedule])
new_values = []
for i_value in range(0, len(_lighting_reference.schedules[i_schedule].values)):
_new_value = 0
for usage_zone in self.usage_zones:
_new_value += usage_zone.percentage * usage_zone.lighting.schedules[i_schedule].values[i_value]
new_values.append(_new_value)
schedule.values = new_values
_schedules.append(schedule)
self._lighting.schedules = _schedules
return self._lighting return self._lighting
@property @property
@ -402,47 +402,47 @@ class ThermalZone:
""" """
if self.usage_zones is None: if self.usage_zones is None:
return None return None
if self._appliances is None:
self._appliances = Appliances()
_appliances_density = 0
_convective_part = 0
_radiative_part = 0
_latent_part = 0
for usage_zone in self.usage_zones:
if usage_zone.appliances is None:
return None
_appliances_density += usage_zone.percentage * usage_zone.appliances.density
if usage_zone.appliances.convective_fraction is not None:
_convective_part += usage_zone.percentage * usage_zone.appliances.density \
* usage_zone.appliances.convective_fraction
_radiative_part += usage_zone.percentage * usage_zone.appliances.density \
* usage_zone.appliances.radiative_fraction
_latent_part += usage_zone.percentage * usage_zone.appliances.density \
* usage_zone.appliances.latent_fraction
self._appliances.density = _appliances_density
if _appliances_density > 0:
self._appliances.convective_fraction = _convective_part / _appliances_density
self._appliances.radiative_fraction = _radiative_part / _appliances_density
self._appliances.latent_fraction = _latent_part / _appliances_density
else:
self._appliances.convective_fraction = 0
self._appliances.radiative_fraction = 0
self._appliances.latent_fraction = 0
_appliances_reference = self.usage_zones[0].appliances self._appliances = Appliances()
if _appliances_reference.schedules is not None: _appliances_density = 0
_schedules = [] _convective_part = 0
for i_schedule in range(0, len(_appliances_reference.schedules)): _radiative_part = 0
schedule = copy.deepcopy(_appliances_reference.schedules[i_schedule]) _latent_part = 0
new_values = [] for usage_zone in self.usage_zones:
for i_value in range(0, len(_appliances_reference.schedules[i_schedule].values)): if usage_zone.appliances is None:
_new_value = 0 return None
for usage_zone in self.usage_zones: _appliances_density += usage_zone.percentage * usage_zone.appliances.density
_new_value += usage_zone.percentage * usage_zone.appliances.schedules[i_schedule].values[i_value] if usage_zone.appliances.convective_fraction is not None:
new_values.append(_new_value) _convective_part += usage_zone.percentage * usage_zone.appliances.density \
schedule.values = new_values * usage_zone.appliances.convective_fraction
_schedules.append(schedule) _radiative_part += usage_zone.percentage * usage_zone.appliances.density \
self._appliances.schedules = _schedules * usage_zone.appliances.radiative_fraction
_latent_part += usage_zone.percentage * usage_zone.appliances.density \
* usage_zone.appliances.latent_fraction
self._appliances.density = _appliances_density
if _appliances_density > 0:
self._appliances.convective_fraction = _convective_part / _appliances_density
self._appliances.radiative_fraction = _radiative_part / _appliances_density
self._appliances.latent_fraction = _latent_part / _appliances_density
else:
self._appliances.convective_fraction = 0
self._appliances.radiative_fraction = 0
self._appliances.latent_fraction = 0
_appliances_reference = self.usage_zones[0].appliances
if _appliances_reference.schedules is not None:
_schedules = []
for i_schedule in range(0, len(_appliances_reference.schedules)):
schedule = copy.deepcopy(_appliances_reference.schedules[i_schedule])
new_values = []
for i_value in range(0, len(_appliances_reference.schedules[i_schedule].values)):
_new_value = 0
for usage_zone in self.usage_zones:
_new_value += usage_zone.percentage * usage_zone.appliances.schedules[i_schedule].values[i_value]
new_values.append(_new_value)
schedule.values = new_values
_schedules.append(schedule)
self._appliances.schedules = _schedules
return self._appliances return self._appliances
@property @property
@ -453,54 +453,54 @@ class ThermalZone:
""" """
if self.usage_zones is None: if self.usage_zones is None:
return None return None
if self._internal_gains is None:
_internal_gain = InternalGain()
_days = [cte.MONDAY, cte.TUESDAY, cte.WEDNESDAY, cte.THURSDAY, cte.FRIDAY, cte.SATURDAY, cte.SUNDAY, cte.HOLIDAY]
_average_internal_gain = 0
_convective_fraction = 0
_radiative_fraction = 0
_latent_fraction = 0
_schedules = None
_base_schedule = Schedule()
_base_schedule.type = cte.INTERNAL_GAINS
_base_schedule.time_range = cte.DAY
_base_schedule.time_step = cte.HOUR
_base_schedule.data_type = cte.ANY_NUMBER
_schedules_defined = True
values = numpy.zeros(24, 8)
for usage_zone in self.usage_zones:
for internal_gain in usage_zone.internal_gains:
_average_internal_gain += internal_gain.average_internal_gain * usage_zone.percentage
_convective_fraction += internal_gain.average_internal_gain * usage_zone.percentage \
* internal_gain.convective_fraction
_radiative_fraction += internal_gain.average_internal_gain * usage_zone.percentage \
* internal_gain.radiative_fraction
_latent_fraction += internal_gain.average_internal_gain * usage_zone.percentage \
* internal_gain.latent_fraction
for usage_zone in self.usage_zones:
for internal_gain in usage_zone.internal_gains:
if len(internal_gain.schedules) == 0:
_schedules_defined = False
break
for day, _schedule in enumerate(internal_gain.schedules):
for v, value in enumerate(_schedule.values):
values[v, day] += value * usage_zone.percentage
if _schedules_defined: _internal_gain = InternalGain()
_schedules = [] _days = [cte.MONDAY, cte.TUESDAY, cte.WEDNESDAY, cte.THURSDAY, cte.FRIDAY, cte.SATURDAY, cte.SUNDAY, cte.HOLIDAY]
for day in range(0, len(_days)): _average_internal_gain = 0
_schedule = copy.deepcopy(_base_schedule) _convective_fraction = 0
_schedule.day_types = [_days[day]] _radiative_fraction = 0
_schedule.values = values[:day] _latent_fraction = 0
_schedules.append(_schedule) _schedules = None
_base_schedule = Schedule()
_base_schedule.type = cte.INTERNAL_GAINS
_base_schedule.time_range = cte.DAY
_base_schedule.time_step = cte.HOUR
_base_schedule.data_type = cte.ANY_NUMBER
_schedules_defined = True
values = numpy.zeros(24, 8)
for usage_zone in self.usage_zones:
for internal_gain in usage_zone.internal_gains:
_average_internal_gain += internal_gain.average_internal_gain * usage_zone.percentage
_convective_fraction += internal_gain.average_internal_gain * usage_zone.percentage \
* internal_gain.convective_fraction
_radiative_fraction += internal_gain.average_internal_gain * usage_zone.percentage \
* internal_gain.radiative_fraction
_latent_fraction += internal_gain.average_internal_gain * usage_zone.percentage \
* internal_gain.latent_fraction
for usage_zone in self.usage_zones:
for internal_gain in usage_zone.internal_gains:
if len(internal_gain.schedules) == 0:
_schedules_defined = False
break
for day, _schedule in enumerate(internal_gain.schedules):
for v, value in enumerate(_schedule.values):
values[v, day] += value * usage_zone.percentage
_internal_gain.convective_fraction = _convective_fraction / _average_internal_gain if _schedules_defined:
_internal_gain.radiative_fraction = _radiative_fraction / _average_internal_gain _schedules = []
_internal_gain.latent_fraction = _latent_fraction / _average_internal_gain for day in range(0, len(_days)):
_internal_gain.average_internal_gain = _average_internal_gain _schedule = copy.deepcopy(_base_schedule)
_internal_gain.type = 'mean_value' _schedule.day_types = [_days[day]]
_internal_gain.schedules = _schedules _schedule.values = values[:day]
self._internal_gains = [_internal_gain] _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.type = 'mean_value'
_internal_gain.schedules = _schedules
self._internal_gains = [_internal_gain]
return self._internal_gains return self._internal_gains
@property @property
@ -511,55 +511,55 @@ class ThermalZone:
""" """
if self.usage_zones is None: if self.usage_zones is None:
return None return None
if self._thermal_control is None:
self._thermal_control = ThermalControl()
_mean_heating_set_point = 0
_heating_set_back = 0
_mean_cooling_set_point = 0
for usage_zone in self.usage_zones:
_mean_heating_set_point += usage_zone.percentage * usage_zone.thermal_control.mean_heating_set_point
_heating_set_back += usage_zone.percentage * usage_zone.thermal_control.heating_set_back
_mean_cooling_set_point += usage_zone.percentage * usage_zone.thermal_control.mean_cooling_set_point
self._thermal_control.mean_heating_set_point = _mean_heating_set_point
self._thermal_control.heating_set_back = _heating_set_back
self._thermal_control.mean_cooling_set_point = _mean_cooling_set_point
_thermal_control_reference = self.usage_zones[0].thermal_control self._thermal_control = ThermalControl()
_types_reference = [] _mean_heating_set_point = 0
if _thermal_control_reference.hvac_availability_schedules is not None: _heating_set_back = 0
_types_reference.append([cte.HVAC_AVAILABILITY, _thermal_control_reference.hvac_availability_schedules]) _mean_cooling_set_point = 0
if _thermal_control_reference.heating_set_point_schedules is not None: for usage_zone in self.usage_zones:
_types_reference.append([cte.HEATING_SET_POINT, _thermal_control_reference.heating_set_point_schedules]) _mean_heating_set_point += usage_zone.percentage * usage_zone.thermal_control.mean_heating_set_point
if _thermal_control_reference.cooling_set_point_schedules is not None: _heating_set_back += usage_zone.percentage * usage_zone.thermal_control.heating_set_back
_types_reference.append([cte.COOLING_SET_POINT, _thermal_control_reference.cooling_set_point_schedules]) _mean_cooling_set_point += usage_zone.percentage * usage_zone.thermal_control.mean_cooling_set_point
self._thermal_control.mean_heating_set_point = _mean_heating_set_point
self._thermal_control.heating_set_back = _heating_set_back
self._thermal_control.mean_cooling_set_point = _mean_cooling_set_point
for i_type in range(0, len(_types_reference)): _thermal_control_reference = self.usage_zones[0].thermal_control
_schedules = [] _types_reference = []
_schedule_type = _types_reference[i_type][1] if _thermal_control_reference.hvac_availability_schedules is not None:
for i_schedule in range(0, len(_schedule_type)): _types_reference.append([cte.HVAC_AVAILABILITY, _thermal_control_reference.hvac_availability_schedules])
schedule = copy.deepcopy(_schedule_type[i_schedule]) if _thermal_control_reference.heating_set_point_schedules is not None:
new_values = [] _types_reference.append([cte.HEATING_SET_POINT, _thermal_control_reference.heating_set_point_schedules])
for i_value in range(0, len(_schedule_type[i_schedule].values)): if _thermal_control_reference.cooling_set_point_schedules is not None:
_new_value = 0 _types_reference.append([cte.COOLING_SET_POINT, _thermal_control_reference.cooling_set_point_schedules])
for usage_zone in self.usage_zones:
if _types_reference[i_type][0] == cte.HVAC_AVAILABILITY: for i_type in range(0, len(_types_reference)):
_new_value += usage_zone.percentage * \ _schedules = []
usage_zone.thermal_control.hvac_availability_schedules[i_schedule].values[i_value] _schedule_type = _types_reference[i_type][1]
elif _types_reference[i_type][0] == cte.HEATING_SET_POINT: for i_schedule in range(0, len(_schedule_type)):
_new_value += usage_zone.percentage * \ schedule = copy.deepcopy(_schedule_type[i_schedule])
usage_zone.thermal_control.heating_set_point_schedules[i_schedule].values[i_value] new_values = []
elif _types_reference[i_type][0] == cte.COOLING_SET_POINT: for i_value in range(0, len(_schedule_type[i_schedule].values)):
_new_value += usage_zone.percentage * \ _new_value = 0
usage_zone.thermal_control.cooling_set_point_schedules[i_schedule].values[i_value] for usage_zone in self.usage_zones:
new_values.append(_new_value) if _types_reference[i_type][0] == cte.HVAC_AVAILABILITY:
schedule.values = new_values _new_value += usage_zone.percentage * \
_schedules.append(schedule) usage_zone.thermal_control.hvac_availability_schedules[i_schedule].values[i_value]
if i_type == 0: elif _types_reference[i_type][0] == cte.HEATING_SET_POINT:
self._thermal_control.hvac_availability_schedules = _schedules _new_value += usage_zone.percentage * \
elif i_type == 1: usage_zone.thermal_control.heating_set_point_schedules[i_schedule].values[i_value]
self._thermal_control.heating_set_point_schedules = _schedules elif _types_reference[i_type][0] == cte.COOLING_SET_POINT:
elif i_type == 2: _new_value += usage_zone.percentage * \
self._thermal_control.cooling_set_point_schedules = _schedules usage_zone.thermal_control.cooling_set_point_schedules[i_schedule].values[i_value]
new_values.append(_new_value)
schedule.values = new_values
_schedules.append(schedule)
if i_type == 0:
self._thermal_control.hvac_availability_schedules = _schedules
elif i_type == 1:
self._thermal_control.heating_set_point_schedules = _schedules
elif i_type == 2:
self._thermal_control.cooling_set_point_schedules = _schedules
return self._thermal_control return self._thermal_control