solved feature in idf generator

This commit is contained in:
Pilar Monsalvete 2023-06-06 16:09:33 -04:00
parent c0a2a8a2f9
commit 4ccf16411c
4 changed files with 46 additions and 19 deletions

View File

@ -617,9 +617,12 @@ class ThermalZone:
_mean_peak_flow = 0 _mean_peak_flow = 0
_mean_service_temperature = 0 _mean_service_temperature = 0
for usage in self.usages: for usage in self.usages:
_mean_peak_density_load += usage.percentage * usage.domestic_hot_water.density if usage.domestic_hot_water.density is not None:
_mean_peak_flow += usage.percentage * usage.domestic_hot_water.peak_flow _mean_peak_density_load += usage.percentage * usage.domestic_hot_water.density
_mean_service_temperature += usage.percentage * usage.domestic_hot_water.service_temperature if usage.domestic_hot_water.peak_flow is not None:
_mean_peak_flow += usage.percentage * usage.domestic_hot_water.peak_flow
if usage.domestic_hot_water.service_temperature is not None:
_mean_service_temperature += usage.percentage * usage.domestic_hot_water.service_temperature
self._domestic_hot_water.density = _mean_peak_density_load self._domestic_hot_water.density = _mean_peak_density_load
self._domestic_hot_water.peak_flow = _mean_peak_flow self._domestic_hot_water.peak_flow = _mean_peak_flow
self._domestic_hot_water.service_temperature = _mean_service_temperature self._domestic_hot_water.service_temperature = _mean_service_temperature

View File

@ -83,6 +83,7 @@ class Idf:
def __init__(self, city, output_path, idf_file_path, idd_file_path, epw_file_path, export_type="Surfaces", def __init__(self, city, output_path, idf_file_path, idd_file_path, epw_file_path, export_type="Surfaces",
target_buildings=None): target_buildings=None):
self._city = city self._city = city
self._sanity_check()
self._output_path = str(output_path.resolve()) self._output_path = str(output_path.resolve())
self._output_file = str((output_path / f'{city.name}.idf').resolve()) self._output_file = str((output_path / f'{city.name}.idf').resolve())
self._export_type = export_type self._export_type = export_type
@ -106,6 +107,25 @@ class Idf:
self._adjacent_buildings += building.neighbours self._adjacent_buildings += building.neighbours
self._export() self._export()
def _sanity_check(self):
levels_of_detail = self._city.level_of_detail
if levels_of_detail.geometry is None:
raise AttributeError('Level of detail of geometry not assigned')
if levels_of_detail.geometry < 1:
raise AttributeError(f'Level of detail of geometry = {levels_of_detail.geometry}. Required minimum level 1')
if levels_of_detail.construction is None:
raise AttributeError('Level of detail of construction not assigned')
if levels_of_detail.construction < 2:
raise AttributeError(f'Level of detail of construction = {levels_of_detail.construction}. Required minimum level 2')
if levels_of_detail.usage is None:
raise AttributeError('Level of detail of usage not assigned')
if levels_of_detail.usage < 2:
raise AttributeError(f'Level of detail of usage = {levels_of_detail.usage}. Required minimum level 2')
if levels_of_detail.weather is None:
raise AttributeError('Level of detail of weather not assigned')
if levels_of_detail.weather < 2:
raise AttributeError(f'Level of detail of weather = {levels_of_detail.weather}. Required minimum level 2')
@staticmethod @staticmethod
def _matrix_to_list(points, lower_corner): def _matrix_to_list(points, lower_corner):
lower_x = lower_corner[0] lower_x = lower_corner[0]
@ -294,9 +314,9 @@ class Idf:
return return
def _add_construction(self, thermal_boundary): def _add_construction(self, thermal_boundary):
vegetation_name = f'{thermal_boundary.construction_name}_{thermal_boundary.parent_surface.vegetation.name}'
for construction in self._idf.idfobjects[self._CONSTRUCTION]: for construction in self._idf.idfobjects[self._CONSTRUCTION]:
if thermal_boundary.parent_surface.vegetation is not None: if thermal_boundary.parent_surface.vegetation is not None:
vegetation_name = f'{thermal_boundary.construction_name}_{thermal_boundary.parent_surface.vegetation.name}'
if construction.Name == vegetation_name: if construction.Name == vegetation_name:
return return
else: else:
@ -313,6 +333,7 @@ class Idf:
layers = thermal_boundary.layers layers = thermal_boundary.layers
# The constructions should have at least one layer # The constructions should have at least one layer
if thermal_boundary.parent_surface.vegetation is not None: if thermal_boundary.parent_surface.vegetation is not None:
vegetation_name = f'{thermal_boundary.construction_name}_{thermal_boundary.parent_surface.vegetation.name}'
_kwargs = {'Name': vegetation_name, _kwargs = {'Name': vegetation_name,
'Outside_Layer': thermal_boundary.parent_surface.vegetation.name} 'Outside_Layer': thermal_boundary.parent_surface.vegetation.name}
for i in range(0, len(layers) - 1): for i in range(0, len(layers) - 1):
@ -429,25 +450,28 @@ class Idf:
for zone in self._idf.idfobjects["ZONE"]: for zone in self._idf.idfobjects["ZONE"]:
if zone.Name == f'{zone_name}_infiltration': if zone.Name == f'{zone_name}_infiltration':
return return
schedule = f'Infiltration schedules {thermal_zone.usage_name}' schedule = f'Infiltration schedules {thermal_zone.usage_name}'
if schedule not in self._idf.idfobjects[self._HOURLY_SCHEDULE]: # todo: if the schedule doesn't exist, does the idf notices??
return # We shouldn't check this because the schedules could be written later
self._idf.newidfobject(self._INFILTRATION, # if schedule not in self._idf.idfobjects[self._COMPACT_SCHEDULE]:
Name=f'{zone_name}_infiltration', # return
Zone_or_ZoneList_Name=zone_name, self._idf.newidfobject(self._INFILTRATION,
Schedule_Name=schedule, Name=f'{zone_name}_infiltration',
Design_Flow_Rate_Calculation_Method='AirChanges/Hour', Zone_or_ZoneList_Name=zone_name,
Air_Changes_per_Hour=thermal_zone.infiltration_rate_system_off Schedule_Name=schedule,
) Design_Flow_Rate_Calculation_Method='AirChanges/Hour',
Air_Changes_per_Hour=thermal_zone.infiltration_rate_system_off
)
def _add_ventilation(self, thermal_zone, zone_name): def _add_ventilation(self, thermal_zone, zone_name):
for zone in self._idf.idfobjects["ZONE"]: for zone in self._idf.idfobjects["ZONE"]:
if zone.Name == f'{zone_name}_ventilation': if zone.Name == f'{zone_name}_ventilation':
return return
schedule = f'Ventilation schedules {thermal_zone.usage_name}' schedule = f'Ventilation schedules {thermal_zone.usage_name}'
#if schedule not in self._idf.idfobjects[self._HOURLY_SCHEDULE]: # todo: if the schedule doesn't exist, does the idf notices??
# return # We shouldn't check this because the schedules could be written later
# todo: revise ventilation with Pilar # if schedule not in self._idf.idfobjects[self._COMPACT_SCHEDULE]:
# return
self._idf.newidfobject(self._VENTILATION, self._idf.newidfobject(self._VENTILATION,
Name=f'{zone_name}_ventilation', Name=f'{zone_name}_ventilation',
Zone_or_ZoneList_Name=zone_name, Zone_or_ZoneList_Name=zone_name,

View File

@ -76,7 +76,7 @@ class InselMonthlyEnergyBalance:
if levels_of_detail.geometry is None: if levels_of_detail.geometry is None:
raise AttributeError('Level of detail of geometry not assigned') raise AttributeError('Level of detail of geometry not assigned')
if levels_of_detail.geometry < 1: if levels_of_detail.geometry < 1:
raise AttributeError(f'Level of detail of geometry = {levels_of_detail.geometry}. Required minimum level 0.5') raise AttributeError(f'Level of detail of geometry = {levels_of_detail.geometry}. Required minimum level 1')
if levels_of_detail.construction is None: if levels_of_detail.construction is None:
raise AttributeError('Level of detail of construction not assigned') raise AttributeError('Level of detail of construction not assigned')
if levels_of_detail.construction < 1: if levels_of_detail.construction < 1:

View File

@ -67,4 +67,4 @@ class EnergyBuildingsExportsFactory:
Export the city given to the class using the given export type handler Export the city given to the class using the given export type handler
:return: None :return: None
""" """
return getattr(self, self._export_type, lambda: None) return getattr(self, self._export_type, lambda: None)