2020-05-19 17:00:15 -04:00
|
|
|
import sys
|
2021-05-26 16:28:39 -04:00
|
|
|
import ast
|
2020-05-19 17:00:15 -04:00
|
|
|
from insel.insel import Insel
|
2020-05-01 13:59:09 -04:00
|
|
|
from pathlib import Path
|
2021-05-26 16:28:39 -04:00
|
|
|
from populate import Populate
|
|
|
|
from simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
|
|
|
|
from imports.weather_factory import WeatherFactory
|
2020-05-19 17:00:15 -04:00
|
|
|
from insel.templates.thermal_demand_dynamic_simulation import ThermalDemandDynamicSimulation as Templates
|
|
|
|
from helpers.simulation_parameters import SimulationParameters as Sp
|
2021-05-26 16:28:39 -04:00
|
|
|
import helpers.constants as cte
|
|
|
|
from imports.geometry_factory import GeometryFactory
|
2020-05-01 13:59:09 -04:00
|
|
|
|
2021-05-26 16:28:39 -04:00
|
|
|
name_gml = 'one_building_in_kelowna.gml'
|
|
|
|
example_path = Path(__file__).parent
|
|
|
|
full_path_gml = (example_path / 'tests' / 'tests_data' / name_gml).resolve()
|
|
|
|
outputs_path = (example_path / 'tests' / 'tests_outputs').resolve()
|
2020-05-01 18:33:06 -04:00
|
|
|
keep_files = True
|
|
|
|
|
|
|
|
# Initialize the city model and add thermal- and usage-related parameters
|
2020-05-01 13:59:09 -04:00
|
|
|
# todo: add several steps:
|
|
|
|
# - simplification of the data model (for all work-flows)
|
|
|
|
# - internal zoning of buildings (for dynamic simulation only)
|
2021-05-26 16:28:39 -04:00
|
|
|
city = GeometryFactory('citygml', full_path_gml).city
|
|
|
|
|
|
|
|
populated_city = Populate(city).populated_city
|
|
|
|
print(len(city.buildings))
|
|
|
|
quit()
|
|
|
|
|
|
|
|
weather_format = 'epw'
|
|
|
|
city.climate_reference_city = args.climate_reference_city
|
|
|
|
path = (Path(args.project_folder) / 'tmp').resolve()
|
|
|
|
city.climate_file = (path / f'{args.climate_reference_city}.cli').resolve()
|
|
|
|
WeatherFactory(weather_format, populated_city, file_name=args.weather_file_name).enrich()
|
|
|
|
for building in populated_city.buildings:
|
|
|
|
if cte.HOUR not in building.external_temperature:
|
|
|
|
print('No external temperature found')
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
if cte.MONTH not in building.external_temperature:
|
|
|
|
building.external_temperature[cte.MONTH] = mv.MonthlyValues().\
|
|
|
|
get_mean_values(building.external_temperature[cte.MONTH][[weather_format]])
|
|
|
|
|
|
|
|
max_buildings_handled_by_sra = 500
|
|
|
|
for building in city.buildings:
|
|
|
|
for surface in building.surfaces:
|
|
|
|
surface.swr = 0.2
|
|
|
|
sra = SimplifiedRadiosityAlgorithm(city, Path(args.project_folder).resolve(), args.weather_file_name)
|
|
|
|
if ast.literal_eval(args.use_cached_sra_file):
|
2020-05-19 11:22:15 -04:00
|
|
|
sra.results()
|
2021-05-26 16:28:39 -04:00
|
|
|
sra.set_irradiance_surfaces(populated_city)
|
2020-05-19 11:22:15 -04:00
|
|
|
else:
|
2021-05-26 16:28:39 -04:00
|
|
|
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(args.project_folder).resolve(), args.weather_file_name)
|
|
|
|
sra_new.call_sra(weather_format, keep_files=True)
|
|
|
|
sra_new.set_irradiance_surfaces(populated_city, building_name=building.name)
|
|
|
|
else:
|
|
|
|
sra.call_sra(weather_format, keep_files=keep_files)
|
|
|
|
sra.set_irradiance_surfaces(populated_city)
|
2020-05-01 13:59:09 -04:00
|
|
|
|
2020-05-01 18:33:06 -04:00
|
|
|
# Demand calculation (one model per building)
|
2020-05-19 17:00:15 -04:00
|
|
|
for city_object in city.city_objects:
|
2020-05-26 17:15:48 -04:00
|
|
|
full_path_out = (outputs_path / city_object.name).resolve()
|
2020-05-19 17:00:15 -04:00
|
|
|
(example_path / 'third_party_files/sra').resolve()
|
|
|
|
full_path_wea = (example_path / 'third_party_files/insel' / (city_object.name + '.weather')).resolve()
|
|
|
|
full_path_ig = (example_path / 'third_party_files/insel' / (city_object.name + '.ig')).resolve()
|
2020-05-19 17:23:29 -04:00
|
|
|
|
2020-05-19 17:00:15 -04:00
|
|
|
insel_file_name = city_object.name + '.insel'
|
|
|
|
try:
|
|
|
|
content = Templates.generate_thermal_dynamic_template(city_object, full_path_out, full_path_wea, full_path_ig, Sp)
|
|
|
|
insel = Insel(example_path, insel_file_name, content, mode=2, keep_files=keep_files).results
|
|
|
|
except:
|
|
|
|
print(sys.exc_info()[1])
|
|
|
|
print('Building ' + city_object.name + ' could not be processed')
|
|
|
|
continue
|