Class: ReduceVentilationByPercentage

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

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#alter_performance(object, design_spec_outdoor_air_reduction_percent, runner) ⇒ Object

def to alter performance and life cycle costs of objects



199
200
201
202
203
204
205
206
207
208
# File 'lib/measures/ReduceVentilationByPercentage/measure.rb', line 199

def alter_performance(object, design_spec_outdoor_air_reduction_percent, runner)
  # edit instance based on percentage reduction
  instance = object

  # not checking if fields are empty because these are optional like values for space infiltration are.
  new_outdoor_air_per_person = instance.setOutdoorAirFlowperPerson(instance.outdoorAirFlowperPerson - instance.outdoorAirFlowperPerson * design_spec_outdoor_air_reduction_percent * 0.01)
  new_outdoor_air_per_floor_area = instance.setOutdoorAirFlowperFloorArea(instance.outdoorAirFlowperFloorArea - instance.outdoorAirFlowperFloorArea * design_spec_outdoor_air_reduction_percent * 0.01)
  new_outdoor_air_ach = instance.setOutdoorAirFlowAirChangesperHour(instance.outdoorAirFlowAirChangesperHour - instance.outdoorAirFlowAirChangesperHour * design_spec_outdoor_air_reduction_percent * 0.01)
  new_outdoor_air_rate = instance.setOutdoorAirFlowRate(instance.outdoorAirFlowRate - instance.outdoorAirFlowRate * design_spec_outdoor_air_reduction_percent * 0.01)
end

#arguments(model) ⇒ Object

define the arguments that the user will input



26
27
28
29
30
31
32
33
34
35
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
# File 'lib/measures/ReduceVentilationByPercentage/measure.rb', line 26

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
  design_spec_outdoor_air_reduction_percent = OpenStudio::Measure::OSArgument.makeDoubleArgument('design_spec_outdoor_air_reduction_percent', true)
  design_spec_outdoor_air_reduction_percent.setDisplayName('Design Specification Outdoor Air Reduction (%).')
  design_spec_outdoor_air_reduction_percent.setDefaultValue(30.0)
  args << design_spec_outdoor_air_reduction_percent

  # no cost required to reduce required amount of outdoor air. Cost increase or decrease will relate to system sizing and ongoing energy use due to change in outdoor air provided.

  return args
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/ReduceVentilationByPercentage/measure.rb', line 21

def name
  return 'ReduceVentilationByPercentage'
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.



121
122
123
124
125
126
127
128
129
# File 'lib/measures/ReduceVentilationByPercentage/measure.rb', line 121

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



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

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)
  design_spec_outdoor_air_reduction_percent = runner.getDoubleArgumentValue('design_spec_outdoor_air_reduction_percent', 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 design_spec_outdoor_air_reduction_percent and for reasonableness
  if design_spec_outdoor_air_reduction_percent > 100
    runner.registerError('Please enter a value less than or equal to 100 for the Outdoor Air Requirement reduction percentage.')
    return false
  elsif design_spec_outdoor_air_reduction_percent == 0
    runner.registerInfo('No Outdoor Air Requirement adjustment requested, but some life cycle costs may still be affected.')
  elsif (design_spec_outdoor_air_reduction_percent < 1) && (design_spec_outdoor_air_reduction_percent > -1)
    runner.registerWarning("A Outdoor Air Requirement reduction percentage of #{design_spec_outdoor_air_reduction_percent} percent is abnormally low.")
  elsif design_spec_outdoor_air_reduction_percent > 90
    runner.registerWarning("A Outdoor Air Requirement reduction percentage of #{design_spec_outdoor_air_reduction_percent} percent is abnormally high.")
  elsif design_spec_outdoor_air_reduction_percent < 0
    runner.registerInfo('The requested value for Outdoor Air Requirement reduction percentage was negative. This will result in an increase in the Outdoor Air Requirement.')
  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 design_spec_outdoor_air_objects objects used in the model
  design_spec_outdoor_air_objects = model.getDesignSpecificationOutdoorAirs
  # TODO: - it would be nice to give ranges for different calculation methods but would take some work.

  # counters needed for measure
  altered_instances = 0

  # reporting initial condition of model
  if !design_spec_outdoor_air_objects.empty?
    runner.registerInitialCondition("The initial model contained #{design_spec_outdoor_air_objects.size} design specification outdoor air objects.")
  else
    runner.registerInitialCondition('The initial model did not contain any design specification outdoor air.')
  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

  # split apart any shared uses of design specification outdoor air
  design_spec_outdoor_air_objects.each do |design_spec_outdoor_air_object|
    direct_use_count = design_spec_outdoor_air_object.directUseCount
    next if direct_use_count <= 1
    direct_uses = design_spec_outdoor_air_object.sources
    original_cloned = false

    # adjust count test for direct uses that are component data
    direct_uses.each do |direct_use|
      component_data_source = direct_use.to_ComponentData
      if !component_data_source.empty?
        direct_use_count -= 1
      end
    end
    next if direct_use_count <= 1

    direct_uses.each do |direct_use|
      # clone and hookup design spec OA
      space_type_source = direct_use.to_SpaceType
      if !space_type_source.empty?
        space_type_source = space_type_source.get
        cloned_object = design_spec_outdoor_air_object.clone
        space_type_source.setDesignSpecificationOutdoorAir(cloned_object.to_DesignSpecificationOutdoorAir.get)
        original_cloned = true
      end

      space_source = direct_use.to_Space
      if !space_source.empty?
        space_source = space_source.get
        cloned_object = design_spec_outdoor_air_object.clone
        space_source.setDesignSpecificationOutdoorAir(cloned_object.to_DesignSpecificationOutdoorAir.get)
        original_cloned = true
      end
    end

    # delete the now unused design spec OA
    if original_cloned
      runner.registerInfo("Making shared object #{design_spec_outdoor_air_object.name} unique.")
      design_spec_outdoor_air_object.remove
    end
  end

  # def to alter performance and life cycle costs of objects
  def alter_performance(object, design_spec_outdoor_air_reduction_percent, runner)
    # edit instance based on percentage reduction
    instance = object

    # not checking if fields are empty because these are optional like values for space infiltration are.
    new_outdoor_air_per_person = instance.setOutdoorAirFlowperPerson(instance.outdoorAirFlowperPerson - instance.outdoorAirFlowperPerson * design_spec_outdoor_air_reduction_percent * 0.01)
    new_outdoor_air_per_floor_area = instance.setOutdoorAirFlowperFloorArea(instance.outdoorAirFlowperFloorArea - instance.outdoorAirFlowperFloorArea * design_spec_outdoor_air_reduction_percent * 0.01)
    new_outdoor_air_ach = instance.setOutdoorAirFlowAirChangesperHour(instance.outdoorAirFlowAirChangesperHour - instance.outdoorAirFlowAirChangesperHour * design_spec_outdoor_air_reduction_percent * 0.01)
    new_outdoor_air_rate = instance.setOutdoorAirFlowRate(instance.outdoorAirFlowRate - instance.outdoorAirFlowRate * design_spec_outdoor_air_reduction_percent * 0.01)
  end

  # array of instances to change
  instances_array = []

  # loop through space types
  space_types.each do |space_type|
    next if space_type.spaces.size <= 0
    instances_array << space_type.designSpecificationOutdoorAir
  end

  # get spaces 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|
    instances_array << space.designSpecificationOutdoorAir
  end

  instance_processed = []

  instances_array.each do |instance|
    next if instance.empty?
    instance = instance.get

    # only continue if this instance has not been processed yet
    next if instance_processed.include? instance
    instance_processed << instance

    # call def to alter performance and life cycle costs
    alter_performance(instance, design_spec_outdoor_air_reduction_percent, runner)

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

  if altered_instances == 0
    runner.registerAsNotApplicable('No design specification outdoor air objects were found in the specified space type(s).')
  end

  # report final condition
  affected_area_ip = OpenStudio.convert(affected_area_si, 'm^2', 'ft^2').get
  runner.registerFinalCondition("#{altered_instances} design specification outdoor air objects in the model were altered affecting #{neat_numbers(affected_area_ip, 0)}(ft^2).")

  return true
end