-
Notifications
You must be signed in to change notification settings - Fork 5
/
battery_electric_vehicle.py
414 lines (344 loc) · 14.6 KB
/
battery_electric_vehicle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
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
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
from dataclasses import field
from typing import Sequence, Union
from oemof.solph import Investment
from oemof.solph._plumbing import sequence as solph_sequence
from oemof.solph.buses import Bus
from oemof.solph.components import Converter, GenericStorage, Sink
from oemof.solph.flows import Flow
from oemof.tabular._facade import Facade, dataclass_facade
@dataclass_facade
class Bev(GenericStorage, Facade):
r"""A fleet of Battery electric vehicles with controlled/flexible charging,
(G2V), vehicle-to-grid (V2G) or uncontrolled/fixed charging (inflex).
This facade consists of mulitple oemof.solph components:
- a GenericStorage as storage unit
- a Bus as internal bus
- a Sink to model the drive consumption (if no mobility bus is
given)
- a Converter to convert the energy to the electricity bus (optional V2G)
- a Converter to convert the energy to e.g. pkm (optional if mobility bus
is given)
Charging and discharging capacity is assumed to be equal.
Multiple fleets can be modelled and connected to a common bus
(mobility_bus) to apply one demand for all modelled fleets.
Parameters
----------
electricity_bus: oemof.solph.Bus
The electricity bus where the BEV is connected to.
mobility_bus: oemof.solph.Bus
A bus which is used to connect a common demand for multiple BEV
instances (optional).
charging_power : int
The total charging/discharging power of the fleet (e.g. in MW).
charging_potential: int
Maximum charging potential in investment optimization.
availability : float, array of float
Availability of the fleet at the charging stations (e.g. 0.8).
storage_capacity: int
The total storage capacity of the fleet (e.g. in MWh).
initial_storage_capacity: float
The relative storage content in the timestep before the first
time step of optimization (between 0 and 1).
Note: When investment mode is used in a multi-period model,
`initial_storage_level` is not supported.
Storage output is forced to zero until the storage unit is invested in.
min_storage_level : array of float
Relative profile of minimum storage level (min SOC).The normed minimum
storage content as fraction of the storage capacity or the capacity
that has been invested into (between 0 and 1).
max_storage_level : array of float
Relative profile of maximum storage level (max SOC).
drive_power: int
The total driving capacity of the fleet (e.g. in MW) if no mobility_bus
is connected.
drive_consumption : array of float
Relative profile of drive consumption of the fleet
v2g: bool
If True, Vehicle-to-grid option is enabled, default: False
loss_rate: float
The relative loss/self discharge of the storage content per time unit,
default: 0
efficiency_mob_g2v: float
Efficiency at the charging station (grid-to-vehicle), default: 1
efficiency_mob_v2g: float
Efficiency at the charging station (vehicle-to-grid), default: 1
efficiency_sto_in: float
Efficiency of charging the batteries, default: 1
efficiency_sto_out: float
Efficiency of discharging the batteries, default: 1
efficiency_mob_electrical: float
Efficiency of the electrical drive train per 100 km (optional).
default: 1
pkm_conversion_rate: float
Conversion rate from energy to e.g. pkm if mobility_bus passed
(optional) default: 1
expandable: bool
If True, the fleet is expandable, default: False
Charging_power and storage_capacity are then interpreted as existing
capacities at the first investment period.
lifetime: int
Total lifetime of the fleet in years.
age: int
Age of the existing fleet at the first investment period in years.
invest_c_rate: float
Invested storage capacity per power rate
(e.g. 60/20 = 3h charging/discharging time)
bev_storage_capacity: int
Storage capacity of one vehicle in kWh.
bev_capacity: int
Charging capacity of one vehicle in kW.
bev_invest_costs: float, array of float
Investment costs for new vehicle unit. EUR/vehicle
fixed_costs: float, array of float
Operation independent costs for existing and new vehicle units.
(e.g. EUR/(vehicle*a))
variable_costs: float, array of float
Variable costs of the fleet (e.g. in EUR/MWh).
fixed_investment_costs
balanced : boolean
Couple storage level of first and last time step.
(Total inflow and total outflow are balanced.)
input_parameters: dict
Dictionary to specify parameters on the input edge. You can use
all keys that are available for the oemof.solph.network.Flow class.
e.g. fixed charging timeseries for the storage can be passed with
{"fix": [1,0.5,...]}
output_parameters: dict
see: input_parameters
e.g. fixed discharging timeseries for the storage can be passed with
{"fix": [1,0.5,...]}
The vehicle fleet is modelled as a storage together with an internal
sink with fixed flow:
.. math::
x^{level}(t) =
x^{level}(t-1) \cdot (1 - c^{loss\_rate}(t))
+ c^{efficiency\_charging}(t) \cdot x^{flow, in}(t)
- \frac{x^{drive\_power}(t)}{c^{efficiency\_discharging}(t)}
- \frac{x^{flow, v2g}(t)}
{c^{efficiency\_discharging}(t) \cdot c^{efficiency\_v2g}(t)}
\qquad \forall t \in T
Note
----
As the Bev is a sub-class of `oemof.solph.GenericStorage` you also
pass all arguments of this class.
The concept is similar to the one described in the following publications
with the difference that uncontrolled charging is not (yet) considered.
Wulff, N., Steck, F., Gils, H. C., Hoyer-Klick, C., van den Adel,
B., & Anderson, J. E. (2020).
Comparing power-system and user-oriented battery electric vehicle
charging representation and
its implications on energy system modeling.
Energies, 13(5). https://doi.org/10.3390/en13051093
Diego Luca de Tena Costales. (2014).
Large Scale Renewable Power Integration with Electric Vehicles.
https://doi.org/10.04.2014
Examples
--------
Basic usage example of the Bev class with an arbitrary selection of
attributes.
>>> from oemof import solph
>>> from oemof.tabular import facades
>>> my_bus = solph.Bus('my_bus')
>>> my_bev = Bev(
... label='my_bev',
... bus=el_bus,
... carrier='electricity',
... tech='bev',
... storage_capacity=1000,
... capacity=50,
... availability=[0.8, 0.7, 0.6],
... drive_power=[0.3, 0.2, 0.5],
... amount=450,
# ... loss_rate=0.01,
... initial_storage_level=0,
... min_storage_level=[0.1, 0.2, 0.15],
... max_storage_level=[0.9, 0.95, 0.92],
... efficiency=0.93
... )
"""
electricity_bus: Bus
mobility_bus: Bus = None
charging_power: int = 0
charging_potential: int = None
availability: Union[float, Sequence[float]] = 1
storage_capacity: int = 0
initial_storage_capacity: float = 0
drive_power: int = 0
drive_consumption: Sequence[float] = None
v2g: bool = False
efficiency_mob_g2v: float = 1
efficiency_mob_v2g: float = 1
efficiency_mob_electrical: float = 1
efficiency_sto_in: float = 1
efficiency_sto_out: float = 1
pkm_conversion_rate: float = 1
expandable: bool = False
lifetime: int = 20
age: int = 0
invest_c_rate: Sequence[float] = None
bev_invest_costs: Sequence[float] = None
variable_costs: Union[float, Sequence[float]] = 0
fixed_costs: Union[float, Sequence[float]] = 0
fixed_investment_costs: Union[float, Sequence[float]] = 0
balanced: bool = False
input_parameters: dict = field(default_factory=dict)
output_parameters: dict = field(default_factory=dict)
def build_solph_components(self):
# use label as prefix for subnodes
self.facade_label = self.label
self.label = self.label + "-storage"
# convert to solph sequences
self.availability = solph_sequence(self.availability)
# TODO: check if this is correct
self.nominal_storage_capacity = self.storage_capacity
# self.nominal_storage_capacity = self._nominal_value(
# self.storage_capacity)
self.balanced = self.balanced # TODO to be false in multi-period
# create internal bus
internal_bus = Bus(label=self.facade_label + "-bus")
self.bus = internal_bus
subnodes = [internal_bus]
# ##### Vehicle2Grid Converter #####
if self.v2g:
vehicle_to_grid = Converter(
label=self.facade_label + "-v2g",
inputs={
internal_bus: Flow(
# variable_costs=self.carrier_cost,
# **self.input_parameters
)
},
outputs={
self.electricity_bus: Flow(
nominal_value=self._nominal_value(
value=self.charging_power
),
# max=self.availability, # doesn't work with investment
variable_costs=None,
investment=self._investment(bev=True),
)
},
# Includes storage charging efficiencies
conversion_factors={internal_bus: self.efficiency_mob_g2v},
# TODO check efficiencies
)
subnodes.append(vehicle_to_grid)
# Drive consumption
if self.mobility_bus:
# ##### PKM Converter #####
# converts energy to e.g. pkm
# connects it to a special mobility bus
pkm_converter = Converter(
label=self.facade_label + "-2pkm",
inputs={
internal_bus: Flow(
# **self.output_parameters
)
},
outputs={
self.mobility_bus: Flow(
nominal_value=self._nominal_value(self.charging_power),
max=self.availability,
variable_costs=None,
investment=self._investment(bev=True),
)
},
conversion_factors={
self.bus: self.pkm_conversion_rate
* self.efficiency_mob_electrical
# * 100 # TODO pro 100 km?
},
)
subnodes.append(pkm_converter)
else:
# ##### Consumption Sink #####
# fixed demand for this fleet only
if self.expandable:
raise NotImplementedError(
"Consumption sink for expandable BEV not implemented yet!"
"Please use a `mobility_bus` + `Sink` instead. Optimizing"
"one fleet alone may not yield meaningful results."
)
else:
driving_consumption = Sink(
label=self.facade_label + "-consumption",
inputs={
internal_bus: Flow(
nominal_value=self.drive_power,
fix=self.drive_consumption,
)
},
)
subnodes.append(driving_consumption)
# ##### Storage ########
if self.expandable:
# self.capacity_cost = self.bev_invest_costs
self.storage_capacity_cost = 0
# self.investment = self._investment(bev=False)
self.invest_relation_input_output = 1 # charge/discharge equal
# invest_c_rate = Energy/Power = h
self.invest_relation_input_capacity = (
1 / self.invest_c_rate
) # Power/Energy
self.invest_relation_output_capacity = (
1 / self.invest_c_rate
) # Power/Energy
for attr in ["invest_relation_input_output"]:
if getattr(self, attr) is None:
raise AttributeError(
(
"You need to set attr " "`{}` " "for component {}"
).format(attr, self.label)
)
# ##### Grid2Vehicle #####
# containts the whole investment costs for bev
flow_in = Flow(
# max=self.availability,
investment=Investment(
ep_costs=self.bev_invest_costs,
maximum=self._get_maximum_additional_invest(
"charging_potential", "charging_power"
),
existing=getattr(self, "charging_power", 0),
lifetime=getattr(self, "lifetime", None),
age=getattr(self, "age", 0),
fixed_costs=getattr(self, "fixed_investment_costs", None),
),
variable_costs=self.variable_costs,
**self.input_parameters,
)
# set investment, but no costs (as relation input / output = 1)
flow_out = Flow(
investment=Investment(
existing=getattr(self, "charging_power", 0),
lifetime=getattr(self, "lifetime", None),
age=getattr(self, "age", 0),
),
**self.output_parameters,
)
# required for correct grouping in oemof.solph.components
self._invest_group = True
else:
flow_in = Flow(
nominal_value=self._nominal_value(self.charging_power),
max=self.availability,
**self.input_parameters,
)
flow_out = Flow(
nominal_value=self._nominal_value(self.charging_power),
# max=self.availability,
variable_costs=self.variable_costs,
**self.output_parameters,
)
# TODO check conversion factors
self.inflow_conversion_factor = solph_sequence(
self.efficiency_mob_g2v * self.efficiency_sto_in
)
self.outflow_conversion_factor = solph_sequence(
self.efficiency_sto_out
)
self.inputs.update({self.electricity_bus: flow_in})
self.outputs.update({self.bus: flow_out})
self._set_flows()
# many components in facade
self.subnodes = subnodes