Class: AddEVLoad

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

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

Note: If a DC Fast Charger at the PSN site is the intended option, the charging behavior and control choices are ignored. Thus far, there is one load profile for a DC fast charger; not different ones for different bldgs. define the arguments that the user will input



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

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

  # Make an argument for the charging flexibility options (workplace charging only).
  charge_delay_chs = OpenStudio::StringVector.new
  charge_delay_chs << 'Max Delay'
  charge_delay_chs << 'Min Delay'
  charge_delay_chs << 'Min Power'

  delay_type = OpenStudio::Measure::OSArgument.makeChoiceArgument('delay_type', charge_delay_chs, true)
  delay_type.setDisplayName('Charging Flexibility Option')
  delay_type.setDefaultValue('Min Delay')
  delay_type.setDescription('Represents charging flexibility scenarios applied to workplace charging. Min Delay indicates EVs begin charging immediately upon arriving at work, Max Delay indicates EVs are plugged in immediately but do not begin charging until necessary and Min Power indicates EVs are charged at minimum rate over the parking event.')
  args << delay_type

  # Make an argument for the consumer charging behavior parameter.
  consumer_charge_chs = OpenStudio::StringVector.new
  consumer_charge_chs << 'Business as Usual'
  consumer_charge_chs << 'Free Workplace Charging at Project Site'
  consumer_charge_chs << 'Free Workplace Charging Across Metro Area'

  charge_behavior = OpenStudio::Measure::OSArgument.makeChoiceArgument('charge_behavior', consumer_charge_chs, true)
  charge_behavior.setDisplayName('Consumer Charging Behavior')
  charge_behavior.setDefaultValue('Business as Usual')
  charge_behavior.setDescription('Describes different scenarios of EV Charging. Business as Usual represents home dominant charging behavior where the majority of the electrical energy consumed by EV charging is during evening hours and overnight. Free Workplace Charging at Project Site indicates that the peak power draw from EV charging on weekdays occurs during morning hours, due to EV charging at workplaces. Overnight residential charging remains a significant share of the total electricity use for EV charging. Free Workplace Charging Across Metro Area reduces the Home EV charging relative to the Free Workplace Charging at Project Site scenario, for people who work elsewhere and can charge their vehicles for free at those workplaces.')
  args << charge_behavior

  # Make a vector for the charging station type argument.
  chg_station_type_chs = OpenStudio::StringVector.new
  chg_station_type_chs << 'Typical Home'
  chg_station_type_chs << 'Typical Public'
  chg_station_type_chs << 'Typical Work'

  # Make an argument for charging station type.
  chg_station_type = OpenStudio::Measure::OSArgument.makeChoiceArgument('chg_station_type', chg_station_type_chs, true)
  chg_station_type.setDisplayName('Charging Station Type')
  chg_station_type.setDefaultValue('Typical Public')
  args << chg_station_type

  # Make an argument for the % of vehicles parked at the building that are EVs.
  ev_percent = OpenStudio::Measure::OSArgument.makeDoubleArgument('ev_percent', true)
  ev_percent.setDisplayName('Percent of Vehicles Parked at Building That Are EVs')
  ev_percent.setDefaultValue(100)
  ev_percent.setDescription('Denotes percentage of vehicles between 0 to 100 that are electric on site.')
  args << ev_percent

  # Make an argument for using occupancy from OpenStudio Model.
  ev_use_model_occupancy = OpenStudio::Measure::OSArgument.makeBoolArgument('ev_use_model_occupancy', true)
  ev_use_model_occupancy.setDisplayName('Use occupancy from OpenStudio Model to determine number of electric vehicles')
  ev_use_model_occupancy.setDefaultValue(true)
  args << ev_use_model_occupancy

  return args
end

#descriptionObject

human readable description



18
19
20
# File 'lib/measures/add_ev_load/measure.rb', line 18

def description
  return 'This measure adds a load associated with charging of electric vehicles (EVs) to a building in URBANopt. EV load profiles were generated in EVI-Pro for specific building types. This measure allows running of customized load profiles for buildings in the Pena Station Next project, and also for generating typical charging load profiles based on the location type (home, public, or office).'
end

#modeler_descriptionObject

human readable description of modeling approach



23
24
25
# File 'lib/measures/add_ev_load/measure.rb', line 23

def modeler_description
  return 'This measure adds an EV charging load to a building model. Load profiles for EV charging were generated in EVI-Pro. Different options are available for charging control type and charging behavior.'
end

#nameObject

human readable name



13
14
15
# File 'lib/measures/add_ev_load/measure.rb', line 13

def name
  return 'Add_EV_Load'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



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

def run(model, runner, user_arguments)
  super(model, runner, user_arguments)

  # Assign the user arguments to variables.
  delay_type = runner.getStringArgumentValue('delay_type', user_arguments)
  charge_behavior = runner.getStringArgumentValue('charge_behavior', user_arguments)
  chg_station_type = runner.getStringArgumentValue('chg_station_type', user_arguments)
  ev_percent = runner.getDoubleArgumentValue('ev_percent', user_arguments)
  ev_use_model_occupancy = runner.getBoolArgumentValue('ev_use_model_occupancy', user_arguments)

  # use the built-in error checking
  if !runner.validateUserArguments(arguments(model), user_arguments)
    return false
  end

  if ev_percent < 0 || ev_percent > 100
    runner.registerError('Percent of vehicles on site that are electric is outside of acceptable bounds. Please choose a value between 0 and 100.')
    return false
  end

  # Set file name based on arguments selected and then choose the DOW within schedule selection.
  # Set key based on user-selected charging behavior.
  if charge_behavior == 'Business as Usual'
    charge_key = 1
    runner.registerInfo("charge key = #{charge_key}")
  elsif charge_behavior == 'Free Workplace Charging at Project Site'
    charge_key = 2
    runner.registerInfo("charge key = #{charge_key}")
  else
    charge_key = 3
    runner.registerInfo("charge key = #{charge_key}")
  end

  # Set key based on user-selected charging flexibility.
  if delay_type == 'Min Delay'
    flex_key = 1
    runner.registerInfo("flex key = #{flex_key}")
  elsif delay_type == 'Max Delay'
    flex_key = 2
    runner.registerInfo("flex key = #{flex_key}")
  else
    flex_key = 3
    runner.registerInfo("flex key = #{flex_key}")
  end

  file_path = "#{__dir__}/resources/"

  # Sets key based on charging station type, for general charging load profiles. Will use this to average columns appropriately.
  if chg_station_type == 'Typical Home'
    chg_station_key = 1
    runner.registerInfo("charge station type = #{chg_station_type}")
    runner.registerInfo("charge station key = #{chg_station_key}")
    # Assumed occupancy density is the typical occupancy density for charging station type determined by using a weighted
    # average of building type and associated occupancy density 
    assumed_occupancy_density = 0.003
    runner.registerInfo("assumed occupancy = #{assumed_occupancy_density}")
  elsif chg_station_type == 'Typical Work'
    chg_station_key = 2
    runner.registerInfo("charge station type = #{chg_station_type}")
    runner.registerInfo("charge station key = #{chg_station_key}")
    assumed_occupancy_density = 0.005
    runner.registerInfo("assumed occupancy = #{assumed_occupancy_density}")
  elsif chg_station_type == 'Typical Public'
    chg_station_key = 3
    runner.registerInfo("charge station type = #{chg_station_type}")
    runner.registerInfo("charge station key = #{chg_station_key}")
    assumed_occupancy_density = 0.0226
    runner.registerInfo("assumed occupancy = #{assumed_occupancy_density}")
  end

  # Creating a schedule:ruleset
  ev_sch = OpenStudio::Model::ScheduleRuleset.new(model)
  ev_sch.setName('EV Charging Power Draw')

  # Create a schedule:ruleset for DC fast charging.
  ev_sch_fast = OpenStudio::Model::ScheduleRuleset.new(model)
  ev_sch_fast.setName('EV DC Fast Charging Power Draw')

  # Create arrays of desired values
  public_indices = [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 52, 53, 54, 57, 58, 60, 61, 62, 63, 64, 65, 81, 99, 100, 102]
  work_indices = [7, 19, 20, 27, 28, 29, 30, 31, 32, 36, 37, 42, 43, 44, 46, 50, 51, 55, 69, 70, 71, 86, 88, 91, 92, 93]
  home_indices = [15, 16, 17, 18, 21, 22, 23, 24, 25, 26, 33, 34, 35, 38, 39, 40, 41, 45, 47, 48, 49, 56, 59, 66, 67, 68, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 85, 87, 89, 90, 94, 95, 96, 97, 98, 101]

  # The load profiles referenced were generated based on an assumption of 50% of passenger vehicles being EVs.
  assumed_percent = 50

  # Read in the three necessary files, for the typical PSN case (all PSN bldgs, including fast chargers).
  # Read in wkday load profiles.
  dow_key = 1
  file_name = "chg#{charge_key}_dow#{dow_key}_flex#{flex_key}.csv"
  wkday_load = CSV.read("#{file_path}/#{file_name}", headers: false, converters: :all)
  wkday_load = wkday_load.to_a # Convert to an array.
  wkday_load = wkday_load.transpose
  # Read in Saturday load profiles.
  dow_key = 2
  file_name = "chg#{charge_key}_dow#{dow_key}_flex#{flex_key}.csv"
  sat_load = CSV.read("#{file_path}/#{file_name}", headers: false, converters: :all)
  sat_load = sat_load.to_a # Convert to an array.
  sat_load = sat_load.transpose
  # Read in Sunday load profiles.
  dow_key = 3
  file_name = "chg#{charge_key}_dow#{dow_key}_flex#{flex_key}.csv"
  sun_load = CSV.read("#{file_path}/#{file_name}", headers: false, converters: :all)
  sun_load = sun_load.to_a # Convert to an array.
  sun_load = sun_load.transpose

  # For non-PSN analysis, select which load profile is needed based on the charging station key.

  if chg_station_key == 1
    indices = home_indices
  elsif chg_station_key == 2
    indices = work_indices
  elsif chg_station_key == 3
    indices = public_indices
  end

  space_type = model.getSpaceTypes[0]
  model_occupancy = space_type.people.size
  floor_area = space_type.floorArea
  model_occupancy_density = space_type.getPeoplePerFloorArea(floor_area)
  model_occupancy_density = model_occupancy_density/10.76 # Convert to people per ft2

  # Populate the average weekday load for non PSN case. The load profiles used in this case are averaged based on the selected charging station type,(given the selected charging flexibility option and charging behavior option), and scaled for the percent of vehicles that are EVs.
  if chg_station_type != 'Pena Station Next Analysis' && chg_station_type != 'Pena Station Next Analysis--DC Fast Charger'
    wkday_load_sel = wkday_load.values_at(*indices)
    avg_load_wkday = []
    wkday_load_sel = wkday_load_sel.transpose
    if ev_use_model_occupancy
      runner.registerInfo("model occupancy density = #{model_occupancy_density}")
      for i in 0..wkday_load[0].length - 1
        avg_load_wkday[i] = ((wkday_load_sel[i].reduce(0, :+) / wkday_load_sel[i].length) * ev_percent/assumed_percent) * (model_occupancy_density/assumed_occupancy_density) # Scale profiles generated from 50% EV scenario by occupancy of OpenStudio model (number of vehicles is assumed to be the same as occupancy of the building).
      end
    else
      for i in 0..wkday_load[0].length - 1
        avg_load_wkday[i] = (wkday_load_sel[i].reduce(0, :+) / wkday_load_sel[i].length) * ev_percent / assumed_percent # Scale profiles generated from 50% EV scenario by % of vehicles that are EVs.
      end
    end

    wkday_max_load = avg_load_wkday.max

    # Populate the average Saturday load.
    sat_load_sel = sat_load.values_at(*indices)
    avg_load_sat = []
    sat_load_sel = sat_load_sel.transpose
    if ev_use_model_occupancy
      for i in 0..sat_load[0].length - 1
        avg_load_sat[i] = ((sat_load_sel[i].reduce(0, :+) / sat_load_sel[i].length) * ev_percent / assumed_percent) * (model_occupancy_density/assumed_occupancy_density) # Scale profiles generated from 50% EV scenario by occupancy of OpenStudio model and apply ev_percent (number of vehicles is assumed to be the same as occupancy of the building).
      end
    else
      for i in 0..sat_load[0].length - 1
        avg_load_sat[i] = (sat_load_sel[i].reduce(0, :+) / sat_load_sel[i].length) * ev_percent / assumed_percent # Scale profiles generated from 50% EV scenario by % of vehicles that are EVs.
      end
    end

    sat_max_load = avg_load_sat.max

    # Populate the average Sunday load.
    sun_load_sel = sun_load.values_at(*indices)
    avg_load_sun = []
    sun_load_sel = sun_load_sel.transpose
    if ev_use_model_occupancy
      for i in 0..sun_load[0].length - 1
        avg_load_sun[i] = ((sun_load_sel[i].reduce(0, :+) / sun_load_sel[i].length) * ev_percent / assumed_percent) * (model_occupancy_density/assumed_occupancy_density) # Scale profiles generated from 50% EV scenario by occupancy of OpenStudio model and apply ev_percent (number of vehicles is assumed to be the same as occupancy of the building).
      end
    else
      for i in 0..sun_load[0].length - 1
        avg_load_sun[i] = (sun_load_sel[i].reduce(0, :+) / sun_load_sel[i].length) * ev_percent / assumed_percent # Scale profiles generated from 50% EV scenario by % of vehicles that are EVs.
      end
    end

    sun_max_load = avg_load_sun.max

    # Calculate the overall maximum load
    max_load = [wkday_max_load, sat_max_load, sun_max_load].max

    # Normalize each load profile based on the overall maximum load.

    avg_load_wkday_norm = avg_load_wkday.map { |value| value / max_load }
    avg_load_sat_norm = avg_load_sat.map { |value| value / max_load }
    avg_load_sun_norm = avg_load_sun.map { |value| value / max_load }

  end

  # Create schedules for regular EV charging.
  # Uses Sunday schedule for winter design day.
  if chg_station_type != 'Pena Station Next Analysis--DC Fast Charger'
    ev_sch_winter = OpenStudio::Model::ScheduleDay.new(model)
    ev_sch.setWinterDesignDaySchedule(ev_sch_winter)
    ev_sch.winterDesignDaySchedule.setName('EV Charging Winter Design Day')
    # Loop through all the values and add to schedule
    avg_load_sun_norm.each_with_index do |value, i| # Reading in the data from the array created from the csv file, with the values normalized to maximum power draw.
      time = OpenStudio::Time.new(0, 0, (i + 1) * 15, 0) # OpenStudio::Time.new(day,hr of day, minute of hr, seconds of hr?)
      ev_sch.winterDesignDaySchedule.addValue(time, value)
    end
    runner.registerInfo(" WDD schedule = #{avg_load_wkday_norm}")
    # ...repeat for all 24 hrs (or whatever granularity)

    # Summer design day. Uses weekday schedule for summer design day.
    ev_sch_summer = OpenStudio::Model::ScheduleDay.new(model)
    ev_sch.setSummerDesignDaySchedule(ev_sch_summer)
    ev_sch.summerDesignDaySchedule.setName('EV Charging Summer Design Day')
    # Loop through all the values and add to schedule
    avg_load_wkday_norm.each_with_index do |value, i|
      time = OpenStudio::Time.new(0, 0, (i + 1) * 15, 0) # OpenStudio::Time.new(day,hr of day, minute of hr, seconds of hr?)
      ev_sch.summerDesignDaySchedule.addValue(time, value)
    end

    # Default day (use this for weekdays)
    ev_sch.defaultDaySchedule.setName('EV Charging Default')
    # Loop through all the values and add to schedule
    avg_load_wkday_norm.each_with_index do |value, i|
      time = OpenStudio::Time.new(0, 0, (i + 1) * 15, 0) # OpenStudio::Time.new(day,hr of day, minute of hr, seconds of hr?)
      ev_sch.defaultDaySchedule.addValue(time, value)
    end

    # Saturday
    ev_sch_sat_rule = OpenStudio::Model::ScheduleRule.new(ev_sch)
    ev_sch_sat_rule.setName('ev_sch_sat_rule')
    ev_sch_sat_rule.setApplySaturday(true)
    ev_sch_sat = ev_sch_sat_rule.daySchedule
    ev_sch_sat.setName('EV Charging Sat')
    # Loop through all the values and add to schedule
    avg_load_sat_norm.each_with_index do |value, i|
      time = OpenStudio::Time.new(0, 0, (i + 1) * 15, 0) # OpenStudio::Time.new(day,hr of day, minute of hr, seconds of hr?)
      ev_sch_sat.addValue(time, value)
    end

    # Sunday
    ev_sch_sun_rule = OpenStudio::Model::ScheduleRule.new(ev_sch)
    ev_sch_sun_rule.setName('ev_sch_sun_rule')
    ev_sch_sun_rule.setApplySunday(true)
    ev_sch_sun = ev_sch_sun_rule.daySchedule
    ev_sch_sun.setName('EV Charging Sun')
    # Loop through all the values and add to schedule
    avg_load_sun_norm.each_with_index do |value, i|
      time = OpenStudio::Time.new(0, 0, (i + 1) * 15, 0)
      ev_sch_sun.addValue(time, value)
    end
  end

  if chg_station_type != 'Pena Station Next Analysis--DC Fast Charger'

    # Adding an EV charger definition and instance for the regular EV charging.
    ev_charger_def = OpenStudio::Model::ExteriorFuelEquipmentDefinition.new(model)
    ev_charger_level = max_load * 1000 # Converting from kW to watts
    ev_charger_def.setName("#{ev_charger_level} w EV Charging Definition")
    ev_charger_def.setDesignLevel(ev_charger_level)

    # creating EV charger object for the regular EV charging.
    ev_charger = OpenStudio::Model::ExteriorFuelEquipment.new(ev_charger_def, ev_sch)
    ev_charger.setName("#{ev_charger_level} w EV Charger")
    ev_charger.setFuelType('Electricity')
    ev_charger.setEndUseSubcategory('Electric Vehicles')
    runner.registerInfo("multiplier (kW) = #{max_load}}")
  end
  return true
end