Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Schedules module #1656

Merged
merged 16 commits into from
Jan 12, 2024
Merged

Refactor Schedules module #1656

merged 16 commits into from
Jan 12, 2024

Conversation

mdahlhausen
Copy link
Collaborator

@mdahlhausen mdahlhausen commented Jan 10, 2024

Pull request overview

This PR moves several schedules methods from:

openstudio-standards-0.4.0/lib/openstudio-standards/standards/Standards.Model.rb
openstudio-standards-0.4.0/lib/openstudio-standards/standards/Standards.ScheduleCompact.rb
openstudio-standards-0.4.0/lib/openstudio-standards/standards/Standards.ScheduleConstant.rb
openstudio-standards-0.4.0/lib/openstudio-standards/standards/Standards.ScheduleRuleset.rb

to the OpenstudioStandards::Schedules module

Pull Request Author

  • Method changes or additions
  • Added tests for added methods
  • If methods have been deprecated, update rest of code to use the new methods
  • Documented new methods using yard syntax
  • Resolved yard documentation errors for new code (ran bundle exec rake doc)
  • Resolved rubocop syntax errors for new code (ran bundle exec rake rubocop)
  • All new and existing tests passes

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a code review on GitHub
  • All related changes have been implemented: method additions, changes, tests
  • Check rubocop errors
  • Check yard doc errors
  • If fixing a defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If a new feature, test the new feature and try creative ways to break it
  • CI status: all green or justified

schedule_constant_annual_equivalent_full_load_hrs -> schedule_constant_get_equivalent_full_load_hours
get_8760_values_from_schedule_constant -> schedule_constant_get_hourly_values

note that the get_8760_values_from_schedule_constant method added an extra 24 hours for holiday schedules, but those extra hours are never used in the code. It's only used with ScheduleRuleset returns.
schedule_compact_annual_min_max_value -> schedule_compact_get_min_max
add generic schedule_get_min_max method
schedule_compact_design_day_min_max_value -> schedule_compact_get_design_day_min_max
day_schedule_equivalent_full_load_hrs -> schedule_day_get_equivalent_full_load_hours
schedule_ruleset_design_day_min_max_value -> schedule_ruleset_get_design_day_min_max
schedule_ruleset_annual_equivalent_full_load_hrs -> schedule_ruleset_get_equivalent_full_load_hours
+ schedule_get_design_day_min_max
+ schedule_get_equivalent_full_load_hours
+ schedule_constant_get_design_day_min_max
- removed old tests for schedule ruleset methods
simplified some sections of code with switch statements depending on schedule type to the generic schedule_get method
schedule_ruleset_annual_hours_above_value -> schedule_ruleset_get_hours_above_value
also fixed method because it was giving total eflh, not the sum of hours above a value
replace two methods:
schedule_ruleset_annual_hourly_values -> schedule_ruleset_get_hourly_values
get_8760_values_from_schedule_ruleset -> schedule_ruleset_get_hourly_values

both of the methods failed the tests to get the proper values.

schedule_ruleset_annual_hourly_values averages values at 15, 30, 45, which will improperly weight value changes not at 15 min intervals.

get_8760_values_from_schedule_ruleset assumed schedules have fixed intervals, which likely won't be true in cases of splines or ramps for custom parametric schedules

the new method schedule_ruleset_get_hourly_values uses the smallest time interval in a day schedule to calculate the averages, which is more accurate.

calls to the old methods replaced with the generic schedule_get_hourly_values

additionally:
- get_8760_values_from_schedule
+ schedule_day_get_hourly_values
+ schedule_get_hourly_values
model_add_schedule_type_limits -> create_schedule_type_limits
model_add_constant_schedule_ruleset -> create_constant_schedule_ruleset
@mdahlhausen
Copy link
Collaborator Author

mdahlhausen commented Jan 11, 2024

@weilixu I'd appreciate your review of the changes in this PR that impact PRM methods.

In particular, there are several PRM methods that get hourly values.
The hourly values methods previously returned an array of 8760 hours + 24 hours for leap years + 24 holiday values.
As far as I could tell, the holiday values were never used, so the new methods don't include that.

I also made a change to how hourly values are calculated, which is in the change from get_8760_values_from_schedule_ruleset() to OpenstudioStandards::Schedules.schedule_ruleset_get_hourly_values(). get_8760_values_from_schedule_ruleset() would loop through day schedules at a fixed interval and average values in the hour. It would not return the correct average if the schedule included changes at a non-fixed interval. I added a new method, schedule_day_get_hourly_values which finds the minimum interval length in a schedule day object, and uses that to do the time sampling/averaging. This gives accurately calculates the average. The downside is this method can take a while.

Copy link
Collaborator

@weilixu weilixu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @mdahlhausen That was a lot work to make the repo organized and improved!
I have a few comments as suggestions. I think your changes make sense and do not see any major impact to PRM routine.

year_end_date = nil
if schedule_ruleset.model.yearDescription.is_initialized
year_description = schedule_ruleset.model.yearDescription.get
year = year_description.assumedYear
Copy link
Collaborator

@weilixu weilixu Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually had an internal discussion on the assumedYear. Does this assumedYear guaranteed a non-leap year?
The reason is the PRM guideline requires PRM run in a non-leap year, so we may need some functions to make sure we are not running in leap year simulation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weilixu

It does not guarantee a non-leap year. How about at the start of the PRM methods, adding a check for the year, and setting to a default non-leap year if it is a leap year?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weilixu looking more at the PRM code, there are a few places that use schedule_get_hourly_values. It seems those places specifically loop through weeks and hours to get exactly 8760 values, get_fan_hours_per_week for example:

  def get_fan_hours_per_week(model, air_loop)
    fan_schedule = air_loop.availabilitySchedule
    fan_hours_8760 = OpenstudioStandards::Schedules.schedule_get_hourly_values(fan_schedule)
    fan_hours_52 = []

    hr_of_yr = -1
    (0..51).each do |iweek|
      week_sum = 0
      (0..167).each do |hr_of_wk|
        hr_of_yr += 1
        week_sum += fan_hours_8760[hr_of_yr]
      end
      fan_hours_52 << week_sum
    end
    max_fan_hours = fan_hours_52.max
    return max_fan_hours
  end

I'm wondering if we need to make any changes if the PRM methods that use the methods all force 8760 values anyways.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be safe, it seems the best way forward is to fix the year to a non-leap year if the AssumedYear is a leap year.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdahlhausen mdahlhausen merged commit f0be45c into master Jan 12, 2024
0 of 2 checks passed
@mdahlhausen mdahlhausen deleted the refactor/schedules_module branch January 12, 2024 21:14
@mdahlhausen mdahlhausen changed the title Refactor/schedules module Refactor Schedules module Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants