Class: AdjustSystemEfficiencies

Inherits:
OpenStudio::Ruleset::ModelUserScript
  • Object
show all
Defined in:
lib/measures/AdjustSystemEfficiencies/measure.rb

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

define the arguments that the user will input



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/measures/AdjustSystemEfficiencies/measure.rb', line 24

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

  # Heating efficiency multiplier
  heating_efficiency_multiplier = OpenStudio::Ruleset::OSArgument.makeDoubleArgument('heating_efficiency_multiplier', true)
  heating_efficiency_multiplier.setDisplayName('Heating Efficiency Multiplier')
  heating_efficiency_multiplier.setDefaultValue(1.0)
  args << heating_efficiency_multiplier

  # Cooling cop multiplier
  cooling_cop_multiplier = OpenStudio::Ruleset::OSArgument.makeDoubleArgument('cooling_cop_multiplier', true)
  cooling_cop_multiplier.setDisplayName('Cooling COP Multiplier')
  cooling_cop_multiplier.setDefaultValue(1.0)
  args << cooling_cop_multiplier

  return args
end

#modify_boiler_hot_water(component, heating_efficiency_multiplier) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/measures/AdjustSystemEfficiencies/measure.rb', line 67

def modify_boiler_hot_water(component, heating_efficiency_multiplier)
  nominal_thermal_efficiency = component.nominalThermalEfficiency
  new_efficiency = heating_efficiency_multiplier * nominal_thermal_efficiency
  if new_efficiency > 1
    return false
  end
  return component.setNominalThermalEfficiency(new_efficiency)
end

#modify_chiller_electric_eir(component, cooling_cop_multiplier) ⇒ Object



76
77
78
79
# File 'lib/measures/AdjustSystemEfficiencies/measure.rb', line 76

def modify_chiller_electric_eir(component, cooling_cop_multiplier)
  referenceCOP = component.referenceCOP
  return component.setReferenceCOP(cooling_cop_multiplier * referenceCOP)
end

#modify_coil_cooling_dx_single_speed(component, cooling_cop_multiplier) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/measures/AdjustSystemEfficiencies/measure.rb', line 42

def modify_coil_cooling_dx_single_speed(component, cooling_cop_multiplier)
  # Prior to 3.5.0 it's Optional, after it's a double
  rated_cop = OpenStudio::OptionalDouble.new(component.ratedCOP)
  if rated_cop.empty?
    return false
  end

  temp = OpenStudio::OptionalDouble.new(cooling_cop_multiplier * rated_cop.get)
  component.setRatedCOP(temp)
  return true
end

#modify_coil_cooling_dx_two_speed(component, cooling_cop_multiplier) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/measures/AdjustSystemEfficiencies/measure.rb', line 54

def modify_coil_cooling_dx_two_speed(component, cooling_cop_multiplier)
  # Prior to 3.5.0 it's Optional, after it's a double
  rated_low_speed_cop = OpenStudio::OptionalDouble.new(component.ratedLowSpeedCOP)
  rated_high_speed_cop = OpenStudio::OptionalDouble.new(component.ratedHighSpeedCOP)
  if rated_low_speed_cop.empty? || rated_high_speed_cop.empty?
    return false
  end

  component.setRatedLowSpeedCOP(cooling_cop_multiplier * rated_low_speed_cop.get)
  component.setRatedHighSpeedCOP(cooling_cop_multiplier * rated_high_speed_cop.get)
  return true
end

#modify_coil_heating_electric(component, heating_efficiency_multiplier) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/measures/AdjustSystemEfficiencies/measure.rb', line 91

def modify_coil_heating_electric(component, heating_efficiency_multiplier)
  efficiency = component.efficiency
  new_efficiency = heating_efficiency_multiplier * efficiency
  if new_efficiency > 1
    return false
  end
  return component.setEfficiency(new_efficiency)
end

#modify_coil_heating_gas(component, heating_efficiency_multiplier) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/measures/AdjustSystemEfficiencies/measure.rb', line 81

def modify_coil_heating_gas(component, heating_efficiency_multiplier)
  gas_burner_efficiency = component.gasBurnerEfficiency
  new_efficiency = heating_efficiency_multiplier * gas_burner_efficiency
  if new_efficiency > 1
    return false
  end
  component.setGasBurnerEfficiency(new_efficiency)
  return true
end

#nameObject

define the name that a user will see, this method may be deprecated as the display name in PAT comes from the name field in measure.xml



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

def name
  return 'AdjustSystemEfficiencies'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



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
251
252
253
254
255
256
257
258
259
260
261
262
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
# File 'lib/measures/AdjustSystemEfficiencies/measure.rb', line 101

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
  heating_efficiency_multiplier = runner.getDoubleArgumentValue('heating_efficiency_multiplier', user_arguments)
  cooling_cop_multiplier = runner.getDoubleArgumentValue('cooling_cop_multiplier', user_arguments)

  if heating_efficiency_multiplier <= 0
    runner.registerError('Heating efficiency multiplier must be greater than 0')
    return false
  end

  if cooling_cop_multiplier <= 0
    runner.registerError('Cooling COP multiplier must be greater than 0')
    return false
  end

  num_heating_objects_modified = 0
  num_cooling_objects_modified = 0

  # loop over all air loops
  model.getAirLoopHVACs.each do |air_loop|
    modified = false
    air_loop.supplyComponents.each do |component|
      # CoilHeatingGas
      if !component.to_CoilHeatingGas.empty?
        component = component.to_CoilHeatingGas.get
        if !modify_coil_heating_gas(component, heating_efficiency_multiplier)
          runner.registerError("Cannot modify heating efficiency for #{component.name.get} by multiplier #{heating_efficiency_multiplier}")
          return false
        else
          num_heating_objects_modified += 1
          modified = true
        end

      # CoilHeatingElectric
      elsif !component.to_CoilHeatingElectric.empty?
        component = component.to_CoilHeatingElectric.get
        if !modify_coil_heating_electric(component, heating_efficiency_multiplier)
          runner.registerError("Cannot modify heating efficiency for #{component.name.get} by multiplier #{heating_efficiency_multiplier}")
          return false
        else
          num_heating_objects_modified += 1
          modified = true
        end

      # CoilCoolingDXSingleSpeed
      elsif !component.to_CoilCoolingDXSingleSpeed.empty?
        component = component.to_CoilCoolingDXSingleSpeed.get
        if !modify_coil_cooling_dx_single_speed(component, cooling_cop_multiplier)
          runner.registerError("Cannot modify COP for #{component.name.get} by multiplier #{cooling_cop_multiplier}")
          return false
        else
          num_cooling_objects_modified += 1
          modified = true
        end

      # CoilCoolingDXTwoSpeed
      elsif !component.to_CoilCoolingDXTwoSpeed.empty?
        component = component.to_CoilCoolingDXTwoSpeed.get
        if !modify_coil_cooling_dx_two_speed(component, cooling_cop_multiplier)
          runner.registerError("Cannot modify COP for #{component.name.get} by multiplier #{cooling_cop_multiplier}")
          return false
        else
          num_cooling_objects_modified += 1
          modified = true
        end
      end
    end

    if !modified
      runner.registerWarning("No heating or cooling elements found for air loop #{air_loop.name.get}")
    end
  end

  # loop over all plant loops
  model.getPlantLoops.each do |plant_loop|
    modified = false
    plant_loop.supplyComponents.each do |component|
      # BoilerHotWater
      if !component.to_BoilerHotWater.empty?
        component = component.to_BoilerHotWater.get
        if !modify_boiler_hot_water(component, heating_efficiency_multiplier)
          runner.registerError("Cannot modify heating efficiency for #{component.name.get} by multiplier #{heating_efficiency_multiplier}")
          return false
        else
          num_heating_objects_modified += 1
          modified = true
        end

      # ChillerElectricEIR
      elsif !component.to_ChillerElectricEIR.empty?
        component = component.to_ChillerElectricEIR.get
        if !modify_chiller_electric_eir(component, cooling_cop_multiplier)
          runner.registerError("Cannot modify COP for #{component.name.get} by multiplier #{cooling_cop_multiplier}")
          return false
        else
          num_cooling_objects_modified += 1
          modified = true
        end
      end
    end

    if !modified
      runner.registerWarning("No heating or cooling elements found for plant loop #{plant_loop.name.get}")
    end
  end

  # loop over all thermal zones
  model.getThermalZones.each do |thermal_zone|
    modified = false
    equipment = thermal_zone.equipment
    equipment.each do |component|
      if !component.to_ZoneHVACPackagedTerminalAirConditioner.empty?
        component = component.to_ZoneHVACPackagedTerminalAirConditioner.get

        heating_coil = component.heatingCoil
        # CoilHeatingGas
        if !heating_coil.to_CoilHeatingGas.empty?
          component = heating_coil.to_CoilHeatingGas.get
          if !modify_coil_heating_gas(component, heating_efficiency_multiplier)
            runner.registerError("Cannot modify heating efficiency for #{component.name.get} by multiplier #{heating_efficiency_multiplier}")
            return false
          else
            num_heating_objects_modified += 1
            modified = true
          end

        # CoilHeatingElectric
        elsif !heating_coil.to_CoilHeatingElectric.empty?
          component = heating_coil.to_CoilHeatingElectric.get
          if !modify_coil_heating_electric(component, heating_efficiency_multiplier)
            runner.registerError("Cannot modify heating efficiency for #{component.name.get} by multiplier #{heating_efficiency_multiplier}")
            return false
          else
            num_heating_objects_modified += 1
            modified = true
          end

        else
          runner.registerInfo("Unknown heating coil type for #{heating_coil.name.get}")
          # return false
        end

        cooling_coil = component.coolingCoil
        # CoilCoolingDXSingleSpeed
        if !cooling_coil.to_CoilCoolingDXSingleSpeed.empty?
          component = cooling_coil.to_CoilCoolingDXSingleSpeed.get
          if !modify_coil_cooling_dx_single_speed(component, cooling_cop_multiplier)
            runner.registerError("Cannot modify COP for #{component.name.get} by multiplier #{cooling_cop_multiplier}")
            return false
          else
            num_cooling_objects_modified += 1
            modified = true
          end

        # CoilCoolingDXTwoSpeed
        elsif !cooling_coil.to_CoilCoolingDXTwoSpeed.empty?
          component = cooling_coil.to_CoilCoolingDXTwoSpeed.get
          if !modify_coil_cooling_dx_two_speed(component, cooling_cop_multiplier)
            runner.registerError("Cannot modify COP for #{component.name.get} by multiplier #{cooling_cop_multiplier}")
            return false
          else
            num_cooling_objects_modified += 1
            modified = true
          end

        else
          runner.registerError("Unknown cooling coil type for #{cooling_coil.name.get}")
          return false
        end

      end
    end

    # DLM: todo check if any zone equipment that is not a terminal
    # if equipment.size > 0 and not modified
    #  runner.registerWarning("No heating or cooling elements found for thermal zone #{thermal_zone.name.get}")
    # end
  end

  # reporting final condition of model
  runner.registerFinalCondition("Modified efficiencies for #{num_heating_objects_modified} heating objects and #{num_cooling_objects_modified} cooling objects.")

  return true
end