Coverage for teaser/examples/e11_export_besmod_models.py: 93%

28 statements  

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

1# # Example 11: Export Modelica models for BESMod library using TEASER API 

2# This module demonstrates how to export building models from a TEASER project 

3# to ready-to-run simulation models for the Modelica BESMod library. 

4# BESMod enables seamless integration with state-of-the-art energy systems, 

5# such as heat pumps and photovoltaic systems. These systems can be utilized 

6# to generate primary energy demand curves (e.g., for electricity or gas) or 

7# to conduct in-depth analyses of building energy systems. In contrast, 

8# AixLib focuses on ideal heat demand calculation, and IBPSA on 

9# free floating temperature without an ideal heater. 

10# You can execute this example using 

11# [jupyter-notebook](https://mybinder.org/v2/gh/RWTH-EBC/TEASER/main?labpath=docs%2Fjupyter_notebooks) 

12 

13import teaser.examples.e1_generate_archetype as e1 

14import teaser.logic.utilities as utilities 

15import os 

16 

17 

18def example_export_besmod(): 

19 """This function demonstrates the export to Modelica library BESMod using 

20 the API function of TEASER""" 

21 

22 # ## Standard export 

23 # In e1_generate_archetype we created a Project with three archetype 

24 # buildings to get this Project we rerun this example 

25 

26 prj = e1.example_generate_archetype() 

27 

28 # Configure project settings to ensure compatibility with BESMod. The BESMod 

29 # library uses the AixLib.ThermalZones.ReducedOrder.ThermalZone.ThermalZone model 

30 # with 4 elements for the demand building model. Other numbers of elements are possible, 

31 # but compatability with ARoof for PV and AFloor for UFH systems must be checked first. 

32 # Set these parameters in the project: 

33 prj.used_library_calc = 'AixLib' 

34 prj.number_of_elements_calc = 4 

35 

36 # BESMod allows building models to be included in predefined example energy systems: 

37 examples = [ 

38 "TEASERHeatLoadCalculation", # Ideal electric heater for heat load calculations 

39 "HeatPumpMonoenergetic", # Heat pump with radiators, buffer and DHW storage, and PV 

40 "GasBoilerBuildingOnly" # Gas boiler with radiators 

41 ] 

42 

43 # For the hydraulic systems, you have to specify a nominal supply temperature 

44 # for heat transfer, e.g. in radiators. 

45 # Multiple options are available: 

46 

47 # Option 1: Set a single value for all buildings and zones. 

48 THydSup_nominal = 55 + 273.15 

49 

50 # Option 2: Set values for each building or thermal zone. 

51 THydSup_nominal = {"ResidentialBuilding": 328.15, 

52 "OfficeBuilding": 328.15, 

53 "InstituteBuilding": {"Office": 343.15, 

54 "Floor": 343.15, 

55 "Storage": 343.15, 

56 "Meeting": 343.15, 

57 "Restroom": 343.15, 

58 "ICT": 343.15, 

59 "Laboratory": 328.15}, 

60 "InstituteBuildingMoisture": 343.15, 

61 "ResidentialBuildingTabula": 328.15, 

62 "ResidentialBuildingTabulaMulti": 328.15} 

63 

64 # Option 3: Specify values based on construction year. 

65 # Here, the value of the next higher specified year is set to the building. 

66 # The classification here is taken from: 

67 # https://www.ffe.de/projekte/waermepumpen-fahrplan-finanzielle-kipppunkte-zur-modernisierung-mit-waermepumpen-im-wohngebaeudebestand/ 

68 THydSup_nominal = { 

69 1950: 90 + 273.15, 

70 1980: 70 + 273.15, 

71 2010: 55 + 273.15, 

72 2024: 35 + 273.15 

73 } 

74 

75 # In the examples, the parameters for BESMod.Systems.UserProfiles.TEASERProfiles are configured, 

76 # including internal gains and heating profiles for each zone. 

77 # BESMod requires 24-hour heating profiles, which are used 

78 # to define the parameters of the `setBakTSetZone` Pulse block. 

79 # By default, the TEASER profiles are applied, but these can be customized if needed. 

80 

81 # Additionally, location-specific parameters must be set, which can be achieved using the following function. 

82 # The default values provided here correspond to Mannheim. 

83 weather_file_path = utilities.get_full_path( 

84 os.path.join( 

85 "data", 

86 "input", 

87 "inputdata", 

88 "weatherdata", 

89 "DEU_BW_Mannheim_107290_TRY2010_12_Jahr_BBSR.mos")) 

90 

91 prj.set_location_parameters(t_outside=262.65, 

92 t_ground=286.15, 

93 weather_file_path=weather_file_path, 

94 calc_all_buildings=True) 

95 

96 # To make sure the parameters are calculated correctly we recommend to 

97 # run prj.calc_all_buildings() function which is here already done in the set_location_parameters function. 

98 

99 # Export all buildings to BESMod and include them in predefined example systems. 

100 path = prj.export_besmod( 

101 THydSup_nominal=THydSup_nominal, 

102 path=None, 

103 examples=examples 

104 ) 

105 

106 # ## Partial retrofit export 

107 # The partial retrofit option of the energy system in BESMod can also be utilized. 

108 # For more information on this see BESMod.UsersGuide.GettingStarted.Parameterization. 

109 # To enable this here, the nominal heat flow of each zone in the building must be extracted prior to the retrofit. 

110 QBuiOld_flow_design = { 

111 bldg.name: { 

112 tz.name: tz.model_attr.heat_load for tz in bldg.thermal_zones 

113 } 

114 for bldg in prj.buildings 

115 } 

116 

117 # Retrofit project buildings and recalculate parameters. 

118 prj.name = "ArchetypeExample_partial_retrofit" 

119 prj.retrofit_all_buildings( 

120 year_of_retrofit=2015, 

121 type_of_retrofit="adv_retrofit", 

122 window_type='Alu- oder Stahlfenster, Isolierverglasung', 

123 material='EPS_perimeter_insulation_top_layer' 

124 ) 

125 prj.calc_all_buildings() 

126 

127 # By default, radiator transfer systems are not retrofitted when the 

128 # QBuiOld_flow_design parameter is provided and differs from the new nominal heat flow. 

129 # Additionally, new THydSup_nominal temperatures can be specified alongside 

130 # THydSupOld_design values, which are used for radiator sizing but not for control settings. 

131 

132 path = prj.export_besmod( 

133 THydSup_nominal=THydSup_nominal, 

134 QBuiOld_flow_design=QBuiOld_flow_design, 

135 path=None, 

136 examples=examples 

137 ) 

138 

139 # ## Custom export 

140 # Additionally, we have the flexibility to define custom templates for including buildings in specific setups. 

141 # For instance, a custom template is defined here to include the building in the 

142 # ModelicaConferencePaper example from BESMod, which features an integrated battery system. 

143 

144 # Custom template 

145 # ``` 

146 # < %namespace file = "/modelica_language/" import="get_list" / > 

147 # within ${bldg.parent.name}.${bldg.name}; 

148 # model ModelicaConferencePaper${bldg.name} 

149 # extends BESMod.Examples.ModelicaConferencePaper.PartialModelicaConferenceUseCase( 

150 # redeclare ${bldg.name} building, 

151 # redeclare BESMod.Systems.UserProfiles.TEASERProfiles 

152 # userProfiles(fileNameIntGains=Modelica.Utilities.Files.loadResource( 

153 # "modelica://${bldg.parent.name}/${bldg.name}/InternalGains_${bldg.name}.txt"), 

154 # setBakTSetZone(amplitude=${get_list(setBakTSetZone_amplitude)}, 

155 # width =${get_list(setBakTSetZone_width)}, 

156 # startTime =${get_list(setBakTSetZone_startTime)})), 

157 # systemParameters(nZones=${len(bldg.thermal_zones)}, 

158 # QBui_flow_nominal = building.QRec_flow_nominal, 

159 # TOda_nominal =${TOda_nominal}, 

160 # TSetZone_nominal =${get_list(TSetZone_nominal)}, 

161 # THydSup_nominal =${THydSup_nominal}, 

162 # QBuiOld_flow_design =${QBuiOld_flow_design}, 

163 # THydSupOld_design =${THydSupOld_design}, 

164 # filNamWea = Modelica.Utilities.Files.loadResource( 

165 # "modelica://${bldg.parent.name}/Resources/${bldg.parent.weather_file_name}"))); 

166 # 

167 # extends Modelica.Icons.Example; 

168 # 

169 # annotation(experiment(StopTime=172800, 

170 # Interval=600, 

171 # Tolerance=1e-06), 

172 # __Dymola_Commands(file= 

173 # "Resources/Scripts/Dymola/${bldg.name}/ModelicaConferencePaper${bldg.name}.mos" 

174 # "Simulate and plot")); 

175 # end 

176 # ModelicaConferencePaper${bldg.name}; 

177 # ``` 

178 

179 prj.name = "ArchetypeExample_custom" 

180 

181 custom_template_path = os.path.join( 

182 os.path.dirname(__file__), "examplefiles", "custom_besmod_templates" 

183 ) 

184 custom_example_template = {"ModelicaConferencePaper": os.path.join(custom_template_path, "custom_template.txt")} 

185 

186 # The template also includes a .mos script as part of its annotation. 

187 # By default, the provided examples export a basic "simulate and plot" script, 

188 # which is incorporated into their annotation, as shown in the custom example. 

189 # Additionally, you have the flexibility to modify the template for existing examples 

190 # and define custom scripts for your tailored examples. 

191 

192 custom_script = {"HeatPumpMonoenergetic": os.path.join(custom_template_path, "custom_script_hp_mono.txt"), 

193 "ModelicaConferencePaper": os.path.join(custom_template_path, "custom_script.txt")} 

194 

195 path = prj.export_besmod( 

196 THydSup_nominal=THydSup_nominal, 

197 path=None, 

198 examples=examples, 

199 custom_examples=custom_example_template, 

200 custom_script=custom_script 

201 ) 

202 

203 return path 

204 

205 

206if __name__ == '__main__': 

207 example_export_besmod() 

208 

209 print("Example 11: That's it! :)")