Skip to content

Commit

Permalink
Merge pull request #1722 from NREL/fix/zero_ppl_space_occ_sch
Browse files Browse the repository at this point in the history
Return zero schedule when no people in space from spaces_get_occupancy_schedule
  • Loading branch information
mdahlhausen authored Apr 7, 2024
2 parents 2ec6da2 + 7c7d68e commit 9391825
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/openstudio-standards/space/space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ def self.spaces_get_occupancy_schedule(spaces, sch_name: nil, occupied_percentag
OpenStudio.logFree(OpenStudio::Debug, 'openstudio.standards.space', "Finding space schedules for #{sch_name}.")
end

# create schedule
if sch_name.nil?
sch_name = "#{spaces.size} space(s) Occ Sch"
end

# Get all the occupancy schedules in spaces.
# Include people added via the SpaceType and hard-assigned to the Space itself.
occ_schedules_num_occ = {} # hash of People ScheduleRuleset => design occupancy for that People object
Expand Down Expand Up @@ -395,7 +400,13 @@ def self.spaces_get_occupancy_schedule(spaces, sch_name: nil, occupied_percentag
# total occupancy from all people
total_design_occ = occ_schedules_num_occ.values.sum

OpenStudio.logFree(OpenStudio::Debug, 'openstudio.standards.space', " Total #{total_design_occ.round} people in #{spaces.size} spaces.")
OpenStudio.logFree(OpenStudio::Debug, 'openstudio.standards.space', "Total #{total_design_occ.round} people in #{spaces.size} spaces.")

# if design occupancy is zero, return zero schedule
if total_design_occ.zero?
schedule_ruleset = OpenstudioStandards::Schedules.create_constant_schedule_ruleset(spaces[0].model, 0.0, name: sch_name)
return schedule_ruleset
end

# get one 8760 array of the sum of each schedule's hourly occupancy
combined_hourly_occ = all_schedule_hourly_occ.transpose.map(&:sum)
Expand Down Expand Up @@ -439,9 +450,6 @@ def self.spaces_get_occupancy_schedule(spaces, sch_name: nil, occupied_percentag
end

# create schedule
if sch_name.nil?
sch_name = "#{spaces.size} space(s) Occ Sch"
end
schedule_ruleset = OpenStudio::Model::ScheduleRuleset.new(spaces[0].model)
schedule_ruleset.setName(sch_name.to_s)
# add properties to schedule
Expand Down
14 changes: 14 additions & 0 deletions test/modules/space/test_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ def test_spaces_get_occupancy_schedule
ppl3.setNumberofPeopleSchedule(ppl_sch3)
ppl3.setSpace(space2)

polygon = OpenStudio::Point3dVector.new
origin = OpenStudio::Point3d.new(0.0, 10.0, 0.0)
polygon << origin
polygon << origin + OpenStudio::Vector3d.new(0.0, 5.0, 0.0)
polygon << origin + OpenStudio::Vector3d.new(5.0, 5.0, 0.0)
polygon << origin + OpenStudio::Vector3d.new(5.0, 0.0, 0.0)
space3 = OpenStudio::Model::Space.fromFloorPrint(polygon, 1.0, model).get

# space with no people
zero_schedule = @space.spaces_get_occupancy_schedule([space3], sch_name: 'test empty occupancy frac')
zero_min_max = @sch.schedule_get_min_max(zero_schedule)
assert_equal(0.0, zero_min_max['min'])
assert_equal(0.0, zero_min_max['max'])

# fractional values
occ_sch_fracs = @space.spaces_get_occupancy_schedule([space1,space2], sch_name: 'test occupancy frac', occupied_percentage_threshold: nil, threshold_calc_method: nil)
puts "Fractional Values: #{occ_sch_fracs.scheduleRules.size} Schedule Rules"
Expand Down

0 comments on commit 9391825

Please sign in to comment.