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.



2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
# File 'lib/openstudio-standards/btap/geometry.rb', line 2203

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



2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
# File 'lib/openstudio-standards/btap/geometry.rb', line 2234

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



2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
# File 'lib/openstudio-standards/btap/geometry.rb', line 2220

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



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

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



2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
# File 'lib/openstudio-standards/btap/geometry.rb', line 2304

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



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

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