Module: BTAP::Geometry::BuildingStoreys

Defined in:
lib/openstudio-standards/btap/geometry.rb

Class Method Summary collapse

Class Method Details

.auto_assign_spaces_to_stories(model) ⇒ Object

This method will delete any exisiting stories and then try to assign stories based on the z-axis origin of the space.



2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
# File 'lib/openstudio-standards/btap/geometry.rb', line 2185

def self.auto_assign_spaces_to_stories(model)
  #delete existing stories.
  model.getBuildingStorys.sort.each {|buildingstory| buildingstory.remove}
  #create hash of building storeys, index is the Z-axis origin of the space.
  building_story_hash = Hash.new()
  model.getSpaces.sort.each do |space|
    if building_story_hash[space.zOrigin].nil?
      building_story_hash[space.zOrigin] = OpenStudio::Model::BuildingStory.new(model)
      building_story_hash[space.zOrigin].setName(building_story_hash.length.to_s)
    end


    space.setBuildingStory(building_story_hash[space.zOrigin])
  end
end

.auto_assign_stories(model) ⇒ Object

override run to implement the functionality of your script model is an OpenStudio::Model::Model, runner is a OpenStudio::Ruleset::UserScriptRunner



2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
# File 'lib/openstudio-standards/btap/geometry.rb', line 2216

def self.auto_assign_stories(model)

  # get all spaces
  spaces = model.getSpaces

  #puts("Assigning Stories to Spaces")

  # make has of spaces and minz values
  sorted_spaces = Hash.new
  spaces.sort.each do |space|
    # loop through space surfaces to find min z value
    z_points = []
    space.surfaces.each do |surface|
      surface.vertices.each do |vertex|
        z_points << vertex.z
      end
    end
    minz = z_points.min + space.zOrigin
    sorted_spaces[space] = minz
  end

  # pre-sort spaces
  sorted_spaces = sorted_spaces.sort {|a, b| a[1]<=>b[1]}


  # this should take the sorted list and make and assign stories
  sorted_spaces.sort.each do |space|
    space_obj = space[0]
    space_minz = space[1]
    if space_obj.buildingStory.empty?

      story = getStoryForNominalZCoordinate(model, space_minz)
      #puts("Setting story of Space " + space_obj.name.get + " to " + story.name.get + ".")
      space_obj.setBuildingStory(story)
    end
  end
end

.get_zones_from_storey(storey) ⇒ Object

Get the zones in a storey



2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
# File 'lib/openstudio-standards/btap/geometry.rb', line 2202

def self.get_zones_from_storey(storey)
  #check to see if the storey has a zone that is part of the zone list. 
  zones = Array.new
  storey.spaces.sort.each do |space|
    if not space.thermalZone.empty? and not zones.include?(space.thermalZone.get)
      zones.push(space.thermalZone.get)
    end
  end
  return zones
end

.getStoryAboveGround(model) ⇒ Object



2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
# File 'lib/openstudio-standards/btap/geometry.rb', line 2271

def self.getStoryAboveGround(model)
  count = 0
  model.getBuildingStorys.sort.each do |story|
    z = story.nominalZCoordinate
    unless z.empty?
      if z.to_f >= 0
        #puts story.name.get
        count += 1
      end
    end
  end
  return count
end

.getStoryBelowGround(model) ⇒ Object



2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
# File 'lib/openstudio-standards/btap/geometry.rb', line 2286

def self.getStoryBelowGround(model)
  count = 0
  model.getBuildingStorys.sort.each do |story|
    z = story.nominalZCoordinate
    unless z.empty?
      if z.to_f < 0
        #puts story.name.get
        count += 1
      end
    end
  end
  return count
end

.getStoryForNominalZCoordinate(model, minz) ⇒ Object

find the first story with z coordinate, create one if needed



2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
# File 'lib/openstudio-standards/btap/geometry.rb', line 2255

def self.getStoryForNominalZCoordinate(model, minz)

  model.getBuildingStorys.sort.each do |story|
    z = story.nominalZCoordinate
    if not z.empty?
      if minz == z.get
        return story
      end
    end
  end

  story = OpenStudio::Model::BuildingStory.new(model)
  story.setNominalZCoordinate(minz)
  return story
end