erased populate and created enrich in libs.helpers.

add new constants to helpers.constants
This commit is contained in:
Pilar 2021-06-10 10:48:30 -04:00
parent 22b32cbb8e
commit fc9d7ef307
2 changed files with 73 additions and 112 deletions

116
main.py
View File

@ -1,15 +1,18 @@
import sys
import ast
from insel.insel import Insel
from pathlib import Path
from populate import Populate
from helpers.enrich_city import EnrichCity
from simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from imports.weather_factory import WeatherFactory
from insel.templates.thermal_demand_dynamic_simulation import ThermalDemandDynamicSimulation as Templates
from helpers.simulation_parameters import SimulationParameters as Sp
import helpers.constants as cte
from imports.geometry_factory import GeometryFactory
from imports.geometry_feeders.helpers.geometry_helper import GeometryHelper
from imports.geometry.helpers.geometry_helper import GeometryHelper
from city_model_structure.city import City
from city_model_structure.building import Building
from city_model_structure.attributes.polygon import Polygon
from city_model_structure.attributes.surface import Surface
name_gml = 'one_building_in_kelowna.gml'
function_format = 'hft'
@ -24,56 +27,83 @@ 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
keep_files = False
pickle_created = False
pickle_file = 'tests/tests_data/one_building_in_kelowna.pickle'
# Initialize the city model and add thermal- and usage-related parameters
# todo: add several steps:
# - simplification of the data model (for all work-flows)
# - internal zoning of buildings (for dynamic simulation only)
city = GeometryFactory('citygml', full_path_gml).city
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]
# todo: simplification of the data model
populated_city = Populate(city).populated_city(construction_format, usage_format, schedules_format)
if not pickle_created:
city = GeometryFactory('citygml', full_path_gml).city
weather_format = 'epw'
city.climate_reference_city = climate_reference_city
city.climate_file = (tmp_path / f'{climate_reference_city}.cli').resolve()
WeatherFactory(weather_format, populated_city, base_path=weather_path, file_name=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()
max_buildings_handled_by_sra = 500
for building in city.buildings:
for surface in building.surfaces:
surface.swr = 0.2
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
# Building division by storey
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(populated_city, building_name=building.name)
building.average_storey_height = 1.5
building.storeys_above_ground = 2
storeys = building.storeys
if len(storeys) != len(building.thermal_zones):
# todo:assign one thermal zone per storey
for storey in storeys:
surfaces = []
for face in storey.faces:
# todo: review for obj with windows
points = []
for vertex_index in face:
points.append(storey.vertices[vertex_index])
solid_polygon = Polygon(points)
perimeter_polygon = solid_polygon
surface = Surface(solid_polygon, perimeter_polygon)
surfaces.append(surface)
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
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)
else:
sra.call_sra(weather_format, keep_files=keep_files)
sra.set_irradiance_surfaces(city, mode=1)
# print(city.buildings[0].surfaces[1].global_irradiance['hour'].sra)
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:
sra.call_sra(weather_format, keep_files=keep_files)
sra.set_irradiance_surfaces(populated_city, mode=1)
print(city.buildings[0].surfaces[1].global_irradiance)
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
quit()
# Demand calculation (one model per building)
for city_object in city.city_objects:
full_path_out = (outputs_path / city_object.name).resolve()
(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()
full_path_wea = (tmp_path / (city_object.name + '.weather')).resolve()
full_path_ig = (tmp_path / (city_object.name + '.ig')).resolve()
insel_file_name = city_object.name + '.insel'
try:

View File

@ -1,69 +0,0 @@
"""
Populate city
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
"""
from imports.construction_factory import ConstructionFactory
from imports.usage_factory import UsageFactory
from imports.schedules_factory import SchedulesFactory
class Populate:
def __init__(self, city):
self._city = city
self._populated_city = None
self._errors = []
@property
def errors(self):
return self._errors
def populated_city(self, construction_format, usage_format, schedules_format):
if self._populated_city is None:
self._errors = []
print('original:', len(self._city.buildings))
# Step 2.1: Thermal parameters
ConstructionFactory(construction_format, self._city).enrich()
for building in self._city.buildings:
# infiltration_rate_system_off is a mandatory parameter.
# If it is not returned, extract the building from the calculation list
if building.thermal_zones[0].infiltration_rate_system_off is None:
self._city.remove_city_object(building)
if self._city.buildings is None:
self._errors.append('no archetype found per construction')
self._populated_city = self._city
return self._populated_city
print('enriched with construction:', len(self._city.buildings))
# Step 2.2: Usage parameters
UsageFactory(usage_format, self._city).enrich()
for building in self._city.buildings:
# At least one thermal zone must be created.
# If it is not created, extract the building from the calculation list
if len(building.usage_zones) <= 0:
self._city.remove_city_object(building)
if self._city.buildings is None:
self._errors.append('no archetype found per usage')
self._populated_city = self._city
return self._populated_city
print('enriched with usage:', len(self._city.buildings))
# Step 2.3: Schedules parameters
SchedulesFactory(schedules_format, self._city).enrich()
for building in self._city.buildings:
counter_schedules = 0
for usage_zone in building.usage_zones:
# At least one schedule must be created at each thermal zone.
# If it is not created, extract the building from the calculation list
if len(usage_zone.schedules) > 0:
counter_schedules += 1
if counter_schedules < len(building.usage_zones):
self._city.remove_city_object(building)
if self._city.buildings is None:
self._errors.append('no archetype found per usage')
self._populated_city = self._city
print('enriched with occupancy:', len(self._city.buildings))
return self._populated_city