dynamic_building_simulation/insel/templates/monthly_energy_balance.py

141 lines
6.5 KiB
Python

from helpers.library_codes import LibraryCodes
class MonthlyEnergyBalance:
@staticmethod
def generate_meb_template(city_object, temperatures, outputs_path):
lc = LibraryCodes()
file = ""
file += "s 1 do\r\n"
file += "p 1 1 12 1\r\n"
file += "\r\n"
file += "s 4 d18599 1 20 21\r\n"
surfaces = city_object.surfaces
for i in range(1, len(surfaces) + 1):
file += str(100 + i) + ' % Radiation surface ' + str(i) + '\r\n'
file += 'p 4' + '\r\n'
# BUILDING PARAMETERS
file += str(city_object.heated_volume) + ' % BP(1) Heated Volume (vBrutto)\r\n'
file += str(city_object.average_storey_height) + ' % BP(2) Average storey height / m\r\n'
file += str(city_object.storeys_above_ground) + ' % BP(3) Number of storeys above ground\r\n'
file += str(city_object.attic_heated) + ' % BP(4) Attic heating type (0=no room, 1=unheated, 2=heated)\r\n'
file += str(city_object.basement_heated) + ' % BP(5) Cellar heating type (0=no room, 1=unheated, ' \
'2=heated, 99=invalid)\r\n'
# todo: this method and the insel model have to be reviewed for more than one thermal zone
thermal_zone = city_object.thermal_zones[0]
file += str(thermal_zone.indirectly_heated_area_ratio) + ' % BP(6) Indirectly heated area ratio\r\n'
file += str(thermal_zone.effective_thermal_capacity) + ' % BP(7) Effective heat capacity\r\n'
file += str(thermal_zone.additional_thermal_bridge_u_value) + ' % BP(8) Additional U-value for heat bridge\r\n'
# todo: ensure that this line is not needed
# file += str(usage_parameters().standard) + ' % BP(9) Usage type (0=standard, 1=IWU)\r\n'
# ZONES AND SURFACES
file += str(len(city_object.thermal_zones)) + ' % BP(10) Number $z$ of zones\r\n'
i = 0
for usage_zone in city_object.usage_zones:
percentage_usage = 1
file += str(float(city_object.foot_print.area) * percentage_usage) + ' % BP(11) #1 Area of zone ' + \
str(i + 1) + ' (sqm)' + '\r\n'
total_internal_gains = 0
for ig in usage_zone.internal_gains:
total_internal_gains += float(ig.average_internal_gain) * \
(float(ig.convective_fraction) + float(ig.radiative_fraction))
file += str(total_internal_gains) + ' % BP(12) #2 Internal gains of zone ' + str(i + 1) + '\r\n'
file += str(usage_zone.heating_setpoint) + ' % BP(13) #3 Heating setpoint temperature zone ' + \
str(i + 1) + ' (tSetHeat)' + '\r\n'
file += str(usage_zone.heating_setback) + ' % BP(14) #4 Heating setback temperature zone ' + \
str(i + 1) + ' (tSetbackHeat)' + '\r\n'
file += str(usage_zone.cooling_setpoint) + ' % BP(15) #5 Cooling setpoint temperature zone ' + \
str(i + 1) + ' (tSetCool)' + '\r\n'
file += str(usage_zone.hours_day) + ' % BP(16) #6 Usage hours per day zone ' + str(i + 1) + '\r\n'
file += str(usage_zone.days_year) + ' % BP(17) #7 Usage days per year zone ' + str(i + 1) + '\r\n'
if usage_zone.min_air_change is None:
raise Exception('Ventilation air rate is not initialized')
file += str(usage_zone.min_air_change) + ' % BP(18) #8 Minimum air change rate zone ' + \
str(i + 1) + ' (h^-1)' + '\r\n'
i += 1
file += str(len(surfaces)) + ' % Number of surfaces = BP(11+8z)\r\n'
file += '% 1. Surface type (1=wall, 2=ground 3=roof, 4=flat roof)' + '\r\n'
file += '% 2. Areas above ground' + '\r\n'
file += '% 3. Areas below ground' + '\r\n'
file += '% 4. U-value' + '\r\n'
file += '% 5. Window area' + '\r\n'
file += '% 6. Window frame fraction' + '\r\n'
file += '% 7. Window U-value' + '\r\n'
file += '% 8. Window g-value' + '\r\n'
file += '% 9. Short-wave reflectance' + '\r\n'
file += '% #1 #2 #3 #4 #5 #6 #7 #8 #9' + '\r\n'
# todo: this method has to be reviewed for more than one thermal opening per thermal boundary
for thermal_boundary in city_object.thermal_zones[0].bounded:
type_code = lc.construction_types_to_code(thermal_boundary.type)
string = type_code + ' ' + str(thermal_boundary.area_above_ground) + ' ' + \
str(thermal_boundary.area_below_ground) + ' ' + str(thermal_boundary.u_value) + ' ' + \
str(thermal_boundary.window_area) + ' '
if thermal_boundary.window_area <= 0.001:
string = string + '0 0 0 '
else:
string = string + str(thermal_boundary.thermal_openings[0].frame_ratio) + ' ' + \
str(thermal_boundary.thermal_openings[0].u_value) + ' ' + \
str(thermal_boundary.thermal_openings[0].g_value) + ' '
if thermal_boundary.outside_solar_absorptance is not None:
string += str(thermal_boundary.shortwave_reflectance) + '\r\n'
else:
string += '0 \r\n'
file += string
file += '\r\n'
file += 's 20 polyg 1\r\n'
file += 'p 20 12 % Monthly ambient temperature\r\n'
i = 1
for temperature in temperatures[['temperature']].to_numpy():
file += str(i) + ' ' + str(temperature[0]) + '\r\n'
i += 1
file += '\r\n'
file += 's 21 polyg 1\r\n'
file += 'p 21 12 % Monthly sky temperature\r\n'
i = 1
for temperature in temperatures[['sky temperature']].to_numpy():
file += str(i) + ' ' + str(temperature[0]) + '\r\n'
i += 1
i = 0
for surface in surfaces:
file += '\r\n'
file += 's ' + str(101 + i) + ' polyg 1 % Monthly surface radiation (W/sqm)\r\n'
file += 'p ' + str(101 + i) + ' 12 % Azimuth ' + str(surface.azimuth) + \
', inclination ' + str(surface.inclination) + ' degrees\r\n'
j = 1
for global_irradiance_month in surface.global_irradiance_month:
file += str(j) + ' ' + str(global_irradiance_month) + '\r\n'
j += 1
i += 1
file += '\r\n'
file += '% ONE YEAR\r\n'
file += 's 300 cum 4.1 4.2\r\n'
file += 's 303 atend 300.1 300.2\r\n'
file += 's 304 screen 303.1 303.2 4.5\r\n'
file += "p 304 '(''Yearly results: qh = '',F13.2,'' qc = ''F13.2,'' kWh a^-1 meanUvalue = '',F6.3)'\r\n"
file += '\r\n'
file += '% MONTHLY\r\n'
file += 's 305 screen 4.1 4.2\r\n'
file += "p 305 '(''qh = '',F13.2,'' qc = ''F13.2,'' kWh a^-1'')'\r\n"
file += '\r\n'
file += 's ' + str(310) + ' WRITE\r\n'
file += '4.1 4.2\r\n'
file += 'p ' + str(301) + '\r\n'
file += '1 % Mode\r\n'
file += '0 % Suppress FNQ inputs\r\n'
file += "'" + str(outputs_path) + "' % File name\r\n"
file += "'*' % Fortran format\r\n"
return file