Coverage for test/unit/tasks/bps/test_enrich_use_cond.py: 100%
141 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 17:09 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 17:09 +0000
1from bim2sim.elements.mapping.units import ureg
2from bim2sim.kernel.decision.decisionhandler import DebugDecisionHandler
3from bim2sim.sim_settings import BuildingSimSettings
4from bim2sim.tasks.bps import EnrichUseConditions, enrich_use_cond
5from bim2sim.utilities.common_functions import get_use_conditions_dict, \
6 get_pattern_usage
7from test.unit.elements.helper import SetupHelperBPS
8from test.unit.tasks import TestTask
11class TestEnrichUseConditions(TestTask):
12 @classmethod
13 def simSettingsClass(cls):
14 return BuildingSimSettings()
16 @classmethod
17 def testTask(cls):
18 return EnrichUseConditions(cls.playground)
20 @classmethod
21 def helper(cls):
22 return SetupHelperBPS()
24 def test_enrichment_maintained_illuminance_false(self):
25 """Test if sim_setting to false leads to fixed lighting power"""
26 self.playground.sim_settings.use_maintained_illuminance = False
27 tz = self.helper.get_thermalzone(
28 guid='ThermalZone001',
29 usage='Office',
30 gross_area=10)
31 elements = {tz.guid: tz}
32 answers = ()
33 reads = (elements,)
34 test_res = self.run_task(answers, reads)
35 self.assertEqual(tz.lighting_power, tz.fixed_lighting_power)
36 self.assertEqual(tz.lighting_power, 15.9 * ureg.watt / ureg.m ** 2)
38 def test_enrichment_single_office_common_conditions(self):
39 """Tests enrichment of single office with common use conditions."""
40 self.playground.sim_settings.use_maintained_illuminance = True
42 tz = self.helper.get_thermalzone(
43 guid='ThermalZone001',
44 usage='Office',
45 gross_area=10)
46 elements = {tz.guid: tz}
47 answers = ()
48 reads = (elements,)
49 test_res = self.run_task(answers, reads)
50 self.assertEqual(tz.usage, 'Single office')
51 self.assertEqual(tz.machines, 7.0 * ureg.watt / ureg.m ** 2)
52 self.assertEqual(tz.use_maintained_illuminance, True)
53 self.assertEqual(tz.lighting_power, 10 / 3 * ureg.watt / ureg.m ** 2)
55 def test_enrichment_sim_setting_without_overwrite(self):
56 """Tests enrichment of single office without overwrite via settings."""
57 print(self.playground.sim_settings.heating_tz_overwrite)
58 print(self.playground.sim_settings.cooling_tz_overwrite)
59 print(self.playground.sim_settings.ahu_tz_overwrite)
60 tz = self.helper.get_thermalzone(
61 guid='ThermalZone001',
62 usage='Office',
63 gross_area=10)
64 elements = {tz.guid: tz}
65 answers = ()
66 reads = (elements,)
67 test_res = self.run_task(answers, reads)
68 self.assertTrue(tz.with_heating)
69 self.assertFalse(tz.with_cooling)
70 self.assertFalse(tz.with_ahu)
72 def test_enrichment_sim_setting_overwrite(self):
73 """Tests enrichment of single office with overwrite via settings."""
74 self.playground.sim_settings.heating_tz_overwrite = True
75 self.playground.sim_settings.cooling_tz_overwrite = True
76 self.playground.sim_settings.ahu_tz_overwrite = True
78 tz = self.helper.get_thermalzone(
79 guid='ThermalZone001',
80 usage='Office',
81 gross_area=10)
82 elements = {tz.guid: tz}
83 answers = ()
84 reads = (elements,)
85 test_res = self.run_task(answers, reads)
86 self.assertTrue(tz.with_heating)
87 self.assertTrue(tz.with_cooling)
88 self.assertTrue(tz.with_ahu)
90 def test_enrichment_sim_setting_overwrite_false(self):
91 """Tests enrichment of single office with overwrite via settings."""
92 self.playground.sim_settings.heating_tz_overwrite = False
93 self.playground.sim_settings.cooling_tz_overwrite = False
94 self.playground.sim_settings.ahu_tz_overwrite = False
96 tz = self.helper.get_thermalzone(
97 guid='ThermalZone001',
98 usage='Office',
99 gross_area=10)
100 elements = {tz.guid: tz}
101 answers = ()
102 reads = (elements,)
103 test_res = self.run_task(answers, reads)
104 self.assertFalse(tz.with_heating)
105 self.assertFalse(tz.with_cooling)
106 self.assertFalse(tz.with_ahu)
108 def test_bldg_ahu_enrichment(self):
109 """Test if enrichment of AHU on tz level sets AHU on bldg level"""
110 self.playground.sim_settings.ahu_tz_overwrite = True
112 elements = self.helper.get_setup_simple_house()
114 answers = ()
115 reads = (elements,)
116 test_res = self.run_task(answers, reads)
117 bldg = elements['bldg001']
118 tz = elements['tz001']
119 self.assertTrue(tz.with_ahu)
120 self.assertTrue(bldg.with_ahu)
122 def test_bldg_ahu_enrichment_false(self):
123 """Test if enrichment of AHU on tz level sets AHU on bldg level"""
124 self.playground.sim_settings.ahu_tz_overwrite = False
126 elements = self.helper.get_setup_simple_house()
128 answers = ()
129 reads = (elements,)
130 test_res = self.run_task(answers, reads)
131 bldg = elements['bldg001']
132 tz = elements['tz001']
133 self.assertFalse(tz.with_ahu)
134 self.assertFalse(bldg.with_ahu)
136 def test_bldg_ahu_enrichment_complete(self):
137 """Test if enrichment of AHU on tz level sets AHU on bldg level"""
138 self.playground.sim_settings.ahu_tz_overwrite = True
139 self.playground.sim_settings.ahu_heating_overwrite = True
140 self.playground.sim_settings.ahu_cooling_overwrite = True
141 self.playground.sim_settings.ahu_dehumidification_overwrite = True
142 self.playground.sim_settings.ahu_humidification_overwrite = True
143 self.playground.sim_settings.ahu_heat_recovery_overwrite = True
144 self.playground.sim_settings.ahu_heat_recovery_efficiency_overwrite = \
145 0.8
147 elements = self.helper.get_setup_simple_house()
149 answers = ()
150 reads = (elements,)
151 test_res = self.run_task(answers, reads)
152 bldg = elements['bldg001']
153 tz = elements['tz001']
154 self.assertTrue(tz.with_ahu)
155 self.assertTrue(bldg.with_ahu)
156 self.assertTrue(bldg.ahu_heating)
157 self.assertTrue(bldg.ahu_cooling)
158 self.assertTrue(bldg.ahu_dehumidification)
159 self.assertTrue(bldg.ahu_humidification)
160 self.assertTrue(bldg.ahu_heat_recovery)
161 self.assertEqual(bldg.ahu_heat_recovery_efficiency, 0.8)
163 def test_infiltration_sim_setting_overwrite(self):
164 """Test if enrichment of infiltration on tz level works."""
165 self.playground.sim_settings.use_constant_infiltration_overwrite = True
166 self.playground.sim_settings.base_infiltration_rate_overwrite = 0.5
168 elements = self.helper.get_setup_simple_house()
170 answers = ()
171 reads = (elements,)
172 test_res = self.run_task(answers, reads)
173 bldg = elements['bldg001']
174 tz = elements['tz001']
175 self.assertTrue(tz.use_constant_infiltration)
176 self.assertEqual(tz.base_infiltration, 0.5)
178 def test_with_five_different_zones(self):
179 """Tests if usages get set correctly for five ThermalZone elements.
181 The first ThermalZone has a usage that can be identified by regular
182 expressions ('Wohnen').
183 The second ThermalZone is a direct fit to the existing usage
184 conditions.
185 The third and fourth ThermalZone can't be identified due to random
186 names
187 , but the third one is similar to the first).
188 The fifth ThermalZone can again be identified using the office_usage
189 function.
191 """
192 prj_name = 'test'
193 usages = [
194 'Wohnen',
195 'Living',
196 'NotToIdentify', # should be found as 'Bed room'
197 'NotToIdentifyAsWell', # should be found as 'Kitchen'
198 'Office'
199 ]
200 gross_areas = [
201 100,
202 100,
203 100,
204 100,
205 100
206 ]
207 tz_elements = self.helper.get_thermalzones_diff_usage(
208 usages, gross_areas)
209 expected_usages_list = [
210 'Living',
211 'Living',
212 'Bed room',
213 'Kitchen - preparations, storage',
214 'Open-plan Office (7 or more employees)'
215 ]
216 expected_usages = {
217 tz_elements[i]: expected_usages_list[i] for i in range(
218 len(tz_elements))}
219 tz_elements_dict = {tz.guid: tz for tz in tz_elements}
220 handler = DebugDecisionHandler(
221 answers=['Bed room', 'Kitchen - preparations, storage'])
222 # No custom usages and use conditions required for this test
223 custom_usage_path = None
224 custom_use_conditions_path = None
225 self.use_conditions = get_use_conditions_dict(custom_usage_path)
226 pattern_usage = get_pattern_usage(
227 self.use_conditions, custom_use_conditions_path)
228 found_usages = handler.handle(
229 enrich_use_cond.EnrichUseConditions.enrich_usages(
230 pattern_usage, tz_elements_dict))
231 self.assertDictEqual(
232 expected_usages,
233 found_usages)