Class: ReplaceWaterHeaterMixedWithThermalStorageChilledWater

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

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

define the arguments that the user will input



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/measures/replace_water_heater_mixed_with_thermal_storage_chilled_water/measure.rb', line 29

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

  # the name of the water heater to replace
  wh_name = OpenStudio::Measure::OSArgument.makeStringArgument('wh_name', true)
  wh_name.setDisplayName('Name of Water Heater to Replace')
  wh_name.setDescription('This object will be replaced with a new Thermal Storage Chilled Water object.')
  wh_name.setDefaultValue('CHW Tank Placeholder')
  args << wh_name

  return args
end

#descriptionObject

human readable description



19
20
21
# File 'lib/measures/replace_water_heater_mixed_with_thermal_storage_chilled_water/measure.rb', line 19

def description
  return 'This measure is a quick fix for GUI issue that prevents putting thermal storage on two plant loops.'
end

#modeler_descriptionObject

human readable description of modeling approach



24
25
26
# File 'lib/measures/replace_water_heater_mixed_with_thermal_storage_chilled_water/measure.rb', line 24

def modeler_description
  return 'The model in this case used a water heater mixed as a place holder. This measure will take a string argument, and will replace the water heater with a new thermal storage chilled water object.'
end

#nameObject

human readable name



14
15
16
# File 'lib/measures/replace_water_heater_mixed_with_thermal_storage_chilled_water/measure.rb', line 14

def name
  return 'Replace Water Heater Mixed with Thermal Storage Chilled Water'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



43
44
45
46
47
48
49
50
51
52
53
54
55
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
# File 'lib/measures/replace_water_heater_mixed_with_thermal_storage_chilled_water/measure.rb', line 43

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
  wh_name = runner.getStringArgumentValue('wh_name', user_arguments)

  # check the wh_name for reasonableness
  if wh_name.empty?
    runner.registerError('Empty water heater name was entered.')
    return false
  end

  # report initial condition of model
  runner.registerInitialCondition("The building started with #{model.getThermalStorageChilledWaterStratifieds.size} chilled water objects.")

  # create thermal storage object
  new_chilled_water = OpenStudio::Model::ThermalStorageChilledWaterStratified.new(model)
  # puts new_chilled_water

  placeholder = nil

  # loop through plant loops and swap objects
  model.getPlantLoops.each do |plant_loop|
    puts "Checking #{plant_loop.name}"

    plant_loop.supplyComponents.each do |component|
      if component.name.to_s == wh_name
        placeholder = component
        puts "found #{component.name}"

        # swap components
        supply_inlet_node = component.to_WaterToWaterComponent.get.supplyInletModelObject.get.to_Node.get
        new_chilled_water.addToNode(supply_inlet_node)
        demand_inlet_node = component.to_WaterToWaterComponent.get.demandInletModelObject.get.to_Node.get
        new_chilled_water.addToNode(demand_inlet_node)

      end
    end
  end

  # remove unused water heater from the model
  if !placeholder.nil?
    puts 'Removing water heater'
    placeholder.remove
  end

  # report final condition of model
  runner.registerFinalCondition("The building finished with #{model.getThermalStorageChilledWaterStratifieds.size} chilled water objects.")

  return true
end