Skip to content

Commit

Permalink
daylight saving impact
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingli committed Jan 31, 2025
1 parent 3bbb283 commit 95c6722
Show file tree
Hide file tree
Showing 5 changed files with 417 additions and 7 deletions.
4 changes: 3 additions & 1 deletion measures/ResStockArgumentsPostHPXML/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def modify_schedule(hpxml, building_index, args, runner, schedule)
weather: weather,
epw_path: epw_path,
minutes_per_step: minutes_per_step,
runner: runner)
runner: runner,
hpxml: hpxml,
building_index: building_index)
flexibility_inputs = get_flexibility_inputs(args, minutes_per_step, building_id)
schedule_modifier.modify_setpoints(schedule, flexibility_inputs)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class HVACScheduleModifier
def initialize(state:, sim_year:, weather:, epw_path:, minutes_per_step:, runner:)
def initialize(state:, sim_year:, weather:, epw_path:, minutes_per_step:, runner:, hpxml:, building_index:)
@state = state
@minutes_per_step = minutes_per_step
@runner = runner
Expand All @@ -28,17 +28,21 @@ def initialize(state:, sim_year:, weather:, epw_path:, minutes_per_step:, runner
current_dir = File.dirname(__FILE__)
@peak_hours_dict_shift = JSON.parse(File.read("#{current_dir}/seasonal_shifting_peak_hours.json"))
@peak_hours_dict_shed = JSON.parse(File.read("#{current_dir}/seasonal_shedding_peak_hours.json"))
@hpxml = hpxml
@hpxml_bldg = @hpxml.buildings[building_index]
end

def modify_setpoints(setpoints, flexibility_inputs)
log_inputs(flexibility_inputs)
dst_info = _daylight_savings_month_day()
puts dst_info
heating_setpoint = setpoints[:heating_setpoint].dup
cooling_setpoint = setpoints[:cooling_setpoint].dup
raise "heating_setpoint.length != cooling_setpoint.length" unless heating_setpoint.length == cooling_setpoint.length

total_indices = heating_setpoint.length
total_indices.times do |index|
offset_times = _get_peak_times(index, flexibility_inputs)
offset_times = _get_peak_times(index, flexibility_inputs, dst_info)
day_type = _get_day_type(index)
if day_type == 'heating'
heating_setpoint[index] += _get_setpoint_offset(index, 'heating', offset_times, flexibility_inputs)
Expand Down Expand Up @@ -69,10 +73,15 @@ def _clip_setpoints(day_type, setpoint)
setpoint
end

def _get_peak_times(index, flexibility_inputs)
month = _get_month(index:)
def _get_peak_times(index, flexibility_inputs, dst_info)
month, day = _get_month_day(index:)

pre_peak_duration = flexibility_inputs.pre_peak_duration_steps
peak_hour_start, peak_hour_end = _get_peak_hour(pre_peak_duration, month:)
dst_adjust_hour = _dst_ajustment(month, day, dst_info)
peak_hour_start += dst_adjust_hour
peak_hour_end += dst_adjust_hour

peak_times = DailyPeakIndices.new
random_shift_steps = flexibility_inputs.random_shift_steps
peak_times.peak_start_index = peak_hour_start * @num_timesteps_per_hour + random_shift_steps
Expand Down Expand Up @@ -103,10 +112,12 @@ def _get_setpoint_offset(index, setpoint_type, offset_times, flexibility_inputs)
end
end

def _get_month(index:)
def _get_month_day(index:)
start_of_year = Date.new(@sim_year, 1, 1)
index_date = start_of_year + (index.to_f / @num_timesteps_per_hour / 24)
index_date.month
index_date.day
return index_date.month, index_date.day
end

def _get_peak_hour(pre_peak_duration, month:)
Expand All @@ -124,6 +135,55 @@ def _get_peak_hour(pre_peak_duration, month:)
end
end

def _daylight_savings_month_day()
if @hpxml_bldg.dst_enabled
if @hpxml_bldg.dst_begin_month.nil? || @hpxml_bldg.dst_begin_day.nil? || @hpxml_bldg.dst_end_month.nil? || @hpxml_bldg.dst_end_day.nil?
if (not @weather.header.DSTStartDate.nil?) && (not @weather.header.DSTEndDate.nil?)
# Use weather file DST dates if available
dst_start_date = @weather.header.DSTStartDate
dst_end_date = @weather.header.DSTEndDate
@hpxml_bldg.dst_begin_month = dst_start_date.monthOfYear.value
@hpxml_bldg.dst_begin_day = dst_start_date.dayOfMonth
@hpxml_bldg.dst_end_month = dst_end_date.monthOfYear.value
@hpxml_bldg.dst_end_day = dst_end_date.dayOfMonth
else
# Roughly average US dates according to https://en.wikipedia.org/wiki/Daylight_saving_time_in_the_United_States
@hpxml_bldg.dst_begin_month = 3
@hpxml_bldg.dst_begin_day = 12
@hpxml_bldg.dst_end_month = 11
@hpxml_bldg.dst_end_day = 5
end
@hpxml_bldg.dst_begin_month_isdefaulted = true
@hpxml_bldg.dst_begin_day_isdefaulted = true
@hpxml_bldg.dst_end_month_isdefaulted = true
@hpxml_bldg.dst_end_day_isdefaulted = true
end
else
@hpxml_bldg.dst_begin_month = 0
@hpxml_bldg.dst_begin_day = 0
@hpxml_bldg.dst_end_month = 0
@hpxml_bldg.dst_end_day = 0
end
dst_info = {dst_begin_month: @hpxml_bldg.dst_begin_month,
dst_begin_day: @hpxml_bldg.dst_begin_day,
dst_end_month: @hpxml_bldg.dst_end_month,
dst_end_day: @hpxml_bldg.dst_end_day}
return dst_info
end

def _dst_ajustment(month, day, dst_info)
if month > dst_info[:dst_begin_month] && month < dst_info[:dst_end_month]
dst_adjust_hour = 1
elsif month == dst_info[:dst_begin_month] && day >= dst_info[:dst_begin_day] # double check
dst_adjust_hour = 1
elsif month == dst_info[:dst_end_month] && day < dst_info[:dst_end_day] # double check
dst_adjust_hour = 1
else
dst_adjust_hour = 0
end
return dst_adjust_hour
end

def _get_day_type(index)
day = index / @steps_in_day
if @daily_avg_temps[day] < 66.0
Expand Down
3 changes: 2 additions & 1 deletion measures/ResStockArgumentsPostHPXML/tests/baseline.osw
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"steps": [
{
"arguments": {
"site_state_code" : "CO",
"site_state_code" : "CO",
"simulation_control_daylight_saving_enabled": false,
"air_leakage_house_pressure": 50,
"site_shielding_of_home": "normal",
"air_leakage_units": "ACH",
Expand Down
Loading

0 comments on commit 95c6722

Please sign in to comment.