Skip to content

Instantly share code, notes, and snippets.

@jmarrec
Last active October 20, 2023 09:50
Show Gist options
  • Save jmarrec/a9ac7d2955c8c4f2fe191bc0204b844f to your computer and use it in GitHub Desktop.
Save jmarrec/a9ac7d2955c8c4f2fe191bc0204b844f to your computer and use it in GitHub Desktop.
Add a Swimming Pool to an OpenStudio model
# Created model via CLI call: `openstudio -e "m = OpenStudio::Model::exampleModel(); m.save('example_model.osm')"`
require 'openstudio'
include OpenStudio::Model
# Helper to load a model in one line
# It will raise if the path (or the model) isn't valid
#
# @param path [String] The path to the osm
# @return [OpenStudio::Model::Model] the resulting model.
def osload(path)
translator = OpenStudio::OSVersion::VersionTranslator.new
ospath = OpenStudio::Path.new(path)
model = translator.loadModel(ospath)
if model.empty?
raise "Path '#{path}' is not a valid path to an OpenStudio Model"
else
model = model.get
end
return model
end
m = osload('example_model.osm')
first_zone = m.getThermalZones.sort_by { |c| c.name.to_s }.first
floor_surface = first_zone.spaces[0].surfaces.select { |s| s.surfaceType == 'Floor' }[0]
# Create a SwimmingPoolIndoor. You'll be able to change it in the OS App after
swimmingPoolIndoor = OpenStudio::Model::SwimmingPoolIndoor.new(m, floor_surface)
# Create a Plant Loop
heating_loop = PlantLoop.new(m)
# Or get one by name
# heating_loop = m.getPlantLoopByName("My Plant Loop").get
# Connect the pool to the heating loop
heating_loop.addDemandBranchForComponent(swimmingPoolIndoor)
m.save('example_model.osm', true)
# Create a test model
openstudio -e "m = OpenStudio::Model::exampleModel(); m.save('example_model.osm')"
# Add a SwimmingPoolIndoor to that model via the above script
openstudio add_swimming_pool.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment