Coverage for teaser/data/output/ibpsa_output.py: 98%

43 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2025-04-29 16:01 +0000

1# Created May 2016 

2# TEASER Development Team 

3 

4"""modelica_output 

5 

6This module contains function to call Templates for IBPSA model generation 

7""" 

8 

9import teaser.data.output.modelica_output as modelica_output 

10import os.path 

11import teaser.logic.utilities as utilities 

12from mako.template import Template 

13from mako.lookup import TemplateLookup 

14 

15 

16def export_ibpsa( 

17 buildings, 

18 prj, 

19 path=None, 

20 library='AixLib'): 

21 """Exports models for IBPSA library 

22 

23 Export a building to several models for 

24 IBPSA.ThermalZones.ReducedOrder. Depending on the chosen calculation 

25 method models for 1, 2, 3, or 4 element model are exported. In addition 

26 you can specify if windows should be lumped into the walls, like it is 

27 done in VDI 6007 (merge_windows=True) or not. For each zone, one model is 

28 exported, if you want to combine all thermal zones into one model, consider 

29 using AixLib. The export includes internal gains from use conditions ( 

30 calculated in teaser.logic.calculation.ibpsa) but does not include any 

31 heating or cooling equipment. 

32 

33 

34 Parameters 

35 ---------- 

36 

37 buildings : list of instances of Building 

38 list of TEASER instances of a Building that are exported If you 

39 want to 

40 export a single building, please pass it over as a list containing 

41 only that building. 

42 prj : instance of Project 

43 Instance of TEASER Project object to access Project related 

44 information, e.g. name or version of used libraries 

45 path : string 

46 if the Files should not be stored in default output path of TEASER, 

47 an alternative path can be specified as a full path 

48 library : str 

49 Used library within the framework of IBPSA library. The 

50 models are identical in each library, but IBPSA Modelica library is 

51 just a core set of models and should not be used standalone. 

52 Valid values are 'AixLib' (default), 'Buildings', 

53 'BuildingSystems' and 'IDEAS'. 

54 

55 Attributes 

56 ---------- 

57 

58 lookup : TemplateLookup object 

59 Instance of mako.TemplateLookup to store general functions for templates 

60 model_template_1 : Template object 

61 Template for ThermalZoneRecord using 1 element model 

62 model_template_2 : Template object 

63 Template for ThermalZoneRecord using 2 element model 

64 model_template_3 : Template object 

65 Template for ThermalZoneRecord using 3 element model 

66 model_template_4 : Template object 

67 Template for ThermalZoneRecord using 4 element model 

68 

69 """ 

70 

71 uses = uses = [ 

72 'Modelica(version="' + prj.modelica_info.version + '")', 

73 library + '(version="' + prj.buildings[-1].library_attr.version[ 

74 library] + '")'] 

75 

76 if path is None: 

77 path = utilities.get_full_path("") 

78 

79 lookup = TemplateLookup(directories=[utilities.get_full_path( 

80 os.path.join('data', 'output', 'modelicatemplate'))]) 

81 model_template_1 = Template( 

82 filename=utilities.get_full_path( 

83 "data/output/modelicatemplate/IBPSA/IBPSA_OneElement"), 

84 lookup=lookup) 

85 model_template_2 = Template( 

86 filename=utilities.get_full_path( 

87 "data/output/modelicatemplate/IBPSA/IBPSA_TwoElements"), 

88 lookup=lookup) 

89 model_template_3 = Template( 

90 filename=utilities.get_full_path( 

91 "data/output/modelicatemplate/IBPSA/IBPSA_ThreeElements"), 

92 lookup=lookup) 

93 model_template_4 = Template( 

94 filename=utilities.get_full_path( 

95 "data/output/modelicatemplate/IBPSA/IBPSA_FourElements"), 

96 lookup=lookup) 

97 

98 modelica_output.create_package( 

99 path=path, 

100 name=prj.name, 

101 uses=uses) 

102 modelica_output.create_package_order( 

103 path=path, 

104 package_list=buildings, 

105 extra=None) 

106 modelica_output.copy_weather_data(prj.weather_file_path, path) 

107 

108 for i, bldg in enumerate(buildings): 

109 

110 ass_error = "You chose AixLib calculation, " \ 

111 "but want to export IBPSA models, " \ 

112 "this is not possible" 

113 

114 assert bldg.used_library_calc == 'IBPSA', ass_error 

115 

116 bldg_path = os.path.join(path, bldg.name) 

117 

118 utilities.create_path(bldg_path) 

119 utilities.create_path(os.path.join(bldg_path, bldg.name + "_Models")) 

120 

121 modelica_output.create_package( 

122 path=bldg_path, 

123 name=bldg.name, 

124 within=bldg.parent.name) 

125 

126 modelica_output.create_package_order( 

127 path=bldg_path, 

128 package_list=[], 

129 extra=[bldg.name + "_Models"]) 

130 

131 zone_path = os.path.join( 

132 bldg_path, 

133 bldg.name + "_Models") 

134 

135 for zone in bldg.thermal_zones: 

136 

137 zone.parent.library_attr.file_internal_gains = \ 

138 'InternalGains_' + bldg.name + zone.name + '.txt' 

139 bldg.library_attr.modelica_gains_boundary( 

140 zone=zone, 

141 path=zone_path) 

142 

143 with open(os.path.join( 

144 zone_path, bldg.name + '_' + zone.name + '.mo'), 'w') as out_file: 

145 

146 if type(zone.model_attr).__name__ == "OneElement": 

147 out_file.write(model_template_1.render_unicode(zone=zone, 

148 library=library)) 

149 elif type(zone.model_attr).__name__ == "TwoElement": 

150 out_file.write(model_template_2.render_unicode(zone=zone, 

151 library=library)) 

152 elif type(zone.model_attr).__name__ == "ThreeElement": 

153 out_file.write(model_template_3.render_unicode(zone=zone, 

154 library=library)) 

155 elif type(zone.model_attr).__name__ == "FourElement": 

156 out_file.write(model_template_4.render_unicode(zone=zone, 

157 library=library)) 

158 

159 

160 modelica_output.create_package( 

161 path=zone_path, 

162 name=bldg.name + "_Models", 

163 within=prj.name + '.' + bldg.name) 

164 

165 modelica_output.create_package_order( 

166 path=zone_path, 

167 package_list=bldg.thermal_zones, 

168 addition=bldg.name + "_") 

169 

170 print("Exports can be found here:") 

171 print(path)