complete refactor

This commit is contained in:
Guille Gutierrez 2024-10-03 15:40:02 +02:00
parent 16b0726db7
commit afe5e433ea
20 changed files with 73 additions and 39 deletions

View File

@ -28,6 +28,7 @@ from hub.exports.building_energy.idf_helper.idf_shading import IdfShading
from hub.exports.building_energy.idf_helper.idf_surfaces import IdfSurfaces from hub.exports.building_energy.idf_helper.idf_surfaces import IdfSurfaces
from hub.exports.building_energy.idf_helper.idf_thermostat import IdfThermostat from hub.exports.building_energy.idf_helper.idf_thermostat import IdfThermostat
from hub.exports.building_energy.idf_helper.idf_ventilation import IdfVentilation from hub.exports.building_energy.idf_helper.idf_ventilation import IdfVentilation
from hub.exports.building_energy.idf_helper.idf_window import IdfWindow
from hub.exports.building_energy.idf_helper.idf_windows_constructions import IdfWindowsConstructions from hub.exports.building_energy.idf_helper.idf_windows_constructions import IdfWindowsConstructions
from hub.exports.building_energy.idf_helper.idf_windows_material import IdfWindowsMaterial from hub.exports.building_energy.idf_helper.idf_windows_material import IdfWindowsMaterial
from hub.exports.building_energy.idf_helper.idf_zone import IdfZone from hub.exports.building_energy.idf_helper.idf_zone import IdfZone
@ -47,7 +48,6 @@ class CercIdf(IdfBase):
def __init__(self, city, output_path, idf_file_path, idd_file_path, epw_file_path, target_buildings=None): def __init__(self, city, output_path, idf_file_path, idd_file_path, epw_file_path, target_buildings=None):
super().__init__(city, output_path, idf_file_path, idd_file_path, epw_file_path, target_buildings) super().__init__(city, output_path, idf_file_path, idd_file_path, epw_file_path, target_buildings)
self._add_surfaces = IdfSurfaces.add self._add_surfaces = IdfSurfaces.add
self._add_schedule = IdfSchedule.add
self._add_file_schedule = IdfFileSchedule.add self._add_file_schedule = IdfFileSchedule.add
self._add_idf_schedule = IdfSchedule.add self._add_idf_schedule = IdfSchedule.add
self._add_construction = IdfConstruction.add self._add_construction = IdfConstruction.add
@ -64,6 +64,7 @@ class CercIdf(IdfBase):
self._add_heating_system = IdfHeatingSystem.add self._add_heating_system = IdfHeatingSystem.add
self._add_dhw = IdfDhw.add self._add_dhw = IdfDhw.add
self._add_shading = IdfShading.add self._add_shading = IdfShading.add
self._add_windows = IdfWindow.add
with open(self._idf_file_path, 'r') as base_idf: with open(self._idf_file_path, 'r') as base_idf:
lines = base_idf.readlines() lines = base_idf.readlines()
@ -72,9 +73,6 @@ class CercIdf(IdfBase):
self._idf_file.writelines(lines) self._idf_file.writelines(lines)
self._export() self._export()
# Create base values
self._create_geometry_rules()
def _create_geometry_rules(self): def _create_geometry_rules(self):
file = self._files['zones'] file = self._files['zones']
self._write_to_idf_format(file, idf_cte.GLOBAL_GEOMETRY_RULES) self._write_to_idf_format(file, idf_cte.GLOBAL_GEOMETRY_RULES)
@ -179,43 +177,49 @@ class CercIdf(IdfBase):
occ.sensible_radiative_internal_gain + occ.sensible_radiative_internal_gain +
occ.latent_internal_gain occ.latent_internal_gain
) / occ.occupancy_density ) / occ.occupancy_density
self._add_idf_schedule(usage, 'Infiltration', self._create_infiltration_schedules(thermal_zone)) self._add_idf_schedule(self, usage, 'Infiltration', self._create_infiltration_schedules(thermal_zone))
self._add_idf_schedule(usage, 'Ventilation', self._create_ventilation_schedules(thermal_zone)) self._add_idf_schedule(self, usage, 'Ventilation', self._create_ventilation_schedules(thermal_zone))
self._add_idf_schedule(usage, 'Occupancy', thermal_zone.occupancy.occupancy_schedules) self._add_idf_schedule(self, usage, 'Occupancy', thermal_zone.occupancy.occupancy_schedules)
self._add_idf_schedule(usage, 'HVAC AVAIL', thermal_zone.thermal_control.hvac_availability_schedules) self._add_idf_schedule(self, usage, 'HVAC AVAIL', thermal_zone.thermal_control.hvac_availability_schedules)
self._add_idf_schedule(usage, 'Heating thermostat', self._add_idf_schedule(self, usage, 'Heating thermostat',
thermal_zone.thermal_control.heating_set_point_schedules) thermal_zone.thermal_control.heating_set_point_schedules)
self._add_idf_schedule(usage, 'Cooling thermostat', self._add_idf_schedule(self, usage, 'Cooling thermostat',
thermal_zone.thermal_control.cooling_set_point_schedules) thermal_zone.thermal_control.cooling_set_point_schedules)
self._add_idf_schedule(usage, 'Lighting', thermal_zone.lighting.schedules) self._add_idf_schedule(self, usage, 'Lighting', thermal_zone.lighting.schedules)
self._add_idf_schedule(usage, 'Appliance', thermal_zone.appliances.schedules) self._add_idf_schedule(self, usage, 'Appliance', thermal_zone.appliances.schedules)
self._add_idf_schedule(usage, 'DHW_prof', thermal_zone.domestic_hot_water.schedules) self._add_idf_schedule(self, usage, 'DHW_prof', thermal_zone.domestic_hot_water.schedules)
self._add_idf_schedule(usage, 'DHW_temp', self._create_constant_value_schedules(service_temperature, 24)) self._add_idf_schedule(self, usage, 'DHW_temp',
self._add_idf_schedule(usage, 'Activity Level', self._create_constant_value_schedules(total_heat, 24)) self._create_constant_value_schedules(service_temperature, 24))
self._add_file_schedule(usage, 'cold_temp', self._add_idf_schedule(self, usage, 'Activity Level', self._create_constant_value_schedules(total_heat, 24))
self._add_file_schedule(self, usage, 'cold_temp',
self._create_constant_value_schedules(building.cold_water_temperature[cte.HOUR], self._create_constant_value_schedules(building.cold_water_temperature[cte.HOUR],
24)) 24))
for thermal_boundary in thermal_zone.thermal_boundaries: for thermal_boundary in thermal_zone.thermal_boundaries:
self._add_material(thermal_boundary) self._add_material(self, thermal_boundary)
self._add_construction(thermal_boundary) self._add_construction(self, thermal_boundary)
for thermal_opening in thermal_boundary.thermal_openings: for thermal_opening in thermal_boundary.thermal_openings:
self._add_windows_material(thermal_opening) self._add_windows_material(self, thermal_opening)
self._add_windows_constructions() self._add_windows_constructions(self)
self._add_zone(thermal_zone, building.name) self._add_zone(self, thermal_zone, building.name)
self._add_occupancy(thermal_zone, building.name) self._add_occupancy(self, thermal_zone, building.name)
self._add_lighting(thermal_zone, building.name) self._add_lighting(self, thermal_zone, building.name)
self._add_appliance(thermal_zone, building.name) self._add_appliance(self, thermal_zone, building.name)
self._add_infiltration(thermal_zone, building.name) self._add_infiltration(self, thermal_zone, building.name)
self._add_ventilation(thermal_zone, building.name) self._add_ventilation(self, thermal_zone, building.name)
self._add_thermostat(thermal_zone) self._add_thermostat(self, thermal_zone)
self._add_heating_system(thermal_zone, building.name) self._add_heating_system(self, thermal_zone, building.name)
self._add_dhw(thermal_zone, building.name) self._add_dhw(self, thermal_zone, building.name)
if is_target: if is_target:
self._add_surfaces(building, building.name) self._add_surfaces(self, building, building.name)
self._add_windows(self, building, building.name)
else: else:
self._add_shading(building) self._add_shading(self, building)
self._create_output_control_lighting() # Add lighting control to the lighting self._create_output_control_lighting() # Add lighting control to the lighting
# Create base values
self._create_geometry_rules()
# Merge files # Merge files
self._merge_files() self._merge_files()
self._add_outputs() self._add_outputs()

View File

@ -31,7 +31,7 @@ NON_SUN_EXPOSED = 'NoSun'
NON_WIND_EXPOSED = 'NoWind' NON_WIND_EXPOSED = 'NoWind'
EMPTY = '' EMPTY = ''
idf_surfaces = { idf_surfaces_dictionary = {
cte.WALL: 'wall', cte.WALL: 'wall',
cte.GROUND: 'floor', cte.GROUND: 'floor',
cte.ROOF: 'roof' cte.ROOF: 'roof'

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfAppliance(IdfBase): class IdfAppliance(IdfBase):
@staticmethod
def add(self, thermal_zone, zone_name): def add(self, thermal_zone, zone_name):
schedule_name = f'Appliance schedules {thermal_zone.usage_name}' schedule_name = f'Appliance schedules {thermal_zone.usage_name}'
storeys_number = int(thermal_zone.total_floor_area / thermal_zone.footprint_area) storeys_number = int(thermal_zone.total_floor_area / thermal_zone.footprint_area)

View File

@ -4,6 +4,8 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfConstruction(IdfBase): class IdfConstruction(IdfBase):
@staticmethod
def _add_solid_material(self, layer): def _add_solid_material(self, layer):
file = self._files['solid_materials'] file = self._files['solid_materials']
self._write_to_idf_format(file, idf_cte.SOLID_MATERIAL) self._write_to_idf_format(file, idf_cte.SOLID_MATERIAL)
@ -17,6 +19,7 @@ class IdfConstruction(IdfBase):
self._write_to_idf_format(file, layer.solar_absorptance, 'Solar Absorptance') self._write_to_idf_format(file, layer.solar_absorptance, 'Solar Absorptance')
self._write_to_idf_format(file, layer.visible_absorptance, 'Visible Absorptance', ';') self._write_to_idf_format(file, layer.visible_absorptance, 'Visible Absorptance', ';')
@staticmethod
def _add_default_material(self): def _add_default_material(self):
layer = Layer() layer = Layer()
layer.material_name = 'DefaultMaterial' layer.material_name = 'DefaultMaterial'
@ -27,12 +30,13 @@ class IdfConstruction(IdfBase):
layer.thermal_absorptance = 0.9 layer.thermal_absorptance = 0.9
layer.solar_absorptance = 0.9 layer.solar_absorptance = 0.9
layer.visible_absorptance = 0.7 layer.visible_absorptance = 0.7
self._add_solid_material(layer) IdfConstruction._add_solid_material(self, layer)
return layer return layer
@staticmethod
def add(self, thermal_boundary): def add(self, thermal_boundary):
if thermal_boundary.layers is None: if thermal_boundary.layers is None:
thermal_boundary.layers = [self._add_default_material()] thermal_boundary.layers = [IdfConstruction._add_default_material(self)]
name = f'{thermal_boundary.construction_name} {thermal_boundary.parent_surface.type}' name = f'{thermal_boundary.construction_name} {thermal_boundary.parent_surface.type}'
if name not in self._constructions_added_to_idf: if name not in self._constructions_added_to_idf:

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfDhw(IdfBase): class IdfDhw(IdfBase):
@staticmethod
def add(self, thermal_zone, zone_name): def add(self, thermal_zone, zone_name):
name = f'DHW {zone_name}' name = f'DHW {zone_name}'
peak_flow_rate = thermal_zone.domestic_hot_water.peak_flow * thermal_zone.total_floor_area peak_flow_rate = thermal_zone.domestic_hot_water.peak_flow * thermal_zone.total_floor_area

View File

@ -5,6 +5,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfFileSchedule(IdfBase): class IdfFileSchedule(IdfBase):
@staticmethod
def add(self, usage, schedule_type, schedules): def add(self, usage, schedule_type, schedules):
schedule_name = f'{schedule_type} schedules {usage}' schedule_name = f'{schedule_type} schedules {usage}'
for schedule in schedules: for schedule in schedules:

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfHeatingSystem(IdfBase): class IdfHeatingSystem(IdfBase):
@staticmethod
def add(self, thermal_zone, zone_name): def add(self, thermal_zone, zone_name):
availability_schedule = f'HVAC AVAIL SCHEDULES {thermal_zone.usage_name}' availability_schedule = f'HVAC AVAIL SCHEDULES {thermal_zone.usage_name}'
thermostat_name = f'Thermostat {thermal_zone.usage_name}' thermostat_name = f'Thermostat {thermal_zone.usage_name}'

View File

@ -1,9 +1,10 @@
import hub.exports.building_energy.idf_helper as idf_cte import hub.exports.building_energy.idf_helper as idf_cte
import hub.helpers.constants as cte
from hub.exports.building_energy.idf_helper.idf_base import IdfBase from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfInfiltration(IdfBase): class IdfInfiltration(IdfBase):
@staticmethod
def add(self, thermal_zone, zone_name): def add(self, thermal_zone, zone_name):
schedule_name = f'Infiltration schedules {thermal_zone.usage_name}' schedule_name = f'Infiltration schedules {thermal_zone.usage_name}'
infiltration = thermal_zone.infiltration_rate_system_off * cte.HOUR_TO_SECONDS infiltration = thermal_zone.infiltration_rate_system_off * cte.HOUR_TO_SECONDS

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfLighting(IdfBase): class IdfLighting(IdfBase):
@staticmethod
def add(self, thermal_zone, zone_name): def add(self, thermal_zone, zone_name):
storeys_number = int(thermal_zone.total_floor_area / thermal_zone.footprint_area) storeys_number = int(thermal_zone.total_floor_area / thermal_zone.footprint_area)
watts_per_zone_floor_area = thermal_zone.lighting.density * storeys_number watts_per_zone_floor_area = thermal_zone.lighting.density * storeys_number

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfMaterial(IdfBase): class IdfMaterial(IdfBase):
@staticmethod
def _add_solid_material(self, layer): def _add_solid_material(self, layer):
file = self._files['solid_materials'] file = self._files['solid_materials']
self._write_to_idf_format(file, idf_cte.SOLID_MATERIAL) self._write_to_idf_format(file, idf_cte.SOLID_MATERIAL)
@ -16,6 +17,7 @@ class IdfMaterial(IdfBase):
self._write_to_idf_format(file, layer.solar_absorptance, 'Solar Absorptance') self._write_to_idf_format(file, layer.solar_absorptance, 'Solar Absorptance')
self._write_to_idf_format(file, layer.visible_absorptance, 'Visible Absorptance', ';') self._write_to_idf_format(file, layer.visible_absorptance, 'Visible Absorptance', ';')
@staticmethod
def _add_nomass_material(self, layer): def _add_nomass_material(self, layer):
file = self._files['nomass_materials'] file = self._files['nomass_materials']
self._write_to_idf_format(file, idf_cte.NOMASS_MATERIAL) self._write_to_idf_format(file, idf_cte.NOMASS_MATERIAL)
@ -26,11 +28,12 @@ class IdfMaterial(IdfBase):
self._write_to_idf_format(file, 0.7, 'Solar Absorptance') self._write_to_idf_format(file, 0.7, 'Solar Absorptance')
self._write_to_idf_format(file, 0.7, 'Visible Absorptance', ';') self._write_to_idf_format(file, 0.7, 'Visible Absorptance', ';')
@staticmethod
def add(self, thermal_boundary): def add(self, thermal_boundary):
for layer in thermal_boundary.layers: for layer in thermal_boundary.layers:
if layer.material_name not in self._materials_added_to_idf: if layer.material_name not in self._materials_added_to_idf:
self._materials_added_to_idf[layer.material_name] = True self._materials_added_to_idf[layer.material_name] = True
if layer.no_mass: if layer.no_mass:
self._add_nomass_material(layer) IdfMaterial._add_nomass_material(self, layer)
else: else:
self._add_solid_material(layer) IdfMaterial._add_solid_material(self, layer)

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfOccupancy(IdfBase): class IdfOccupancy(IdfBase):
@staticmethod
def add(self, thermal_zone, zone_name): def add(self, thermal_zone, zone_name):
number_of_people = thermal_zone.occupancy.occupancy_density * thermal_zone.total_floor_area number_of_people = thermal_zone.occupancy.occupancy_density * thermal_zone.total_floor_area
fraction_radiant = 0 fraction_radiant = 0

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfSchedule(IdfBase): class IdfSchedule(IdfBase):
@staticmethod
def add(self, usage, schedule_type, schedules): def add(self, usage, schedule_type, schedules):
if len(schedules) < 1: if len(schedules) < 1:
return return

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfShading(IdfBase): class IdfShading(IdfBase):
@staticmethod
def add(self, building): def add(self, building):
name = building.name name = building.name
file = self._files['shading'] file = self._files['shading']

View File

@ -4,13 +4,14 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfSurfaces(IdfBase): class IdfSurfaces(IdfBase):
@staticmethod
def add(self, building, zone_name): def add(self, building, zone_name):
# Verify if create building surfaces "by hand" it's faster wwr it's missing # Verify if create building surfaces "by hand" it's faster wwr it's missing
zone_name = f'{zone_name}' zone_name = f'{zone_name}'
file = self._files['surfaces'] file = self._files['surfaces']
for thermal_zone in building.thermal_zones_from_internal_zones: for thermal_zone in building.thermal_zones_from_internal_zones:
for index, boundary in enumerate(thermal_zone.thermal_boundaries): for index, boundary in enumerate(thermal_zone.thermal_boundaries):
surface_type = idf_cte.idf_surfaces[boundary.parent_surface.type] surface_type = idf_cte.idf_surfaces_dictionary[boundary.parent_surface.type]
outside_boundary_condition = idf_cte.OUTDOORS outside_boundary_condition = idf_cte.OUTDOORS
sun_exposure = idf_cte.SUN_EXPOSED sun_exposure = idf_cte.SUN_EXPOSED
wind_exposure = idf_cte.WIND_EXPOSED wind_exposure = idf_cte.WIND_EXPOSED

View File

@ -3,7 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfThermostat(IdfBase): class IdfThermostat(IdfBase):
@staticmethod
def add(self, thermal_zone): def add(self, thermal_zone):
thermostat_name = f'Thermostat {thermal_zone.usage_name}' thermostat_name = f'Thermostat {thermal_zone.usage_name}'
heating_schedule = f'Heating thermostat schedules {thermal_zone.usage_name}' heating_schedule = f'Heating thermostat schedules {thermal_zone.usage_name}'

View File

@ -4,6 +4,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfVentilation(IdfBase): class IdfVentilation(IdfBase):
@staticmethod
def add(self, thermal_zone, zone_name): def add(self, thermal_zone, zone_name):
schedule_name = f'Ventilation schedules {thermal_zone.usage_name}' schedule_name = f'Ventilation schedules {thermal_zone.usage_name}'
air_change = thermal_zone.mechanical_air_change * cte.HOUR_TO_SECONDS air_change = thermal_zone.mechanical_air_change * cte.HOUR_TO_SECONDS

View File

@ -0,0 +1,9 @@
import hub.exports.building_energy.idf_helper as idf_cte
import hub.helpers.constants as cte
from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfWindow(IdfBase):
@staticmethod
def add(self, building, zone_name):
pass

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfWindowsConstructions(IdfBase): class IdfWindowsConstructions(IdfBase):
@staticmethod
def add(self): def add(self):
glazing_index = self._windows_added_to_idf['glazing_index'] + 1 glazing_index = self._windows_added_to_idf['glazing_index'] + 1
for i in range(1, glazing_index): for i in range(1, glazing_index):

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfWindowsMaterial(IdfBase): class IdfWindowsMaterial(IdfBase):
@staticmethod
def add(self, thermal_opening): def add(self, thermal_opening):
name = f'{thermal_opening.overall_u_value}_{thermal_opening.g_value}' name = f'{thermal_opening.overall_u_value}_{thermal_opening.g_value}'
if name not in self._windows_added_to_idf: if name not in self._windows_added_to_idf:

View File

@ -3,6 +3,7 @@ from hub.exports.building_energy.idf_helper.idf_base import IdfBase
class IdfZone(IdfBase): class IdfZone(IdfBase):
@staticmethod
def add(self, thermal_zone, zone_name): def add(self, thermal_zone, zone_name):
file = self._files['zones'] file = self._files['zones']
self._write_to_idf_format(file, idf_cte.ZONE) self._write_to_idf_format(file, idf_cte.ZONE)