Class: ReduceSpaceInfiltrationByPercentage

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

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#alter_performance(object, space_infiltration_reduction_percent, constant_coefficient, temperature_coefficient, wind_speed_coefficient, wind_speed_squared_coefficient, alter_coef, runner) ⇒ Object

def to alter performance and life cycle costs of objects



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
# File 'lib/measures/ReduceSpaceInfiltrationByPercentage/measure.rb', line 233

def alter_performance(object, space_infiltration_reduction_percent, constant_coefficient, temperature_coefficient, wind_speed_coefficient, wind_speed_squared_coefficient, alter_coef, runner)
  # edit instance based on percentage reduction
  instance = object
  if !instance.designFlowRate.empty?
    new_infiltration_design_flow_rate = instance.setDesignFlowRate(instance.designFlowRate.get - instance.designFlowRate.get * space_infiltration_reduction_percent * 0.01)
  elsif !instance.flowperSpaceFloorArea.empty?
    new_infiltration_flow_floor_area = instance.setFlowperSpaceFloorArea(instance.flowperSpaceFloorArea.get - instance.flowperSpaceFloorArea.get * space_infiltration_reduction_percent * 0.01)
  elsif !instance.flowperExteriorSurfaceArea.empty?
    new_infiltration_flow_ext_area = instance.setFlowperExteriorSurfaceArea(instance.flowperExteriorSurfaceArea.get - instance.flowperExteriorSurfaceArea.get * space_infiltration_reduction_percent * 0.01)
  elsif !instance.flowperExteriorWallArea.empty?
    new_infiltration_flow_ext_area = instance.setFlowperExteriorWallArea(instance.flowperExteriorWallArea.get - instance.flowperExteriorWallArea.get * space_infiltration_reduction_percent * 0.01)
  elsif !instance.airChangesperHour.empty?
    new_infiltration_ach = instance.setAirChangesperHour(instance.airChangesperHour.get - instance.airChangesperHour.get * space_infiltration_reduction_percent * 0.01)
  else
    runner.registerWarning("'#{instance.name}' is used by one or more instances and has no load values.")
  end

  # only alter coefficients if requested
  if alter_coef
    instance.setConstantTermCoefficient(constant_coefficient)
    instance.setTemperatureTermCoefficient(temperature_coefficient)
    instance.setVelocityTermCoefficient(wind_speed_coefficient)
    instance.setVelocitySquaredTermCoefficient(wind_speed_squared_coefficient)
  end
end

#arguments(model) ⇒ Object

define the arguments that the user will input



36
37
38
39
40
41
42
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
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
# File 'lib/measures/ReduceSpaceInfiltrationByPercentage/measure.rb', line 36

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

  # make a choice argument for model objects
  space_type_handles = OpenStudio::StringVector.new
  space_type_display_names = OpenStudio::StringVector.new

  # putting model object and names into hash
  space_type_args = model.getSpaceTypes
  space_type_args_hash = {}
  space_type_args.each do |space_type_arg|
    space_type_args_hash[space_type_arg.name.to_s] = space_type_arg
  end

  # looping through sorted hash of model objects
  space_type_args_hash.sort.map do |key, value|
    # only include if space type is used in the model
    if !value.spaces.empty?
      space_type_handles << value.handle.to_s
      space_type_display_names << key
    end
  end

  # add building to string vector with space type
  building = model.getBuilding
  space_type_handles << building.handle.to_s
  space_type_display_names << '*Entire Building*'

  # make a choice argument for space type
  space_type = OpenStudio::Measure::OSArgument.makeChoiceArgument('space_type', space_type_handles, space_type_display_names)
  space_type.setDisplayName('Apply the Measure to a Specific Space Type or to the Entire Model.')
  space_type.setDefaultValue('*Entire Building*') # if no space type is chosen this will run on the entire building
  args << space_type

  # make an argument for reduction percentage
  space_infiltration_reduction_percent = OpenStudio::Measure::OSArgument.makeDoubleArgument('space_infiltration_reduction_percent', true)
  space_infiltration_reduction_percent.setDisplayName('Space Infiltration Power Reduction')
  space_infiltration_reduction_percent.setDefaultValue(30.0)
  space_infiltration_reduction_percent.setUnits('%')
  args << space_infiltration_reduction_percent

  # make an argument for constant_coefficient
  constant_coefficient = OpenStudio::Measure::OSArgument.makeDoubleArgument('constant_coefficient', true)
  constant_coefficient.setDisplayName('Constant Coefficient')
  constant_coefficient.setDefaultValue(1.0)
  args << constant_coefficient

  # make an argument for temperature_coefficient
  temperature_coefficient = OpenStudio::Measure::OSArgument.makeDoubleArgument('temperature_coefficient', true)
  temperature_coefficient.setDisplayName('Temperature Coefficient')
  temperature_coefficient.setDefaultValue(0.0)
  args << temperature_coefficient

  # make an argument for wind_speed_coefficient
  wind_speed_coefficient = OpenStudio::Measure::OSArgument.makeDoubleArgument('wind_speed_coefficient', true)
  wind_speed_coefficient.setDisplayName('Wind Speed Coefficient')
  wind_speed_coefficient.setDefaultValue(0.0)
  args << wind_speed_coefficient

  # make an argument for wind_speed_squared_coefficient
  wind_speed_squared_coefficient = OpenStudio::Measure::OSArgument.makeDoubleArgument('wind_speed_squared_coefficient', true)
  wind_speed_squared_coefficient.setDisplayName('Wind Speed Squared Coefficient')
  wind_speed_squared_coefficient.setDefaultValue(0.0)
  args << wind_speed_squared_coefficient

  # make an argument for alter_coef
  alter_coef = OpenStudio::Measure::OSArgument.makeBoolArgument('alter_coef', true)
  alter_coef.setDisplayName('Alter constant temperature and wind speed coefficients.')
  alter_coef.setDescription('Setting this to false will result in infiltration objects that maintain the coefficients from the initial model. Setting this to true replaces the existing coefficients with the values entered for the coefficient arguments in this measure')
  alter_coef.setDefaultValue(true)
  args << alter_coef

  # make an argument for material and installation cost
  material_and_installation_cost = OpenStudio::Measure::OSArgument.makeDoubleArgument('material_and_installation_cost', true)
  material_and_installation_cost.setDisplayName('Increase in Material and Installation Costs for Building per Affected Floor Area')
  material_and_installation_cost.setDefaultValue(0.0)
  material_and_installation_cost.setUnits('$/ft^2')
  args << material_and_installation_cost

  # make an argument for O & M cost
  om_cost = OpenStudio::Measure::OSArgument.makeDoubleArgument('om_cost', true)
  om_cost.setDisplayName('O & M Costs for Construction per Affected Floor Area')
  om_cost.setDefaultValue(0.0)
  om_cost.setUnits('$/ft^2')
  args << om_cost

  # make an argument for O & M frequency
  om_frequency = OpenStudio::Measure::OSArgument.makeIntegerArgument('om_frequency', true)
  om_frequency.setDisplayName('O & M Frequency')
  om_frequency.setDefaultValue(1)
  om_frequency.setUnits('whole years')
  args << om_frequency

  return args
end

#descriptionObject

human readable description



26
27
28
# File 'lib/measures/ReduceSpaceInfiltrationByPercentage/measure.rb', line 26

def description
  return 'This measure will reduce space infiltration rates by the requested percentage. A cost per square foot of building area can be added to the model.'
end

#modeler_descriptionObject

human readable description of modeling approach



31
32
33
# File 'lib/measures/ReduceSpaceInfiltrationByPercentage/measure.rb', line 31

def modeler_description
  return 'This can be run across a space type or the entire building. Costs will be associated with the building. If infiltration objects are removed at a later date, the costs will remain.'
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



21
22
23
# File 'lib/measures/ReduceSpaceInfiltrationByPercentage/measure.rb', line 21

def name
  return 'ReduceSpaceInfiltrationByPercentage'
end

#neat_numbers(number, roundto = 2) ⇒ Object

helper to make numbers pretty (converts 4125001.25641 to 4,125,001.26 or 4,125,001). The definition be called through this measure.



196
197
198
199
200
201
202
203
204
# File 'lib/measures/ReduceSpaceInfiltrationByPercentage/measure.rb', line 196

def neat_numbers(number, roundto = 2) # round to 0 or 2)
  if roundto == 2
    number = format '%.2f', number
  else
    number = number.round
  end
  # regex to add commas
  number.to_s.reverse.gsub(/([0-9]{3}(?=([0-9])))/, '\\1,').reverse
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



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
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
# File 'lib/measures/ReduceSpaceInfiltrationByPercentage/measure.rb', line 133

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
  object = runner.getOptionalWorkspaceObjectChoiceValue('space_type', user_arguments, model)
  space_infiltration_reduction_percent = runner.getDoubleArgumentValue('space_infiltration_reduction_percent', user_arguments)
  constant_coefficient = runner.getDoubleArgumentValue('constant_coefficient', user_arguments)
  temperature_coefficient = runner.getDoubleArgumentValue('temperature_coefficient', user_arguments)
  wind_speed_coefficient = runner.getDoubleArgumentValue('wind_speed_coefficient', user_arguments)
  wind_speed_squared_coefficient = runner.getDoubleArgumentValue('wind_speed_squared_coefficient', user_arguments)
  alter_coef = runner.getBoolArgumentValue('alter_coef', user_arguments)
  material_and_installation_cost = runner.getDoubleArgumentValue('material_and_installation_cost', user_arguments)
  om_cost = runner.getDoubleArgumentValue('om_cost', user_arguments)
  om_frequency = runner.getIntegerArgumentValue('om_frequency', user_arguments)

  # check the space_type for reasonableness and see if measure should run on space type or on the entire building
  apply_to_building = false
  space_type = nil
  if object.empty?
    handle = runner.getStringArgumentValue('space_type', user_arguments)
    if handle.empty?
      runner.registerError('No space type was chosen.')
    else
      runner.registerError("The selected space type with handle '#{handle}' was not found in the model. It may have been removed by another measure.")
    end
    return false
  else
    if !object.get.to_SpaceType.empty?
      space_type = object.get.to_SpaceType.get
    elsif !object.get.to_Building.empty?
      apply_to_building = true
    else
      runner.registerError('Script Error - argument not showing up as space type or building.')
      return false
    end
  end

  # check the space_infiltration_reduction_percent and for reasonableness
  if space_infiltration_reduction_percent > 100
    runner.registerError('Please enter a value less than or equal to 100 for the Space Infiltration reduction percentage.')
    return false
  elsif space_infiltration_reduction_percent == 0
    runner.registerInfo('No Space Infiltration adjustment requested, but infiltration coefficients or life cycle costs may still be affected.')
  elsif (space_infiltration_reduction_percent < 1) && (space_infiltration_reduction_percent > -1)
    runner.registerWarning("A Space Infiltration reduction percentage of #{space_infiltration_reduction_percent} percent is abnormally low.")
  elsif space_infiltration_reduction_percent > 90
    runner.registerWarning("A Space Infiltration reduction percentage of #{space_infiltration_reduction_percent} percent is abnormally high.")
  elsif space_infiltration_reduction_percent < 0
    runner.registerInfo('The requested value for Space Infiltration reduction percentage was negative. This will result in an increase in Space Infiltration.')
  end

  # TODO: - currently not checking for negative $/ft^2 for material_and_installation_cost and om_cost, confirm if E+ will allow negative cost

  if om_frequency < 1
    runner.registerError('Choose an integer greater than 0 for O & M Frequency.')
  end

  # helper to make numbers pretty (converts 4125001.25641 to 4,125,001.26 or 4,125,001). The definition be called through this measure.
  def neat_numbers(number, roundto = 2) # round to 0 or 2)
    if roundto == 2
      number = format '%.2f', number
    else
      number = number.round
    end
    # regex to add commas
    number.to_s.reverse.gsub(/([0-9]{3}(?=([0-9])))/, '\\1,').reverse
  end

  # get space infiltration objects used in the model
  space_infiltration_objects = model.getSpaceInfiltrationDesignFlowRates
  # TODO: - it would be nice to give ranges for different calculation methods but would take some work.

  # counters needed for measure
  altered_instances = 0
  affected_area_si = 0

  # reporting initial condition of model
  if !space_infiltration_objects.empty?
    runner.registerInitialCondition("The initial model contained #{space_infiltration_objects.size} space infiltration objects.")
  else
    runner.registerInitialCondition('The initial model did not contain any space infiltration objects.')
  end

  # get space types in model
  building = model.building.get
  if apply_to_building
    space_types = model.getSpaceTypes
    affected_area_si = building.floorArea
  else
    space_types = []
    space_types << space_type # only run on a single space type
    affected_area_si = space_type.floorArea
  end

  # def to alter performance and life cycle costs of objects
  def alter_performance(object, space_infiltration_reduction_percent, constant_coefficient, temperature_coefficient, wind_speed_coefficient, wind_speed_squared_coefficient, alter_coef, runner)
    # edit instance based on percentage reduction
    instance = object
    if !instance.designFlowRate.empty?
      new_infiltration_design_flow_rate = instance.setDesignFlowRate(instance.designFlowRate.get - instance.designFlowRate.get * space_infiltration_reduction_percent * 0.01)
    elsif !instance.flowperSpaceFloorArea.empty?
      new_infiltration_flow_floor_area = instance.setFlowperSpaceFloorArea(instance.flowperSpaceFloorArea.get - instance.flowperSpaceFloorArea.get * space_infiltration_reduction_percent * 0.01)
    elsif !instance.flowperExteriorSurfaceArea.empty?
      new_infiltration_flow_ext_area = instance.setFlowperExteriorSurfaceArea(instance.flowperExteriorSurfaceArea.get - instance.flowperExteriorSurfaceArea.get * space_infiltration_reduction_percent * 0.01)
    elsif !instance.flowperExteriorWallArea.empty?
      new_infiltration_flow_ext_area = instance.setFlowperExteriorWallArea(instance.flowperExteriorWallArea.get - instance.flowperExteriorWallArea.get * space_infiltration_reduction_percent * 0.01)
    elsif !instance.airChangesperHour.empty?
      new_infiltration_ach = instance.setAirChangesperHour(instance.airChangesperHour.get - instance.airChangesperHour.get * space_infiltration_reduction_percent * 0.01)
    else
      runner.registerWarning("'#{instance.name}' is used by one or more instances and has no load values.")
    end

    # only alter coefficients if requested
    if alter_coef
      instance.setConstantTermCoefficient(constant_coefficient)
      instance.setTemperatureTermCoefficient(temperature_coefficient)
      instance.setVelocityTermCoefficient(wind_speed_coefficient)
      instance.setVelocitySquaredTermCoefficient(wind_speed_squared_coefficient)
    end
  end

  # loop through space types
  space_types.each do |space_type|
    next if space_type.spaces.size <= 0
    space_type_infiltration_objects = space_type.spaceInfiltrationDesignFlowRates
    space_type_infiltration_objects.each do |space_type_infiltration_object|
      # call def to alter performance and life cycle costs
      alter_performance(space_type_infiltration_object, space_infiltration_reduction_percent, constant_coefficient, temperature_coefficient, wind_speed_coefficient, wind_speed_squared_coefficient, alter_coef, runner)

      # rename
      updated_instance_name = space_type_infiltration_object.setName("#{space_type_infiltration_object.name} #{space_infiltration_reduction_percent} percent reduction")
      altered_instances += 1
    end
  end

  # getting spaces in the model
  spaces = model.getSpaces

  # get space types in model
  if apply_to_building
    spaces = model.getSpaces
  else
    if !space_type.spaces.empty?
      spaces = space_type.spaces # only run on a single space type
    end
  end

  spaces.each do |space|
    space_infiltration_objects = space.spaceInfiltrationDesignFlowRates
    space_infiltration_objects.each do |space_infiltration_object|
      # call def to alter performance and life cycle costs
      alter_performance(space_infiltration_object, space_infiltration_reduction_percent, constant_coefficient, temperature_coefficient, wind_speed_coefficient, wind_speed_squared_coefficient, alter_coef, runner)

      # rename
      updated_instance_name = space_infiltration_object.setName("#{space_infiltration_object.name} #{space_infiltration_reduction_percent} percent reduction")
      altered_instances += 1
    end
  end

  if (altered_instances == 0) && (material_and_installation_cost == 0) && (om_cost == 0)
    runner.registerAsNotApplicable('No space infiltration objects were found in the specified space type(s) and no life cycle costs were requested.')
  end

  # only add LifeCyCyleCostItem if the user entered some non 0 cost values
  affected_area_ip = OpenStudio.convert(affected_area_si, 'm^2', 'ft^2').get
  if (material_and_installation_cost != 0) || (om_cost != 0)
    lcc_mat = OpenStudio::Model::LifeCycleCost.createLifeCycleCost('LCC_Mat - Cost to Adjust Infiltration', building, affected_area_ip * material_and_installation_cost, 'CostPerEach', 'Construction', 0, 0) # 0 for expected life will result infinite expected life
    lcc_om = OpenStudio::Model::LifeCycleCost.createLifeCycleCost('LCC_OM - Cost to Adjust Infiltration', building, affected_area_ip * om_cost, 'CostPerEach', 'Maintenance', om_frequency, 0) # o&m costs start after at sane time that material and installation costs occur
    runner.registerInfo("Costs related to the change in infiltration are attached to the building object. Any subsequent measures that may affect infiltration won't affect these costs.")
    final_cost = lcc_mat.get.totalCost
  else
    runner.registerInfo('Cost arguments were not provided, no cost objects were added to the model.')
    final_cost = 0
  end

  # report final condition
  runner.registerFinalCondition("#{altered_instances} space infiltration objects in the model were altered affecting #{neat_numbers(affected_area_ip, 0)}(ft^2) at a total cost of $#{neat_numbers(final_cost, 0)}.")

  return true
end