Class: ReduceLightingLoadsByPercentage

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

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#add_to_baseline_demo_cost_counter(baseline_object, demo_cost_initial_const) ⇒ Object

helper def to add to demo cost related to baseline objects



267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/measures/ReduceLightingLoadsByPercentage/measure.rb', line 267

def add_to_baseline_demo_cost_counter(baseline_object, demo_cost_initial_const)
  counter = 0
  if demo_cost_initial_const == true
    baseline_object_LCCs = baseline_object.lifeCycleCosts
    baseline_object_LCCs.each do |baseline_object_LCC|
      if baseline_object_LCC.category == 'Salvage'
        counter += baseline_object_LCC.totalCost
      end
    end
  end
  return counter
end

#alter_performance_and_lcc(object, lighting_power_reduction_percent, material_and_installation_cost, demolition_cost, om_cost, years_until_costs_start, expected_life, om_frequency, runner) ⇒ Object

def to alter performance and life cycle costs of objects



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
318
319
320
# File 'lib/measures/ReduceLightingLoadsByPercentage/measure.rb', line 281

def alter_performance_and_lcc(object, lighting_power_reduction_percent, material_and_installation_cost, demolition_cost, om_cost, years_until_costs_start, expected_life, om_frequency, runner)
  # edit clone based on percentage reduction
  new_def = object
  if !new_def.lightingLevel.empty?
    new_lighting_level = new_def.setLightingLevel(new_def.lightingLevel.get - new_def.lightingLevel.get * lighting_power_reduction_percent * 0.01)
  elsif !new_def.wattsperSpaceFloorArea.empty?
    new_lighting_per_area = new_def.setWattsperSpaceFloorArea(new_def.wattsperSpaceFloorArea.get - new_def.wattsperSpaceFloorArea.get * lighting_power_reduction_percent * 0.01)
  elsif !new_def.wattsperPerson.empty?
    new_lighting_per_person = new_def.setWattsperPerson(new_def.wattsperPerson.get - new_def.wattsperPerson.get * lighting_power_reduction_percent * 0.01)
  else
    runner.registerWarning("'#{new_def.name}' is used by one or more instances and has no load values. Its performance was not altered.")
  end

  new_def_LCCs = new_def.lifeCycleCosts
  if new_def_LCCs.empty?
    if material_and_installation_cost.abs + demolition_cost.abs + om_cost.abs != 0
      runner.registerWarning("'#{new_def.name}' had no life cycle cost objects. No cost was added for it.")
    end
  else
    new_def_LCCs.each do |new_def_LCC|
      if new_def_LCC.category == 'Construction'
        new_def_LCC.setCost(new_def_LCC.cost * (1 + material_and_installation_cost / 100))
        new_def_LCC.setYearsFromStart(years_until_costs_start) # just uses argument value, does not need existing value
        new_def_LCC.setRepeatPeriodYears(expected_life) # just uses argument value, does not need existing value
      elsif new_def_LCC.category == 'Salvage'
        new_def_LCC.setCost(new_def_LCC.cost * (1 + demolition_cost / 100))
        new_def_LCC.setYearsFromStart(years_until_costs_start + expected_life) # just uses argument value, does not need existing value
        new_def_LCC.setRepeatPeriodYears(expected_life) # just uses argument value, does not need existing value
      elsif new_def_LCC.category == 'Maintenance'
        new_def_LCC.setCost(new_def_LCC.cost * (1 + om_cost / 100))
        new_def_LCC.setRepeatPeriodYears(om_frequency) # just uses argument value, does not need existing value
      end

      # reset any month durations
      new_def_LCC.resetRepeatPeriodMonths
      new_def_LCC.resetMonthsFromStart
    end

  end
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
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
# File 'lib/measures/ReduceLightingLoadsByPercentage/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
  lighting_power_reduction_percent = OpenStudio::Measure::OSArgument.makeDoubleArgument('lighting_power_reduction_percent', true)
  lighting_power_reduction_percent.setDisplayName('Lighting Power Reduction')
  lighting_power_reduction_percent.setDefaultValue(30.0)
  lighting_power_reduction_percent.setUnits('%')
  args << lighting_power_reduction_percent

  # 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 Cost for Lighting per Floor Area')
  material_and_installation_cost.setDefaultValue(0.0)
  material_and_installation_cost.setUnits('%')
  args << material_and_installation_cost

  # make an argument for demolition cost
  demolition_cost = OpenStudio::Measure::OSArgument.makeDoubleArgument('demolition_cost', true)
  demolition_cost.setDisplayName('Increase in Demolition Costs for Lighting per Floor Area')
  demolition_cost.setDefaultValue(0.0)
  demolition_cost.setUnits('%')
  args << demolition_cost

  # make an argument for years until costs start
  years_until_costs_start = OpenStudio::Measure::OSArgument.makeIntegerArgument('years_until_costs_start', true)
  years_until_costs_start.setDisplayName('Years Until Costs Start')
  years_until_costs_start.setDefaultValue(0)
  years_until_costs_start.setUnits('whole years')
  args << years_until_costs_start

  # make a choice argument for when demo costs occur
  demo_cost_initial_const = OpenStudio::Measure::OSArgument.makeBoolArgument('demo_cost_initial_const', true)
  demo_cost_initial_const.setDisplayName('Demolition Costs Occur During Initial Construction')
  demo_cost_initial_const.setDefaultValue(false)
  args << demo_cost_initial_const

  # make an argument for expected life
  expected_life = OpenStudio::Measure::OSArgument.makeIntegerArgument('expected_life', true)
  expected_life.setDisplayName('Expected Life')
  expected_life.setDefaultValue(15)
  expected_life.setUnits('whole years')
  args << expected_life

  # make an argument for O & M cost
  om_cost = OpenStudio::Measure::OSArgument.makeDoubleArgument('om_cost', true)
  om_cost.setDisplayName('Increase O & M Costs for Lighting per Floor Area')
  om_cost.setDefaultValue(0.0)
  om_cost.setUnits('%')
  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



16
17
18
# File 'lib/measures/ReduceLightingLoadsByPercentage/measure.rb', line 16

def description
  return 'The lighting system in this building uses more power per area than is required with the latest lighting technologies.  Replace the lighting system with a newer, more efficient lighting technology.  Newer technologies provide the same amount of light but use less energy in the process.'
end

#get_total_costs_for_objects(objects) ⇒ Object

helper that loops through lifecycle costs getting total costs under “Construction” or “Salvage” category and add to counter if occurs during year 0



221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/measures/ReduceLightingLoadsByPercentage/measure.rb', line 221

def get_total_costs_for_objects(objects)
  counter = 0
  objects.each do |object|
    object_LCCs = object.lifeCycleCosts
    object_LCCs.each do |object_LCC|
      if (object_LCC.category == 'Construction') || (object_LCC.category == 'Salvage')
        if object_LCC.yearsFromStart == 0
          counter += object_LCC.totalCost
        end
      end
    end
  end
  return counter
end

#modeler_descriptionObject

human readable description of modeling approach



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

def modeler_description
  return 'This measure supports models which have a mixture of lighting assigned to spaces and space types.  The lighting may be specified as individual luminaires, lighting equipment level, lighting power per area, or lighting power per person. Loop through all lights and luminaires in the specified space type or the entire building. Clone the definition if it is shared by other lights, rename and adjust the power based on the specified percentage. Link the new definition to the existing lights or luminaire instance.  Adjust the power for lighting equipment assigned to a particular space but only if that space is part of the selected space type by  looping through the objects first in space types and then in spaces, but again only for spaces that are in the specified space type (unless the entire building has been chosen).  Material and installation cost increases will be applied to all costs related to both the definition and instance of the lighting object.  If this measure includes baseline costs, then the material and installation costs of the lighting objects in the baseline model will be summed together and added as a capital cost on the building object.'
end

#nameObject

define the name that a user will see



11
12
13
# File 'lib/measures/ReduceLightingLoadsByPercentage/measure.rb', line 11

def name
  return 'Reduce Lighting Loads by Percentage'
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.



205
206
207
208
209
210
211
212
213
# File 'lib/measures/ReduceLightingLoadsByPercentage/measure.rb', line 205

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



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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/measures/ReduceLightingLoadsByPercentage/measure.rb', line 119

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)
  lighting_power_reduction_percent = runner.getDoubleArgumentValue('lighting_power_reduction_percent', user_arguments)
  material_and_installation_cost = runner.getDoubleArgumentValue('material_and_installation_cost', user_arguments)
  demolition_cost = runner.getDoubleArgumentValue('demolition_cost', user_arguments)
  years_until_costs_start = runner.getIntegerArgumentValue('years_until_costs_start', user_arguments)
  demo_cost_initial_const = runner.getBoolArgumentValue('demo_cost_initial_const', user_arguments)
  expected_life = runner.getIntegerArgumentValue('expected_life', 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 lighting_power_reduction_percent and for reasonableness
  if lighting_power_reduction_percent > 100
    runner.registerError('Please Enter a Value less than or equal to 100 for the Lighting Power Reduction Percentage.')
    return false
  elsif lighting_power_reduction_percent == 0
    runner.registerInfo('No lighting power adjustment requested, but some life cycle costs may still be affected.')
  elsif (lighting_power_reduction_percent < 1) && (lighting_power_reduction_percent > -1)
    runner.registerWarning("A Lighting Power Reduction Percentage of #{lighting_power_reduction_percent} percent is abnormally low.")
  elsif lighting_power_reduction_percent > 90
    runner.registerWarning("A Lighting Power Reduction Percentage of #{lighting_power_reduction_percent} percent is abnormally high.")
  elsif lighting_power_reduction_percent < 0
    runner.registerInfo('The requested value for lighting power reduction percentage was negative. This will result in an increase in lighting power.')
  end

  # check lifecycle cost arguments for reasonableness
  if material_and_installation_cost < -100
    runner.registerError("Material and Installation Cost percentage increase can't be less than -100.")
    return false
  end

  if demolition_cost < -100
    runner.registerError("Demolition Cost percentage increase can't be less than -100.")
    return false
  end

  if years_until_costs_start < 0
    runner.registerError('Enter an integer greater than or equal to 0 for Years Until Costs Start.')
    return false
  end

  if expected_life < 1
    runner.registerError('Enter an integer greater than or equal to 1 for Expected Life.')
    return false
  end

  if om_cost < -100
    runner.registerError("O & M Cost percentage increase can't be less than -100.")
    return false
  end

  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

  # helper to make it easier to do unit conversions on the fly.  The definition be called through this measure.
  def unit_helper(number, from_unit_string, to_unit_string)
    converted_number = OpenStudio.convert(OpenStudio::Quantity.new(number, OpenStudio.createUnit(from_unit_string).get), OpenStudio.createUnit(to_unit_string).get).get.value
  end

  # helper that loops through lifecycle costs getting total costs under "Construction" or "Salvage" category and add to counter if occurs during year 0
  def get_total_costs_for_objects(objects)
    counter = 0
    objects.each do |object|
      object_LCCs = object.lifeCycleCosts
      object_LCCs.each do |object_LCC|
        if (object_LCC.category == 'Construction') || (object_LCC.category == 'Salvage')
          if object_LCC.yearsFromStart == 0
            counter += object_LCC.totalCost
          end
        end
      end
    end
    return counter
  end

  # counter for demo cost of baseline objects
  demo_costs_of_baseline_objects = 0

  # counter for year 0 capital costs
  yr0_capital_totalCosts = 0

  # get initial light and luminaire costs and multiply by -1
  yr0_capital_totalCosts += get_total_costs_for_objects(model.getLightsDefinitions) * -1
  yr0_capital_totalCosts += get_total_costs_for_objects(model.getLuminaireDefinitions) * -1

  # report initial condition
  building = model.getBuilding
  building_lighting_power = building.lightingPower

  # method should always return double but this is work around for when it is nan because of 0 floor area
  if building.floorArea > 0.0
    building_LPD = unit_helper(building.lightingPowerPerFloorArea, 'W/m^2', 'W/ft^2')
    runner.registerInitialCondition("The model's initial building lighting power was  #{neat_numbers(building_lighting_power, 0)} watts, a lighting power density of #{neat_numbers(building_LPD)} w/ft^2.")
  else
    runner.registerInitialCondition("The model's initial building lighting power was  #{neat_numbers(building_lighting_power, 0)} watts. Building Area is not greater than 0 so an LPD can't be calculated.")
  end

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

  # helper def to add to demo cost related to baseline objects
  def add_to_baseline_demo_cost_counter(baseline_object, demo_cost_initial_const)
    counter = 0
    if demo_cost_initial_const == true
      baseline_object_LCCs = baseline_object.lifeCycleCosts
      baseline_object_LCCs.each do |baseline_object_LCC|
        if baseline_object_LCC.category == 'Salvage'
          counter += baseline_object_LCC.totalCost
        end
      end
    end
    return counter
  end

  # def to alter performance and life cycle costs of objects
  def alter_performance_and_lcc(object, lighting_power_reduction_percent, material_and_installation_cost, demolition_cost, om_cost, years_until_costs_start, expected_life, om_frequency, runner)
    # edit clone based on percentage reduction
    new_def = object
    if !new_def.lightingLevel.empty?
      new_lighting_level = new_def.setLightingLevel(new_def.lightingLevel.get - new_def.lightingLevel.get * lighting_power_reduction_percent * 0.01)
    elsif !new_def.wattsperSpaceFloorArea.empty?
      new_lighting_per_area = new_def.setWattsperSpaceFloorArea(new_def.wattsperSpaceFloorArea.get - new_def.wattsperSpaceFloorArea.get * lighting_power_reduction_percent * 0.01)
    elsif !new_def.wattsperPerson.empty?
      new_lighting_per_person = new_def.setWattsperPerson(new_def.wattsperPerson.get - new_def.wattsperPerson.get * lighting_power_reduction_percent * 0.01)
    else
      runner.registerWarning("'#{new_def.name}' is used by one or more instances and has no load values. Its performance was not altered.")
    end

    new_def_LCCs = new_def.lifeCycleCosts
    if new_def_LCCs.empty?
      if material_and_installation_cost.abs + demolition_cost.abs + om_cost.abs != 0
        runner.registerWarning("'#{new_def.name}' had no life cycle cost objects. No cost was added for it.")
      end
    else
      new_def_LCCs.each do |new_def_LCC|
        if new_def_LCC.category == 'Construction'
          new_def_LCC.setCost(new_def_LCC.cost * (1 + material_and_installation_cost / 100))
          new_def_LCC.setYearsFromStart(years_until_costs_start) # just uses argument value, does not need existing value
          new_def_LCC.setRepeatPeriodYears(expected_life) # just uses argument value, does not need existing value
        elsif new_def_LCC.category == 'Salvage'
          new_def_LCC.setCost(new_def_LCC.cost * (1 + demolition_cost / 100))
          new_def_LCC.setYearsFromStart(years_until_costs_start + expected_life) # just uses argument value, does not need existing value
          new_def_LCC.setRepeatPeriodYears(expected_life) # just uses argument value, does not need existing value
        elsif new_def_LCC.category == 'Maintenance'
          new_def_LCC.setCost(new_def_LCC.cost * (1 + om_cost / 100))
          new_def_LCC.setRepeatPeriodYears(om_frequency) # just uses argument value, does not need existing value
        end

        # reset any month durations
        new_def_LCC.resetRepeatPeriodMonths
        new_def_LCC.resetMonthsFromStart
      end

    end
  end

  # make a hash of old defs and new lights and luminaire defs
  cloned_lights_defs = {}
  cloned_luminaire_defs = {}

  # loop through space types
  space_types.each do |space_type|
    next if space_type.spaces.size <= 0
    space_type_lights = space_type.lights
    space_type_lights.each do |space_type_light|
      # clone def if it has not already been cloned
      exist_def = space_type_light.lightsDefinition
      if cloned_lights_defs.any? { |k, v| k.to_s == exist_def.name.to_s }
        new_def = cloned_lights_defs[exist_def.name.to_s]
      else
        # clone rename and add to hash
        new_def = exist_def.clone(model)
        new_def_name = new_def.setName("#{exist_def.name} - #{lighting_power_reduction_percent} percent reduction")
        cloned_lights_defs[exist_def.name.to_s] = new_def
        new_def = new_def.to_LightsDefinition.get

        # add demo cost of object being removed to one counter for one time demo cost for baseline objects
        demo_costs_of_baseline_objects += add_to_baseline_demo_cost_counter(exist_def, demo_cost_initial_const)

        # call def to alter performance and life cycle costs
        alter_performance_and_lcc(new_def, lighting_power_reduction_percent, material_and_installation_cost, demolition_cost, om_cost, years_until_costs_start, expected_life, om_frequency, runner)

      end

      # link instance with clone and rename
      updated_instance = space_type_light.setLightsDefinition(new_def.to_LightsDefinition.get)
      updated_instance_name = space_type_light.setName("#{space_type_light.name} #{lighting_power_reduction_percent} percent reduction")
    end

    space_type_luminaires = space_type.luminaires
    space_type_luminaires.each do |space_type_luminaire|
      # clone def if it has not already been cloned
      exist_def = space_type_luminaire.luminaireDefinition
      if cloned_luminaire_defs.any? { |k, v| k.to_s == exist_def.name }
        new_def = cloned_luminaire_defs[exist_def.name]
      else
        # clone rename and add to hash
        new_def = exist_def.clone(model)
        new_def_name = new_def.setName("#{new_def.name} - #{lighting_power_reduction_percent} percent reduction")
        cloned_luminaire_defs[exist_def.name] = new_def
        new_def = new_def.to_LightsDefinition.get

        # add demo cost of object being removed to one counter for one time demo cost for baseline objects
        demo_costs_of_baseline_objects += add_to_baseline_demo_cost_counter(exist_def, demo_cost_initial_const)

        # call def to alter performance and life cycle costs
        alter_performance_and_lcc(new_def, lighting_power_reduction_percent, material_and_installation_cost, demolition_cost, om_cost, years_until_costs_start, expected_life, om_frequency, runner)

      end

      # link instance with clone and rename
      updated_instance = space_type_light.setLightsDefinition(new_def.to_LightsDefinition.get)
      updated_instance_name = space_type_light.setName("#{space_type_light.name} #{lighting_power_reduction_percent} percent reduction")
    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_lights = space.lights
    space_lights.each do |space_light|
      # clone def if it has not already been cloned
      exist_def = space_light.lightsDefinition
      if cloned_lights_defs.any? { |k, v| k.to_s == exist_def.name.to_s }
        new_def = cloned_lights_defs[exist_def.name.to_s]
      else
        # clone rename and add to hash
        new_def = exist_def.clone(model)
        new_def_name = new_def.setName("#{new_def.name} - #{lighting_power_reduction_percent} percent reduction")
        cloned_lights_defs[exist_def.name.to_s] = new_def
        new_def = new_def.to_LightsDefinition.get

        # add demo cost of object being removed to one counter for one time demo cost for baseline objects
        demo_costs_of_baseline_objects += add_to_baseline_demo_cost_counter(exist_def, demo_cost_initial_const)

        # call def to alter performance and life cycle costs
        alter_performance_and_lcc(new_def, lighting_power_reduction_percent, material_and_installation_cost, demolition_cost, om_cost, years_until_costs_start, expected_life, om_frequency, runner)

      end

      # link instance with clone and rename
      updated_instance = space_light.setLightsDefinition(new_def.to_LightsDefinition.get)
      updated_instance_name = space_light.setName("#{space_light.name} #{lighting_power_reduction_percent} percent reduction")
    end

    space_luminaires = space.luminaires
    space_luminaires.each do |space_luminaire|
      # clone def if it has not already been cloned
      exist_def = space_luminaire.luminaireDefinition
      if cloned_luminaire_defs.any? { |k, v| k.to_s == exist_def.name }
        new_def = cloned_luminaire_defs[exist_def.name]
      else
        # clone rename and add to hash
        new_def = exist_def.clone(model)
        new_def_name = new_def.setName("#{new_def.name} - #{lighting_power_reduction_percent} percent reduction")
        cloned_luminaire_defs[exist_def.name] = new_def
        new_def = new_def.to_LightsDefinition.get

        # add demo cost of object being removed to one counter for one time demo cost for baseline objects
        demo_costs_of_baseline_objects += add_to_baseline_demo_cost_counter(exist_def, demo_cost_initial_const)

        # call def to alter performance and life cycle costs
        alter_performance_and_lcc(new_def, lighting_power_reduction_percent, material_and_installation_cost, demolition_cost, om_cost, years_until_costs_start, expected_life, om_frequency, runner)

      end

      # link instance with clone and rename
      updated_instance = space_light.setLightsDefinition(new_def)
      updated_instance_name = space_light.setName("#{space_light.name} - #{lighting_power_reduction_percent} percent reduction")
    end
  end

  if cloned_lights_defs.empty? && cloned_luminaire_defs.empty?
    runner.registerAsNotApplicable('No lighting or luminaire objects were found in the specified space type(s).')
  end

  # get final light and luminaire costs to use in final condition
  yr0_capital_totalCosts += get_total_costs_for_objects(model.getLightsDefinitions)
  yr0_capital_totalCosts += get_total_costs_for_objects(model.getLuminaireDefinitions)

  # add one time demo cost of removed lights and luminaires if appropriate
  if demo_cost_initial_const == true
    building = model.getBuilding
    lcc_baseline_demo = OpenStudio::Model::LifeCycleCost.createLifeCycleCost('LCC_baseline_demo', building, demo_costs_of_baseline_objects, 'CostPerEach', 'Salvage', 0, years_until_costs_start).get # using 0 for repeat period since one time cost.
    runner.registerInfo("Adding one time cost of $#{neat_numbers(lcc_baseline_demo.totalCost, 0)} related to demolition of baseline objects.")

    # if demo occurs on year 0 then add to initial capital cost counter
    if lcc_baseline_demo.yearsFromStart == 0
      yr0_capital_totalCosts += lcc_baseline_demo.totalCost
    end
  end

  # report final condition
  final_building = model.getBuilding
  final_building_lighting_power = final_building.lightingPower

  # method should always return double but this is work around for when it is nan because of 0 floor area
  if building.floorArea > 0.0
    final_building_LPD = unit_helper(final_building.lightingPowerPerFloorArea, 'W/m^2', 'W/ft^2')
    runner.registerFinalCondition("The model's final final lighting power was  #{neat_numbers(final_building_lighting_power, 0)} watts, a lighting power density of #{neat_numbers(final_building_LPD)} w/ft^2. Initial capital costs associated with the improvements are $#{neat_numbers(yr0_capital_totalCosts, 0)}.")
  else
    runner.registerFinalCondition("The model's final final lighting power was  #{neat_numbers(final_building_lighting_power, 0)} wattsBuilding Area is not greater than 0 so an LPD can't be calculated.")
  end

  return true
end

#unit_helper(number, from_unit_string, to_unit_string) ⇒ Object

helper to make it easier to do unit conversions on the fly. The definition be called through this measure.



216
217
218
# File 'lib/measures/ReduceLightingLoadsByPercentage/measure.rb', line 216

def unit_helper(number, from_unit_string, to_unit_string)
  converted_number = OpenStudio.convert(OpenStudio::Quantity.new(number, OpenStudio.createUnit(from_unit_string).get), OpenStudio.createUnit(to_unit_string).get).get.value
end