Coverage for bim2sim/examples/e1_template_plugin.py: 0%

28 statements  

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

1import tempfile 

2from pathlib import Path 

3 

4import bim2sim 

5from bim2sim import Project, ConsoleDecisionHandler, run_project 

6from bim2sim.elements import bps_elements 

7from bim2sim.utilities.common_functions import filter_elements 

8from bim2sim.utilities.types import IFCDomain 

9from bim2sim.elements.base_elements import Material 

10 

11 

12def run_simple_project(): 

13 """Run a bim2sim project with the TemplatePlugin. 

14  

15 This example will show how to set up a project based on an IFC file, 

16 how to create bim2sim elements based on the existing IFC data with all 

17 relevant elements for building performance simulation and how to review and 

18 analyze the resulting elements 

19 """ 

20 # Create a temp directory for the project, feel free to use a "normal" 

21 # directory 

22 project_path = Path(tempfile.TemporaryDirectory( 

23 prefix='bim2sim_example2').name) 

24 

25 # Set the ifc path to use and define which domain the IFC belongs to. 

26 # This is done via a dictionary, where the key is the domain and the value 

27 # the path to the IFC file. We are using an architecture domain IFC file 

28 # here from the FZK-Haus which is a simple IFC provided by KIT. 

29 ifc_paths = { 

30 IFCDomain.arch: 

31 Path(bim2sim.__file__).parent.parent / 

32 'test/resources/arch/ifc/AC20-FZK-Haus.ifc', 

33 } 

34 

35 # Create a new project, based on the created temporary directory, the 

36 # defined ifc_paths and the template plugin. The template plugin is just 

37 # for explanation and holds some basic tasks to convert IFC data into 

38 # bim2sim elements structure without creating any simulation models. 

39 # By looking into the plugin definition we can find the following: 

40 # default_tasks = [ 

41 # common.LoadIFC, 

42 # common.CheckIfc, 

43 # common.CreateElements, 

44 # bps.CreateSpaceBoundaries, 

45 # common.BindStoreys, 

46 # common.Weather, 

47 # ] 

48 # This means that these 7 tasks are performed when not using interactive 

49 # mode (see e2_interactive_project.py for more information about 

50 # interactive mode). For detailed information about the different tasks 

51 # please have a look at their documentation. 

52 

53 project = Project.create( 

54 project_path, ifc_paths, 'Template') 

55 

56 # Next to the plugin that should be used we can do further configuration 

57 # by using the `sim_settings`. `sim_settings` are meant to configure the 

58 # creation of the simulation model and assign information before starting 

59 # the process. This can be either weather data files, default simulation 

60 # time of the created model but also what kind of enrichment should be used 

61 # or what elements are relevant for the simulation. For more information 

62 # please review the documentation for `sim_settings`. 

63 

64 # Let's assign a weather file first. This is currently needed, even if no 

65 # simulation is performed 

66 project.sim_settings.weather_file_path = ( 

67 Path(bim2sim.__file__).parent.parent / 

68 'test/resources/weather_files/DEU_NW_Aachen.105010_TMYx.mos') 

69 

70 # Assign the enrichment for use conditions of thermal zones. 

71 

72 # bim2sim allows to enrich the use conditions, e.g. how many persons are 

73 # in a room at what times. For this we are using the data and profiles 

74 # provided by DIN 18599. To assign the correct enrichment to specific 

75 # rooms/thermal zones, we need to match these to the conditions provided 

76 # by DIN 18599. bim2sim automatically does some matching based on regular 

77 # expressions, translations, pre-configured mappings and the existing room 

78 # information in the IFC, but this doesn't cover all cases. Especially 

79 # if rooms are named "room 1" or similar and no further usage information 

80 # is provided by the IFC. In this case user input decisions will be 

81 # queried. To reduce these queries, we can set pre-configured .json files 

82 # to match the room names to usages via `sim_settings`. 

83 # The `sim_setting` `prj_custom_usages` allows to specify the path to the 

84 # .json file that holds the mapping. 

85 

86 # As the IFC we are using has an attic which is identified by its 

87 # IfcLongName and the commonUsages mapping as Living space. Let's assume 

88 # this attic is used as a private gym because our residents are quite fit 

89 # people. We can assign a different usage by simply creating a customUsages 

90 # file and assign the usage type "Exercise room" to the room type 

91 # "Galerie". We already stored the .json file under the test resources, 

92 # have a look at it. 

93 # In the next step we assign this file to the project by setting: 

94 project.sim_settings.prj_custom_usages = (Path( 

95 bim2sim.__file__).parent.parent / "test/resources/arch/custom_usages/" 

96 "customUsagesAC20-FZK-Haus.json") 

97 

98 # If we don't want to use the standard data for usage conditions, we 

99 # can change them. We created a project specific UseConditions file for 

100 # this in the test resources section. In this we assume that our residents 

101 # like to sleep at quite cold conditions of 16 °C. So we adjusted the 

102 # "heating_profile" entry. We leave the data for the other usages 

103 # untouched. 

104 

105 # Let's assign this use conditions file: 

106 project.sim_settings.prj_use_conditions = (Path( 

107 bim2sim.__file__).parent.parent / "test/resources/arch/custom_usages/" 

108 "UseConditionsAC20-FZK-Haus.json") 

109 

110 # By default bim2sim tries to calculate the heating profile based on given 

111 # information from the IFC. As the used IFC has information about the set 

112 # temperature, we need an additional `sim_setting` to force the overwrite 

113 # of the existing data in the IFC. 

114 project.sim_settings.setpoints_from_template = True 

115 

116 # Before we can run the project, we need to assign a DecisionHandler. To 

117 # understand this, we need to understand why we need such a handler. 

118 # Decisions in bim2sim are used to get user input whenever information in 

119 # the IFC are unclear. E.g. if the usage type of a room can't be 

120 # identified, we use a decision to query the user what usage the room has. 

121 # As we don't know at which point a decision comes up, we are using 

122 # generators and yield to iterate over them. If you want to understand 

123 # deeper how this works, have a look at the decision documentation. 

124 # For usage as console tool, we implemented the ConsoleDecisionHandler, 

125 # which we are going to assign in the next step. 

126 # There are multiple ways to run a project. One is to use the run_project() 

127 # function and assign which project to run and which decision handler to 

128 # use. In our case this is: 

129 run_project(project, ConsoleDecisionHandler()) 

130 

131 # After the project is finished, we can review the results. As we don't 

132 # create any simulation model with the template Plugin, our results are 

133 # mainly the identified bim2sim elements and the enriched data in this 

134 # elements. Let's get the created bim2sim elements. Everything that is 

135 # created by the different tasks during the runtime is stored in the 

136 # playground state. The playground manages the different tasks and their 

137 # information. To get the bim2sim elements, we can simply get them from the 

138 # state with the following command: 

139 b2s_elements = project.playground.state['elements'] 

140 

141 # Let's filter all ThermalZone entities, we can do this by a loop, or use 

142 # a pre-build function of bim2sim: 

143 all_thermal_zones = filter_elements(b2s_elements, 'ThermalZone') 

144 

145 # Let's print some data about our zones and review the enriched data for 

146 # our zones: 

147 for tz in all_thermal_zones: 

148 print('##########') 

149 print(f"Name of the zone: {tz.name}") 

150 print(f"Area of the zone: {tz.net_area}") 

151 print(f"Volume of the zone: {tz.volume}") 

152 print(f"Daily heating profile of the zone: {tz.heating_profile}") 

153 print('##########') 

154 

155 # We can see that our provided heating profiles are correctly taken into 

156 # account. The enriched thermal zones now hold all information required for 

157 # a building performance simulation. For complete examples with model 

158 # creation and simulations please go the examples of the plugins. 

159 

160 

161if __name__ == '__main__': 

162 run_simple_project()