2021-04-13 14:12:45 -04:00
|
|
|
"""
|
|
|
|
Simplified Radiosity Algorithm
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Guillermo.GutierrezMorote@concordia.ca
|
|
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
import xmltodict
|
|
|
|
|
2021-04-13 19:00:28 -04:00
|
|
|
|
2021-04-13 14:12:45 -04:00
|
|
|
class SimplifiedRadiosityAlgorithm:
|
|
|
|
|
|
|
|
def __init__(self, city, file_name, begin_month=1, begin_day=1, end_month=12, end_day=31):
|
|
|
|
self._file_name = file_name
|
|
|
|
self._begin_month = begin_month
|
|
|
|
self._begin_day = begin_day
|
|
|
|
self._end_month = end_month
|
|
|
|
self._end_day = end_day
|
|
|
|
self._city = city
|
|
|
|
self._export()
|
|
|
|
|
|
|
|
def _correct_point(self, point):
|
|
|
|
# correct the x, y, z values into the reference frame set by city lower_corner
|
|
|
|
x = point[0] - self._city.lower_corner[0]
|
|
|
|
y = point[1] - self._city.lower_corner[1]
|
|
|
|
z = point[2] - self._city.lower_corner[2]
|
|
|
|
return [x, y, z]
|
|
|
|
|
2021-06-09 10:46:53 -04:00
|
|
|
def _export(self, target_buildings_names=None):
|
2021-04-13 14:12:45 -04:00
|
|
|
buildings = []
|
|
|
|
for building_index, building in enumerate(self._city.buildings):
|
2021-06-09 10:46:53 -04:00
|
|
|
if target_buildings_names is None:
|
|
|
|
target_buildings_names = []
|
|
|
|
simulate = 'true'
|
|
|
|
else:
|
|
|
|
simulate = 'false'
|
|
|
|
for name in target_buildings_names:
|
|
|
|
if building.name == name:
|
|
|
|
simulate = 'true'
|
2021-04-13 14:12:45 -04:00
|
|
|
building_dict = {
|
|
|
|
'@Name': f'{building.name}',
|
|
|
|
'@id': f'{building_index}',
|
|
|
|
'@key': f'{building.name}',
|
2021-06-09 10:46:53 -04:00
|
|
|
'@Simulate': f'{simulate}'
|
2021-04-13 14:12:45 -04:00
|
|
|
}
|
|
|
|
walls, roofs, floors = [], [], []
|
|
|
|
for surface in building.surfaces:
|
|
|
|
surface_dict = {
|
|
|
|
'@id': f'{surface.id}',
|
|
|
|
'@ShortWaveReflectance': f'{surface.swr}'
|
|
|
|
}
|
|
|
|
for point_index, point in enumerate(surface.perimeter_polygon.points):
|
|
|
|
point = self._correct_point(point)
|
|
|
|
surface_dict[f'V{point_index}'] = {
|
|
|
|
'@x': f'{point[0]}',
|
|
|
|
'@y': f'{point[1]}',
|
|
|
|
'@z': f'{point[2]}'
|
|
|
|
}
|
2021-06-03 10:17:36 -04:00
|
|
|
if surface.type == 'Wall':
|
2021-04-14 10:22:29 -04:00
|
|
|
walls.append(surface_dict)
|
2021-06-03 10:17:36 -04:00
|
|
|
elif surface.type == 'Roof':
|
2021-04-14 10:22:29 -04:00
|
|
|
roofs.append(surface_dict)
|
|
|
|
else:
|
|
|
|
floors.append(surface_dict)
|
2021-04-13 14:12:45 -04:00
|
|
|
building_dict['Wall'] = walls
|
|
|
|
building_dict['Roof'] = roofs
|
|
|
|
building_dict['Floor'] = floors
|
|
|
|
buildings.append(building_dict)
|
|
|
|
sra = {
|
|
|
|
'CitySim': {
|
|
|
|
'@name': f'{self._file_name.name}',
|
|
|
|
'Simulation': {
|
|
|
|
'@beginMonth': f'{self._begin_month}',
|
|
|
|
'@beginDay': f'{self._begin_day}',
|
|
|
|
'@endMonth': f'{self._end_month}',
|
|
|
|
'@endDay': f'{self._end_day}',
|
|
|
|
},
|
|
|
|
'Climate': {
|
|
|
|
'@location': f'{self._city.climate_file}',
|
|
|
|
'@city': f'{self._city.climate_reference_city}'
|
|
|
|
},
|
|
|
|
'District': {
|
|
|
|
'FarFieldObstructions': None,
|
|
|
|
'Building': buildings
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
with open(self._file_name, "w") as file:
|
|
|
|
file.write(xmltodict.unparse(sra, pretty=True, short_empty_elements=True))
|
|
|
|
return
|