OpenStudio clean up routine after changing system type for several zones
I wrote a measure to switch selected zones from central systems to single-zone system. The central system can have water coils, both cooling and heating, and therefore could be attached to a chiller and/or boiler loop. The chiller loop can be connected to a condenser water loop.
Basically, before doing anything, I'm storing the pre-existing airloops. Then, after switching the selected zones to another system type, those zones are no longer on the pre-existing airloops.
What I'd like to do is to clean up any unused Loops after that. My idea is:
- loop on Pre-existing AirLoops, delete all those don't have any zones anymore but before deletion check if connected to boiler and/or chiller loops and store those associated chiller and boiler loops.
- Loop on associated chiller loops and if demand components are linked to no air loop, delete chiller loop, but before deletion check if chiller is connected to a condenser water loop and store it
- Loop on associated condenser water loops and if not linked to any other demand component, delete it
- Do something similar to associated hot water loops.
I'm in the middle of writing this cleanup routine, and it's proving pretty time consuming.
Considering this seems like a legitimate and, I think, quite often useful routine, I think there are good chances somebody better at Ruby/OS Measures has already written it, but I haven't found it yet.
Does anybody know if that's already been done, so I don't have to reinvent the wheel?
My first stab at it here (starting line 267 till line 439 - missing boiler section, as well as integrating chiller.secondaryPlantLoop to get the condenser loops as per @David Goldwasser 's answer here)
I have the start of a measure to remove orphan objects and unused resources, but so far it only focuses on envelope, internal loads, schedules, and constructions. Ideally this will eventually would go through HVAC as well. It is possible that @aparker or @Kyle Benne have some code to do this.
Instead of storing the pre-existing loops, maybe make it generic to work on any model.
I did it this way because of two things:
@Julien Marrec Sometimes I wonder if the API should be doing this kind of clean up for you, but to this point I have resisted the urge because I think removing entire systems as a side effect of removing a component would be a little surprising. I would certainly reconsider if there was a strong feeling from a number of knowledgeable users. Maybe just some supporting methods in the API would be good. Something like AirLoopHVAC::removeUnusedSystems().
I'd second the supporting method
removeUnusedSystems()
. I've got a draft of it here. Missing the boiler section that I didn't need for this specific project.