Class: ZEDGK12InteriorLighting

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

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

define the arguments that the user will input



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/measures/zedgk_12_interior_lighting/measure.rb', line 33

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

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

  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



28
29
30
# File 'lib/measures/zedgk_12_interior_lighting/measure.rb', line 28

def name
  return 'ZEDG K12 Interior Lighting'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



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

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

  # prepare rule hash
  rules = [] # target, space type, LPD_ip

  # currently only target is lower energy, but setup hash this way so could add baseline in future
  # climate zone doesn't impact values for LPD in ZEDG

  # populate rules hash
  rules << ['LowEnergy', 'PrimarySchool', 'Auditorium', 0.5] # no change
  rules << ['LowEnergy', 'PrimarySchool', 'Cafeteria', 0.4] # changed from 0.7 to 0.4
  rules << ['LowEnergy', 'PrimarySchool', 'Classroom', 0.4] # changed from 0.8 to 0.4
  rules << ['LowEnergy', 'PrimarySchool', 'Corridor', 0.4] # no change
  rules << ['LowEnergy', 'PrimarySchool', 'Gym', 0.5] # changed from 1.0 to 0.5
  rules << ['LowEnergy', 'PrimarySchool', 'Kitchen', 0.6] # changed from 0.8 to 0.6 (first pass zedg was 0.45)
  rules << ['LowEnergy', 'PrimarySchool', 'Library', 0.4] # changed from 0.8 to 0.4
  rules << ['LowEnergy', 'PrimarySchool', 'Lobby', 0.7] # changed from 0.7 to 0.7 (first pass zedg was 0.5)
  rules << ['LowEnergy', 'PrimarySchool', 'Mechanical', 0.4] # no change
  rules << ['LowEnergy', 'PrimarySchool', 'Office', 0.5] # changed from 0.6 to 0.5
  rules << ['LowEnergy', 'PrimarySchool', 'Restroom', 0.4] # changed from 0.5 to 0.4
  rules << ['LowEnergy', 'SecondarySchool', 'Auditorium', 0.5] # no change
  rules << ['LowEnergy', 'SecondarySchool', 'Cafeteria', 0.4] # changed from 0.7 to 0.4
  rules << ['LowEnergy', 'SecondarySchool', 'Classroom', 0.4] # changed from 0.8 to 0.4
  rules << ['LowEnergy', 'SecondarySchool', 'Corridor', 0.4] # no change
  rules << ['LowEnergy', 'SecondarySchool', 'Gym', 0.8] # changed from 1.0 to 0.75 then to 0.8
  rules << ['LowEnergy', 'SecondarySchool', 'Kitchen', 0.6] # changed from 0.8 to 0.6 (first pass zedg was 0.45)
  rules << ['LowEnergy', 'SecondarySchool', 'Library', 0.5] # changed from 0.8 to 0.5
  rules << ['LowEnergy', 'SecondarySchool', 'Lobby', 0.7] # changed from 0.7 to 0.7 (first pass zedg was 0.5)
  rules << ['LowEnergy', 'SecondarySchool', 'Mechanical', 0.4] # no change
  rules << ['LowEnergy', 'SecondarySchool', 'Office', 0.5] # changed from 0.6 to 0.5
  rules << ['LowEnergy', 'SecondarySchool', 'Restroom', 0.4] # changed from 0.5 to 0.4

  # make rule hash for cleaner code
  rulesHash = {}
  rules.each do |rule|
    rulesHash["#{rule[0]} #{rule[1]} #{rule[2]}"] = rule[3]
  end

  # calculate building LPD
  building = model.getBuilding
  initialLpdDisplay = OsLib_HelperMethods.neatConvertWithUnitDisplay(building.lightingPowerPerFloorArea, 'W/m^2', 'W/ft^2', 2) # can add choices for unit display

  # calculate initial LPD to use later
  lightDefs = model.getLightsDefinitions
  initialCostForLights = OsLib_HelperMethods.getTotalCostForObjects(lightDefs)

  # reporting initial condition of model
  runner.registerInitialCondition("The building started with an LPD #{initialLpdDisplay}.")

  # global variables for costs
  expected_life = 25
  years_until_costs_start = 0

  # loop through space types
  model.getSpaceTypes.each do |spaceType|
    # skip of not used in model
    next if spaceType.spaces.empty?

    # confirm recognized spaceType standards information
    standardsInfo = OsLib_HelperMethods.getSpaceTypeStandardsInformation([spaceType])
    if rulesHash["LowEnergy #{standardsInfo[spaceType][0]} #{standardsInfo[spaceType][1]}"].nil?
      runner.registerInfo("Couldn't map #{spaceType.name} to a recognized space type used in the ZEDG. Lighting levels for this SpaceType will not be altered.")
      next
    end

    # get initial LPD for space type
    initialSpaceTypeLpd = OsLib_LightingAndEquipment.getLpdForSpaceArray(spaceType.spaces)

    # get target LPD
    targetLPD = OpenStudio.convert(rulesHash["LowEnergy #{standardsInfo[spaceType][0]} #{standardsInfo[spaceType][1]}"], 'W/ft^2', 'W/m^2').to_f

    # harvest any hard assigned schedules along with lighting power of light. If there is no default the use the largest one of these
    oldLights = []
    spaceType.lights.each do |light|
      oldLights << light
    end

    # remove lights associated directly with spaces
    spaceLightRemoved = false
    spaceLightsSchedules = []
    spaceType.spaces.each do |space|
      lights = space.lights
      lights.each do |light|
        oldLights << light
        light.remove
        spaceLightRemoved = true
      end
    end

    # in future versions will use (lighting power)weighted average schedule merge for new schedule
    oldScheduleHash = OsLib_LightingAndEquipment.createHashOfInternalLoadWithHardAssignedSchedules(oldLights)
    oldLights.size == oldScheduleHash.size ? (defaultUsedAtLeastOnce = false) : (defaultUsedAtLeastOnce = true)

    # add new lights
    spaceType.setLightingPowerPerFloorArea(targetLPD) # not sure if this is instance or def?
    newLight = spaceType.lights[0]
    newLightDef = newLight.lightsDefinition
    newLightDef.setName("ZEDG K12 - #{standardsInfo[spaceType][1]} lights")

    # add cost to lights
    lcc_lights = OpenStudio::Model::LifeCycleCost.createLifeCycleCost("lcc_#{newLightDef.name}", newLightDef, material_cost_ip, 'CostPerArea', 'Construction', expected_life, years_until_costs_start)

    # report change
    if !spaceType.lightingPowerPerFloorArea.empty?
      oldLpdDisplay = OsLib_HelperMethods.neatConvertWithUnitDisplay(initialSpaceTypeLpd, 'W/m^2', 'W/ft^2', 1)
      newLpdDisplay = OsLib_HelperMethods.neatConvertWithUnitDisplay(spaceType.lightingPowerPerFloorArea.get, 'W/m^2', 'W/ft^2', 1) # can add choices for unit display
      runner.registerInfo("Changing LPD of #{spaceType.name} space type to #{newLpdDisplay} from #{oldLpdDisplay}")
    else
      runner.registerInfo("For some reason no LPD was set for #{spaceType.name} space type.")
    end

    if spaceLightRemoved
      runner.registerInfo("One more more lights directly assigned to spaces using #{spaceType.name} were removed. This is to limit lighting to what is added by this measure.")
    end

    # adjust schedules as necessary only hard assign if the default schedule was never used
    if (defaultUsedAtLeastOnce == false) && !oldLights.empty?
      # retrieve hard assigned schedule
      newLight.setSchedule(oldScheduleHash.sort.reverse[0][0])
    else
      if newLight.schedule.empty?
        runner.registerWarning("Didn't find an inherited or hard assigned schedule for lights in #{spaceType.name} or underlying spaces. Please add a schedule before running a simulation.")
      end
    end
  end

  # warn if some spaces didn't have lights altered at all (this would apply to spaces with space types not mapped)
  model.getSpaces.each do |space|
    next if !space.spaceType.empty?
    runner.registerWarning("#{space.name} doesn't have a space type. Couldn't identify target LPD without a space type. Lights were not altered.")
  end

  # calculate final building LPD
  building = model.getBuilding
  finalLpdDisplay = OsLib_HelperMethods.neatConvertWithUnitDisplay(building.lightingPowerPerFloorArea, 'W/m^2', 'W/ft^2', 2) # can add choices for unit display

  # calculate final LPD to use later
  lightDefs = model.getLightsDefinitions
  finalCostForLights = OsLib_HelperMethods.getTotalCostForObjects(lightDefs)

  # change in cost
  costRelatedToMeasure = finalCostForLights - initialCostForLights
  costRelatedToMeasureDisplay = OsLib_HelperMethods.neatConvertWithUnitDisplay(costRelatedToMeasure, '$', '$', 0, true, false, false, false) # bools (prefix,suffix,space,parentheses)

  # reporting final condition of model
  if costRelatedToMeasure > 0
    runner.registerFinalCondition("The resulting building has an LPD #{finalLpdDisplay}. Initial capital cost related to this measure is #{costRelatedToMeasureDisplay}.")
  else
    runner.registerFinalCondition("The resulting building has an LPD #{finalLpdDisplay}.")
  end

  return true
end