Coverage for bim2sim/plugins/PluginComfort/test/integration/test_comfort.py: 0%

178 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-12 17:09 +0000

1import sys 

2import unittest 

3from shutil import copyfile, copytree, rmtree 

4from pathlib import Path 

5 

6import os 

7 

8import bim2sim 

9from bim2sim.kernel.decision.decisionhandler import DebugDecisionHandler 

10from bim2sim.utilities.test import IntegrationBase 

11from bim2sim.utilities.types import IFCDomain 

12 

13# raise unittest.SkipTest("Integration tests not reliable for automated use") 

14sample_root = Path(__file__).parent.parent.parent / 'test/resources/arch/ifc' 

15DEBUG_COMFORT = False 

16 

17 

18class IntegrationBaseComfort(IntegrationBase): 

19 # HACK: We have to remember stderr because eppy resets it currently. 

20 def setUp(self): 

21 self.old_stderr = sys.stderr 

22 self.working_dir = os.getcwd() 

23 super().setUp() 

24 

25 def tearDown(self): 

26 if DEBUG_COMFORT: # copy EP-results to home directory for further 

27 # debugging. 

28 if not os.path.exists(Path.home() / 'idf'): 

29 os.mkdir(Path.home() / 'idf') 

30 ifc_name = str(os.listdir(self.project.paths.ifc)[0].split('.ifc')[0]) 

31 temp_dir = Path(self.project.paths.export) / 'EnergyPlus'/\ 

32 'SimResults'/self.project.name 

33 debug_dir = Path.home() / 'idf' / Path(ifc_name + '_EP-results/') 

34 if os.path.exists(debug_dir): 

35 rmtree(debug_dir) 

36 copytree(temp_dir, debug_dir) 

37 try: 

38 copyfile(Path(self.project.paths.export) 

39 / Path(ifc_name + "_combined_STL.stl"), 

40 str(debug_dir) + '/' + str(ifc_name) + "_combined_STL.stl") 

41 copyfile(Path(self.project.paths.export) 

42 / Path(ifc_name + "_space_combined_STL.stl"), 

43 str(debug_dir) + '/' + str(ifc_name) + "_space_combined_STL.stl") 

44 except: 

45 print('No STL for CFD found. ') 

46 copyfile(str(debug_dir) + "/eplusout.expidf", 

47 str(debug_dir) + "/eplusout.idf") 

48 os.chdir(self.working_dir) 

49 sys.stderr = self.old_stderr 

50 super().tearDown() 

51 

52 

53 def model_domain_path(self) -> str: 

54 return 'arch' 

55 

56 def weather_file_path(self) -> Path: 

57 return (self.test_resources_path() / 

58 'weather_files/DEU_NW_Aachen.105010_TMYx.epw') 

59 

60 

61class TestComfortIntegration(IntegrationBaseComfort, unittest.TestCase): 

62 """ 

63 Integration tests for multiple IFC example files. 

64 Tested are both original IFC files and files from Eric Fichter's Space Boundary Generation tool. 

65 """ 

66 # @unittest.skip("") 

67 def test_base_01_FZK_full_run(self): 

68 """Test Original IFC File from FZK-Haus (KIT)""" 

69 ifc_names = {IFCDomain.arch: 'AC20-FZK-Haus.ifc'} 

70 project = self.create_project(ifc_names, 'comfort') 

71 project.sim_settings.create_external_elements = True 

72 project.sim_settings.split_bounds = True 

73 project.sim_settings.add_shadings = True 

74 project.sim_settings.split_shadings = True 

75 project.sim_settings.run_full_simulation = True 

76 project.sim_settings.rename_plot_keys = True 

77 project.sim_settings.create_plots = True 

78 # project.sim_settings.ep_install_path = 'C://EnergyPlusV9-4-0/' 

79 answers = () 

80 handler = DebugDecisionHandler(answers) 

81 for decision, answer in handler.decision_answer_mapping(project.run()): 

82 decision.value = answer 

83 self.assertEqual(0, handler.return_value) 

84 

85 @unittest.skip("") 

86 def test_base_02_FZK_design_day(self): 

87 """Test Original IFC File from FZK-Haus (KIT)""" 

88 ifc_names = {IFCDomain.arch: 'AC20-FZK-Haus.ifc'} 

89 project = self.create_project(ifc_names, 'comfort') 

90 project.sim_settings.run_full_simulation = False 

91 # project.sim_settings.ep_install_path = 'C://EnergyPlusV9-4-0/' 

92 answers = () 

93 handler = DebugDecisionHandler(answers) 

94 return_code = handler.handle(project.run()) 

95 self.assertEqual(0, return_code) 

96 

97 # @unittest.skip("") 

98 def test_base_03_FZK_SB_design_day(self): 

99 """Test IFC File from FZK-Haus (KIT) with generated Space Boundaries""" 

100 # ifc_names = {IFCDomain.arch: 'AC20-FZK-Haus_with_SB44.ifc'} 

101 ifc_names = {IFCDomain.arch: 'AC20-FZK-Haus_with_SB55.ifc'} 

102 project = self.create_project(ifc_names, 'comfort') 

103 project.sim_settings.create_external_elements = True 

104 project.sim_settings.prj_custom_usages = Path( 

105 bim2sim.__file__).parent.parent / \ 

106 "test/resources/arch/custom_usages/" \ 

107 "customUsagesAC20-FZK-Haus_with_SB55.json" 

108 # project.sim_settings.ep_install_path = 'C://EnergyPlusV9-4-0/' 

109 answers = ('Other',) 

110 handler = DebugDecisionHandler(answers) 

111 return_code = handler.handle(project.run()) 

112 self.assertEqual(0, return_code) 

113 

114 @unittest.skip("") 

115 def test_base_04_FZK_SB_full_run(self): 

116 """Test IFC File from FZK-Haus (KIT) with generated Space Boundaries""" 

117 # ifc_names = {IFCDomain.arch: 'AC20-FZK-Haus_with_SB44.ifc'} 

118 ifc_names = {IFCDomain.arch: 'AC20-FZK-Haus_with_SB55.ifc'} 

119 project = self.create_project(ifc_names, 'comfort') 

120 project.sim_settings.create_external_elements = True 

121 project.sim_settings.run_full_simulation = True 

122 project.sim_settings.prj_use_conditions = Path( 

123 bim2sim.__file__).parent.parent / \ 

124 "test/resources/arch/custom_usages/" \ 

125 "UseConditionsAC20-FZK-Haus_with_SB55.json" 

126 project.sim_settings.prj_custom_usages = Path( 

127 bim2sim.__file__).parent.parent / \ 

128 "test/resources/arch/custom_usages/" \ 

129 "customUsagesAC20-FZK-Haus_with_SB55.json" 

130 answers = ('Other',) 

131 handler = DebugDecisionHandler(answers) 

132 return_code = handler.handle(project.run()) 

133 self.assertEqual(0, return_code) 

134 

135 # @unittest.skip("") 

136 def test_base_05_KIT_Inst_design_day(self): 

137 """Test Original IFC File from Institute (KIT)""" 

138 ifc_names = {IFCDomain.arch: 'AC20-Institute-Var-2.ifc'} 

139 project = self.create_project(ifc_names, 'comfort') 

140 project.sim_settings.create_external_elements = True 

141 answers = (2015,) 

142 # project.sim_settings.ep_install_path = 'C://EnergyPlusV9-4-0/' 

143 handler = DebugDecisionHandler(answers) 

144 for decision, answer in handler.decision_answer_mapping(project.run()): 

145 decision.value = answer 

146 self.assertEqual(0, handler.return_value, 

147 "Project did not finish successfully.") 

148 

149 @unittest.skip("") 

150 def test_base_06_KIT_Inst_full_run(self): 

151 """Test Original IFC File from Institute (KIT)""" 

152 ifc_names = {IFCDomain.arch: 'AC20-Institute-Var-2.ifc'} 

153 project = self.create_project(ifc_names, 'comfort') 

154 project.sim_settings.create_external_elements = True 

155 project.sim_settings.run_full_simulation = True 

156 answers = (2015, ) 

157 handler = DebugDecisionHandler(answers) 

158 return_code = handler.handle(project.run()) 

159 self.assertEqual(0, return_code) 

160 

161 @unittest.skip("Skipped due to performance for CI") 

162 def test_base_07_KIT_Inst_SB_design_day(self): 

163 """Test IFC File from Institute (KIT) with generated Space Boundaries""" 

164 ifc_names = {IFCDomain.arch: 'AC20-Institute-Var-2_with_SB-1-0.ifc'} 

165 project = self.create_project(ifc_names, 'comfort') 

166 project.sim_settings.create_external_elements = True 

167 # project.sim_settings.ep_install_path = 'C://EnergyPlusV9-4-0/' 

168 project.sim_settings.prj_custom_usages = Path( 

169 bim2sim.__file__).parent.parent / \ 

170 "test/resources/arch/custom_usages/" \ 

171 "customUsagesAC20-Institute-Var-2_with_SB-1-0.json" 

172 answers = ('Other', 2015) 

173 handler = DebugDecisionHandler(answers) 

174 return_code = handler.handle(project.run()) 

175 self.assertEqual(0, return_code) 

176 

177 @unittest.skip("Skipped due to performance for CI") 

178 def test_base_08_KIT_Inst_SB_full_run(self): 

179 """Test IFC File from Institute (KIT) with generated Space Boundaries""" 

180 ifc_names = {IFCDomain.arch: 'AC20-Institute-Var-2_with_SB-1-0.ifc'} 

181 project = self.create_project(ifc_names, 'comfort') 

182 project.sim_settings.create_external_elements = True 

183 project.sim_settings.run_full_simulation = True 

184 project.sim_settings.prj_custom_usages = Path( 

185 bim2sim.__file__).parent.parent / \ 

186 "test/resources/arch/custom_usages/" \ 

187 "customUsagesAC20-Institute-Var-2_with_SB-1-0.json" 

188 answers = ('Other', 2015) 

189 handler = DebugDecisionHandler(answers) 

190 return_code = handler.handle(project.run()) 

191 self.assertEqual(0, return_code) 

192 

193 @unittest.skip("") 

194 def test_DigitalHub_SB89(self): 

195 """Test DigitalHub IFC, includes regression test""" 

196 ifc_names = {IFCDomain.arch: 'FM_ARC_DigitalHub_with_SB89.ifc'} 

197 project = self.create_project(ifc_names, 'comfort') 

198 project.sim_settings.create_external_elements = True 

199 project.sim_settings.cooling_tz_overwrite = True 

200 project.sim_settings.construction_class_windows = \ 

201 'Waermeschutzverglasung, dreifach' 

202 project.sim_settings.prj_use_conditions = Path( 

203 bim2sim.__file__).parent.parent / \ 

204 "test/resources/arch/custom_usages/" \ 

205 "UseConditionsFM_ARC_DigitalHub.json" 

206 project.sim_settings.prj_custom_usages = Path( 

207 bim2sim.__file__).parent.parent / \ 

208 "test/resources/arch/custom_usages/" \ 

209 "customUsagesFM_ARC_DigitalHub_with_SB89.json" 

210 space_boundary_genenerator = 'Other' 

211 handle_proxies = (*(None,)*12,) 

212 construction_year = 2015 

213 project.sim_settings.split_bounds = False 

214 project.sim_settings.add_shadings = True 

215 project.sim_settings.split_shadings = False 

216 project.sim_settings.run_full_simulation = False 

217 answers = (space_boundary_genenerator, 

218 *handle_proxies, 

219 construction_year, 

220 project.sim_settings.split_bounds, 

221 project.sim_settings.add_shadings, 

222 project.sim_settings.split_shadings, 

223 project.sim_settings.run_full_simulation) 

224 handler = DebugDecisionHandler(answers) 

225 return_code = handler.handle(project.run()) 

226 self.assertEqual(0, return_code) 

227 

228 @unittest.skip("Skipped due to performance for CI") 

229 def test_base_09_DH_design_day(self): 

230 """Test DigitalHub IFC""" 

231 ifc_names = {IFCDomain.arch: 'FM_ARC_DigitalHub_fixed002.ifc'} 

232 project = self.create_project(ifc_names, 'comfort') 

233 project.sim_settings.create_external_elements = True 

234 project.sim_settings.prj_use_conditions = Path( 

235 bim2sim.__file__).parent.parent / \ 

236 "test/resources/arch/custom_usages/" \ 

237 "UseConditionsFM_ARC_DigitalHub.json" 

238 project.sim_settings.prj_custom_usages = Path( 

239 bim2sim.__file__).parent.parent / \ 

240 "test/resources/arch/custom_usages/" \ 

241 "customUsagesFM_ARC_DigitalHub_fixed002.json" 

242 space_boundary_genenerator = 'Other' 

243 handle_proxies = (*(None,)*12,) 

244 construction_year = 2015 

245 project.sim_settings.split_bounds = True 

246 project.sim_settings.add_shadings = True 

247 project.sim_settings.split_shadings = True 

248 project.sim_settings.run_full_simulation = True 

249 answers = (space_boundary_genenerator, 

250 *handle_proxies, 

251 construction_year, 

252 project.sim_settings.split_bounds, 

253 project.sim_settings.add_shadings, 

254 project.sim_settings.split_shadings, 

255 project.sim_settings.run_full_simulation) 

256 handler = DebugDecisionHandler(answers) 

257 return_code = handler.handle(project.run()) 

258 self.assertEqual(0, return_code) 

259 

260 # @unittest.skip("Skipped due to performance for CI") 

261 def test_base_13_EDC_SB_design_day(self): 

262 """Test KIT KHH 3 storey IFC with generated Space Boundaries""" 

263 ifc_names = {IFCDomain.arch: 'KIT-EDC_with_SB.ifc'} 

264 project = self.create_project(ifc_names, 'comfort') 

265 project.sim_settings.create_external_elements = True 

266 project.sim_settings.split_bounds = True 

267 project.sim_settings.add_shadings = True 

268 project.sim_settings.split_shadings = True 

269 project.sim_settings.run_full_simulation = False 

270 # project.sim_settings.ep_install_path = 'C://EnergyPlusV9-4-0/' 

271 

272 project.sim_settings.prj_custom_usages = Path( 

273 bim2sim.__file__).parent.parent / \ 

274 "test/resources/arch/custom_usages/" \ 

275 "customUsagesKIT-EDC_with_SB.json" 

276 answers = ('Other', 'Other', 2015) 

277 handler = DebugDecisionHandler(answers) 

278 return_code = handler.handle(project.run()) 

279 self.assertEqual(0, return_code) 

280 

281 

282 

283if __name__ == '__main__': 

284 unittest.main()