Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
0

Openstudio SDK - Add spaceType to model

asked 2022-06-29 16:41:37 -0600

updated 2022-06-30 08:55:51 -0600

I am struggling to understand how to add a space type to a model with the Ruby SDK, for example 189.1-2009 - Office - WholeBuilding - Md Office - CZ1-3.

This is where I got:

space_type = OpenStudio::Model::SpaceType.new(model)
space_type_name = "189.1-2009 - Office - WholeBuilding - Md Office - CZ1-3"
space_type.setStandardsSpaceType(space_type_name)

in the meaaure Space Type and Construction Set Wizard there is a method called wizard from openstudio-extension. It looks like it first defines a standard and then assigns some properties

standard = Standard.build("90.1-2019") # Just guessing the standard
standard.space_type_apply_internal_loads(space_type, true, true, true, true, true, true)
standard.space_type_apply_internal_load_schedules(space_type, true, true, true, true, true, true, true)

I tried this, the space type appears in the OpenStudio App, but it is empty. Is this the right approach?

Any advice on how to proceed? Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-07-01 06:46:51 -0600

I will attempt an answer just in case helps someone else.

I spent a bit of time studying the openstudio-extension-gem that has various modules and methods to create models, assign constructions, spaces, etc., and the openstudio-standards that has all the data for every standard. This is an example code that adds a whole building space type at building level with some additional comments from me.

# OpenStudio
require "/Applications/OpenStudio-3.4.0/Ruby/openstudio.rb"
require "openstudio/extension/core/os_lib_model_generation"
require "openstudio/extension/core/os_lib_helper_methods"
require "openstudio-standards"

include OsLib_ModelGeneration
# include OsLib_HelperMethods

model_name = "testOSM"

model = OpenStudio::Model::Model.new

# pp get_building_types.to_a
building_type = "MediumOffice"

# pp get_templates.to_a
template = "90.1-2019"
# true creates a whole building profile
space_type_hash = get_space_types_from_building_type(building_type, template, true)
puts space_type_hash

# pp get_climate_zones.to_a
climate_zone = "ASHRAE 169-2013-1A"

# reporting initial condition of model
starting_spaceTypes = model.getSpaceTypes.sort
puts starting_spaceTypes.size

# create space_type_map from array
space_type_map = {}
default_space_type_name = nil
space_type_hash.each do |space_type_name, hash|
  next if hash[:space_type_gen] == false # space types like undeveloped and basement are skipped.
  space_type_map[space_type_name] = [] # no spaces to pass in
  if hash[:default]
    default_space_type_name = space_type_name
  end
end
puts space_type_map


# Make the standard applier
standard = Standard.build(template)

# mapping building_type name is needed for a few methods
lookup_building_type = standard.model_get_lookup_name(building_type)
puts lookup_building_type

# I think this is needed because the standards template only has office type
# remap small medium and large office to office 
if building_type.include?("Office") then building_type = "Office" end
puts building_type

# array of starting space types
space_types_starting = model.getSpaceTypes.sort

# create stub space types
space_types_new = []
space_type_hash.each do |space_type_name, hash|
  next if hash[:space_type_gen] == false # space types like undeveloped and basement are skipped.

  # create space type
  space_type = OpenStudio::Model::SpaceType.new(model)
  space_type.setStandardsBuildingType(building_type)
  space_type.setStandardsSpaceType(space_type_name)
  space_type.setName("#{building_type} #{space_type_name}")

  # add to array of new space types
  space_types_new << space_type

  # add internal loads (the nil check isn't ncessary, but I will keep it in as a warning instad of an error)
  test = standard.space_type_apply_internal_loads(space_type, true, true, true, true, true, true)
  if test.nil?
    puts "Could not add loads for #{space_type.name}. Not expected for #{template} #{lookup_building_type}"
  end

  # the last bool test it to make thermostat schedules. They are added to the model but not assigned
  standard.space_type_apply_internal_load_schedules(space_type, true, true, true, true, true, true, true)

  # assign colors
  standard.space_type_apply_rendering_color(space_type)

  # exend space type name to include the template. Consider this as well for load defs
  space_type.setName("#{space_type.name} - #{template}")
  puts "Added space type named #{space_type.name}"
end

# identify default space type. Not sure about this, just copied from the measure
space_type_standards_info_hash = OsLib_HelperMethods.getSpaceTypeStandardsInformation(space_types_new)
puts space_type_standards_info_hash
default_space_type = nil
space_type_standards_info_hash.each do |space_type, standards_array|
  standards_space_type = standards_array[1]
  if default_space_type_name == standards_space_type
    default_space_type = space_type
  end
end

# set default space type
building = model.getBuilding
if !default_space_type.nil?
  building.setSpaceType(default_space_type)
end

model.save("#{model_name}.osm", true)
edit flag offensive delete link more
0

answered 2022-07-11 12:39:54 -0600

I tested and confirmed there is an issue for some building types in OpenStudio 3.4. I have specifically identified that it impacts RetailStripmall and RetailStandalone. I'll work on fix, but if in ext gem may not be accessible until next installer. I'll also make test more robust to catch this if it happens in the future.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2022-06-29 16:41:37 -0600

Seen: 250 times

Last updated: Jul 11 '22