Finished the changes to divide buildings by storey to be used in dynamic bulding simulations. Some unittests don't pass yet but the problem can come from the gml reading.

This commit is contained in:
Pilar 2021-08-10 17:09:42 -04:00
parent 70c020ee77
commit a28774fde0
7 changed files with 31 additions and 47 deletions

View File

@ -33,7 +33,7 @@ class Building(CityObject):
self._year_of_construction = year_of_construction self._year_of_construction = year_of_construction
self._function = function self._function = function
self._average_storey_height = None self._average_storey_height = None
self._storeys_above_ground = None self._storeys_above_ground = 1
self._floor_area = None self._floor_area = None
self._roof_type = None self._roof_type = None
self._thermal_zones = [] self._thermal_zones = []
@ -111,19 +111,11 @@ class Building(CityObject):
Get city object usage zones Get city object usage zones
:return: [UsageZone] :return: [UsageZone]
""" """
if len(self._usage_zones) == 0:
for thermal_zone in self.thermal_zones:
self._usage_zones.extend(thermal_zone.usage_zones)
return self._usage_zones return self._usage_zones
@usage_zones.setter
def usage_zones(self, values):
"""
Set city objects usage zones
:param values: [UsageZones]
:return: None
"""
self._usage_zones = values
for thermal_zone in self.thermal_zones:
thermal_zone.usage_zones = values
@property @property
def terrains(self) -> List[Surface]: def terrains(self) -> List[Surface]:
""" """
@ -180,6 +172,9 @@ class Building(CityObject):
City object thermal zones City object thermal zones
:return: [ThermalZone] :return: [ThermalZone]
""" """
if len(self._thermal_zones) == 0:
for storey in self.storeys:
self._thermal_zones.append(storey.thermal_zone)
return self._thermal_zones return self._thermal_zones
@property @property
@ -307,7 +302,10 @@ class Building(CityObject):
number_of_storeys, height = self._calculate_number_storeys_and_height(self.average_storey_height, self.eave_height, number_of_storeys, height = self._calculate_number_storeys_and_height(self.average_storey_height, self.eave_height,
self.storeys_above_ground) self.storeys_above_ground)
if number_of_storeys == 0: if number_of_storeys == 0:
return Storey('storey_0', self.surfaces, [None, None]) raise Exception(f'Number of storeys cannot be 0')
if number_of_storeys == 1:
return [Storey('storey_0', self.surfaces, [None, None])]
storeys = [] storeys = []
surfaces_child_last_storey = [] surfaces_child_last_storey = []

View File

@ -94,5 +94,5 @@ class Storey:
:return: ThermalZone :return: ThermalZone
""" """
if self._thermal_zone is None: if self._thermal_zone is None:
self._thermal_zone = ThermalZone(self.virtual_surfaces) self._thermal_zone = ThermalZone(self.thermal_boundaries)
return self._thermal_zone return self._thermal_zone

View File

@ -260,8 +260,11 @@ class Surface:
new_solid_polygon = Polygon(self.solid_polygon.inverse) new_solid_polygon = Polygon(self.solid_polygon.inverse)
new_perimeter_polygon = Polygon(self.perimeter_polygon.inverse) new_perimeter_polygon = Polygon(self.perimeter_polygon.inverse)
new_holes_polygons = [] new_holes_polygons = []
for hole in self.holes_polygons: if self.holes_polygons is not None:
new_holes_polygons.append(Polygon(hole.inverse)) for hole in self.holes_polygons:
new_holes_polygons.append(Polygon(hole.inverse))
else:
new_holes_polygons = None
self._inverse = Surface(new_solid_polygon, new_perimeter_polygon, new_holes_polygons, cte.VIRTUAL_INTERNAL) self._inverse = Surface(new_solid_polygon, new_perimeter_polygon, new_holes_polygons, cte.VIRTUAL_INTERNAL)
return self._inverse return self._inverse

View File

@ -17,10 +17,9 @@ class ThermalZone:
""" """
ThermalZone class ThermalZone class
""" """
def __init__(self, surfaces): def __init__(self, thermal_boundaries):
self._surfaces = surfaces
self._floor_area = None self._floor_area = None
self._bounded = None self._bounded = thermal_boundaries
self._is_mechanically_ventilated = None self._is_mechanically_ventilated = None
self._additional_thermal_bridge_u_value = None self._additional_thermal_bridge_u_value = None
self._effective_thermal_capacity = None self._effective_thermal_capacity = None
@ -92,7 +91,8 @@ class ThermalZone:
""" """
if self._floor_area is None: if self._floor_area is None:
self._floor_area = 0 self._floor_area = 0
for s in self._surfaces: for thermal_boundary in self.bounded:
s = thermal_boundary.surface
if s.type == 'Ground': if s.type == 'Ground':
self._floor_area += s.perimeter_polygon.area self._floor_area += s.perimeter_polygon.area
return self._floor_area return self._floor_area
@ -105,24 +105,6 @@ class ThermalZone:
""" """
return self._bounded return self._bounded
@bounded.setter
def bounded(self, value):
"""
Set thermal boundaries bounding with the thermal zone
:param value: [ThermalBoundary]
:return: None
"""
self._bounded = value
@property
def surfaces(self) -> List[Surface]:
# todo: This property should be erased (@Guille: why??)
"""
Get thermal zone surfaces
:return: [Surface]
"""
return self._surfaces
@property @property
def additional_thermal_bridge_u_value(self): def additional_thermal_bridge_u_value(self):
""" """

View File

@ -40,9 +40,10 @@ class HftUsageParameters(HftUsageInterface):
mix_usage = False mix_usage = False
if not mix_usage: if not mix_usage:
# just one usage_zone # just one usage_zone
usage_zone = UsageZone() for thermal_zone in building.thermal_zones:
self._assign_values(usage_zone, archetype) usage_zone = UsageZone()
building.usage_zones = [usage_zone] self._assign_values(usage_zone, archetype)
thermal_zone.usage_zone = [usage_zone]
def _search_archetype(self, building_usage): def _search_archetype(self, building_usage):
for building_archetype in self._usage_archetypes: for building_archetype in self._usage_archetypes:

View File

@ -35,6 +35,7 @@ class TestConstructionFactory(TestCase):
:return: None :return: None
""" """
# todo: file = 'pluto_building.gml' -> it has 0 surfaces!!
file = 'pluto_building.gml' file = 'pluto_building.gml'
city = self._get_citygml(file) city = self._get_citygml(file)
for building in city.buildings: for building in city.buildings:

View File

@ -53,7 +53,9 @@ class TestGeometryFactory(TestCase):
Test city objects in the city Test city objects in the city
:return: None :return: None
""" """
file = 'one_building_in_kelowna.gml' # todo @Guille: when reading gml, pluto_building.gml has no surfaces
#file = 'one_building_in_kelowna.gml'
file = 'pluto_building.gml'
city = self._get_citygml(file) city = self._get_citygml(file)
self.assertTrue(len(city.buildings) == 1) self.assertTrue(len(city.buildings) == 1)
for building in city.buildings: for building in city.buildings:
@ -68,9 +70,7 @@ class TestGeometryFactory(TestCase):
self.assertIsNone(building.basement_heated, 'building basement_heated is not none') self.assertIsNone(building.basement_heated, 'building basement_heated is not none')
self.assertIsNone(building.attic_heated, 'building attic_heated is not none') self.assertIsNone(building.attic_heated, 'building attic_heated is not none')
self.assertIsNotNone(building.terrains, 'building terrains is none') self.assertIsNotNone(building.terrains, 'building terrains is none')
self.assertIsNotNone(building.usage_zones, 'building usage_zones is none')
self.assertIsNone(building.average_storey_height, 'building average_storey_height is not none') self.assertIsNone(building.average_storey_height, 'building average_storey_height is not none')
self.assertIsNone(building.storeys_above_ground, 'building storeys_above_ground is not none')
self.assertIsNot(len(building.thermal_zones), 0, 'no building thermal_zones defined') self.assertIsNot(len(building.thermal_zones), 0, 'no building thermal_zones defined')
self.assertIsNotNone(building.type, 'building type is none') self.assertIsNotNone(building.type, 'building type is none')
self.assertIsNotNone(building.max_height, 'building max_height is none') self.assertIsNotNone(building.max_height, 'building max_height is none')
@ -110,7 +110,6 @@ class TestGeometryFactory(TestCase):
for building in city.buildings: for building in city.buildings:
self.assertIsNot(len(building.thermal_zones), 0, 'no building thermal_zones defined') self.assertIsNot(len(building.thermal_zones), 0, 'no building thermal_zones defined')
for thermal_zone in building.thermal_zones: for thermal_zone in building.thermal_zones:
self.assertIsNotNone(thermal_zone.surfaces, 'thermal_zone surfaces is none')
self.assertIsNotNone(thermal_zone.bounded, 'thermal_zone bounded is none') self.assertIsNotNone(thermal_zone.bounded, 'thermal_zone bounded is none')
self.assertIsNotNone(thermal_zone.floor_area, 'thermal_zone floor_area is none') self.assertIsNotNone(thermal_zone.floor_area, 'thermal_zone floor_area is none')
self.assertIsNotNone(thermal_zone.is_heated, 'thermal_zone heated is none') self.assertIsNotNone(thermal_zone.is_heated, 'thermal_zone heated is none')
@ -140,11 +139,11 @@ class TestGeometryFactory(TestCase):
for thermal_zone in building.thermal_zones: for thermal_zone in building.thermal_zones:
self.assertIsNot(len(thermal_zone.bounded), 0, 'no building thermal_boundaries defined') self.assertIsNot(len(thermal_zone.bounded), 0, 'no building thermal_boundaries defined')
for thermal_boundary in thermal_zone.bounded: for thermal_boundary in thermal_zone.bounded:
print(thermal_boundary.surface.type)
print(thermal_boundary.surface.area_above_ground)
self.assertIsNotNone(thermal_boundary.surface, 'thermal_boundary surface is none') self.assertIsNotNone(thermal_boundary.surface, 'thermal_boundary surface is none')
self.assertIsNotNone(thermal_boundary.type, 'thermal_boundary type is none') self.assertIsNotNone(thermal_boundary.type, 'thermal_boundary type is none')
self.assertIsNotNone(thermal_boundary.area, 'thermal_boundary area is none') self.assertIsNotNone(thermal_boundary.area, 'thermal_boundary area is none')
self.assertIsNotNone(thermal_boundary.area_above_ground, 'thermal_boundary area_above_ground is none')
self.assertIsNotNone(thermal_boundary.area_below_ground, 'thermal_boundary area_below_ground is none')
self.assertIsNotNone(thermal_boundary.azimuth, 'thermal_boundary azimuth is none') self.assertIsNotNone(thermal_boundary.azimuth, 'thermal_boundary azimuth is none')
self.assertIsNotNone(thermal_boundary.delimits, 'thermal_boundary delimits is none') self.assertIsNotNone(thermal_boundary.delimits, 'thermal_boundary delimits is none')
self.assertIsNotNone(thermal_boundary.inclination, 'thermal_boundary inclination is none') self.assertIsNotNone(thermal_boundary.inclination, 'thermal_boundary inclination is none')