Adjustment to changes in libs

This commit is contained in:
Pilar 2021-03-02 18:58:06 -05:00
parent 6985d2445c
commit a17e575948
3 changed files with 78 additions and 44 deletions

View File

@ -4,7 +4,7 @@ from pathlib import Path
import pandas as pd import pandas as pd
import csv import csv
from factories.weather_feeders.helpers.weather import Weather as wt from imports.weather_feeders.helpers.weather import Weather as wt
class MonthlyEnergyBalance: class MonthlyEnergyBalance:
@ -20,61 +20,61 @@ class MonthlyEnergyBalance:
surfaces = building.surfaces surfaces = building.surfaces
for i in range(1, len(surfaces) + 1): for i in range(1, len(surfaces) + 1):
file += str(100 + i) + '.1 % Radiation surface ' + str(i) + '\r\n' file += str(100 + i) + '.1 % Radiation surface ' + str(i) + '\n'
file += 'p 4' + '\r\n' file += 'p 4' + '\n'
# BUILDING PARAMETERS # BUILDING PARAMETERS
file += str(building.heated_volume) + ' % BP(1) Heated Volume (vBrutto)\r\n' file += str(0.85*building.heated_volume) + ' % BP(1) Heated Volume (vBrutto)\n'
file += str(building.average_storey_height) + ' % BP(2) Average storey height / m\r\n' file += str(building.average_storey_height) + ' % BP(2) Average storey height / m\n'
file += str(building.storeys_above_ground) + ' % BP(3) Number of storeys above ground\r\n' file += str(building.storeys_above_ground) + ' % BP(3) Number of storeys above ground\n'
file += str(building.attic_heated) + ' % BP(4) Attic heating type (0=no room, 1=unheated, 2=heated)\r\n' file += str(building.attic_heated) + ' % BP(4) Attic heating type (0=no room, 1=unheated, 2=heated)\n'
file += str(building.basement_heated) + ' % BP(5) Cellar heating type (0=no room, 1=unheated, ' \ file += str(building.basement_heated) + ' % BP(5) Cellar heating type (0=no room, 1=unheated, ' \
'2=heated, 99=invalid)\r\n' '2=heated, 99=invalid)\n'
# todo: this method and the insel model have to be reviewed for more than one thermal zone # todo: this method and the insel model have to be reviewed for more than one thermal zone
thermal_zone = building.thermal_zones[0] thermal_zone = building.thermal_zones[0]
file += str(thermal_zone.indirectly_heated_area_ratio) + ' % BP(6) Indirectly heated area ratio\r\n' file += str(thermal_zone.indirectly_heated_area_ratio) + ' % BP(6) Indirectly heated area ratio\n'
file += str(thermal_zone.effective_thermal_capacity) + ' % BP(7) Effective heat capacity\r\n' file += str(thermal_zone.effective_thermal_capacity) + ' % BP(7) Effective heat capacity\n'
file += str(thermal_zone.additional_thermal_bridge_u_value) + ' % BP(8) Additional U-value for heat bridge\r\n' file += str(thermal_zone.additional_thermal_bridge_u_value) + ' % BP(8) Additional U-value for heat bridge\n'
file += '0 % BP(9) Usage type (0=standard, 1=IWU)\r\n' file += '0 % BP(9) Usage type (0=standard, 1=IWU)\n'
# ZONES AND SURFACES # ZONES AND SURFACES
# todo: is this actually number of thermal zones or of usage zones? # todo: is this actually number of thermal zones or of usage zones?
file += str(len(building.thermal_zones)) + ' % BP(10) Number $z$ of zones\r\n' file += str(len(building.thermal_zones)) + ' % BP(10) Number $z$ of zones\n'
i = 0 i = 0
for usage_zone in building.usage_zones: for usage_zone in building.usage_zones:
percentage_usage = 1 percentage_usage = 1
file += str(float(building.foot_print.area) * percentage_usage) + ' % BP(11) #1 Area of zone ' + \ file += str(float(building.foot_print.area) * percentage_usage) + ' % BP(11) #1 Area of zone ' + \
str(i + 1) + ' (sqm)' + '\r\n' str(i + 1) + ' (sqm)' + '\n'
total_internal_gains = 0 total_internal_gains = 0
for ig in usage_zone.internal_gains: for ig in usage_zone.internal_gains:
total_internal_gains += float(ig.average_internal_gain) * \ total_internal_gains += float(ig.average_internal_gain) * \
(float(ig.convective_fraction) + float(ig.radiative_fraction)) (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(total_internal_gains) + ' % BP(12) #2 Internal gains of zone ' + str(i + 1) + '\n'
file += str(usage_zone.heating_setpoint) + ' % BP(13) #3 Heating setpoint temperature zone ' + \ file += str(usage_zone.heating_setpoint) + ' % BP(13) #3 Heating setpoint temperature zone ' + \
str(i + 1) + ' (tSetHeat)' + '\r\n' str(i + 1) + ' (tSetHeat)' + '\n'
file += str(usage_zone.heating_setback) + ' % BP(14) #4 Heating setback temperature zone ' + \ file += str(usage_zone.heating_setback) + ' % BP(14) #4 Heating setback temperature zone ' + \
str(i + 1) + ' (tSetbackHeat)' + '\r\n' str(i + 1) + ' (tSetbackHeat)' + '\n'
file += str(usage_zone.cooling_setpoint) + ' % BP(15) #5 Cooling setpoint temperature zone ' + \ file += str(usage_zone.cooling_setpoint) + ' % BP(15) #5 Cooling setpoint temperature zone ' + \
str(i + 1) + ' (tSetCool)' + '\r\n' str(i + 1) + ' (tSetCool)' + '\n'
file += str(usage_zone.hours_day) + ' % BP(16) #6 Usage hours per day zone ' + str(i + 1) + '\r\n' file += str(usage_zone.hours_day) + ' % BP(16) #6 Usage hours per day zone ' + str(i + 1) + '\n'
file += str(usage_zone.days_year) + ' % BP(17) #7 Usage days per year zone ' + str(i + 1) + '\r\n' file += str(usage_zone.days_year) + ' % BP(17) #7 Usage days per year zone ' + str(i + 1) + '\n'
if usage_zone.mechanical_air_change is None: if usage_zone.mechanical_air_change is None:
raise Exception('Ventilation air rate is not initialized') raise Exception('Ventilation air rate is not initialized')
file += str(usage_zone.mechanical_air_change) + ' % BP(18) #8 Minimum air change rate zone ' + \ file += str(usage_zone.mechanical_air_change) + ' % BP(18) #8 Minimum air change rate zone ' + \
str(i + 1) + ' (h^-1)' + '\r\n' str(i + 1) + ' (h^-1)' + '\n'
i += 1 i += 1
file += str(len(surfaces)) + ' % Number of surfaces = BP(11+8z)\r\n' file += str(len(surfaces)) + ' % Number of surfaces = BP(11+8z)\n'
file += '% 1. Surface type (1=wall, 2=ground 3=roof, 4=flat roof)' + '\r\n' file += '% 1. Surface type (1=wall, 2=ground 3=roof, 4=flat roof)' + '\n'
file += '% 2. Areas above ground' + '\r\n' file += '% 2. Areas above ground' + '\n'
file += '% 3. Areas below ground' + '\r\n' file += '% 3. Areas below ground' + '\n'
file += '% 4. U-value' + '\r\n' file += '% 4. U-value' + '\n'
file += '% 5. Window area' + '\r\n' file += '% 5. Window area' + '\n'
file += '% 6. Window frame fraction' + '\r\n' file += '% 6. Window frame fraction' + '\n'
file += '% 7. Window U-value' + '\r\n' file += '% 7. Window U-value' + '\n'
file += '% 8. Window g-value' + '\r\n' file += '% 8. Window g-value' + '\n'
file += '% 9. Short-wave reflectance' + '\r\n' file += '% 9. Short-wave reflectance' + '\n'
file += '% #1 #2 #3 #4 #5 #6 #7 #8 #9' + '\r\n' file += '% #1 #2 #3 #4 #5 #6 #7 #8 #9' + '\n'
# todo: this method has to be reviewed for more than one thermal opening per thermal boundary # todo: this method has to be reviewed for more than one thermal opening per thermal boundary
for thermal_boundary in building.thermal_zones[0].bounded: for thermal_boundary in building.thermal_zones[0].bounded:

53
main.py
View File

@ -15,9 +15,10 @@ from populate import Populate
from insel.insel import Insel from insel.insel import Insel
from insel.templates.monthly_energy_balance import MonthlyEnergyBalance as templates from insel.templates.monthly_energy_balance import MonthlyEnergyBalance as templates
from simplified_radiosity_algorithm.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm from simplified_radiosity_algorithm.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from factories.geometry_factory import GeometryFactory from imports.geometry_factory import GeometryFactory
from factories.weather_factory import WeatherFactory from imports.weather_factory import WeatherFactory
from city_model_structure.city import City from city_model_structure.city import City
import datetime
parser = ArgumentParser(description='Monthly energy balance workflow v0.1.') parser = ArgumentParser(description='Monthly energy balance workflow v0.1.')
required = parser.add_argument_group('required arguments') required = parser.add_argument_group('required arguments')
@ -40,18 +41,27 @@ try:
except SystemExit: except SystemExit:
sys.exit() sys.exit()
keep_files = True keep_files = True
print('begin_time', datetime.datetime.now())
# Step 1: Initialize the city model # Step 1: Initialize the city model
pickle_file = '' pickle_file = ''
if ast.literal_eval(args.use_pickle_file): if ast.literal_eval(args.use_pickle_file):
pickle_file = Path(args.input_geometry_file).resolve() pickle_file = Path(args.input_geometry_file).resolve()
city = City.load(pickle_file) city = City.load(pickle_file)
else: else:
city = GeometryFactory(args.geometry_type, Path(args.input_geometry_file).resolve()).city file = Path(args.input_geometry_file).resolve()
pickle_file = Path(str(file).replace('.gml', '.pickle'))
city = GeometryFactory(args.geometry_type, file).city
city.save(pickle_file)
# Step 2: Populate city adding thermal- and usage-related parameters # Step 2: Populate city adding thermal- and usage-related parameters
populated_step_in_pickle = ast.literal_eval(args.populated_step_in_pickle) populated_step_in_pickle = ast.literal_eval(args.populated_step_in_pickle)
if populated_step_in_pickle: if populated_step_in_pickle:
populated_city = city populated_city = city
for building in populated_city.buildings:
for usage_zone in building.usage_zones:
usage_zone.heating_setpoint = 20
usage_zone.heating_setback = 17
else: else:
populated_city = Populate(city).populated_city populated_city = Populate(city).populated_city
pickle_file = Path(str(pickle_file).replace('.pickle', '_populated.pickle')) pickle_file = Path(str(pickle_file).replace('.pickle', '_populated.pickle'))
@ -60,6 +70,7 @@ if populated_city.buildings is None:
print('No building to be calculated') print('No building to be calculated')
sys.exit() sys.exit()
print('populating_time', datetime.datetime.now())
# Step 3: Populate city adding climate-related parameters # Step 3: Populate city adding climate-related parameters
weather_step_in_pickle = ast.literal_eval(args.weather_step_in_pickle) weather_step_in_pickle = ast.literal_eval(args.weather_step_in_pickle)
if not weather_step_in_pickle: if not weather_step_in_pickle:
@ -101,13 +112,31 @@ if not weather_step_in_pickle:
pickle_file = Path(str(pickle_file).replace('.pickle', '_weather.pickle')) pickle_file = Path(str(pickle_file).replace('.pickle', '_weather.pickle'))
populated_city.save(pickle_file) populated_city.save(pickle_file)
print('begin_insel_time', datetime.datetime.now())
# Step 4: Demand calculation (one model per building) # Step 4: Demand calculation (one model per building)
print_results = None print_results = None
file = 'city name: ' + city.name + '\r\n' # todo: city.name needs location and so, internet connection
# file = 'city name: ' + city.name + '\n'
file = 'city name: Kelowna\n'
i = 0 i = 0
for building in populated_city.buildings: for building in populated_city.buildings:
if 3000 < i and building.name != 'BLD122177': if building.name != 'BLD122177':
print(building.name) print(building.name)
# todo: default values to be defined at each specific workflow!
building.heated = True
building.cooled = False
building.attic_heated = 2
building.basement_heated = 1
for thermal_boundary in building.thermal_zones[0].bounded:
thermal_boundary.hi = 10
thermal_boundary.he = 25
for thermal_opening in thermal_boundary.thermal_openings:
thermal_opening.hi = 10
thermal_opening.he = 25
building.thermal_zones[0].indirectly_heated_area_ratio = 0.25
building.thermal_zones[0].additional_thermal_bridge_u_value = 0.05
building.usage_zones[0].mechanical_air_change = 0.35
building.thermal_zones[0].infiltration_rate_system_on = 0
full_path_out = Path(args.project_folder + '/outputs/' + building.name + '_insel.out').resolve() full_path_out = Path(args.project_folder + '/outputs/' + building.name + '_insel.out').resolve()
full_path_out.parent.mkdir(parents=True, exist_ok=True) full_path_out.parent.mkdir(parents=True, exist_ok=True)
insel_file_name = building.name + '.insel' insel_file_name = building.name + '.insel'
@ -120,10 +149,14 @@ for building in populated_city.buildings:
print_results = new_building print_results = new_building
else: else:
print_results = pd.concat([print_results, new_building], axis='columns') print_results = pd.concat([print_results, new_building], axis='columns')
file += '\r\n' file += '\n'
file += 'name: ' + building.name + '\r\n' file += 'name: ' + building.name + '\n'
file += 'year of construction: ' + building.year_of_construction + '\r\n' file += 'year of construction: ' + building.year_of_construction + '\n'
file += 'function: ' + building.function + '\r\n' file += 'function: ' + building.function + '\n'
file += 'floor area: ' + str(building.thermal_zones[0].floor_area) + '\n'
file += 'storeys: ' + str(building.storeys_above_ground) + '\n'
file += 'heated_volume: ' + str(building.heated_volume) + '\n'
file += 'volume: ' + str(building.volume) + '\n'
except ValueError: except ValueError:
print(sys.exc_info()[1]) print(sys.exc_info()[1])
@ -137,3 +170,5 @@ print_results.to_csv(full_path_results)
full_path_metadata = Path(args.project_folder + '/outputs/metadata.csv').resolve() full_path_metadata = Path(args.project_folder + '/outputs/metadata.csv').resolve()
with open(full_path_metadata, 'w') as metadata_file: with open(full_path_metadata, 'w') as metadata_file:
metadata_file.write(file) metadata_file.write(file)
print('end_time', datetime.datetime.now())

View File

@ -4,8 +4,8 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
""" """
from factories.physics_factory import PhysicsFactory from imports.physics_factory import PhysicsFactory
from factories.usage_factory import UsageFactory from imports.usage_factory import UsageFactory
from city_model_structure.city import City from city_model_structure.city import City
@ -50,7 +50,6 @@ class Populate:
for building in tmp_city.buildings: for building in tmp_city.buildings:
# heating_setpoint is a mandatory parameter. # heating_setpoint is a mandatory parameter.
# If it is not returned, extract the building from the calculation list # If it is not returned, extract the building from the calculation list
print(len(building.usage_zones))
if len(building.usage_zones) > 0: if len(building.usage_zones) > 0:
self._populated_city.add_city_object(building) self._populated_city.add_city_object(building)
if self._populated_city.buildings is None: if self._populated_city.buildings is None: