Class: WaterHeaterMixedMultiplier
- Inherits:
-
OpenStudio::Measure::ModelMeasure
- Object
- OpenStudio::Measure::ModelMeasure
- WaterHeaterMixedMultiplier
- Defined in:
- lib/measures/WaterHeaterMixedMultiplier/measure.rb
Overview
start the measure
Instance Method Summary collapse
-
#arguments(model) ⇒ Object
define the arguments that the user will input.
- #change_name(object, maximum_capacity_multiplier, minimum_capacity_multiplier, thermal_efficiency_multiplier, fuel_type, orig_fuel_type) ⇒ Object
- #check_multiplier(runner, multiplier) ⇒ Object
-
#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.
Instance Method Details
#arguments(model) ⇒ Object
define the arguments that the user will input
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 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/measures/WaterHeaterMixedMultiplier/measure.rb', line 46 def arguments(model) args = OpenStudio::Measure::OSArgumentVector.new # make a choice argument for model objects water_heater_handles = OpenStudio::StringVector.new water_heater_display_names = OpenStudio::StringVector.new # putting model object and names into hash water_heater_args = model.getWaterHeaterMixeds water_heater_args.each do |water_heater_arg| water_heater_handles << water_heater_arg.handle.to_s water_heater_display_names << water_heater_arg.name.to_s end # add building to string vector with space type building = model.getBuilding water_heater_handles << building.handle.to_s water_heater_display_names << '*All WaterHeaterMixeds*' water_heater_handles << '0' water_heater_display_names << '*None*' # make a choice argument for space type water_heater = OpenStudio::Measure::OSArgument.makeChoiceArgument('water_heater', water_heater_handles, water_heater_display_names) water_heater.setDisplayName('Apply the Measure to a SINGLE WaterHeaterMixed, ALL the WaterHeaterMixeds or NONE.') water_heater.setDefaultValue('*All WaterHeaterMixeds*') # if no space type is chosen this will run on the entire building args << water_heater # maximum_capacity_multiplier maximum_capacity_multiplier = OpenStudio::Measure::OSArgument.makeDoubleArgument('maximum_capacity_multiplier', true) maximum_capacity_multiplier.setDisplayName('Multiplier for Heater Maximum Capacity.') maximum_capacity_multiplier.setDescription('Multiplier for Heater Maximum Capacity.') maximum_capacity_multiplier.setDefaultValue(1.0) maximum_capacity_multiplier.setMinValue(0.0) args << maximum_capacity_multiplier # minimum_capacity_multiplier minimum_capacity_multiplier = OpenStudio::Measure::OSArgument.makeDoubleArgument('minimum_capacity_multiplier', true) minimum_capacity_multiplier.setDisplayName('Multiplier for Heater Minimum Capacity.') minimum_capacity_multiplier.setDescription('Multiplier for Heater Minimum Capacity.') minimum_capacity_multiplier.setDefaultValue(1.0) args << minimum_capacity_multiplier # thermal_efficiency_multiplier thermal_efficiency_multiplier = OpenStudio::Measure::OSArgument.makeDoubleArgument('thermal_efficiency_multiplier', true) thermal_efficiency_multiplier.setDisplayName('Multiplier for Thermal Efficiency.') thermal_efficiency_multiplier.setDescription('Multiplier for Thermal Efficiency.') thermal_efficiency_multiplier.setDefaultValue(1.0) args << thermal_efficiency_multiplier # make a choice argument for fuel type fuel_type = OpenStudio::StringVector.new fuel_type << 'NaturalGas' fuel_type << 'Electricity' fuel_type << 'PropaneGas' # heater_fuel_type heater_fuel_type = OpenStudio::Measure::OSArgument.makeChoiceArgument('fuel_type', fuel_type, fuel_type) heater_fuel_type.setDisplayName('Heater Fuel Type.') heater_fuel_type.setDescription('Heater Fuel Type.') heater_fuel_type.setDefaultValue('NaturalGas') args << heater_fuel_type args end |
#change_name(object, maximum_capacity_multiplier, minimum_capacity_multiplier, thermal_efficiency_multiplier, fuel_type, orig_fuel_type) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/measures/WaterHeaterMixedMultiplier/measure.rb', line 23 def change_name(object, maximum_capacity_multiplier, minimum_capacity_multiplier, thermal_efficiency_multiplier, fuel_type, orig_fuel_type) nameString = object.name.get.to_s if maximum_capacity_multiplier != 1.0 nameString += " #{maximum_capacity_multiplier.round(2)}x maxCap" end if minimum_capacity_multiplier != 1.0 nameString += " #{minimum_capacity_multiplier.round(2)}x minCap" end if thermal_efficiency_multiplier != 1.0 nameString += " #{thermal_efficiency_multiplier.round(2)}x thermEff" end nameString += " #{fuel_type} fuel Change" if orig_fuel_type != fuel_type object.setName(nameString) end |
#check_multiplier(runner, multiplier) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/measures/WaterHeaterMixedMultiplier/measure.rb', line 38 def check_multiplier(runner, multiplier) if multiplier < 0 runner.registerError("Multiplier #{multiplier} cannot be negative.") false end end |
#description ⇒ Object
human readable description
14 15 16 |
# File 'lib/measures/WaterHeaterMixedMultiplier/measure.rb', line 14 def description 'This is a general purpose measure to calibrate WaterHeaterMixed with a Multiplier.' end |
#modeler_description ⇒ Object
human readable description of modeling approach
19 20 21 |
# File 'lib/measures/WaterHeaterMixedMultiplier/measure.rb', line 19 def modeler_description 'It will be used for calibration of WaterHeaterMixed. User can choose between a SINGLE WaterHeaterMixed or ALL the WaterHeaterMixed objects.' end |
#name ⇒ Object
human readable name
9 10 11 |
# File 'lib/measures/WaterHeaterMixedMultiplier/measure.rb', line 9 def name 'Water Heater Mixed Multiplier' end |
#run(model, runner, user_arguments) ⇒ Object
define what happens when the measure is run
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 |
# File 'lib/measures/WaterHeaterMixedMultiplier/measure.rb', line 112 def run(model, runner, user_arguments) super(model, runner, user_arguments) # use the built-in error checking unless runner.validateUserArguments(arguments(model), user_arguments) return false end # assign the user inputs to variables water_heater_object = runner.getOptionalWorkspaceObjectChoiceValue('water_heater', user_arguments, model) water_heater_handle = runner.getStringArgumentValue('water_heater', user_arguments) fuel_type = runner.getStringArgumentValue('fuel_type', user_arguments) thermal_efficiency_multiplier = runner.getDoubleArgumentValue('thermal_efficiency_multiplier', user_arguments) check_multiplier(runner, thermal_efficiency_multiplier) maximum_capacity_multiplier = runner.getDoubleArgumentValue('maximum_capacity_multiplier', user_arguments) check_multiplier(runner, maximum_capacity_multiplier) minimum_capacity_multiplier = runner.getDoubleArgumentValue('minimum_capacity_multiplier', user_arguments) check_multiplier(runner, minimum_capacity_multiplier) # find objects to change water_heaters = [] building = model.getBuilding building_handle = building.handle.to_s runner.registerInfo("water_heater_handle: #{water_heater_handle}") # setup water_heaters if water_heater_handle == building_handle # Use ALL SpaceTypes runner.registerInfo('Applying change to ALL SpaceTypes') water_heaters = model.getWaterHeaterMixeds elsif water_heater_handle == 0.to_s # SpaceTypes set to NONE so do nothing runner.registerInfo('Applying change to NONE SpaceTypes') elsif !water_heater_handle.empty? # Single WaterHeaterMixed handle found, check if object is good if !water_heater_object.get.to_WaterHeaterMixed.empty? runner.registerInfo("Applying change to #{water_heater_object.get.name} WaterHeaterMixed") water_heaters << water_heater_object.get.to_WaterHeaterMixed.get else runner.registerError("WaterHeaterMixed with handle #{water_heater_handle} could not be found.") end else runner.registerError('WaterHeaterMixed handle is empty.') return false end altered_heaters = [] altered_thermalefficiency = [] altered_max_cap = [] altered_min_cap = [] # report initial condition of model runner.registerInitialCondition("Applying Multiplier to #{water_heaters.size} Water Heaters.") # loop through space types water_heaters.each do |water_heater| altered_heater = false # modify maximum_capacity_multiplier if maximum_capacity_multiplier != 1.0 && water_heater.heaterMaximumCapacity.is_initialized runner.registerInfo("Applying #{maximum_capacity_multiplier}x maximum capacity multiplier to #{water_heater.name.get}.") water_heater.setHeaterMaximumCapacity(water_heater.heaterMaximumCapacity.get * maximum_capacity_multiplier) altered_max_cap << water_heater.handle.to_s altered_heater = true end # modify minimum_capacity_multiplier if minimum_capacity_multiplier != 1.0 && water_heater.heaterMinimumCapacity.is_initialized runner.registerInfo("Applying #{minimum_capacity_multiplier}x minimum capacity multiplier to #{water_heater.name.get}.") water_heater.setHeaterMaximumCapacity(water_heater.heaterMinimumCapacity.get * minimum_capacity_multiplier) altered_min_cap << water_heater.handle.to_s altered_heater = true end # modify thermal_efficiency_multiplier if thermal_efficiency_multiplier != 1.0 && water_heater.heaterThermalEfficiency.is_initialized runner.registerInfo("Applying #{thermal_efficiency_multiplier}x thermal efficiency multiplier to #{water_heater.name.get}.") water_heater.setHeaterThermalEfficiency(water_heater.heaterThermalEfficiency.get * thermal_efficiency_multiplier) altered_thermalefficiency << water_heater.handle.to_s altered_heater = true end orig_fuel_type = water_heater.heaterFuelType if orig_fuel_type != fuel_type runner.registerInfo("Changing Fuel Type to #{fuel_type} for #{water_heater.name.get}.") water_heater.setHeaterFuelType(fuel_type) altered_heater = true end next unless altered_heater altered_heaters << water_heater.handle.to_s change_name(water_heater, maximum_capacity_multiplier, minimum_capacity_multiplier, thermal_efficiency_multiplier, fuel_type, orig_fuel_type) runner.registerInfo("WaterHeater name changed to: #{water_heater.name.get}") end # na if nothing in model to look at if altered_heaters.empty? runner.registerAsNotApplicable('No WaterHeaters were altered in the model') return true end # report final condition of model runner.registerFinalCondition("#{altered_heaters.size} WaterHeater objects were altered.") true end |