lib/openstudio-standards/geometry/information.rb in openstudio-standards-0.6.0.rc2 vs lib/openstudio-standards/geometry/information.rb in openstudio-standards-0.6.3

- old
+ new

@@ -9,12 +9,12 @@ # # @param area [Double] area # @param perimeter [Double] perimeter # @return [Double] aspect ratio def self.aspect_ratio(area, perimeter) - length = 0.25 * (perimeter + Math.sqrt(perimeter**2 - 16 * area)) - width = 0.25 * (perimeter - Math.sqrt(perimeter**2 - 16 * area)) + length = 0.25 * (perimeter + Math.sqrt((perimeter**2) - (16 * area))) + width = 0.25 * (perimeter - Math.sqrt((perimeter**2) - (16 * area))) aspect_ratio = length / width return aspect_ratio end @@ -158,14 +158,12 @@ # Get the surface's absolute azimuth surface_abs_azimuth = OpenstudioStandards::Geometry.surface_get_absolute_azimuth(surface) # Determine the surface's cardinal direction cardinal_direction = '' - if surface_abs_azimuth >= 0 && surface_abs_azimuth <= 45 + if (surface_abs_azimuth >= 0 && surface_abs_azimuth <= 45) || (surface_abs_azimuth > 315 && surface_abs_azimuth <= 360) cardinal_direction = 'N' - elsif surface_abs_azimuth > 315 && surface_abs_azimuth <= 360 - cardinal_direction = 'N' elsif surface_abs_azimuth > 45 && surface_abs_azimuth <= 135 cardinal_direction = 'E' elsif surface_abs_azimuth > 135 && surface_abs_azimuth <= 225 cardinal_direction = 'S' elsif surface_abs_azimuth > 225 && surface_abs_azimuth <= 315 @@ -446,11 +444,11 @@ end # now sort by areas. area_index = [] array_hash = {} - return array_hash if spaces.size.zero? + return array_hash if spaces.empty? # iterate through each surface in the space space.surfaces.each do |surface| # get the adjacent surface in another space. adj_surface = surface.adjacentSurface @@ -715,14 +713,15 @@ # make edges counter = 0 vertex_hash.each do |k, v| edge_counter += 1 counter += 1 - if vertex_hash.size != counter - edge_hash[edge_counter] = [v, vertex_hash[counter + 1], surface, surface.outsideBoundaryCondition, surface.surfaceType] - else # different code for wrap around vertex + if vertex_hash.size == counter + # different code for wrap around vertex edge_hash[edge_counter] = [v, vertex_hash[1], surface, surface.outsideBoundaryCondition, surface.surfaceType] + else + edge_hash[edge_counter] = [v, vertex_hash[counter + 1], surface, surface.outsideBoundaryCondition, surface.surfaceType] end end end # check edges for matches (need opposite vertices and proper boundary conditions) @@ -830,11 +829,11 @@ multipliers << space.multiplier end # If there are no spaces on this story, assume # a multiplier of 1 - if multipliers.size.zero? + if multipliers.empty? return floor_multiplier end # Calculate the average multiplier and # then convert to integer. @@ -865,21 +864,21 @@ z_origin = space.zOrigin # loop through space surfaces to find min z value space.surfaces.each do |surface| surface.vertices.each do |vertex| - z_heights << vertex.z + z_origin + z_heights << (vertex.z + z_origin) end end end # Error if no z heights were found z = 999.9 - if !z_heights.empty? - z = z_heights.min - else + if z_heights.empty? OpenStudio.logFree(OpenStudio::Error, 'openstudio.standards.Geometry.Information', "For #{building_story.name} could not find the minimum_z_value, which means the story has no spaces assigned or the spaces have no surfaces.") + else + z = z_heights.min end return z end @@ -927,12 +926,12 @@ # @return [Array<OpenStudio::Model::BuildingStory>] Array of OpenStudio BuildingStory objects, empty array if none def self.model_get_building_stories_above_ground(model) above_ground_stories = [] model.getBuildingStorys.sort.each do |story| z = story.nominalZCoordinate - unless z.empty? - above_ground_stories << story if z.to_f >= 0 + if !z.empty? && z.to_f >= 0 + above_ground_stories << story end end return above_ground_stories end @@ -942,12 +941,12 @@ # @return [Array<OpenStudio::Model::BuildingStory>] Array of OpenStudio BuildingStory objects, empty array if none def self.model_get_building_stories_below_ground(model) below_ground_stories = [] model.getBuildingStorys.sort.each do |story| z = story.nominalZCoordinate - unless z.empty? - below_ground_stories << story if z.to_f < 0 + if !z.empty? && z.to_f < 0 + below_ground_stories << story end end return below_ground_stories end @@ -974,17 +973,15 @@ # loop through each space and log window and wall areas spaces.each do |space| # get surface area adjusting for zone multiplier zone = space.thermalZone - if !zone.empty? - zone_multiplier = zone.get.multiplier - if zone_multiplier > 1 - end - else + if zone.empty? # space is not in a thermal zone zone_multiplier = 1 + else + zone_multiplier = zone.get.multiplier end # loop through spaces and skip all that aren't exterior walls and don't match selected cardinal direction space.surfaces.each do |surface| next if surface.surfaceType != 'Wall' @@ -1045,16 +1042,14 @@ end spaces.each do |space| # get surface area adjusting for zone multiplier zone = space.thermalZone - if !zone.empty? - zone_multiplier = zone.get.multiplier - if zone_multiplier > 1 - end - else + if zone.empty? zone_multiplier = 1 # space is not in a thermal zone + else + zone_multiplier = zone.get.multiplier end space.surfaces.each do |s| next if s.surfaceType != 'Wall' next if s.outsideBoundaryCondition != 'Outdoors' @@ -1125,13 +1120,14 @@ # make edges counter = 0 vertex_hash.each do |k, v| edge_counter += 1 counter += 1 - if vertex_hash.size != counter - edge_hash[edge_counter] = [v, vertex_hash[counter + 1], surface, surface.outsideBoundaryCondition, surface.surfaceType] - else # different code for wrap around vertex + if vertex_hash.size == counter + # different code for wrap around vertex edge_hash[edge_counter] = [v, vertex_hash[1], surface, surface.outsideBoundaryCondition, surface.surfaceType] + else + edge_hash[edge_counter] = [v, vertex_hash[counter + 1], surface, surface.outsideBoundaryCondition, surface.surfaceType] end end end # check edges for matches (need opposite vertices and proper boundary conditions)