Class: ReduceDomesticHotWaterUseForPeakHours
- Inherits:
-
OpenStudio::Measure::ModelMeasure
- Object
- OpenStudio::Measure::ModelMeasure
- ReduceDomesticHotWaterUseForPeakHours
- Defined in:
- lib/measures/reduce_domestic_hot_water_use_for_peak_hours/measure.rb
Overview
start the measure
Instance Method Summary collapse
-
#arguments(model) ⇒ Object
define the arguments that the user will input.
-
#description ⇒ Object
human readable description.
-
#modeler_description ⇒ Object
human readable description of modeling approach.
-
#name ⇒ Object
human readable name.
-
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run.
- #update_new_sch(sch_day, start_time, end_time, reduce_pct) ⇒ Object
Instance Method Details
#arguments(model) ⇒ Object
define the arguments that the user will input
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/measures/reduce_domestic_hot_water_use_for_peak_hours/measure.rb', line 30 def arguments(model) args = OpenStudio::Measure::OSArgumentVector.new water_use_reduce_percent = OpenStudio::Measure::OSArgument.makeDoubleArgument('water_use_reduce_percent', true) water_use_reduce_percent.setDisplayName('Percentage Reduction of Domestic Hot Water Use (%)') water_use_reduce_percent.setDescription('Enter a value between 0 and 100') water_use_reduce_percent.setDefaultValue(50.0) args << water_use_reduce_percent # make an argument for the start time of the reduction start_time = OpenStudio::Measure::OSArgument.makeStringArgument('start_time', false) start_time.setDisplayName('Start Time for the Reduction') start_time.setDescription('In HH:MM:SS format') start_time.setDefaultValue('16:00:00') args << start_time # make an argument for the end time of the reduction end_time = OpenStudio::Measure::OSArgument.makeStringArgument('end_time', false) end_time.setDisplayName('End Time for the Reduction') end_time.setDescription('In HH:MM:SS format') end_time.setDefaultValue('21:00:00') args << end_time return args end |
#description ⇒ Object
human readable description
20 21 22 |
# File 'lib/measures/reduce_domestic_hot_water_use_for_peak_hours/measure.rb', line 20 def description return 'This measure reduces the domestic hot water usage by a user-specified percentage for a user-specified time period (usually the peak hours). This is applied to the whole building.' end |
#modeler_description ⇒ Object
human readable description of modeling approach
25 26 27 |
# File 'lib/measures/reduce_domestic_hot_water_use_for_peak_hours/measure.rb', line 25 def modeler_description return 'This measure will clone the flow rate fraction schedules of all the WaterUseEquipment. Then the schedules are adjusted by the specified percentage during the specified time period. ' end |
#name ⇒ Object
human readable name
14 15 16 17 |
# File 'lib/measures/reduce_domestic_hot_water_use_for_peak_hours/measure.rb', line 14 def name # Measure name should be the title case of the class name. return 'Reduce domestic hot water use for peak hours' end |
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/measures/reduce_domestic_hot_water_use_for_peak_hours/measure.rb', line 56 def run(model, runner, user_arguments) super(model, runner, user_arguments) # use the built-in error checking if !runner.validateUserArguments(arguments(model), user_arguments) return false end # assign the user inputs to variables water_use_reduce_percent = runner.getDoubleArgumentValue('water_use_reduce_percent', user_arguments) start_time = runner.getStringArgumentValue('start_time', user_arguments) end_time = runner.getStringArgumentValue('end_time', user_arguments) # validate the percentage if water_use_reduce_percent > 100 runner.registerError('The percentage reduction of domestic hot water use cannot be larger than 100.') return false elsif water_use_reduce_percent < 0 runner.registerWarning('The percentage reduction of domestic hot water use is negative. This will increase the domestic hot water use.') end if start_time.to_f > end_time.to_f runner.registerError('For domestic hot water use adjustment, the end time should be larger than the start time.') return false end if /(\d\d):(\d\d):(\d\d)/.match(start_time) shift_time1 = OpenStudio::Time.new(start_time) else runner.registerError('Start time must be in HH-MM-SS format.') return false end if /(\d\d):(\d\d):(\d\d)/.match(end_time) shift_time2 = OpenStudio::Time.new(end_time) else runner.registerError('End time must be in HH-MM-SS format.') return false end # report initial condition of model runner.registerInitialCondition("The building started with #{model.getWaterUseEquipments.size} WaterUseEquipment and #{(model.getWaterHeaterMixeds + model.getWaterHeaterStratifieds).size} WaterHeaterMixed.") def update_new_sch(sch_day, start_time, end_time, reduce_pct) # grab time-value pairs for modification old_times = sch_day.times old_values = sch_day.values count = 0 old_times.each_with_index do |, i| adjusted_value = old_values[i] * (100 - reduce_pct) * 0.01 if > start_time && < end_time && count == 0 sch_day.addValue(start_time, old_values[i]) sch_day.addValue(, adjusted_value) count = 1 elsif == end_time && count == 0 sch_day.addValue(start_time, old_values[i]) sch_day.addValue(, adjusted_value) count = 2 elsif == start_time && count == 0 sch_day.addValue(, old_values[i]) count = 1 elsif > end_time && count == 0 sch_day.addValue(start_time, old_values[i]) sch_day.addValue(end_time, adjusted_value) sch_day.addValue(, old_values[i]) count = 2 elsif > start_time && < end_time && count==1 sch_day.addValue(, adjusted_value) elsif == end_time && count==1 sch_day.addValue(, adjusted_value) count = 2 elsif > end_time && count == 1 sch_day.addValue(end_time, adjusted_value) sch_day.addValue(, old_values[i]) count = 2 else sch_day.addValue(, old_values[i]) end end return sch_day end yd = model.getYearDescription start_date = yd.makeDate(1, 1) end_date = yd.makeDate(12, 31) changed_water_equip_count = 0 # modify the flow rate fraction schedule for all the water use equipment model.getWaterUseEquipments.each do |water_equip| if water_equip.flowRateFractionSchedule.is_initialized if water_equip.flowRateFractionSchedule.get.to_ScheduleRuleset.is_initialized new_sch = water_equip.flowRateFractionSchedule.get.clone.to_ScheduleRuleset.get sch_name = water_equip.flowRateFractionSchedule.get.name.to_s # rename and duplicate for later modification new_sch.setName(sch_name + ' adjusted') new_sch.defaultDaySchedule.setName(sch_name + ' adjusted Default') update_new_sch(new_sch.defaultDaySchedule, shift_time1, shift_time2, water_use_reduce_percent) new_sch.scheduleRules.each do |rule| update_new_sch(rule.daySchedule, shift_time1, shift_time2, water_use_reduce_percent) end water_equip.setFlowRateFractionSchedule(new_sch) changed_water_equip_count += 1 else runner.registerWarning("The flow rate schedule of water use equipment #{water_equip.name.to_s} is not a ScheduleRuleset, cannot modify with this measure.") end else # when no flow rate fraction assigned, by default it is assuming 1 all the time. new_sch = OpenStudio::Model::ScheduleRuleset.new(model) new_sch.setName("Hot water flow rate fraction sch adjusted") new_sch.defaultDaySchedule.setName('Hot water flow rate fraction sch adjusted Default') new_sch.defaultDaySchedule.addValue(OpenStudio::Time.new(0, 24, 0, 0), 1) update_new_sch(new_sch.defaultDaySchedule, shift_time1, shift_time2, water_use_reduce_percent) water_equip.setFlowRateFractionSchedule(new_sch) changed_water_equip_count += 1 end end changed_water_heater_count = 0 # modify the flow rate fraction schedule of the water heaters all_water_heaters = model.getWaterHeaterMixeds + model.getWaterHeaterStratifieds all_water_heaters.each do |water_heater| if water_heater.useFlowRateFractionSchedule.is_initialized if water_heater.useFlowRateFractionSchedule.get.to_ScheduleRuleset.is_initialized new_sch = water_heater.useFlowRateFractionSchedule.get.clone.to_ScheduleRuleset.get # rename and duplicate for later modification new_sch.setName('Water heater flow rate fraction sch adjusted') new_sch.defaultDaySchedule.setName('Water heater flow rate fraction sch adjusted Default') update_new_sch(new_sch.defaultDaySchedule, shift_time1, shift_time2, water_use_reduce_percent) new_sch.scheduleRules.each do |rule| update_new_sch(rule.daySchedule, shift_time1, shift_time2, water_use_reduce_percent) end water_heater.setUseFlowRateFractionSchedule(new_sch) changed_water_heater_count += 1 else runner.registerWarning("The flow rate schedule of water heater #{water_heater.name.to_s} is not a ScheduleRuleset, cannot modify with this measure.") end end end # report final condition of model runner.registerFinalCondition("The building finished with hot water use reduced for #{changed_water_equip_count} water use equipments and #{changed_water_heater_count} water heaters.") return true end |
#update_new_sch(sch_day, start_time, end_time, reduce_pct) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/measures/reduce_domestic_hot_water_use_for_peak_hours/measure.rb', line 99 def update_new_sch(sch_day, start_time, end_time, reduce_pct) # grab time-value pairs for modification old_times = sch_day.times old_values = sch_day.values count = 0 old_times.each_with_index do |, i| adjusted_value = old_values[i] * (100 - reduce_pct) * 0.01 if > start_time && < end_time && count == 0 sch_day.addValue(start_time, old_values[i]) sch_day.addValue(, adjusted_value) count = 1 elsif == end_time && count == 0 sch_day.addValue(start_time, old_values[i]) sch_day.addValue(, adjusted_value) count = 2 elsif == start_time && count == 0 sch_day.addValue(, old_values[i]) count = 1 elsif > end_time && count == 0 sch_day.addValue(start_time, old_values[i]) sch_day.addValue(end_time, adjusted_value) sch_day.addValue(, old_values[i]) count = 2 elsif > start_time && < end_time && count==1 sch_day.addValue(, adjusted_value) elsif == end_time && count==1 sch_day.addValue(, adjusted_value) count = 2 elsif > end_time && count == 1 sch_day.addValue(end_time, adjusted_value) sch_day.addValue(, old_values[i]) count = 2 else sch_day.addValue(, old_values[i]) end end return sch_day end |