Coverage for teaser/examples/e2_export_aixlib_models.py: 88%

17 statements  

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

1# # Example 2: Export Modelica models for AixLib library using TEASER API 

2# This module contains an example how to export buildings from a TEASER 

3# project to ready-to-run simulation models for Modelica library AixLib. 

4# AixLib focuses on ideal hat demand calculation. In contrast, 

5# IBPSA focuses on the free floating temperature and has no ideal heater, 

6# and BESMod on the coupling to state-of-the-art energy systems. 

7# These models will only simulate using Dymola, the reason for this are state 

8# machines that are used in one AixLib specific AHU model. 

9# You can run this example using the [jupyter-notebook](https://mybinder.org/v2/gh/RWTH-EBC/TEASER/main?labpath=docs%2Fjupyter_notebooks) 

10 

11import teaser.examples.e1_generate_archetype as e1 

12import teaser.logic.utilities as utilities 

13import os 

14 

15 

16def example_export_aixlib(): 

17 """This function demonstrates the export to Modelica library AixLib using 

18 the API function of TEASER""" 

19 

20 # In e1_generate_archetype we created a Project with three archetype 

21 # buildings to get this Project we rerun this example 

22 

23 prj = e1.example_generate_archetype() 

24 

25 # To make sure the export is using the desired parameters you should 

26 # always set model settings in the Project. 

27 # Project().used_library_calc specifies the used Modelica library 

28 # Project().number_of_elements_calc sets the models order 

29 # For more information on models we'd like to refer you to the docs. By 

30 # default TEASER uses a weather file provided in 

31 # teaser.data.input.inputdata.weatherdata. You can use your own weather 

32 # file by setting Project().weather_file_path. However we will use default 

33 # weather file. 

34 # Be careful: Dymola does not like whitespaces in names and filenames, 

35 # thus we will delete them anyway in TEASER. 

36 

37 # for CI testing purpose we set the reference result folder 

38 

39 prj.dir_reference_results = utilities.get_full_path( 

40 os.path.join( 

41 "examples", 

42 "examplefiles", 

43 "ReferenceResults", 

44 "Dymola")) 

45 

46 print(prj.dir_reference_results) 

47 

48 prj.used_library_calc = 'AixLib' 

49 prj.number_of_elements_calc = 2 

50 prj.weather_file_path = utilities.get_full_path( 

51 os.path.join( 

52 "data", 

53 "input", 

54 "inputdata", 

55 "weatherdata", 

56 "DEU_BW_Mannheim_107290_TRY2010_12_Jahr_BBSR.mos")) 

57 

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

59 # run calc_all_buildings() function 

60 

61 prj.calc_all_buildings() 

62 

63 # To export the ready-to-run models simply call Project.export_aixlib(). 

64 # You can specify the path, where the model files should be saved. 

65 # None means, that the default path in your home directory 

66 # will be used. If you only want to export one specific building, you can 

67 # pass over the internal_id of that building and only this model will be 

68 # exported. In this case we want to export all buildings to our home 

69 # directory, thus we are passing over None for both parameters. 

70 

71 # We might want not have all data stored in our result file. By defining 

72 # export_vars as following we can specify which results we want to store 

73 # and define a collection name under which these results are stored. This 

74 # feature only works with Dymola. 

75 

76 export_vars = { 

77 "HeatingDemands": ["*multizone.PHeater*", "*multizone.PHeatAHU"], 

78 "CoolingDemands": ["*multizone.PCooler*", "*multizone.PCoolAHU"], 

79 "Temperatures": ["*multizone.TAir*", "*multizone.TRad*"] 

80 } 

81 

82 path = prj.export_aixlib( 

83 internal_id=None, 

84 path=None, 

85 report=True, 

86 export_vars=export_vars 

87 ) 

88 

89 return path 

90 

91 

92if __name__ == '__main__': 

93 

94 example_export_aixlib() 

95 

96 print("Example 2: That's it! :)")