some reorganization of files to clarify the processes

This commit is contained in:
Pilar 2021-08-31 16:16:22 -04:00
parent 573678a6c5
commit f1f3b78d0a
3 changed files with 68 additions and 36 deletions

View File

@ -8,6 +8,7 @@ import numpy as np
import pandas as pd
from insel.insel import Insel
import helpers.constants as cte
from imports.weather.helpers.weather import Weather as wt
class ThermalDemandDynamicSimulation:
@ -560,15 +561,15 @@ class ThermalDemandDynamicSimulation:
zeros = np.zeros(8760)
content = pd.DataFrame(building.external_temperature[cte.HOUR])
content.rename(columns={content.columns[0]: 'ambient_temperature'})
# content['sky_temperature'] = building.sky_temperature
content['sky_temperature'] = zeros
sky_temperature = wt.sky_temperature(building.external_temperature[cte.HOUR].to_numpy().T[0])
content['sky_temperature'] = np.array(sky_temperature).astype(float)
# content['ground_temperature'] = building.ground_temperature
content['ground_temperature'] = zeros
for i_tb, thermal_boundary in enumerate(building.thermal_boundaries):
if thermal_boundary.surface.type == cte.WALL or thermal_boundary.surface.type == cte.ROOF:
content[f'global_irradiance_{i_tb}'] = thermal_boundary.surface.global_irradiance[cte.HOUR].astype(float)
if len(thermal_boundary.thermal_openings) > 0:
content[f'diffuse_irradiance_{i_tb}'] = zeros
content[f'diffuse_irradiance_{i_tb}'] = building.diffuse[cte.HOUR].astype(float)
g_values = np.full((8760, 1), thermal_boundary.thermal_openings[0].g_value).astype(float)
content[f'g_value_{i_tb}'] = g_values
content[f'darkness_value_{i_tb}'] = zeros
@ -588,7 +589,26 @@ class ThermalDemandDynamicSimulation:
ig_path = self._ig_path
content = pd.DataFrame()
zeros = np.zeros(8760)
# todo: to talk with @Sanam -> where does this information come from?
for i_uz, usage_zone in enumerate(building.usage_zones):
convective_part = 0
radiative_part = 0
for internal_gain in usage_zone.internal_gains:
convective_part += internal_gain.average_internal_gain * internal_gain.convective_fraction
radiative_part += internal_gain.average_internal_gain * internal_gain.radiative_fraction
ventilation_schedule = usage_zone.ventilation_schedule
set_point_cooling = []
for value in usage_zone.cooling_schedule:
if value > 0:
set_point_cooling.append(value * usage_zone.cooling_setpoint)
else:
set_point_cooling.append(1000)
set_point_heating = []
for value in usage_zone.heating_schedule:
if value > 0:
set_point_heating.append(value * usage_zone.cooling_setpoint)
else:
set_point_heating.append(value * usage_zone.cooling_setback)
content[f'convective_part_{i_uz}'] = zeros
content[f'radiative_part_{i_uz}'] = zeros
content[f'ventilation_rate_{i_uz}'] = zeros

74
main.py
View File

@ -1,6 +1,7 @@
import sys
from insel.insel import Insel
from pathlib import Path
import pandas as pd
from helpers.enrich_city import EnrichCity
from simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from imports.weather_factory import WeatherFactory
@ -24,57 +25,72 @@ full_path_gml = (example_path / 'tests' / 'tests_data' / name_gml).resolve()
outputs_path = (example_path / 'tests' / 'tests_outputs').resolve()
tmp_path = (example_path / 'tests' / 'tmp').resolve()
weather_path = (Path(__file__).parent.parent / 'libs' / 'data' / 'weather').resolve()
keep_files = True
pickle_created = True
keep_sra_file = False
keep_insel_file = False
keep_weather_file = False
keep_ig_file = False
pickle_geometry = True
pickle_weather = True
pickle_construction = True
pickle_usage = True
pickle_schedules = True
pickle_file = 'tests/tests_data/one_building_in_kelowna.pickle'
if not pickle_created:
# Load geometry
if not pickle_geometry:
city = GeometryFactory('citygml', full_path_gml).city
city.save(pickle_file)
else:
city = City.load(pickle_file)
# Load weather and calculate radiation
if not pickle_weather:
# user configurable parameters
for building in city.buildings:
for surface in building.surfaces:
surface.swr = 0.2
# load weather
weather_format = 'epw'
city.climate_reference_city = climate_reference_city
city.climate_file = (tmp_path / f'{climate_reference_city}.cli').resolve()
WeatherFactory(weather_format, city, base_path=weather_path, file_name=weather_file_name).enrich()
for building in city.buildings:
if cte.HOUR not in building.external_temperature:
print('No external temperature found')
sys.exit()
max_buildings_handled_by_sra = 500
for building in city.buildings:
for surface in building.surfaces:
surface.swr = 0.2
# calculate radiation on external surfaces
max_buildings_handled_by_sra = 200
path = (example_path / 'tests').resolve()
sra = SimplifiedRadiosityAlgorithm(city, path, weather_file_name)
total_number_of_buildings = len(city.buildings)
if total_number_of_buildings > max_buildings_handled_by_sra:
radius = 80
for building in city.buildings:
new_city = city.region(building.centroid, radius)
sra_new = SimplifiedRadiosityAlgorithm(new_city, path, weather_file_name)
sra_new.call_sra(weather_format, keep_files=keep_files)
sra_new.set_irradiance_surfaces(city, building_name=building.name)
sra = SimplifiedRadiosityAlgorithm(new_city, path, weather_file_name)
sra.call_sra(weather_format, keep_files=keep_sra_file)
sra.set_irradiance_surfaces(city, mode=1, building_name=building.name)
else:
sra.call_sra(weather_format, keep_files=keep_files)
sra = SimplifiedRadiosityAlgorithm(city, path, weather_file_name)
sra.call_sra(weather_format, keep_files=keep_sra_file)
sra.set_irradiance_surfaces(city, mode=1)
for building in city.buildings:
if function_format == 'hft':
building.function = GeometryHelper.hft_to_function[building.function]
elif function_format == 'pluto':
building.function = GeometryHelper.pluto_to_function[building.function]
city = EnrichCity(city).enriched_city(construction_format, usage_format, schedules_format)
city.save(pickle_file)
else:
city = City.load(pickle_file)
# todo: when the enrichment step goes after SRA, check whether srw has changed
# after reading the construction library or not
# Enrich city with construction, usage and schedules
if not pickle_construction or not pickle_usage or not pickle_schedules:
for building in city.buildings:
if function_format == 'hft':
building.function = GeometryHelper.hft_to_function[building.function]
elif function_format == 'pluto':
building.function = GeometryHelper.pluto_to_function[building.function]
city = EnrichCity(city).enriched_city(construction_format, usage_format, schedules_format,
pickle_construction, pickle_usage, pickle_schedules)
city.save(pickle_file)
else:
city = City.load(pickle_file)
# Assign user defined parameters
if not pickle_created:
if not pickle_geometry:
for building in city.buildings:
print(len(building.storeys))
print(building.storeys[0].thermal_boundaries)
@ -123,7 +139,7 @@ for building in city.buildings:
template.generate_ig_file()
template.generate_fij_files()
print(insel_file_name)
insel = Insel(example_path, insel_file_name, content, mode=2, keep_files=keep_files).results
insel = Insel(example_path, insel_file_name, content, mode=2, keep_files=keep_insel_file).results
except:
print(sys.exc_info()[1])

View File

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore