Class: RemoveOrphanObjectsAndUnusedResources
- Inherits:
-
OpenStudio::Measure::ModelMeasure
- Object
- OpenStudio::Measure::ModelMeasure
- RemoveOrphanObjectsAndUnusedResources
- Defined in:
- lib/measures/remove_orphan_objects_and_unused_resources/measure.rb
Overview
start the measure
Instance Method Summary collapse
-
#arguments(model) ⇒ Object
define the arguments that the user will input.
-
#description ⇒ Object
human readable description.
-
#modeler_description ⇒ Object
human readable description of modeling approach.
-
#name ⇒ Object
human readable name.
-
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run.
Instance Method Details
#arguments(model) ⇒ Object
define the arguments that the user will input
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/measures/remove_orphan_objects_and_unused_resources/measure.rb', line 29 def arguments(model) args = OpenStudio::Measure::OSArgumentVector.new # bool to remove unused space_types remove_unused_space_types = OpenStudio::Measure::OSArgument.makeBoolArgument('remove_unused_space_types', true) remove_unused_space_types.setDisplayName('Remove Unused Space Types') remove_unused_space_types.setDefaultValue(false) args << remove_unused_space_types # bool to remove unused load_defs remove_unused_load_defs = OpenStudio::Measure::OSArgument.makeBoolArgument('remove_unused_load_defs', true) remove_unused_load_defs.setDisplayName('Remove Unused Load Definitions') remove_unused_load_defs.setDefaultValue(false) args << remove_unused_load_defs # bool to remove unused schedules remove_unused_schedules = OpenStudio::Measure::OSArgument.makeBoolArgument('remove_unused_schedules', true) remove_unused_schedules.setDisplayName('Remove Unused Schedules Sets and Schedules') remove_unused_schedules.setDefaultValue(false) args << remove_unused_schedules # bool to remove unused curves remove_unused_curves = OpenStudio::Measure::OSArgument.makeBoolArgument('remove_unused_curves', true) remove_unused_curves.setDisplayName('Remove Unused Curves') remove_unused_curves.setDefaultValue(false) args << remove_unused_curves # bool to remove unused constructions remove_unused_constructions = OpenStudio::Measure::OSArgument.makeBoolArgument('remove_unused_constructions', true) remove_unused_constructions.setDisplayName('Remove Unused Construction Sets, Constructions, and Materials') remove_unused_constructions.setDefaultValue(false) args << remove_unused_constructions return args end |
#description ⇒ Object
human readable description
17 18 19 20 21 |
# File 'lib/measures/remove_orphan_objects_and_unused_resources/measure.rb', line 17 def description return "This is the start of a measure that will have expanded functionality over time. It will have two distinct functions. One will be to remove orphan objects. This will typically include things that should never have been left alone and often are not visible in the GUI. This would include load instances without a space or space type, and surfaces without a space. A second functionality is to remove unused resources. This will include things like space types, schedules, constructions, and materials. There will be a series of checkboxes to enable/disable this purge. There won't be an option for the orphan objects. They will always be removed." end |
#modeler_description ⇒ Object
human readable description of modeling approach
24 25 26 |
# File 'lib/measures/remove_orphan_objects_and_unused_resources/measure.rb', line 24 def modeler_description return 'Purging objects like space types, schedules, and constructions requires a specific sequence to be most effective. This measure will first remove unused space types, then load defs, schedules sets, schedules, construction sets, constructions, and then materials. A space type having a construction set assign, will show that construction set as used even if no spaces are assigned to that space type. That is why order is important.' end |
#name ⇒ Object
human readable name
12 13 14 |
# File 'lib/measures/remove_orphan_objects_and_unused_resources/measure.rb', line 12 def name return 'Remove Orphan Objects and Unused Resources' end |
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/measures/remove_orphan_objects_and_unused_resources/measure.rb', line 66 def run(model, runner, user_arguments) super(model, runner, user_arguments) # use the built-in error checking if !runner.validateUserArguments(arguments(model), user_arguments) return false end # assign the user inputs to variables remove_unused_space_types = runner.getBoolArgumentValue('remove_unused_space_types', user_arguments) remove_unused_load_defs = runner.getBoolArgumentValue('remove_unused_load_defs', user_arguments) remove_unused_schedules = runner.getBoolArgumentValue('remove_unused_schedules', user_arguments) remove_unused_curves = runner.getBoolArgumentValue('remove_unused_curves', user_arguments) remove_unused_constructions = runner.getBoolArgumentValue('remove_unused_constructions', user_arguments) # report initial condition of model runner.registerInitialCondition("The model started with #{model.numObjects} objects.") # remove orphan space infiltration objects orphan_flag = false model.getSpaceInfiltrationDesignFlowRates.sort.each do |instance| if (instance.spaceType.is_initialized == false) && (instance.space.is_initialized == false) runner.registerInfo("Removing orphan space infiltration object named #{instance.name}") instance.remove orphan_flag = true end end if !orphan_flag runner.registerInfo('No orphan space infiltration objects were found') end # TODO: - add section to remove orphan effective leakage # remove orphan design spec oa objects orphan_flag = false model.getDesignSpecificationOutdoorAirs.sort.each do |instance| if instance.directUseCount(excludeChildren=true) == 0 runner.registerInfo("Removing orphan design specification outdoor air object named #{instance.name}") instance.remove orphan_flag = true end end if !orphan_flag runner.registerInfo('No orphan design specification outdoor air objects were found') end # remove orphan load instances orphan_flag = false model.getSpaceLoadInstances.sort.each do |instance| if (instance.spaceType.is_initialized == false) && (instance.space.is_initialized == false) # extra check for water use equipment. They may or may not have space. But they should have a water use connection if instance.to_WaterUseEquipment.is_initialized && instance.to_WaterUseEquipment.get.waterUseConnections.is_initialized next end runner.registerInfo("Removing orphan load instance object named #{instance.name}") instance.remove orphan_flag = true end end if !orphan_flag runner.registerInfo('No orphan load instance objects were found') end # remove orphan surfaces orphan_flag = false model.getSurfaces.sort.each do |surface| if !surface.space.is_initialized runner.registerInfo("Removing orphan base surface named #{surface.name}") surface.remove orphan_flag = true end end if !orphan_flag runner.registerInfo('No orphan base surfaces were found') end # remove orphan subsurfaces orphan_flag = false model.getSubSurfaces.sort.each do |subsurface| if !subsurface.surface.is_initialized runner.registerInfo("Removing orphan sub surface named #{subsurface.name}") subsurface.remove orphan_flag = true end end if !orphan_flag runner.registerInfo('No orphan sub surfaces were found') end # remove orphan shading surfaces orphan_flag = false model.getShadingSurfaces.sort.each do |surface| if !surface.shadingSurfaceGroup.is_initialized runner.registerInfo("Removing orphan shading surface named #{surface.name}") surface.remove orphan_flag = true end end if !orphan_flag runner.registerInfo('No orphan shading surfaces were found') end # remove orphan interior partition surfaces orphan_flag = false model.getInteriorPartitionSurfaces.sort.each do |surface| if !surface.interiorPartitionSurfaceGroup.is_initialized runner.registerInfo("Removing orphan interior partition surface named #{surface.name}") surface.remove orphan_flag = true end end if !orphan_flag runner.registerInfo('No orphan interior partition surfaces were found') end # find and remove orphan LifeCycleCost objects lcc_objects = model.getObjectsByType('OS:LifeCycleCost'.to_IddObjectType) # make an array to store the names of the orphan LifeCycleCost objects orphaned_lcc_objects = [] # loop through all LifeCycleCost objects, checking for missing Item Name lcc_objects.each do |lcc_object| if lcc_object.isEmpty(4) orphaned_lcc_objects << lcc_object.handle puts "**(removing object)#{lcc_object.name} is not connected to any model object" runner.registerInfo("Removing orphan lifecycle cost named #{lcc_object.name}") lcc_object.remove end end # summarize the results if orphaned_lcc_objects.length <= 0 runner.registerInfo('no orphaned LifeCycleCost objects were found') end # TODO: - remove surfaces that would trigger error in E+ (less than 3 vertices or too small.) # TODO: - remove empty shading and interior partition groups. Don't think we would want to do this to spaces, since they may contain space types or loads # remove unused space types if remove_unused_space_types unused_flag_counter = 0 model.getSpaceTypes.sort.each do |resource| if resource.spaces.empty? unused_flag_counter += 1 resource.remove end end runner.registerInfo("Removed #{unused_flag_counter} unused space types") end # remove unused load defs if remove_unused_load_defs unused_flag_counter = 0 model.getSpaceLoadDefinitions.sort.each do |resource| if resource.directUseCount(excludeChildren=true) == 0 unused_flag_counter += 1 resource.remove end end runner.registerInfo("Removed #{unused_flag_counter} unused load definitions") end # remove unused default schedule sets if remove_unused_schedules unused_flag_counter = 0 model.getDefaultScheduleSets.sort.each do |resource| if resource.directUseCount(excludeChildren=true) == 0 unused_flag_counter += 1 resource.remove end end runner.registerInfo("Removed #{unused_flag_counter} unused default schedules sets") end # remove unused default schedules if remove_unused_schedules unused_flag_counter = 0 model.getSchedules.sort.each do |resource| if resource.directUseCount(excludeChildren=true) == 0 unused_flag_counter += 1 resource.remove end end runner.registerInfo("Removed #{unused_flag_counter} unused schedules") end # remove unused curves if remove_unused_curves unused_flag_counter = 0 model.getCurves.sort.each do |resource| if resource.directUseCount(excludeChildren=true) == 0 unused_flag_counter += 1 # work-around logic since <OpenStudio::Model::Curve>.remove doesn't work model.removeObject(resource.handle) end end runner.registerInfo("Removed #{unused_flag_counter} unused curves") end # remove unused default schedule sets if remove_unused_constructions unused_flag_counter = 0 model.getDefaultConstructionSets.sort.each do |resource| if resource.directUseCount(excludeChildren=true) == 0 unused_flag_counter += 1 resource.remove end end runner.registerInfo("Removed #{unused_flag_counter} unused default construction sets") # remove default surface and sub surface constructions, but dont' report # these are typically hidden from users and reporting it may be more confusing that helpful unused_flag_counter = 0 model.getDefaultSurfaceConstructionss.sort.each do |resource| if resource.directUseCount(excludeChildren=true) == 0 unused_flag_counter += 1 resource.remove end end # runner.registerInfo("Removed #{unused_flag_counter} unused default surface constructions") unused_flag_counter = 0 model.getDefaultSubSurfaceConstructionss.sort.each do |resource| if resource.directUseCount(excludeChildren=true) == 0 unused_flag_counter += 1 resource.remove end end # runner.registerInfo("Removed #{unused_flag_counter} unused default sub surface constructions") # remove default constructions unused_flag_counter = 0 model.getConstructions.sort.each do |resource| if resource.directUseCount(excludeChildren=true) == 0 unused_flag_counter += 1 resource.remove end end runner.registerInfo("Removed #{unused_flag_counter} unused constructions") # remove unused materials unused_flag_counter = 0 model.getMaterials.sort.each do |resource| if resource.directUseCount(excludeChildren=true) == 0 unused_flag_counter += 1 resource.remove end end runner.registerInfo("Removed #{unused_flag_counter} unused materials") end # report final condition of model runner.registerFinalCondition("The model finished with #{model.numObjects} objects.") return true end |