Class: AddHphw

Inherits:
OpenStudio::Measure::ModelMeasure
  • Object
show all
Defined in:
lib/measures/add_hpwh/measure.rb

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

USER ARGS ——————————————————————————————————— define the arguments that the user will input



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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/measures/add_hpwh/measure.rb', line 85

def arguments(model)
  args = OpenStudio::Measure::OSArgumentVector.new

  # create argument for removal of existing water heater tanks on selected loop

  remove_wh = OpenStudio::Measure::OSArgument.makeBoolArgument('remove_wh', true)
  remove_wh.setDisplayName('Remove existing water heater on selected loop')
  remove_wh.setDescription('')
  remove_wh.setDefaultValue(true)
  args << remove_wh

  # find available plant loops (heating)

  loop_names = []

  unless model.getPlantLoops.empty?
    loops = model.getPlantLoops
    loops.each do |lp|
      unless lp.sizingPlant.loopType.empty?
        next unless lp.sizingPlant.loopType.to_s == 'Heating'
        loop_names << lp.name.to_s
      end
    end
  end

  loop_names << 'Error: No Service Water Loop Found' if loop_names.empty?

  # create argument for loop selection

  loop = OpenStudio::Measure::OSArgument.makeChoiceArgument('loop', loop_names.sort, true)
  loop.setDisplayName('Select hot water loop')
  loop.setDescription('The water tank will be placed on the supply side of this loop.')
  loop.setDefaultValue(loop_names.sort[0])
  args << loop

  # find available spaces for heater location

  zone_names = []

  unless model.getThermalZones.empty?
    zones = model.getThermalZones
    zones.each do |zn|
      zone_names << zn.name.to_s
    end
    zone_names.sort!
  end

  zone_names << 'Error: No Thermal Zones Found' if zone_names.empty?

  # create argument for thermal zone selection (location of water heater)

  zone = OpenStudio::Measure::OSArgument.makeChoiceArgument('zone', zone_names, true)
  zone.setDisplayName('Select thermal zone')
  zone.setDescription('This is where the water heater tank will be placed')
  zone.setDefaultValue(zone_names[0])
  args << zone

  # create argument for water heater type

  type = OpenStudio::Measure::OSArgument.makeChoiceArgument('type',
                                                            ['PumpedCondenser', 'WrappedCondenser', 'Simplified'], true)
  type.setDisplayName('Select heat pump water heater type')
  type.setDescription('')
  type.setDefaultValue('PumpedCondenser')
  args << type

  # find largest current water heater volume - if any mixed tanks are already present. Default is 80 gal.

  default_vol = 80.0 # gal


  wheaters = if !model.getWaterHeaterMixeds.empty?
               model.getWaterHeaterMixeds
             else
               []
             end

  unless wheaters.empty?
    wheaters.each do |wh|
      unless wh.tankVolume.empty?
        default_vol = [default_vol, (wh.tankVolume.to_f / 0.0037854118).round(1)].max # convert m^3 to gal

      end
    end
  end

  # create argument for hot water tank volume

  vol = OpenStudio::Measure::OSArgument.makeDoubleArgument('vol', true)
  vol.setDisplayName('Set hot water tank volume')
  vol.setDescription('[gal]')
  vol.setDefaultValue(default_vol)
  args << vol

  # create argument for heat pump capacity

  cap = OpenStudio::Measure::OSArgument.makeDoubleArgument('cap', true)
  cap.setDisplayName('Set heat pump heating capacity')
  cap.setDescription('[kW]')
  cap.setDefaultValue((23.446 * (default_vol / 80.0)).round(1))
  args << cap

  # create argument for heat pump rated cop

  cop = OpenStudio::Measure::OSArgument.makeDoubleArgument('cop', true)
  cop.setDisplayName('Set heat pump rated COP (heating)')
  cop.setDefaultValue(2.8)
  args << cop

  # create argument for electric backup capacity

  bu_cap = OpenStudio::Measure::OSArgument.makeDoubleArgument('bu_cap', true)
  bu_cap.setDisplayName('Set electric backup heating capacity')
  bu_cap.setDescription('[kW]')
  bu_cap.setDefaultValue((23.446 * (default_vol / 80.0)).round(1))
  args << bu_cap

  # create argument for maximum tank temperature

  max_temp = OpenStudio::Measure::OSArgument.makeDoubleArgument('max_temp', true)
  max_temp.setDisplayName('Set maximum tank temperature')
  max_temp.setDescription('[F]')
  max_temp.setDefaultValue(160)
  args << max_temp

  # create argument for minimum float temperature

  min_temp = OpenStudio::Measure::OSArgument.makeDoubleArgument('min_temp', true)
  min_temp.setDisplayName('Set minimum tank temperature during float')
  min_temp.setDescription('[F]')
  min_temp.setDefaultValue(120)
  args << min_temp

  # create argument for deadband temperature difference between heat pump setpoint and electric backup

  db_temp = OpenStudio::Measure::OSArgument.makeDoubleArgument('db_temp', true)
  db_temp.setDisplayName('Set deadband temperature difference between heat pump and electric backup')
  db_temp.setDescription('[F]')
  db_temp.setDefaultValue(5)
  args << db_temp

  # find existing temperature setpoint schedules for water heater

  all_scheds = model.getSchedules
  temp_sched_names = []
  default_sched = '--Create New @ 140F--'
  default_ambient = ''
  all_scheds.each do |sch|
    next if sch.scheduleTypeLimits.empty?
    next unless sch.scheduleTypeLimits.get.unitType.to_s == 'Temperature'
    temp_sched_names << sch.name.to_s
    if !wheaters.empty? && (sch.name.to_s == wheaters[0].setpointTemperatureSchedule.get.name.to_s)
      default_sched = sch.name.to_s
    end
  end
  temp_sched_names = [default_sched] + temp_sched_names.sort

  # create argument for predefined schedule

  sched = OpenStudio::Measure::OSArgument.makeChoiceArgument('sched', temp_sched_names, true)
  sched.setDisplayName('Select reference tank setpoint temperature schedule')
  sched.setDescription('')
  sched.setDefaultValue(temp_sched_names[0])
  args << sched

  # define possible flex options

  flex_options = ['None', 'Charge - Heat Pump', 'Charge - Electric', 'Float']

  # create choice and string arguments for flex periods

  4.times do |n|
    flex = OpenStudio::Measure::OSArgument.makeChoiceArgument('flex' + n.to_s, flex_options, true)
    flex.setDisplayName("Daily Flex Period #{n + 1}:")
    flex.setDescription('Applies every day in the full run period.')
    flex.setDefaultValue('None')
    args << flex

    flex_hrs = OpenStudio::Measure::OSArgument.makeStringArgument('flex_hrs' + n.to_s, false)
    flex_hrs.setDisplayName('Use 24-Hour Format')
    flex_hrs.setDefaultValue('HH:MM - HH:MM')
    args << flex_hrs
  end

  args
end

#descriptionObject

human readable description



56
57
58
59
60
61
# File 'lib/measures/add_hpwh/measure.rb', line 56

def description
  'This measure adds or replaces existing domestic hot water heater with air source heat pump system and ' \
         'allows for the addition of multiple daily flexible control time windows. The heater/tank system may ' \
         'charge at maximum capacity up to an elevated temperature, or float without any heat addition for a ' \
         'specified timeframe down to a minimum tank temperature.'
end

#modeler_descriptionObject

human readable description of modeling approach



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/measures/add_hpwh/measure.rb', line 64

def modeler_description
  return 'This measure allows selection between three heat pump water heater modeling approaches in EnergyPlus.' \
         'The user may select between the pumped-condenser or wrapped-condenser objects. They may also elect to ' \
         'use a simplified calculation which does not use the heat pump objects, but instead used an electric ' \
         'resistance heater and approximates the equivalent electrical input that would be required from a heat ' \
         "pump. This expedites simulation at the expense of accuracy. \n" \
         'The flexibility of the system is based on user-defined temperatures and times, which are converted into ' \
         'schedule objects. There are four flexibility options. (1) None: normal operation of the DHW system at ' \
         'a fixed tank temperature setpoint. (2) Charge - Heat Pump: the tank is charged to a maximum temperature ' \
         'using only the heat pump. (3) Charge - Electric: the tank is charged using internal electric resistance ' \
         'heaters to a maximum temperature. (4) Float: all heating elements are turned-off for a user-defined time ' \
         'period unless the tank temperature falls below a minimum value. The heat pump will be prioritized in a ' \
         "low tank temperature event, with the electric resistance heaters serving as back-up. \n"
  'Due to the heat pump interaction with zone conditioning as well as tank heating, users may experience ' \
  'simulation errors if the heat pump is too large and placed in an already conditioned zoned. Try using ' \
  'multiple smaller units, modifying the heat pump location within the model, or adjusting the zone thermo' \
  'stat constraints. Use mulitiple instances of the measure to add multiple heat pump water heaters. '
end

#nameObject

human readable name



50
51
52
53
# File 'lib/measures/add_hpwh/measure.rb', line 50

def name
  # Measure name should be the title case of the class name.

  'Add HPWH for Domestic Hot Water'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
# File 'lib/measures/add_hpwh/measure.rb', line 263

def run(model, runner, user_arguments)
  super(model, runner, user_arguments)

  ## ARGUMENT VALIDATION ---------------------------------------------------------------------------------------------

  # Measure does not immedately return false upon error detection. Errors are accumulated throughout this selection

  # before exiting gracefully prior to measure execution.


  # use the built-in error checking

  unless runner.validateUserArguments(arguments(model), user_arguments)
    return false
  end

  # report initial condition of model

  tanks_ic = model.getWaterHeaterMixeds.size + model.getWaterHeaterStratifieds.size
  hpwh_ic = model.getWaterHeaterHeatPumps.size + model.getWaterHeaterHeatPumpWrappedCondensers.size
  runner.registerInitialCondition("The building started with #{tanks_ic} water heater tank(s) and " \
                                  "#{hpwh_ic} heat pump water heater(s).")

  # create empty arrays and initialize variables for future use

  flex = []
  flex_type = []
  flex_hrs = []
  time_check = []
  hours = []
  minutes = []
  flex_times = []

  # assign the user inputs to variables

  remove_wh = runner.getBoolArgumentValue('remove_wh', user_arguments)
  loop = runner.getStringArgumentValue('loop', user_arguments)
  zone = runner.getStringArgumentValue('zone', user_arguments)
  type = runner.getStringArgumentValue('type', user_arguments)
  cap = runner.getDoubleArgumentValue('cap', user_arguments)
  cop = runner.getDoubleArgumentValue('cop', user_arguments)
  bu_cap = runner.getDoubleArgumentValue('bu_cap', user_arguments)
  vol = runner.getDoubleArgumentValue('vol', user_arguments)
  max_temp = runner.getDoubleArgumentValue('max_temp', user_arguments)
  min_temp = runner.getDoubleArgumentValue('min_temp', user_arguments)
  db_temp = runner.getDoubleArgumentValue('db_temp', user_arguments)
  sched = runner.getStringArgumentValue('sched', user_arguments)

  4.times do |n|
    flex << runner.getStringArgumentValue('flex' + n.to_s, user_arguments)
    flex_hrs << runner.getStringArgumentValue('flex_hrs' + n.to_s, user_arguments)
  end

  # check for error inputs

  if loop.include?('Error')
    runner.registerError('No service hot water loop was found. Measure did not run.')
  end

  if zone.include?('Error')
    runner.registerError('No thermal zone was found. Measure did not run.')
  end

  # check capacity, volume, and temps for reasonableness

  if cap < 5
    runner.registerWarning('HPWH heating capacity is less than 5kW ( 17kBtu/hr)')
  end

  if bu_cap < 5
    runner.registerWarning('Backup heating capaicty is less than 5kW ( 17kBtu/hr).')
  end

  if vol < 40
    runner.registerWarning('Tank has less than 40 gallon capacity; check heat pump sizing if model fails.')
  end

  if min_temp < 120
    runner.registerWarning('Minimum tank temperature is very low; consider increasing to at least 120F.')
    runner.registerWarning('Do not store water for long periods at temperatures below 135-140F as those ' \
                          'conditions facilitate the growth of Legionella.')
  end

  if max_temp > 180
    runner.registerWarning('Maximum charging temperature exceeded practical limits; reset to 180F.')
    max_temp = 180.0
  end

  if max_temp > 160
    runner.registerWarning("#{max_temp}F is above or near the limit of the HP performance curves. If the " \
                          'simulation fails with cooling capacity less than 0, you have exceeded performance ' \
                          'limits. Consider setting max temp to less than 160F.')
  end

  # check selected schedule and set flag for later use

  sched_flag = false # flag for either creating new (false) or modifying existing (true) schedule

  if sched == '--Create New @ 140F--'
    runner.registerInfo('No reference water heater temperature setpoint schedule was selected; a new one ' \
                        'will be created.')
  else
    sched_flag = true
    runner.registerInfo("#{sched} will be used as the water heater temperature setpoint schedule.")
  end

  # parse flex_hrs into hours and minuts arrays

  idx = 0
  flex_hrs.each do |fh|
    if flex[idx] != 'None'
      data = fh.split(/[-:]/)
      data.each { |e| e.delete!(' ') }
      if data[2] > data[0]
        flex_type << flex[idx]
        hours << data[0]
        hours << data[2]
        minutes << data[1]
        minutes << data[3]
      else
        flex_type << flex[idx]
        flex_type << flex[idx]
        hours << 0
        hours << data[2]
        hours << data[0]
        hours << 24
        minutes << 0
        minutes << data[3]
        minutes << data[1]
        minutes << 0
      end
    end
    idx += 1
  end

  # convert hours and minutes into OS:Time objects

  idx = 0
  hours.each do |h|
    flex_times << OpenStudio::Time.new(0, h.to_i, minutes[idx].to_i, 0)
    idx += 1
  end

  # flex.delete('None')


  runner.registerInfo("A total of #{idx / 2} flex periods will be added to the selected water heater setpoint schedule.")

  # exit gracefully if errors registered above

  return false unless runner.result.errors.empty?
  ## END ARGUMENT VALIDATION -----------------------------------------------------------------------------------------


  ## CONTROLS: HEAT PUMP HEATING TEMPERATURE SETPOINT SCHEDULE -------------------------------------------------------

  # This section creates the heat pump heating temperature setpoint schedule with flex periods

  # The tank schedule is created here


  # find or create new reference temperature schedule based on sched_flag value

  if sched_flag # schedule already exists and must be modified

    # converts the STRING into a MODEL OBJECT, same variable name

    sched = model.getScheduleRulesetByName(sched).get.clone.to_ScheduleRuleset.get
  else
    # must create new water heater setpoint temperature schedule at 140F

    sched = OpenStudio::Model::ScheduleRuleset.new(model, 60)
  end

  # rename and duplicate for later modification

  sched.setName('Heat Pump Heating Temperature Setpoint')
  sched.defaultDaySchedule.setName('Heat Pump Heating Temperature Setpoint Default')

  # tank_sched = sched.clone.to_ScheduleRuleset.get

  tank_sched = OpenStudio::Model::ScheduleRuleset.new(model, 60 - (db_temp / 1.8 + 2))
  tank_sched.setName('Tank Electric Heater Setpoint')
  tank_sched.defaultDaySchedule.setName('Tank Electric Heater Setpoint Default')

  # grab default day and time-value pairs for modification

  d_day = sched.defaultDaySchedule
  old_times = d_day.times
  old_values = d_day.values
  new_values = Array.new(flex_times.size, 2)

  # find existing values in reference schedule and grab for use in new-rule creation

  flex_times.size.times do |i|
    if i.even?
      n = 0
      old_times.each do |ot|
        new_values[i] = old_values[n] if flex_times[i] <= ot
        n += 1
      end
    elsif flex_type[(i / 2).floor] == 'Charge - Heat Pump'
      new_values[i] = OpenStudio.convert(max_temp, 'F', 'C').get
    elsif flex_type[(i / 2).floor] == 'Float' || flex_type[(i / 2).floor] == 'Charge - Electric'
      new_values[i] = OpenStudio.convert(min_temp, 'F', 'C').get
    end
  end

  # create new rules and add to default day based on flex period options above

  idx = 0
  flex_times.each do |ft|
    d_day.addValue(ft, new_values[idx])
    idx += 1
  end

  ## END CONTROLS: HEAT PUMP HEATING TEMPERATURE SETPOINT SCHEDULE ---------------------------------------------------


  ## CONTROLS: TANK TEMPERATURE SETPOINT SCHEDULE (ELECTRIC BACKUP) --------------------------------------------------

  # This section creates the setpoint temperature schedule for the electric backup heating coils in the water tank


  # grab default day and time-value pairs for modification

  d_day = tank_sched.defaultDaySchedule
  old_times = d_day.times
  old_values = d_day.values
  new_values = Array.new(flex_times.size, 2)

  # find existing values in reference schedule and grab for use in new-rule creation

  flex_times.size.times do |i|
    if i.even?
      n = 0
      old_times.each do |ot|
        new_values[i] = old_values[n] if flex_times[i] <= ot
        n += 1
      end
    elsif flex_type[(i / 2).floor] == 'Charge - Electric'
      new_values[i] = OpenStudio.convert(max_temp, 'F', 'C').get
    elsif flex_type[(i / 2).floor] == 'Float' # || flex_type[(i/2).floor] == 'Charge - Heat Pump'

      new_values[i] = OpenStudio.convert(min_temp - db_temp, 'F', 'C').get
    elsif flex_type[(i / 2).floor] == 'Charge - Heat Pump'
      new_values[i] = 60 - (db_temp / 1.8)
    end
  end

  # create new rules and add to default day based on flex period options above

  idx = 0
  flex_times.each do |ft|
    d_day.addValue(ft, new_values[idx])
    idx += 1
  end

  ## CONTROLS: TANK TEMPERATURE SETPOINT SCHEDULE (ELECTRIC BACKUP) --------------------------------------------------


  ## HARDWARE --------------------------------------------------------------------------------------------------------

  # This section adds the selected type of heat pump water heater to the supply side of the selected loop. If

  # selected, measure will remove any existing water heaters on the supply side of the loop. If old heater(s) are left

  # in place, the new HPWH tank will be placed in front (to the left) of them.


  # use OS standards build - arbitrary selection, but NZE Ready seems appropriate

  std = Standard.build('NREL ZNE Ready 2017')

  # create empty arrays and initialize variables for later use

  old_heater = []
  count = 0

  # convert loop and zone names from STRINGS into OS model OBJECTS

  zone =  model.getThermalZoneByName(zone).get
  loop =  model.getPlantLoopByName(loop).get

  # find and locate old water heater on selected loop, if applicable

  loop_equip = loop.supplyComponents
  loop_equip.each do |le|
    if le.iddObject.name.include?('WaterHeater:Mixed')
      old_heater << model.getWaterHeaterMixedByName(le.name.to_s).get
      count += 1
    elsif le.iddObject.name.include?('WaterHeater:Stratified')
      old_heater << model.getWaterHeaterStratifiedByName(le.name.to_s).get
      count += 1
    end
  end

  unless old_heater.empty?
    inlet = old_heater[0].supplyInletModelObject.get.to_Node.get
    outlet = old_heater[0].supplyOutletModelObject.get.to_Node.get
  end

  # Add heat pump water heater and attach to selected loop

  # Reference: https://github.com/NREL/openstudio-standards/blob/master/lib/

  # => openstudio-standards/prototypes/common/objects/Prototype.ServiceWaterHeating.rb

  if type != 'Simplified'
    hpwh = std.model_add_heatpump_water_heater(model, # model

                                               type: type,                                                           # type

                                               water_heater_capacity: (cap * 1000 / cop),                            # water_heater_capacity

                                               electric_backup_capacity: (bu_cap * 1000),                            # electric_backup_capacity

                                               water_heater_volume: OpenStudio.convert(vol, 'gal', 'm^3').get,       # water_heater_volume

                                               service_water_temperature: OpenStudio.convert(140.0, 'F', 'C').get,   # service_water_temperature

                                               parasitic_fuel_consumption_rate: 3.0,                                 # parasitic_fuel_consumption_rate

                                               swh_temp_sch: sched,                                                  # swh_temp_sch

                                               cop: cop,                                                             # cop

                                               shr: 0.88,                                                            # shr

                                               tank_ua: 3.9,                                                         # tank_ua

                                               set_peak_use_flowrate: false,                                         # set_peak_use_flowrate

                                               peak_flowrate: 0.0,                                                   # peak_flowrate

                                               flowrate_schedule: nil,                                               # flowrate_schedule

                                               water_heater_thermal_zone: zone)                                      # water_heater_thermal_zone

  else
    hpwh = std.model_add_water_heater(model, # model

                                      (cap * 1000),                                                         # water_heater_capacity

                                      OpenStudio.convert(vol, 'gal', 'm^3').get,                            # water_heater_volume

                                      'HeatPump',                                                           # water_heater_fuel

                                      OpenStudio.convert(140.0, 'F', 'C').get,                              # service_water_temperature

                                      3.0,                                                                  # parasitic_fuel_consumption_rate

                                      sched,                                                                # swh_temp_sch

                                      false,                                                                # set_peak_use_flowrate

                                      0.0,                                                                  # peak_flowrate

                                      nil,                                                                  # flowrate_schedule

                                      zone,                                                                 # water_heater_thermal_zone

                                      1)                                                                    # number_water_heaters

  end

  # add tank to appropriate branch and node (will be placed first in series if old tanks not removed)

  # modify objects as ncessary

  if old_heater.empty?
    loop.addSupplyBranchForComponent(hpwh.tank)
  elsif type != 'Simplified'
    hpwh.tank.addToNode(inlet)
    hpwh.setDeadBandTemperatureDifference(db_temp / 1.8)
    runner.registerInfo("#{hpwh.tank.name} was added to the model on #{loop.name}")
  else
    hpwh.addToNode(inlet)
    hpwh.setMaximumTemperatureLimit(OpenStudio.convert(max_temp, 'F', 'C').get)
    runner.registerInfo("#{hpwh.name} was added to the model on #{loop.name}")
  end

  # remove old tank objects if necessary

  if remove_wh
    old_heater.each do |oh|
      runner.registerInfo("#{oh.name} was removed from the model.")
      oh.remove
    end
  end
  ## END HARDWARE ----------------------------------------------------------------------------------------------------


  ## CONTROLS MODIFICATIONS FOR TANK ---------------------------------------------------------------------------------

  # apply schedule to tank

  if type == 'PumpedCondenser'
    hpwh.tank.to_WaterHeaterMixed.get.setSetpointTemperatureSchedule(tank_sched)
  elsif type == 'WrappedCondenser'
    hpwh.tank.to_WaterHeaterStratified.get.setHeater1SetpointTemperatureSchedule(tank_sched)
    hpwh.tank.to_WaterHeaterStratified.get.setHeater2SetpointTemperatureSchedule(tank_sched)
  elsif type == 'Simplified'
    runner.registerInfo('Line 492 was used. Nothing done here yet... Check tank temperature schedules...')
  end
  ## END CONTROLS MODIFICATIONS FOR TANK -----------------------------------------------------------------------------


  ## ADD REPORTED VARIABLES ------------------------------------------------------------------------------------------


  ovar_names = ['Cooling Coil Total Cooling Rate',
                'Cooling Coil Total Water Heating Rate',
                'Cooling Coil Water Heating Electric Power',
                'Cooling Coil Crankcase Heater Electric Power',
                'Water Heater Tank Temperature',
                'Water Heater Heat Loss Rate',
                'Water Heater Heating Rate',
                'Water Heater Use Side Heat Transfer Rate',
                'Water Heater Source Side Heat Transfer Rate',
                'Water Heater Unmet Demand Heat Transfer Rate',
                'Water Heater Electric Power',
                'Water Heater Water Volume Flow Rate',
                'Water Use Connections Hot Water Temperature']

  # Create new output variable objects

  ovars = []
  ovar_names.each do |nm|
    ovars << OpenStudio::Model::OutputVariable.new(nm, model)
  end

  # add temperate schedule outputs - clean up and put names into array, then loop over setting key values

  v = OpenStudio::Model::OutputVariable.new('Schedule Value', model)
  v.setKeyValue(sched.name.to_s)
  ovars << v

  v = OpenStudio::Model::OutputVariable.new('Schedule Value', model)
  v.setKeyValue(tank_sched.name.to_s)
  ovars << v

  if type != 'Simplified'
    v = OpenStudio::Model::OutputVariable.new('Schedule Value', model)
    v.setKeyValue(tank_sched.name.to_s)
    ovars << v
  end

  # Set variable reporting frequency for newly created output variables

  ovars.each do |var|
    var.setReportingFrequency('TimeStep')
  end

  # Register info re: output variables:

  runner.registerInfo("#{ovars.size} output variables were added to the model.")
  ## END ADD REPORTED VARIABLES --------------------------------------------------------------------------------------


  # Register final condition

  hpwh_fc = model.getWaterHeaterHeatPumps.size + model.getWaterHeaterHeatPumpWrappedCondensers.size
  tanks_fc = model.getWaterHeaterMixeds.size + model.getWaterHeaterStratifieds.size
  runner.registerFinalCondition("The building finshed with #{tanks_fc} water heater tank(s) and " \
                                "#{hpwh_fc} heat pump water heater(s).")

  true
end