eris-echo 2.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- echo/__init__.py +1 -0
- echo/configuration.py +178 -0
- echo/constants.py +8 -0
- echo/exceptions.py +16 -0
- echo/functional.py +83 -0
- echo/models/__init__.py +0 -0
- echo/models/agnostic/__init__.py +50 -0
- echo/models/agnostic/aggregation.py +64 -0
- echo/models/agnostic/base.py +84 -0
- echo/models/agnostic/bounded.py +43 -0
- echo/models/agnostic/controlled.py +97 -0
- echo/models/agnostic/flex.py +61 -0
- echo/models/agnostic/input_output.py +30 -0
- echo/models/agnostic/storage.py +307 -0
- echo/models/agnostic/tellegen/__init__.py +6 -0
- echo/models/agnostic/tellegen/base.py +62 -0
- echo/models/agnostic/tellegen/multi_commodity.py +50 -0
- echo/models/agnostic/tellegen/partitioned_multi_commodity.py +88 -0
- echo/models/agnostic/tellegen/three_way_valve.py +122 -0
- echo/models/agnostic/time_delay.py +34 -0
- echo/models/agnostic/time_varying.py +134 -0
- echo/models/base/__init__.py +21 -0
- echo/models/base/edge.py +128 -0
- echo/models/base/node.py +160 -0
- echo/models/base/optimisation_graph.py +546 -0
- echo/models/base/path.py +66 -0
- echo/models/base/port.py +564 -0
- echo/models/base/transform.py +186 -0
- echo/models/base/types.py +7 -0
- echo/models/carbon/__init__.py +4 -0
- echo/models/carbon/aggregation.py +33 -0
- echo/models/carbon/base.py +25 -0
- echo/models/electrical/__init__.py +35 -0
- echo/models/electrical/base.py +37 -0
- echo/models/electrical/ev/__init__.py +14 -0
- echo/models/electrical/ev/base.py +340 -0
- echo/models/electrical/ev/deprecated.py +273 -0
- echo/models/electrical/ev/ev_with_profile.py +137 -0
- echo/models/electrical/ev/v0g.py +264 -0
- echo/models/electrical/ev/v1g.py +85 -0
- echo/models/electrical/ev/v2g.py +84 -0
- echo/models/electrical/generation.py +49 -0
- echo/models/electrical/inverter.py +97 -0
- echo/models/gas/__init__.py +5 -0
- echo/models/gas/base.py +18 -0
- echo/models/gas/boiler_fixedcop.py +65 -0
- echo/models/gas/boiler_tempcontrolled.py +96 -0
- echo/models/prebuilt/__init__.py +17 -0
- echo/models/prebuilt/battery.py +36 -0
- echo/models/prebuilt/diesel_generator.py +57 -0
- echo/models/prebuilt/flex.py +36 -0
- echo/models/prebuilt/load.py +14 -0
- echo/models/prebuilt/scaled_solar.py +19 -0
- echo/models/prebuilt/solar.py +13 -0
- echo/models/scenario.py +63 -0
- echo/models/thermal/__init__.py +15 -0
- echo/models/thermal/base.py +117 -0
- echo/models/thermal/parameterised_chiller.py +228 -0
- echo/models/thermal/parameterised_heatpump.py +496 -0
- echo/models/thermal/simple_chiller.py +139 -0
- echo/models/thermal/simple_heatpump.py +291 -0
- echo/models/thermal/simple_heatpump_dualoutput.py +195 -0
- echo/models/thermal/storage.py +307 -0
- echo/objectives/__init__.py +0 -0
- echo/objectives/base.py +99 -0
- echo/objectives/contingency.py +158 -0
- echo/objectives/power.py +132 -0
- echo/objectives/tariff.py +694 -0
- echo/optimiser.py +460 -0
- echo/py.typed +0 -0
- echo/tracker.py +74 -0
- echo/utils.py +506 -0
- echo/validators.py +290 -0
- echo/visualization.py +229 -0
- eris_echo-2.3.0.dist-info/METADATA +127 -0
- eris_echo-2.3.0.dist-info/RECORD +79 -0
- eris_echo-2.3.0.dist-info/WHEEL +5 -0
- eris_echo-2.3.0.dist-info/licenses/LICENSE.txt +22 -0
- eris_echo-2.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
from typing import cast
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from attrs import define, field
|
|
6
|
+
from deprecated import deprecated
|
|
7
|
+
|
|
8
|
+
from echo.configuration import EVChargeMode, EVChargeStatus, TransformRule
|
|
9
|
+
from echo.exceptions import validate
|
|
10
|
+
from echo.models.base import Transform, TransformNode, TransformTerm
|
|
11
|
+
from echo.models.electrical.base import ElectricalDemand, ElectricalPort
|
|
12
|
+
from echo.models.electrical.ev.base import MobileElectricalStorage
|
|
13
|
+
from echo.models.scenario import EchoConcreteModel
|
|
14
|
+
from echo.utils import TimeExpandableType, fix_port_variable
|
|
15
|
+
from echo.validators import ArrayType
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@deprecated(
|
|
19
|
+
version="2.1.14",
|
|
20
|
+
reason="Supeseded by EVV0G, EVV1G, EVV2G, EVWithProfile and EVBase classes",
|
|
21
|
+
)
|
|
22
|
+
@define
|
|
23
|
+
class EV(TransformNode):
|
|
24
|
+
charge_mode: EVChargeMode | None = None
|
|
25
|
+
available: ArrayType | list | str = field(kw_only=True)
|
|
26
|
+
usage: ArrayType | list = field(kw_only=True)
|
|
27
|
+
connection_port_name: str = "cp"
|
|
28
|
+
tod_charging: ArrayType | list | str | None = None
|
|
29
|
+
interval_duration: int = field(kw_only=True)
|
|
30
|
+
# Battery attributes
|
|
31
|
+
max_capacity: float = field(kw_only=True)
|
|
32
|
+
depth_of_discharge_limit: float = 0
|
|
33
|
+
charging_power_limit: float = field(kw_only=True)
|
|
34
|
+
discharging_power_limit: float = field(kw_only=True)
|
|
35
|
+
charging_efficiency: float = 1
|
|
36
|
+
discharging_efficiency: float = 1
|
|
37
|
+
initial_state_of_charge: float = field(kw_only=True)
|
|
38
|
+
|
|
39
|
+
# next variable is for allowing soc to go below min so as to avoid optimisation failing if there infeasible ev trips
|
|
40
|
+
trip_slack: bool = False # todo call this 'enable_trip_slack' so we can give it straight to port
|
|
41
|
+
# next three variables are for having a 'conservative' ev user lower bound on the soc while it is plugged in
|
|
42
|
+
soc_conserv: TimeExpandableType | None = None
|
|
43
|
+
soc_conserv_cost: float | None = None
|
|
44
|
+
|
|
45
|
+
V0G_delta: ArrayType | list | None = None
|
|
46
|
+
V0G_SOC: ArrayType | list | None = None
|
|
47
|
+
V0G_trip_infeasibility: ArrayType | list | None = None
|
|
48
|
+
charge_status: EVChargeStatus | None = None
|
|
49
|
+
|
|
50
|
+
port_dict_name_to_port_uid_map: dict[str, str] | None = None
|
|
51
|
+
port_dict_name_to_port_name_map: dict[str, str] | None = None
|
|
52
|
+
|
|
53
|
+
def __attrs_post_init__(self) -> None:
|
|
54
|
+
# Check that usage is always <= max discharge of battery, otherwise the problem will be infeasible.
|
|
55
|
+
for i in self.usage:
|
|
56
|
+
if i > self.discharging_power_limit * -1:
|
|
57
|
+
raise ValueError(
|
|
58
|
+
f"Usage requirement of {i} exceeds battery discharge limit of {self.discharging_power_limit}."
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Initialise port_name_to_port_uid_map
|
|
62
|
+
if self.port_dict_name_to_port_uid_map is None:
|
|
63
|
+
self.port_dict_name_to_port_uid_map = {}
|
|
64
|
+
|
|
65
|
+
# Initialise port_name_to_port_uid_map
|
|
66
|
+
if self.port_dict_name_to_port_name_map is None:
|
|
67
|
+
self.port_dict_name_to_port_name_map = {}
|
|
68
|
+
|
|
69
|
+
battery_attributes = [
|
|
70
|
+
"max_capacity",
|
|
71
|
+
"depth_of_discharge_limit",
|
|
72
|
+
"charging_power_limit",
|
|
73
|
+
"discharging_power_limit",
|
|
74
|
+
"charging_efficiency",
|
|
75
|
+
"discharging_efficiency",
|
|
76
|
+
"initial_state_of_charge",
|
|
77
|
+
]
|
|
78
|
+
battery_params = {k: getattr(self, k) for k in battery_attributes}
|
|
79
|
+
if "vehicle" in self.port_dict_name_to_port_uid_map.keys():
|
|
80
|
+
# Preserve uid and port_name if present on port
|
|
81
|
+
vehicle = MobileElectricalStorage(
|
|
82
|
+
uid=self.port_dict_name_to_port_uid_map["vehicle"],
|
|
83
|
+
port_name=self.port_dict_name_to_port_name_map["vehicle"],
|
|
84
|
+
**battery_params,
|
|
85
|
+
)
|
|
86
|
+
else:
|
|
87
|
+
vehicle = MobileElectricalStorage(**battery_params)
|
|
88
|
+
|
|
89
|
+
vehicle.enable_trip_slack = self.trip_slack # Apply trip slack
|
|
90
|
+
self.ports["vehicle"] = vehicle # EV always has a storage port
|
|
91
|
+
|
|
92
|
+
# Preserve uid if present on port
|
|
93
|
+
if "usage" in self.port_dict_name_to_port_uid_map.keys():
|
|
94
|
+
usage_port = ElectricalDemand(
|
|
95
|
+
uid=self.port_dict_name_to_port_uid_map["usage"],
|
|
96
|
+
port_name=self.port_dict_name_to_port_name_map["usage"],
|
|
97
|
+
)
|
|
98
|
+
else:
|
|
99
|
+
usage_port = ElectricalDemand()
|
|
100
|
+
|
|
101
|
+
usage_port.add_demand_profile_from_array(self.usage, expansion_periods=1)
|
|
102
|
+
self.ports["usage"] = usage_port # EV always has a fixed trip port
|
|
103
|
+
|
|
104
|
+
# Customise connection point port type based on the charge mode
|
|
105
|
+
if self.charge_mode == EVChargeMode.V0G:
|
|
106
|
+
self.trip_slack = True # Set slack to true
|
|
107
|
+
vehicle.enable_trip_slack = self.trip_slack
|
|
108
|
+
if self.connection_port_name in self.port_dict_name_to_port_uid_map.keys():
|
|
109
|
+
electrical_demand = ElectricalDemand(
|
|
110
|
+
uid=self.port_dict_name_to_port_uid_map[self.connection_port_name],
|
|
111
|
+
port_name=self.port_dict_name_to_port_name_map[self.connection_port_name],
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
else:
|
|
115
|
+
electrical_demand = ElectricalDemand()
|
|
116
|
+
self.ports[self.connection_port_name] = electrical_demand
|
|
117
|
+
self.process_v0g_charging(self.interval_duration)
|
|
118
|
+
electrical_demand.add_demand_profile_from_array(self.V0G_delta, expansion_periods=1)
|
|
119
|
+
else:
|
|
120
|
+
if self.connection_port_name in self.port_dict_name_to_port_uid_map.keys():
|
|
121
|
+
electrical_port = ElectricalPort(
|
|
122
|
+
uid=self.port_dict_name_to_port_uid_map[self.connection_port_name],
|
|
123
|
+
port_name=self.port_dict_name_to_port_name_map[self.connection_port_name],
|
|
124
|
+
)
|
|
125
|
+
else:
|
|
126
|
+
electrical_port = ElectricalPort()
|
|
127
|
+
electrical_port.set_active_periods_from_array(self.available, expansion_periods=1)
|
|
128
|
+
self.ports[self.connection_port_name] = electrical_port
|
|
129
|
+
if self.charge_mode == EVChargeMode.V1G:
|
|
130
|
+
electrical_port.set_flow_constraints(max_import=self.charging_power_limit, max_export=0.0)
|
|
131
|
+
|
|
132
|
+
# EV needs a custom transformation because of the positive load convention
|
|
133
|
+
self.add_transformation(self.create_ev_transformation())
|
|
134
|
+
|
|
135
|
+
# Set port_dict_name_to_port_uid_map
|
|
136
|
+
if len(self.port_dict_name_to_port_uid_map.keys()) == 0:
|
|
137
|
+
self.port_dict_name_to_port_uid_map = {port_name: port.uid for port_name, port in self.ports.items()}
|
|
138
|
+
|
|
139
|
+
# Set port_dict_name_to_port_name_map
|
|
140
|
+
if len(self.port_dict_name_to_port_name_map.keys()) == 0:
|
|
141
|
+
self.port_dict_name_to_port_name_map = {port_name: port.port_name for port_name, port in self.ports.items()}
|
|
142
|
+
|
|
143
|
+
def update(
|
|
144
|
+
self,
|
|
145
|
+
available: ArrayType | list | str | None = None,
|
|
146
|
+
usage: ArrayType | list | str | None = None,
|
|
147
|
+
initial_state_of_charge: float | None = None,
|
|
148
|
+
interval_duration: int | None = None,
|
|
149
|
+
) -> None:
|
|
150
|
+
self.__init__(
|
|
151
|
+
node_name=self.node_name,
|
|
152
|
+
uid=self.uid,
|
|
153
|
+
charge_mode=self.charge_mode,
|
|
154
|
+
available=available if available is not None else self.available,
|
|
155
|
+
usage=usage if usage is not None else self.usage,
|
|
156
|
+
connection_port_name=self.connection_port_name,
|
|
157
|
+
tod_charging=self.tod_charging,
|
|
158
|
+
interval_duration=interval_duration if interval_duration is not None else self.interval_duration,
|
|
159
|
+
max_capacity=self.max_capacity,
|
|
160
|
+
depth_of_discharge_limit=self.depth_of_discharge_limit,
|
|
161
|
+
charging_power_limit=self.charging_power_limit,
|
|
162
|
+
discharging_power_limit=self.discharging_power_limit,
|
|
163
|
+
charging_efficiency=self.charging_efficiency,
|
|
164
|
+
discharging_efficiency=self.discharging_efficiency,
|
|
165
|
+
initial_state_of_charge=(
|
|
166
|
+
initial_state_of_charge if initial_state_of_charge is not None else self.initial_state_of_charge
|
|
167
|
+
),
|
|
168
|
+
trip_slack=self.trip_slack,
|
|
169
|
+
soc_conserv=self.soc_conserv,
|
|
170
|
+
soc_conserv_cost=self.soc_conserv_cost,
|
|
171
|
+
port_dict_name_to_port_uid_map=self.port_dict_name_to_port_uid_map,
|
|
172
|
+
port_dict_name_to_port_name_map=self.port_dict_name_to_port_name_map,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
def create_ev_transformation(self) -> Transform:
|
|
176
|
+
# Create appropriate transformation: vehicle = cp - usage
|
|
177
|
+
lhs_terms = [
|
|
178
|
+
TransformTerm(var=self.ports["vehicle"], rule=TransformRule.Both, weight=1),
|
|
179
|
+
TransformTerm(var=self.ports["usage"], rule=TransformRule.Both, weight=1),
|
|
180
|
+
TransformTerm(
|
|
181
|
+
var=self.ports[self.connection_port_name],
|
|
182
|
+
rule=TransformRule.Both,
|
|
183
|
+
weight=-1,
|
|
184
|
+
),
|
|
185
|
+
]
|
|
186
|
+
return Transform(lhs_terms=lhs_terms)
|
|
187
|
+
|
|
188
|
+
def process_v0g_charging(self, interval_duration: float) -> None:
|
|
189
|
+
success, ev_soc, ev_delta, trip_infeasibility = self.v0g_charging(interval_duration)
|
|
190
|
+
|
|
191
|
+
self.V0G_delta = ev_delta
|
|
192
|
+
self.V0G_SOC = ev_soc
|
|
193
|
+
if self.tod_charging is not None:
|
|
194
|
+
if success:
|
|
195
|
+
self.charge_status = EVChargeStatus.Feasible
|
|
196
|
+
else: # force convenience charging
|
|
197
|
+
success, ev_soc, ev_delta, trip_infeasibility = self.v0g_charging(interval_duration, force_conv=True)
|
|
198
|
+
self.charge_status = (
|
|
199
|
+
EVChargeStatus.TimeOfDayInfeasibleConvenienceFeasible if success else EVChargeStatus.Infeasible
|
|
200
|
+
)
|
|
201
|
+
self.V0G_delta = ev_delta
|
|
202
|
+
self.V0G_SOC = ev_soc
|
|
203
|
+
|
|
204
|
+
else:
|
|
205
|
+
self.charge_status = EVChargeStatus.Feasible if success else EVChargeStatus.Infeasible
|
|
206
|
+
self.V0G_trip_infeasibility = trip_infeasibility
|
|
207
|
+
|
|
208
|
+
def v0g_charging(
|
|
209
|
+
self,
|
|
210
|
+
interval_duration: float,
|
|
211
|
+
force_conv: bool = False,
|
|
212
|
+
) -> tuple[bool, list[float], float, float]:
|
|
213
|
+
"""Convert V0G vehicle (convenience charging) to a soc profile and a power profile if possible."""
|
|
214
|
+
|
|
215
|
+
if (self.tod_charging is not None) and (not force_conv):
|
|
216
|
+
self.available = self.available * self.tod_charging
|
|
217
|
+
available_len = len(self.available)
|
|
218
|
+
soc = np.zeros((available_len + 1,))
|
|
219
|
+
vehicle = cast(MobileElectricalStorage, self.ports["vehicle"])
|
|
220
|
+
soc[0] = vehicle.initial_state_of_charge
|
|
221
|
+
trip_infeasibility = np.zeros((available_len,))
|
|
222
|
+
delta = np.zeros((available_len,))
|
|
223
|
+
max_capacity = vehicle.max_capacity
|
|
224
|
+
charge_limit = vehicle.charging_power_limit
|
|
225
|
+
charging_efficiency = vehicle.charging_efficiency
|
|
226
|
+
|
|
227
|
+
for t in range(available_len):
|
|
228
|
+
if self.available[t] and (soc[t] < max_capacity): # available to charge and not at max capacity
|
|
229
|
+
delta[t] = min(
|
|
230
|
+
charge_limit,
|
|
231
|
+
(max_capacity - soc[t]) / charging_efficiency / (interval_duration / 60),
|
|
232
|
+
)
|
|
233
|
+
soc[t + 1] = soc[t] + delta[t] * (interval_duration / 60) * charging_efficiency
|
|
234
|
+
else: # if not available then it might be on a trip and using power
|
|
235
|
+
soc[t + 1] = soc[t] - self.usage[t] * (interval_duration / 60)
|
|
236
|
+
trip_infeasibility[t] = -min(soc[t + 1], 0)
|
|
237
|
+
soc[t + 1] = max(soc[t + 1], 0)
|
|
238
|
+
|
|
239
|
+
success = True if (trip_infeasibility.max() == 0) else False
|
|
240
|
+
|
|
241
|
+
return success, soc[1:], delta, trip_infeasibility
|
|
242
|
+
|
|
243
|
+
def verify_node(self) -> None:
|
|
244
|
+
super().verify_node()
|
|
245
|
+
if self.charge_mode == EVChargeMode.V0G:
|
|
246
|
+
validate(
|
|
247
|
+
self.ports[self.connection_port_name].initial_value != 0,
|
|
248
|
+
"V0G connection pt port needs demand profile added.",
|
|
249
|
+
)
|
|
250
|
+
else:
|
|
251
|
+
validate(
|
|
252
|
+
self.ports[self.connection_port_name].active_periods is not None,
|
|
253
|
+
"Add available periods to EV connection pt port",
|
|
254
|
+
)
|
|
255
|
+
validate(
|
|
256
|
+
self.ports["usage"].initial_value != 0,
|
|
257
|
+
"EV usage port needs usage profile added.",
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
def add_node_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame) -> None:
|
|
261
|
+
super().add_node_to_model(model, profile)
|
|
262
|
+
if self.charge_mode == EVChargeMode.V0G:
|
|
263
|
+
# Fix the battery state of charge, the slack variable, and battery charging/discharging
|
|
264
|
+
vehicle = cast(MobileElectricalStorage, self.ports["vehicle"])
|
|
265
|
+
fix_port_variable(model, vehicle.soc_value, self.V0G_SOC, expansion_periods=1)
|
|
266
|
+
fix_port_variable(
|
|
267
|
+
model,
|
|
268
|
+
vehicle.trip_slack,
|
|
269
|
+
self.V0G_trip_infeasibility,
|
|
270
|
+
expansion_periods=1,
|
|
271
|
+
)
|
|
272
|
+
power_profile = np.array(self.V0G_delta) + np.array(self.usage) * -1
|
|
273
|
+
fix_port_variable(model, vehicle.port_name, power_profile, expansion_periods=1)
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import shortuuid
|
|
3
|
+
from attrs import define, field, validators
|
|
4
|
+
|
|
5
|
+
from echo.configuration import (
|
|
6
|
+
EVChargeMode,
|
|
7
|
+
)
|
|
8
|
+
from echo.exceptions import ConfigurationError, validate
|
|
9
|
+
from echo.models.base import Node
|
|
10
|
+
from echo.models.electrical.base import ElectricalDemand
|
|
11
|
+
from echo.validators import ArrayType
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@define
|
|
15
|
+
class EVWithProfile(Node):
|
|
16
|
+
"""An EV defined through a timeseries profile of demand.
|
|
17
|
+
|
|
18
|
+
This EV object is to be used when real world (or modelled) charging data is available; essentially acting as a
|
|
19
|
+
pure load.
|
|
20
|
+
|
|
21
|
+
charging_power_limit (float | None): The maximum charging power of the vehicle. Used for data sanity checks only.
|
|
22
|
+
Positive float in units of power.
|
|
23
|
+
demand (dict[str, float] | ArrayType | list[float] | None): The demand data for the EV. Values must be positive
|
|
24
|
+
floats. Values in units of power.
|
|
25
|
+
set_stateful_attrs_at_init (bool | None): Set attributes with state at object instantiation (True) or
|
|
26
|
+
defer to later (False). If deferring to later, self.set_stateful_attrs() must be used to set these
|
|
27
|
+
attributes. Attributes with state are available and initial_state_of_charge. Defaults to True.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
charge_mode: EVChargeMode = EVChargeMode.DemandProfile
|
|
31
|
+
port_name: str = "demand"
|
|
32
|
+
port_uid: str = field(factory=shortuuid.uuid)
|
|
33
|
+
charging_power_limit: float = field(default=None, validator=validators.optional(validators.ge(0)))
|
|
34
|
+
|
|
35
|
+
# Stateful attributes
|
|
36
|
+
set_stateful_attrs_at_init: bool = True
|
|
37
|
+
demand: dict | ArrayType | list | None = None
|
|
38
|
+
|
|
39
|
+
def __attrs_post_init__(self) -> None:
|
|
40
|
+
|
|
41
|
+
# Set the EV charge mode
|
|
42
|
+
self.charge_mode: EVChargeMode = EVChargeMode.DemandProfile
|
|
43
|
+
|
|
44
|
+
# Create the demand port
|
|
45
|
+
self.ports[self.port_name] = ElectricalDemand(
|
|
46
|
+
port_name=self.port_name,
|
|
47
|
+
uid=self.port_uid,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Set stateful attributes if required
|
|
51
|
+
if self.set_stateful_attrs_at_init:
|
|
52
|
+
self.set_stateful_attrs(demand=self.demand)
|
|
53
|
+
|
|
54
|
+
def set_stateful_attrs(self, demand: dict | ArrayType | list) -> None:
|
|
55
|
+
"""Injects attributes with state into EV node and ports.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
demand: Timeseries data specifying if the load from the EV charging.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
None
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
self.demand = demand
|
|
65
|
+
|
|
66
|
+
# Set profile values of the demand port
|
|
67
|
+
if type(self.demand) is dict:
|
|
68
|
+
self.ports[self.port_name].set_initial_value(self.demand)
|
|
69
|
+
else:
|
|
70
|
+
self.ports[self.port_name].set_initial_value_from_array(self.demand)
|
|
71
|
+
|
|
72
|
+
def verify_node(self) -> None:
|
|
73
|
+
"""Checks data with state has been set for the node and each port.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
None
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
None
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
super().verify_node()
|
|
83
|
+
|
|
84
|
+
# Check node properties
|
|
85
|
+
self._check_stateful_attrs_are_not_none()
|
|
86
|
+
self._check_demand_is_not_more_than_max_import()
|
|
87
|
+
|
|
88
|
+
# Check ports
|
|
89
|
+
self._verify_ports()
|
|
90
|
+
|
|
91
|
+
def _check_stateful_attrs_are_not_none(self) -> None:
|
|
92
|
+
"""Check that node attributes with state have been set.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
None
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
None
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
if self.demand is None:
|
|
102
|
+
raise ConfigurationError(
|
|
103
|
+
f"The demand attribute for {self.node_name} has not been set. Please use set_stateful_attrs()."
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def _check_demand_is_not_more_than_max_import(self) -> None:
|
|
107
|
+
"""Check that the demand does not breach the maximum import limit of the EV.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
None
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
None
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
if self.charging_power_limit is not None:
|
|
117
|
+
max_demand = np.max(np.array(self.demand))
|
|
118
|
+
if max_demand > self.charging_power_limit:
|
|
119
|
+
raise ValueError(
|
|
120
|
+
f"Demand requirement of {max_demand} exceeds maximum charging rate of {self.charging_power_limit}."
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
def _verify_ports(self) -> None:
|
|
124
|
+
"""Check that port attributes with state have been set.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
None
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
None
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
validate(
|
|
134
|
+
self.ports[self.port_name].initial_value != 0,
|
|
135
|
+
f"{self.node_name} demand port '{self.port_name}' does not have a demand profile set. "
|
|
136
|
+
f"Please use set_stateful_attrs() to set it.",
|
|
137
|
+
)
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
from typing import cast
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from attrs import define
|
|
6
|
+
|
|
7
|
+
from echo.configuration import (
|
|
8
|
+
EVChargeMode,
|
|
9
|
+
EVChargeStatus,
|
|
10
|
+
)
|
|
11
|
+
from echo.exceptions import validate
|
|
12
|
+
from echo.models.electrical.base import ElectricalDemand
|
|
13
|
+
from echo.models.electrical.ev.base import EVBase, MobileElectricalStorage
|
|
14
|
+
from echo.models.scenario import EchoConcreteModel
|
|
15
|
+
from echo.utils import fix_port_variable
|
|
16
|
+
from echo.validators import ArrayType, check_initial_state_of_charge_within_bounds
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@define
|
|
20
|
+
class EVV0G(EVBase):
|
|
21
|
+
"""This EV object takes an available and usage dataset to precalculate a demand profile.
|
|
22
|
+
|
|
23
|
+
Once plugged in for charging, it assumes charging at the maximum rate until the battery is full.
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
# Initialise attributes
|
|
28
|
+
V0G_delta: ArrayType | list | None = None
|
|
29
|
+
V0G_SOC: ArrayType | list | None = None
|
|
30
|
+
V0G_trip_infeasibility: ArrayType | list | None = None
|
|
31
|
+
charge_status: EVChargeStatus | None = None
|
|
32
|
+
|
|
33
|
+
def __attrs_post_init__(self) -> None:
|
|
34
|
+
super().__attrs_post_init__()
|
|
35
|
+
|
|
36
|
+
# Set the charge_mode
|
|
37
|
+
self.charge_mode = EVChargeMode.V0G
|
|
38
|
+
|
|
39
|
+
# Create ports
|
|
40
|
+
self._create_usage_port()
|
|
41
|
+
self._create_vehicle_port()
|
|
42
|
+
self._create_connection_point_port()
|
|
43
|
+
|
|
44
|
+
# If setting attributes with state at instantiation, set them now.
|
|
45
|
+
if self.set_stateful_attrs_at_init:
|
|
46
|
+
self.set_stateful_attrs(
|
|
47
|
+
available=self.available,
|
|
48
|
+
usage=self.usage,
|
|
49
|
+
initial_state_of_charge=self.initial_state_of_charge,
|
|
50
|
+
interval_duration=self.interval_duration,
|
|
51
|
+
tod_charging=self.tod_charging,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# EV needs a custom transformation because of the positive load convention
|
|
55
|
+
self.add_transformation(self._create_ev_transformation())
|
|
56
|
+
|
|
57
|
+
# Set port_dict_name_to_port_uid_map and port_dict_name_to_port_name_map
|
|
58
|
+
self.set_port_uid_maps()
|
|
59
|
+
|
|
60
|
+
def _create_connection_point_port(self) -> None:
|
|
61
|
+
"""Creates a connection point port for the EV.min_soc
|
|
62
|
+
|
|
63
|
+
Overwrites EVBase._create_connection_point_port as V0G uses an ElectricalDemand port instead of a
|
|
64
|
+
ElectricalPort.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
None
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
None
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
self.ports[self.connection_port_name] = ElectricalDemand()
|
|
75
|
+
|
|
76
|
+
def set_stateful_attrs(
|
|
77
|
+
self,
|
|
78
|
+
available: ArrayType | list,
|
|
79
|
+
usage: ArrayType | list,
|
|
80
|
+
initial_state_of_charge: float,
|
|
81
|
+
interval_duration: int,
|
|
82
|
+
tod_charging: ArrayType | list | str | None = None,
|
|
83
|
+
) -> None:
|
|
84
|
+
"""Injects attributes with state into EV node and ports.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
available: A List or ArrayType of bools representing the ability for the EV to charge. The bools can have
|
|
88
|
+
values of [False, True] or [0, 1]. 0 and False indicate the EV is not available for charging, 1 and
|
|
89
|
+
True indicate the EV is available for charging.
|
|
90
|
+
usage: An array representing the average power consumption from driving of the EV during a time interval.
|
|
91
|
+
Units of power.
|
|
92
|
+
initial_state_of_charge: The initial charge present in the EV's battery. Positive float of energy units,
|
|
93
|
+
not percentage. Positive float with units of energy.
|
|
94
|
+
interval_duration: The duration between timestamps. Units of minutes.
|
|
95
|
+
tod_charging: Time of day charging allows the EV to charge only during certain time windows (1=allowed,
|
|
96
|
+
0=not allowed). Most commonly used with V0G charging. Defaults to None.
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
None
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
# Update the node attributes.
|
|
103
|
+
self.available = available
|
|
104
|
+
self.usage = usage
|
|
105
|
+
self.initial_state_of_charge = initial_state_of_charge
|
|
106
|
+
self.interval_duration = interval_duration
|
|
107
|
+
self.tod_charging = tod_charging
|
|
108
|
+
|
|
109
|
+
# Set the initial_state_of_charge on the vehicle port
|
|
110
|
+
self.ports["vehicle"].initial_state_of_charge = self.initial_state_of_charge
|
|
111
|
+
|
|
112
|
+
# Check that the initial_state_of_charge is between the min_soc and max_capacity
|
|
113
|
+
check_initial_state_of_charge_within_bounds(
|
|
114
|
+
initial_state_of_charge=self.ports["vehicle"].initial_state_of_charge,
|
|
115
|
+
min_soc=self.ports["vehicle"].min_soc,
|
|
116
|
+
max_capacity=self.ports["vehicle"].max_capacity,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Set stateful attributes for usage port
|
|
120
|
+
self._check_usage_less_than_max_usage()
|
|
121
|
+
self.ports["usage"].add_demand_profile_from_array(self.usage, expansion_periods=1)
|
|
122
|
+
|
|
123
|
+
# Calculate demand
|
|
124
|
+
self._process_v0g_charging(self.interval_duration)
|
|
125
|
+
|
|
126
|
+
# Set stateful attrs for the connection point port
|
|
127
|
+
self.ports[self.connection_port_name].add_demand_profile_from_array(self.V0G_delta, expansion_periods=1)
|
|
128
|
+
|
|
129
|
+
def _process_v0g_charging(self, interval_duration: float) -> None:
|
|
130
|
+
"""Calculate the convenience charging profile for the EV.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
interval_duration: The timestep of the timeseries in minutes.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
None
|
|
137
|
+
|
|
138
|
+
"""
|
|
139
|
+
success, ev_soc, ev_delta, trip_infeasibility = self._v0g_charging(interval_duration)
|
|
140
|
+
|
|
141
|
+
# Set node attributes
|
|
142
|
+
self.V0G_delta = ev_delta
|
|
143
|
+
self.V0G_SOC = ev_soc
|
|
144
|
+
|
|
145
|
+
# Check for time of day charging
|
|
146
|
+
if self.tod_charging is not None:
|
|
147
|
+
if success:
|
|
148
|
+
self.charge_status = EVChargeStatus.Feasible
|
|
149
|
+
else:
|
|
150
|
+
# If there are any infeasibilities, force convenience charging
|
|
151
|
+
success, ev_soc, ev_delta, trip_infeasibility = self._v0g_charging(interval_duration, force_conv=True)
|
|
152
|
+
self.charge_status = (
|
|
153
|
+
EVChargeStatus.TimeOfDayInfeasibleConvenienceFeasible if success else EVChargeStatus.Infeasible
|
|
154
|
+
)
|
|
155
|
+
self.V0G_delta = ev_delta
|
|
156
|
+
self.V0G_SOC = ev_soc
|
|
157
|
+
else:
|
|
158
|
+
self.charge_status = EVChargeStatus.Feasible if success else EVChargeStatus.Infeasible
|
|
159
|
+
|
|
160
|
+
# Set nodes V0G_trip_infeasibility
|
|
161
|
+
self.V0G_trip_infeasibility = trip_infeasibility
|
|
162
|
+
|
|
163
|
+
def _v0g_charging(
|
|
164
|
+
self,
|
|
165
|
+
interval_duration: float,
|
|
166
|
+
force_conv: bool = False,
|
|
167
|
+
) -> tuple[bool, list[float], float, float]:
|
|
168
|
+
"""Convert V0G vehicle (convenience charging) to a soc profile and a power profile if possible.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
interval_duration: The timestep of the timeseries in minutes.
|
|
172
|
+
force_conv: Force convenience charging if time of day (tod) charging is specified
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
success: A bool describing if entire timeseries is feasible (True) or infeasible (False)
|
|
176
|
+
ev_soc: The timeseries profile of the state of charge of the EV
|
|
177
|
+
ev_delta: The timeseries profile of the energy added to the EV
|
|
178
|
+
trip_infeasibility: The timeseries profile of the feasibility of each timestep.
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
# Determine the availability of the EV to charge accounting for the time of day charging preferences
|
|
182
|
+
if (self.tod_charging is not None) and (not force_conv):
|
|
183
|
+
self.available = list(np.array(self.available) * np.array(self.tod_charging))
|
|
184
|
+
|
|
185
|
+
available_len = len(self.available)
|
|
186
|
+
soc = np.zeros((available_len + 1,))
|
|
187
|
+
vehicle = cast(MobileElectricalStorage, self.ports["vehicle"])
|
|
188
|
+
soc[0] = vehicle.initial_state_of_charge
|
|
189
|
+
trip_infeasibility = np.zeros((available_len,))
|
|
190
|
+
delta = np.zeros((available_len,))
|
|
191
|
+
max_capacity = vehicle.max_capacity
|
|
192
|
+
charge_limit = vehicle.charging_power_limit
|
|
193
|
+
charging_efficiency = vehicle.charging_efficiency
|
|
194
|
+
|
|
195
|
+
for t in range(available_len):
|
|
196
|
+
if self.available[t] and (soc[t] < max_capacity): # available to charge and not at max capacity
|
|
197
|
+
delta[t] = min(
|
|
198
|
+
charge_limit,
|
|
199
|
+
(max_capacity - soc[t]) / charging_efficiency / (interval_duration / 60),
|
|
200
|
+
)
|
|
201
|
+
soc[t + 1] = soc[t] + delta[t] * (interval_duration / 60) * charging_efficiency
|
|
202
|
+
else: # if not available then it might be on a trip and using power
|
|
203
|
+
soc[t + 1] = soc[t] - self.usage[t] * (interval_duration / 60)
|
|
204
|
+
trip_infeasibility[t] = -min(soc[t + 1], 0)
|
|
205
|
+
soc[t + 1] = max(soc[t + 1], 0)
|
|
206
|
+
|
|
207
|
+
success: bool = True if (trip_infeasibility.max() == 0) else False
|
|
208
|
+
|
|
209
|
+
return success, soc[1:], delta, trip_infeasibility
|
|
210
|
+
|
|
211
|
+
def _verify_ports(self) -> None:
|
|
212
|
+
"""Checks data with state has been set for each port.
|
|
213
|
+
|
|
214
|
+
Overwrites parent function.
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
None
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
None
|
|
221
|
+
|
|
222
|
+
"""
|
|
223
|
+
validate(
|
|
224
|
+
self.ports[self.connection_port_name].initial_value != 0,
|
|
225
|
+
f"{self.node_name} connection point port does not have a demand profile set.",
|
|
226
|
+
)
|
|
227
|
+
validate(
|
|
228
|
+
self.ports["usage"].initial_value != 0,
|
|
229
|
+
f"{self.node_name} usage port needs does not have a usage profile set.",
|
|
230
|
+
)
|
|
231
|
+
validate(
|
|
232
|
+
(isinstance(self.ports["vehicle"], MobileElectricalStorage))
|
|
233
|
+
and (self.ports["vehicle"].initial_state_of_charge) is not None,
|
|
234
|
+
f"{self.node_name} vehicle port does not have a initial_state_of_charge set.",
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
def add_node_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame | None = None) -> None:
|
|
238
|
+
"""Fix the battery state of charge, the slack variable, and battery charging/discharging for EV.
|
|
239
|
+
|
|
240
|
+
Args:
|
|
241
|
+
model: The concrete model to add the EV to
|
|
242
|
+
profile:
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
None
|
|
246
|
+
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
super().add_node_to_model(model, profile)
|
|
250
|
+
|
|
251
|
+
vehicle = cast(MobileElectricalStorage, self.ports["vehicle"])
|
|
252
|
+
fix_port_variable(model, vehicle.soc_value, self.V0G_SOC, expansion_periods=1)
|
|
253
|
+
|
|
254
|
+
# If there is a trip slack, add the port variable to the model
|
|
255
|
+
if self.enable_trip_slack:
|
|
256
|
+
fix_port_variable(
|
|
257
|
+
model,
|
|
258
|
+
vehicle.trip_slack,
|
|
259
|
+
self.V0G_trip_infeasibility,
|
|
260
|
+
expansion_periods=1,
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
power_profile = np.array(self.V0G_delta) + np.array(self.usage) * -1
|
|
264
|
+
fix_port_variable(model, vehicle.port_name, power_profile, expansion_periods=1)
|