""" TestPhysicsFactory test and validate the city model structure physics parameters SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ from pathlib import Path from unittest import TestCase from imports.geometry_factory import GeometryFactory from imports.physics_factory import PhysicsFactory class TestPhysicsFactory(TestCase): """ TestPhysicsFactory TestCase """ def setUp(self) -> None: """ Configure test environment :return: """ self._city_gml = None self._nyc_with_physics = None self._example_path = (Path(__file__).parent / 'tests_data').resolve() def _get_citygml(self, file_path): if self._city_gml is None: self._city_gml = GeometryFactory('citygml', file_path).city self.assertIsNotNone(self._city_gml, 'city is none') return self._city_gml def _get_city_with_physics(self): if self._nyc_with_physics is None: file_path = (self._example_path / '20buildings.gml').resolve() self._nyc_with_physics = self._get_citygml(file_path) for building in self._nyc_with_physics.buildings: for tz in building.thermal_zones: for tb in tz.bounded: tb.hi = 10 tb.he = 25 for opening in tb.thermal_openings: opening.hi = 10 opening.he = 25 PhysicsFactory('us_new_york', self._nyc_with_physics).enrich() return self._nyc_with_physics def test_city_with_physics_extended_library(self): """ Enrich the city with the physic information and verify it :return: None """ city = self._get_city_with_physics() for building in city.buildings: self.assertIsNotNone(building.average_storey_height, 'average_storey_height is none') self.assertIsNotNone(building.storeys_above_ground, 'storeys_above_ground is none') for thermal_zone in building.thermal_zones: self.assertIsNotNone(thermal_zone.effective_thermal_capacity, 'effective_thermal_capacity is none') self.assertIsNotNone(thermal_zone.additional_thermal_bridge_u_value, 'additional_thermal_bridge_u_value is none') self.assertIsNotNone(thermal_zone.indirectly_heated_area_ratio, 'indirectly_heated_area_ratio is none') self.assertIsNotNone(thermal_zone.infiltration_rate_system_on, 'infiltration_rate_system_on is none') self.assertIsNotNone(thermal_zone.infiltration_rate_system_off, 'infiltration_rate_system_off is none') self.assertIsNotNone(thermal_zone.bounded, 'bounded is none') for thermal_boundary in thermal_zone.bounded: if thermal_boundary.surface.type is not 'Ground': self.assertIsNotNone(thermal_boundary.outside_solar_absorptance, 'outside_solar_absorptance is none') self.assertIsNotNone(thermal_boundary.window_ratio, 'window_ratio is none') def test_reduced_library(self): file_path = (self._example_path / 'lod2_buildings.gml').resolve() city = self._get_citygml(file_path) PhysicsFactory('ca', city).enrich() for building in city.buildings: self.assertIsNotNone(building.average_storey_height, 'average_storey_height is none') self.assertIsNotNone(building.storeys_above_ground, 'storeys_above_ground is none') for thermal_zone in building.thermal_zones: self.assertIsNotNone(thermal_zone.effective_thermal_capacity, 'effective_thermal_capacity is none') self.assertIsNotNone(thermal_zone.additional_thermal_bridge_u_value, 'additional_thermal_bridge_u_value is none') self.assertIsNotNone(thermal_zone.indirectly_heated_area_ratio, 'indirectly_heated_area_ratio is none') self.assertIsNotNone(thermal_zone.infiltration_rate_system_on, 'infiltration_rate_system_on is none') self.assertIsNotNone(thermal_zone.infiltration_rate_system_off, 'infiltration_rate_system_off is none') self.assertIsNotNone(thermal_zone.bounded, 'bounded is none') for thermal_boundary in thermal_zone.bounded: self.assertIsNotNone(thermal_boundary.outside_solar_absorptance, 'outside_solar_absorptance is none') self.assertIsNotNone(thermal_boundary.window_ratio, 'window_ratio is none')