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,85 @@
|
|
|
1
|
+
from attrs import define
|
|
2
|
+
|
|
3
|
+
from echo.configuration import (
|
|
4
|
+
EVChargeMode,
|
|
5
|
+
)
|
|
6
|
+
from echo.models.electrical.ev.base import EVBase
|
|
7
|
+
from echo.validators import ArrayType, check_initial_state_of_charge_within_bounds
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@define
|
|
11
|
+
class EVV1G(EVBase):
|
|
12
|
+
"""An EV with demand managed charging."""
|
|
13
|
+
|
|
14
|
+
def __attrs_post_init__(self) -> None:
|
|
15
|
+
super().__attrs_post_init__()
|
|
16
|
+
|
|
17
|
+
# Set the charge_mode
|
|
18
|
+
self.charge_mode = EVChargeMode.V1G
|
|
19
|
+
|
|
20
|
+
# Create the ports
|
|
21
|
+
self._create_usage_port()
|
|
22
|
+
self._create_vehicle_port()
|
|
23
|
+
self._create_connection_point_port()
|
|
24
|
+
|
|
25
|
+
if self.set_stateful_attrs_at_init:
|
|
26
|
+
self.set_stateful_attrs(
|
|
27
|
+
available=self.available,
|
|
28
|
+
usage=self.usage,
|
|
29
|
+
initial_state_of_charge=self.initial_state_of_charge,
|
|
30
|
+
interval_duration=self.interval_duration,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# EV needs a custom transformation because of the positive load convention
|
|
34
|
+
self.add_transformation(self._create_ev_transformation())
|
|
35
|
+
|
|
36
|
+
# Set port_dict_name_to_port_uid_map and port_dict_name_to_port_name_map
|
|
37
|
+
self.set_port_uid_maps()
|
|
38
|
+
|
|
39
|
+
# For V1G EVs, need to set max_export constraint to 0.
|
|
40
|
+
self.ports[self.connection_port_name].set_flow_constraints(max_import=self.charging_power_limit, max_export=0.0)
|
|
41
|
+
|
|
42
|
+
def set_stateful_attrs(
|
|
43
|
+
self,
|
|
44
|
+
available: ArrayType | list | str,
|
|
45
|
+
usage: ArrayType | list | str,
|
|
46
|
+
initial_state_of_charge: float,
|
|
47
|
+
interval_duration: int,
|
|
48
|
+
) -> None:
|
|
49
|
+
"""Injects attributes with state into EV node and ports.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
available: A List or ArrayType of bools representing the ability for the EV to charge. The bools can have
|
|
53
|
+
values of [False, True] or [0, 1]. 0 and False indicate the EV is not available for charging, 1 and
|
|
54
|
+
True indicate the EV is available for charging.
|
|
55
|
+
usage: An array representing the average power consumption from driving of the EV during a time interval.
|
|
56
|
+
Units of power.
|
|
57
|
+
initial_state_of_charge: The initial charge present in the EV's battery. Positive float of energy units,
|
|
58
|
+
not percentage. Positive float with units of energy.
|
|
59
|
+
interval_duration: The duration between timestamps. Units of minutes.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
None
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
self.available = available
|
|
66
|
+
self.usage = usage
|
|
67
|
+
self.initial_state_of_charge = initial_state_of_charge
|
|
68
|
+
self.interval_duration = interval_duration
|
|
69
|
+
|
|
70
|
+
# Set stateful attributes for usage port
|
|
71
|
+
self._check_usage_less_than_max_usage()
|
|
72
|
+
self.ports["usage"].add_demand_profile_from_array(self.usage, expansion_periods=1)
|
|
73
|
+
|
|
74
|
+
# Set stateful data for the connection point port
|
|
75
|
+
self.ports[self.connection_port_name].set_active_periods_from_array(self.available, expansion_periods=1)
|
|
76
|
+
|
|
77
|
+
# Set the initial_state_of_charge on the vehicle port
|
|
78
|
+
self.ports["vehicle"].initial_state_of_charge = self.initial_state_of_charge
|
|
79
|
+
|
|
80
|
+
# Check that the initial_state_of_charge is between the min_soc and max_capacity
|
|
81
|
+
check_initial_state_of_charge_within_bounds(
|
|
82
|
+
initial_state_of_charge=self.ports["vehicle"].initial_state_of_charge,
|
|
83
|
+
min_soc=self.ports["vehicle"].min_soc,
|
|
84
|
+
max_capacity=self.ports["vehicle"].max_capacity,
|
|
85
|
+
)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
from attrs import define
|
|
2
|
+
|
|
3
|
+
from echo.configuration import (
|
|
4
|
+
EVChargeMode,
|
|
5
|
+
)
|
|
6
|
+
from echo.models.electrical.ev.base import EVBase
|
|
7
|
+
from echo.validators import ArrayType, check_initial_state_of_charge_within_bounds
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@define
|
|
11
|
+
class EVV2G(EVBase):
|
|
12
|
+
"""An EV with demand managed charging and generation managed discharging for purposes of providing energy to an
|
|
13
|
+
electrical network.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __attrs_post_init__(self) -> None:
|
|
17
|
+
super().__attrs_post_init__()
|
|
18
|
+
|
|
19
|
+
# Set the charge_mode
|
|
20
|
+
self.charge_mode = EVChargeMode.V2G
|
|
21
|
+
|
|
22
|
+
# Create the ports
|
|
23
|
+
self._create_usage_port()
|
|
24
|
+
self._create_vehicle_port()
|
|
25
|
+
self._create_connection_point_port()
|
|
26
|
+
|
|
27
|
+
if self.set_stateful_attrs_at_init:
|
|
28
|
+
self.set_stateful_attrs(
|
|
29
|
+
available=self.available,
|
|
30
|
+
usage=self.usage,
|
|
31
|
+
initial_state_of_charge=self.initial_state_of_charge,
|
|
32
|
+
interval_duration=self.interval_duration,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# EV needs a custom transformation because of the positive load convention
|
|
36
|
+
self.add_transformation(self._create_ev_transformation())
|
|
37
|
+
|
|
38
|
+
# Set port_dict_name_to_port_uid_map and port_dict_name_to_port_name_map
|
|
39
|
+
self.set_port_uid_maps()
|
|
40
|
+
|
|
41
|
+
def set_stateful_attrs(
|
|
42
|
+
self,
|
|
43
|
+
available: ArrayType | list | str,
|
|
44
|
+
usage: ArrayType | list | str,
|
|
45
|
+
initial_state_of_charge: float,
|
|
46
|
+
interval_duration: int,
|
|
47
|
+
) -> None:
|
|
48
|
+
"""Injects attributes with state into EV node and ports.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
available: A List or ArrayType of bools representing the ability for the EV to charge. The bools can have
|
|
52
|
+
values of [False, True] or [0, 1]. 0 and False indicate the EV is not available for charging, 1 and
|
|
53
|
+
True indicate the EV is available for charging.
|
|
54
|
+
usage: An array representing the average power consumption from driving of the EV during a time interval.
|
|
55
|
+
Units of power.
|
|
56
|
+
initial_state_of_charge: The initial charge present in the EV's battery. Positive float of energy units,
|
|
57
|
+
not percentage. Positive float with units of energy.
|
|
58
|
+
interval_duration: The duration between timestamps. Units of minutes.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
None
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
self.available = available
|
|
65
|
+
self.usage = usage
|
|
66
|
+
self.initial_state_of_charge = initial_state_of_charge
|
|
67
|
+
self.interval_duration = interval_duration
|
|
68
|
+
|
|
69
|
+
# Set stateful attributes for usage port
|
|
70
|
+
self._check_usage_less_than_max_usage()
|
|
71
|
+
self.ports["usage"].add_demand_profile_from_array(self.usage, expansion_periods=1)
|
|
72
|
+
|
|
73
|
+
# Set stateful data for the connection point port
|
|
74
|
+
self.ports[self.connection_port_name].set_active_periods_from_array(self.available, expansion_periods=1)
|
|
75
|
+
|
|
76
|
+
# Set the initial_state_of_charge on the vehicle port
|
|
77
|
+
self.ports["vehicle"].initial_state_of_charge = self.initial_state_of_charge
|
|
78
|
+
|
|
79
|
+
# Check that the initial_state_of_charge is between the min_soc and max_capacity
|
|
80
|
+
check_initial_state_of_charge_within_bounds(
|
|
81
|
+
initial_state_of_charge=self.ports["vehicle"].initial_state_of_charge,
|
|
82
|
+
min_soc=self.ports["vehicle"].min_soc,
|
|
83
|
+
max_capacity=self.ports["vehicle"].max_capacity,
|
|
84
|
+
)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from attrs import define, field
|
|
3
|
+
|
|
4
|
+
from echo.configuration import (
|
|
5
|
+
OptimisationType,
|
|
6
|
+
Units,
|
|
7
|
+
)
|
|
8
|
+
from echo.models.agnostic import Source
|
|
9
|
+
from echo.models.scenario import EchoConcreteModel
|
|
10
|
+
from echo.utils import set_var_bounds_from_dict
|
|
11
|
+
from echo.validators import ArrayType
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@define
|
|
15
|
+
class ElectricalGeneration(Source):
|
|
16
|
+
"""Electrical generation which can be fixed (non-curtailable) or variable (curtailable)"""
|
|
17
|
+
|
|
18
|
+
units: Units = Units.KW
|
|
19
|
+
curtailable: bool = field(default=False)
|
|
20
|
+
|
|
21
|
+
def add_generation_profile(self, generation: dict) -> None:
|
|
22
|
+
self.set_initial_value(generation)
|
|
23
|
+
|
|
24
|
+
def add_generation_profile_from_array(
|
|
25
|
+
self,
|
|
26
|
+
generation: ArrayType,
|
|
27
|
+
expansion_periods: int = 1,
|
|
28
|
+
time_periods: int | None = None,
|
|
29
|
+
) -> None:
|
|
30
|
+
|
|
31
|
+
self.set_initial_value_from_array(
|
|
32
|
+
array=generation, expansion_periods=expansion_periods, time_periods=time_periods
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
def add_port_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame) -> None:
|
|
36
|
+
# Whether curtailable is set or not affect whether the flow is represented as a parameter or variable
|
|
37
|
+
# Handle that here before calling `add_port_to_model`
|
|
38
|
+
self.flow_type = OptimisationType.Variable if self.curtailable else OptimisationType.Parameter
|
|
39
|
+
|
|
40
|
+
super().add_port_to_model(model, profile)
|
|
41
|
+
|
|
42
|
+
if self.curtailable:
|
|
43
|
+
# Constrain solar gen to be within initial value (max value)
|
|
44
|
+
set_var_bounds_from_dict(
|
|
45
|
+
model=model,
|
|
46
|
+
var_name=self.port_name,
|
|
47
|
+
lb=self.initial_value,
|
|
48
|
+
ub=None,
|
|
49
|
+
)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import pyomo.environ as en
|
|
3
|
+
from attrs import define, field, validators
|
|
4
|
+
from pyomo.core.expr.relational_expr import EqualityExpression
|
|
5
|
+
|
|
6
|
+
from echo.exceptions import validate
|
|
7
|
+
from echo.models.base import Node
|
|
8
|
+
from echo.models.electrical.base import ElectricalPort
|
|
9
|
+
from echo.models.scenario import EchoConcreteModel
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@define
|
|
13
|
+
class Inverter(Node):
|
|
14
|
+
"""An inverter is a node with one AC port and at least one DC port.
|
|
15
|
+
Flows from AC to DC, and DC to AC, are subject to conversion efficiencies.
|
|
16
|
+
|
|
17
|
+
Ports can be specified at construction time using the `ac_port_name` and `dc_ports_names` or the ports can be
|
|
18
|
+
added later by making one call to `add_ac_port` and as many calls to `add_dc_port` as required. It is best not
|
|
19
|
+
to mix these two approaches.
|
|
20
|
+
|
|
21
|
+
When creating ports through the constructor, the ports will be assigned default uids. If you need to flexibility
|
|
22
|
+
of specifying uids for the ports then use the `add_ac_port` and `add_dc_ports` remembering to supply `uid` values.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
max_import: float | None = None
|
|
26
|
+
max_export: float | None = None
|
|
27
|
+
dc_ac_efficiency: float = field(default=1.0, validator=[validators.ge(0), validators.le(1)])
|
|
28
|
+
ac_dc_efficiency: float = field(default=1.0, validator=[validators.ge(0), validators.le(1)])
|
|
29
|
+
ac_port_name: str | None = None
|
|
30
|
+
dc_port_names: list[str] = field(factory=list)
|
|
31
|
+
|
|
32
|
+
def __attrs_post_init__(
|
|
33
|
+
self,
|
|
34
|
+
) -> None:
|
|
35
|
+
if self.ac_port_name:
|
|
36
|
+
self._add_ac_port(port_name=self.ac_port_name)
|
|
37
|
+
for port_name in self.dc_port_names:
|
|
38
|
+
self._add_port(port_name=port_name)
|
|
39
|
+
|
|
40
|
+
def _add_port(self, port_name: str, uid: str | None = None) -> None:
|
|
41
|
+
p = ElectricalPort(port_name=port_name, uid=uid)
|
|
42
|
+
self.ports[port_name] = p
|
|
43
|
+
|
|
44
|
+
def _add_ac_port(self, port_name: str, uid: str | None = None) -> None:
|
|
45
|
+
p = ElectricalPort(port_name=port_name, uid=uid)
|
|
46
|
+
p.set_flow_constraints(max_export=self.max_export, max_import=self.max_import)
|
|
47
|
+
self.ports[port_name] = p
|
|
48
|
+
|
|
49
|
+
def add_dc_port(self, port_name: str, uid: str | None = None) -> None:
|
|
50
|
+
self.dc_port_names.append(port_name)
|
|
51
|
+
self._add_port(port_name=port_name, uid=uid)
|
|
52
|
+
|
|
53
|
+
def add_ac_port(self, port_name: str, uid: str | None = None) -> None:
|
|
54
|
+
self.ac_port_name = port_name
|
|
55
|
+
self._add_ac_port(port_name=self.ac_port_name, uid=uid)
|
|
56
|
+
|
|
57
|
+
def verify_node(self) -> None:
|
|
58
|
+
# Check that we have at least one ac and one dc port
|
|
59
|
+
validate(self.ac_port_name is not None, "Define at least one ac port on inverter.")
|
|
60
|
+
validate(self.dc_port_names is not None, "Define at least one dc port on inverter.")
|
|
61
|
+
# Check that all ports are either ac or dc
|
|
62
|
+
all_port_names = [x for x in self.ports.keys()]
|
|
63
|
+
named_ports = [self.ac_port_name] + self.dc_port_names
|
|
64
|
+
validate(
|
|
65
|
+
set(all_port_names) == set(named_ports),
|
|
66
|
+
"All ports on inverter must be ac or dc.",
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def add_node_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame) -> None:
|
|
70
|
+
super().add_node_to_model(model, profile)
|
|
71
|
+
|
|
72
|
+
ac_port = self.ports[self.ac_port_name]
|
|
73
|
+
# Split ac port into pos/neg, so we can apply the correct efficiencies
|
|
74
|
+
ac_port.constrain_pos_neg(model)
|
|
75
|
+
|
|
76
|
+
def inverter_ac_output_must_track_efficiency(model: EchoConcreteModel, p: int, t: int) -> EqualityExpression:
|
|
77
|
+
"""Apply efficiency constraints"""
|
|
78
|
+
dc_total = 0
|
|
79
|
+
for dc_port_name in self.dc_port_names:
|
|
80
|
+
dc_port = self.ports[dc_port_name]
|
|
81
|
+
dc_total += getattr(model, dc_port.port_name)[p, t]
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
getattr(model, ac_port.pos)[p, t] * self.ac_dc_efficiency
|
|
85
|
+
+ getattr(model, ac_port.neg)[p, t] / self.dc_ac_efficiency
|
|
86
|
+
== dc_total * -1
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
setattr(
|
|
90
|
+
model,
|
|
91
|
+
f"con_inverter_{self.node_name}",
|
|
92
|
+
en.Constraint(
|
|
93
|
+
model.Expansion,
|
|
94
|
+
model.Time,
|
|
95
|
+
rule=inverter_ac_output_must_track_efficiency,
|
|
96
|
+
),
|
|
97
|
+
)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
from echo.models.gas.base import FixedGasPort, FlexGasPort
|
|
2
|
+
from echo.models.gas.boiler_fixedcop import GasBoilerFixedCOP
|
|
3
|
+
from echo.models.gas.boiler_tempcontrolled import TempControlledBoiler
|
|
4
|
+
|
|
5
|
+
__all__ = ["FlexGasPort", "FixedGasPort", "GasBoilerFixedCOP", "TempControlledBoiler"]
|
echo/models/gas/base.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from attrs import define
|
|
2
|
+
|
|
3
|
+
from echo.configuration import Units
|
|
4
|
+
from echo.models.agnostic import FixedPort, FlexPort
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@define
|
|
8
|
+
class FlexGasPort(FlexPort):
|
|
9
|
+
"""A flexible port with flow units of Joules/second"""
|
|
10
|
+
|
|
11
|
+
units: Units = Units.JPS
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@define
|
|
15
|
+
class FixedGasPort(FixedPort):
|
|
16
|
+
"""A Fixed port with flow units of Joules/second"""
|
|
17
|
+
|
|
18
|
+
units: Units = Units.JPS
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import pyomo.environ as en
|
|
2
|
+
from attrs import define, field, validators
|
|
3
|
+
from pyomo.core.expr import EqualityExpression
|
|
4
|
+
|
|
5
|
+
from echo.configuration import Units
|
|
6
|
+
from echo.models.agnostic import FlexPort, InputOutputNode, OffOrConstrainedPort
|
|
7
|
+
from echo.models.scenario import EchoConcreteModel
|
|
8
|
+
from echo.validators import (
|
|
9
|
+
set_output_bounds_validator,
|
|
10
|
+
startup_efficiency_validator,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@define
|
|
15
|
+
class GasBoilerFixedCOP(InputOutputNode):
|
|
16
|
+
"""
|
|
17
|
+
A gas boiler converts gas to heat at a fixed coefficient of performance (COP) where COP = output/input."""
|
|
18
|
+
|
|
19
|
+
input_port_unit: Units = Units.JPS
|
|
20
|
+
output_port_unit: Units = Units.KWT
|
|
21
|
+
|
|
22
|
+
min_input: float | None = field(default=None, validator=set_output_bounds_validator)
|
|
23
|
+
|
|
24
|
+
cop: float = field(
|
|
25
|
+
default=1, validator=[validators.ge(0), startup_efficiency_validator, set_output_bounds_validator]
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
startup_cop: float = field(
|
|
29
|
+
default=1, validator=[validators.ge(0), startup_efficiency_validator, set_output_bounds_validator]
|
|
30
|
+
) # efficiency in startup period
|
|
31
|
+
|
|
32
|
+
def __attrs_post_init__(self) -> None:
|
|
33
|
+
super().__attrs_post_init__()
|
|
34
|
+
|
|
35
|
+
# Add an input and output node, and create the appropriate transformation object
|
|
36
|
+
self.ports[self.input_port_ref] = OffOrConstrainedPort(
|
|
37
|
+
upper_bound=self.max_input, lower_bound=self.min_input, units=self.input_port_unit
|
|
38
|
+
)
|
|
39
|
+
self.ports[self.output_port_ref] = FlexPort(units=self.output_port_unit)
|
|
40
|
+
|
|
41
|
+
def set_ports(self, gas_input_port: OffOrConstrainedPort, thermal_output_port: FlexPort) -> None:
|
|
42
|
+
# Discard existing ports
|
|
43
|
+
self.ports.clear()
|
|
44
|
+
# Add the new ports
|
|
45
|
+
self.input_port_ref = gas_input_port.port_name
|
|
46
|
+
self.output_port_ref = thermal_output_port.port_name
|
|
47
|
+
self.ports[self.input_port_ref] = gas_input_port
|
|
48
|
+
self.ports[self.output_port_ref] = thermal_output_port
|
|
49
|
+
|
|
50
|
+
def apply_node_constraints(self, model: EchoConcreteModel) -> None:
|
|
51
|
+
super().apply_node_constraints(model)
|
|
52
|
+
|
|
53
|
+
def node_constraint(model: EchoConcreteModel, p: int, t: int) -> EqualityExpression:
|
|
54
|
+
p_in = getattr(model, self.ports[self.input_port_ref].port_name)
|
|
55
|
+
p_out = getattr(model, self.ports[self.output_port_ref].port_name)
|
|
56
|
+
if p == 0 and t == 0:
|
|
57
|
+
weighted_inputs = p_in[p, t] * self.startup_cop
|
|
58
|
+
weighted_outputs = 0
|
|
59
|
+
else:
|
|
60
|
+
weighted_inputs = p_in[p, t] * self.startup_cop + p_in[p, t - 1] * (self.cop - self.startup_cop)
|
|
61
|
+
# todo decide whether to include past outputs in rule
|
|
62
|
+
weighted_outputs = p_out[p, t - 1] * -0.0
|
|
63
|
+
return p_out[p, t] == (weighted_inputs + weighted_outputs) * -1
|
|
64
|
+
|
|
65
|
+
setattr(model, "node_con_" + self.node_name, en.Constraint(model.Expansion, model.Time, rule=node_constraint))
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import pyomo.environ as en
|
|
3
|
+
from attrs import define, field, validators
|
|
4
|
+
from pyomo.core.expr import EqualityExpression
|
|
5
|
+
|
|
6
|
+
from echo.configuration import Units
|
|
7
|
+
from echo.models.agnostic import InputOutputNode, OffOrConstrainedPort
|
|
8
|
+
from echo.models.scenario import EchoConcreteModel
|
|
9
|
+
from echo.validators import (
|
|
10
|
+
set_output_bounds_validator,
|
|
11
|
+
startup_efficiency_validator,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@define
|
|
16
|
+
class TempControlledBoiler(InputOutputNode):
|
|
17
|
+
"""
|
|
18
|
+
A temp controlled boiler has an input and output port.
|
|
19
|
+
It has two internal temperature variables, one for exiting water temp and one for returning water temp.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
input_port_unit: Units = Units.JPS
|
|
23
|
+
output_port_unit: Units = Units.KWT
|
|
24
|
+
exit_temp_bounds: tuple = (75, 80)
|
|
25
|
+
return_temp_bounds: tuple = (50, 80)
|
|
26
|
+
|
|
27
|
+
# factor for converting a temperature difference to kW required to achieve that delta T
|
|
28
|
+
deg_to_kw: float = field(kw_only=True)
|
|
29
|
+
|
|
30
|
+
min_input: float | None = field(default=None, validator=set_output_bounds_validator)
|
|
31
|
+
|
|
32
|
+
# coefficient of performance - determines how much of the input energy is delivered as heating energy
|
|
33
|
+
cop: float = field(
|
|
34
|
+
default=1, validator=[validators.ge(0), startup_efficiency_validator, set_output_bounds_validator]
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
startup_cop: float | None = field(
|
|
38
|
+
default=None, validator=[startup_efficiency_validator, set_output_bounds_validator]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# pyomo vars
|
|
42
|
+
return_t: str = ""
|
|
43
|
+
exit_t: str = ""
|
|
44
|
+
|
|
45
|
+
def __attrs_post_init__(self) -> None:
|
|
46
|
+
super().__attrs_post_init__()
|
|
47
|
+
|
|
48
|
+
self.ports[self.input_port_ref] = OffOrConstrainedPort(
|
|
49
|
+
units=self.input_port_unit, lower_bound=self.min_input, upper_bound=self.max_input
|
|
50
|
+
)
|
|
51
|
+
self.ports[self.output_port_ref] = OffOrConstrainedPort(
|
|
52
|
+
units=self.output_port_unit, lower_bound=self.max_output, upper_bound=self.min_output
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
self.return_t = "inlet_temp_" + self.node_name
|
|
56
|
+
self.exit_t = "outlet_temp_" + self.node_name
|
|
57
|
+
|
|
58
|
+
def add_node_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame) -> None:
|
|
59
|
+
super().add_node_to_model(model, profile)
|
|
60
|
+
# Define exit and return temperature variables and bound these appropriately
|
|
61
|
+
setattr(
|
|
62
|
+
model,
|
|
63
|
+
self.return_t,
|
|
64
|
+
en.Var(model.Expansion, model.Time, initialize=0, bounds=self.return_temp_bounds, domain=en.Reals),
|
|
65
|
+
)
|
|
66
|
+
setattr(
|
|
67
|
+
model,
|
|
68
|
+
self.exit_t,
|
|
69
|
+
en.Var(model.Expansion, model.Time, initialize=0, bounds=self.exit_temp_bounds, domain=en.Reals),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def apply_node_constraints(self, model: EchoConcreteModel) -> None:
|
|
73
|
+
# Retrieve some variables
|
|
74
|
+
input_kw = getattr(model, self.ports[self.input_port_ref].port_name)
|
|
75
|
+
output_kw = getattr(model, self.ports[self.output_port_ref].port_name)
|
|
76
|
+
|
|
77
|
+
def constraint2(model: EchoConcreteModel, p: int, t: int) -> EqualityExpression:
|
|
78
|
+
"""return temp at time t - exiting temp at time t == energy removed at t"""
|
|
79
|
+
return (
|
|
80
|
+
getattr(model, self.return_t)[p, t] - getattr(model, self.exit_t)[p, t]
|
|
81
|
+
) * self.deg_to_kw * self.cop == output_kw[p, t]
|
|
82
|
+
|
|
83
|
+
setattr(
|
|
84
|
+
model, "boiler_temp_con2_" + self.node_name, en.Constraint(model.Expansion, model.Time, rule=constraint2)
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def constraint3(model: EchoConcreteModel, p: int, t: int) -> EqualityExpression:
|
|
88
|
+
"""exiting temp at time t = return temp at time t + energy added at time t"""
|
|
89
|
+
return (
|
|
90
|
+
input_kw[p, t]
|
|
91
|
+
== (getattr(model, self.exit_t)[p, t] - getattr(model, self.return_t)[p, t]) * self.deg_to_kw
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
setattr(
|
|
95
|
+
model, "boiler_temp_con3_" + self.node_name, en.Constraint(model.Expansion, model.Time, rule=constraint3)
|
|
96
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from echo.models.prebuilt.battery import Battery
|
|
2
|
+
from echo.models.prebuilt.diesel_generator import DieselGenerator
|
|
3
|
+
from echo.models.prebuilt.flex import FlexElectricalNode, FlexNode, FlexNodeWithEmissions
|
|
4
|
+
from echo.models.prebuilt.load import Load
|
|
5
|
+
from echo.models.prebuilt.scaled_solar import ScaledSolar
|
|
6
|
+
from echo.models.prebuilt.solar import Solar
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"Battery",
|
|
10
|
+
"DieselGenerator",
|
|
11
|
+
"FlexElectricalNode",
|
|
12
|
+
"FlexNode",
|
|
13
|
+
"FlexNodeWithEmissions",
|
|
14
|
+
"Load",
|
|
15
|
+
"ScaledSolar",
|
|
16
|
+
"Solar",
|
|
17
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from attrs import define, field, validators
|
|
2
|
+
|
|
3
|
+
from echo.models.base.node import Node
|
|
4
|
+
from echo.models.electrical import ElectricalStorage
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@define
|
|
8
|
+
class Battery(Node):
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
port_name: str,
|
|
12
|
+
max_capacity: float,
|
|
13
|
+
initial_state_of_charge: float,
|
|
14
|
+
charging_power_limit: float,
|
|
15
|
+
discharging_power_limit: float,
|
|
16
|
+
storage_capacity_cost: float | None = field(default=None, validator=validators.optional(validators.gt(0))),
|
|
17
|
+
charging_efficiency: float = 1,
|
|
18
|
+
discharging_efficiency: float = 1,
|
|
19
|
+
depth_of_discharge_limit: float = 0,
|
|
20
|
+
fixed_storage_capacity: bool = True,
|
|
21
|
+
regularise: bool = False,
|
|
22
|
+
**data,
|
|
23
|
+
) -> None:
|
|
24
|
+
self.__attrs_init__(**data)
|
|
25
|
+
self.ports[port_name] = ElectricalStorage(
|
|
26
|
+
max_capacity=max_capacity,
|
|
27
|
+
depth_of_discharge_limit=depth_of_discharge_limit,
|
|
28
|
+
charging_power_limit=charging_power_limit,
|
|
29
|
+
discharging_power_limit=discharging_power_limit,
|
|
30
|
+
charging_efficiency=charging_efficiency,
|
|
31
|
+
discharging_efficiency=discharging_efficiency,
|
|
32
|
+
initial_state_of_charge=initial_state_of_charge,
|
|
33
|
+
fixed_storage_capacity=fixed_storage_capacity,
|
|
34
|
+
storage_capacity_cost=storage_capacity_cost,
|
|
35
|
+
regularise=regularise,
|
|
36
|
+
)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import pyomo.environ as en
|
|
2
|
+
from attrs import define, field, validators
|
|
3
|
+
from pyomo.core.expr import EqualityExpression
|
|
4
|
+
|
|
5
|
+
from echo.configuration import Units
|
|
6
|
+
from echo.models.agnostic import FlexSink, InputOutputNode, OffOrConstrainedPort
|
|
7
|
+
from echo.models.carbon import CarbonSource
|
|
8
|
+
from echo.models.scenario import EchoConcreteModel
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@define
|
|
12
|
+
class DieselGenerator(InputOutputNode):
|
|
13
|
+
"""
|
|
14
|
+
A diesel generator node. Converts diesel into electricity at a fixed rate of cop which is in units of
|
|
15
|
+
kW/liters per second
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
input_port_unit: Units = Units.LPS
|
|
19
|
+
output_port_unit: Units = Units.KW
|
|
20
|
+
cop: float = field(default=0.4 * 3600, validator=validators.ge(0)) # kW / litres per second
|
|
21
|
+
# ratio of efficiency in startup and shutdown period, # todo: ensure between 0-1 (confloat??)
|
|
22
|
+
startup_efficiency: float = field(default=0.5, validator=validators.ge(0))
|
|
23
|
+
# emissions intensity kg per sec / litre per sec = kg/litre
|
|
24
|
+
C02Intensity: float = field(default=2.7, validator=validators.ge(0))
|
|
25
|
+
|
|
26
|
+
def __attrs_post_init__(self) -> None:
|
|
27
|
+
super().__attrs_post_init__()
|
|
28
|
+
|
|
29
|
+
# add an input and output node, and create appropriate transformations
|
|
30
|
+
self.ports["output"] = OffOrConstrainedPort(
|
|
31
|
+
upper_bound=self.min_output, lower_bound=self.max_output, units=self.output_port_unit
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
self.ports["input"] = FlexSink(units=self.input_port_unit) # the node is importing through this port
|
|
35
|
+
self.ports["co2"] = CarbonSource()
|
|
36
|
+
# todo: add some validators :-)
|
|
37
|
+
|
|
38
|
+
def apply_node_constraints(self, model: EchoConcreteModel) -> None:
|
|
39
|
+
super().apply_node_constraints(model)
|
|
40
|
+
|
|
41
|
+
def node_constraint(model: EchoConcreteModel, p: int, t: int) -> EqualityExpression:
|
|
42
|
+
p_in = getattr(model, self.ports["input"].port_name)
|
|
43
|
+
p_out = getattr(model, self.ports["output"].port_name)
|
|
44
|
+
|
|
45
|
+
if (p == 0) and (t == 0):
|
|
46
|
+
out = p_in[p, t] * self.startup_efficiency * self.cop
|
|
47
|
+
else:
|
|
48
|
+
out = (p_in[p, t] * self.startup_efficiency + p_in[p, t - 1] * (1 - self.startup_efficiency)) * self.cop
|
|
49
|
+
return p_out[p, t] == -out
|
|
50
|
+
|
|
51
|
+
def carbon_rule(model: EchoConcreteModel, p: int, t: int) -> EqualityExpression:
|
|
52
|
+
p_in = getattr(model, self.ports["input"].port_name)
|
|
53
|
+
c_out = getattr(model, self.ports["co2"].port_name)
|
|
54
|
+
return c_out[p, t] == -p_in[p, t]
|
|
55
|
+
|
|
56
|
+
setattr(model, "node_con_" + self.node_name, en.Constraint(model.Expansion, model.Time, rule=node_constraint))
|
|
57
|
+
setattr(model, "node_con_co2_" + self.node_name, en.Constraint(model.Expansion, model.Time, rule=carbon_rule))
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from echo.configuration import Units
|
|
2
|
+
from echo.models.agnostic import FlexPort
|
|
3
|
+
from echo.models.base import Node, TransformNode
|
|
4
|
+
from echo.models.carbon import CarbonSource
|
|
5
|
+
from echo.validators import ArrayType
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FlexNode(Node):
|
|
9
|
+
def __init__(self, port_name: str, port_unit: Units, **data) -> None:
|
|
10
|
+
super().__init__(**data)
|
|
11
|
+
self.ports[port_name] = FlexPort(port_name=port_name, units=port_unit)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class FlexElectricalNode(Node):
|
|
15
|
+
def __init__(self, port_name: str, **data) -> None:
|
|
16
|
+
super().__init__(**data)
|
|
17
|
+
self.ports[port_name] = FlexPort(port_name=port_name, units=Units.KW)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class FlexNodeWithEmissions(TransformNode):
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
emitting_port: str,
|
|
24
|
+
emitting_port_units: Units,
|
|
25
|
+
carbon_port: str,
|
|
26
|
+
emissions_factor: float | ArrayType,
|
|
27
|
+
**data,
|
|
28
|
+
) -> None:
|
|
29
|
+
super().__init__(**data)
|
|
30
|
+
self.ports[emitting_port] = FlexPort(port_name=emitting_port, units=emitting_port_units)
|
|
31
|
+
self.ports[carbon_port] = CarbonSource()
|
|
32
|
+
self.add_emission_transformation(
|
|
33
|
+
emitting_port=self.ports[emitting_port],
|
|
34
|
+
carbon_port=self.ports[carbon_port],
|
|
35
|
+
emission_factor=emissions_factor,
|
|
36
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from echo.configuration import Units
|
|
2
|
+
from echo.models.agnostic import Demand
|
|
3
|
+
from echo.models.base.node import Node
|
|
4
|
+
from echo.validators import ArrayType
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Load(Node):
|
|
8
|
+
def __init__(self, port_name: str, port_unit: Units, profile: dict | ArrayType | list, **data) -> None:
|
|
9
|
+
super().__init__(**data)
|
|
10
|
+
self.ports[port_name] = Demand(units=port_unit)
|
|
11
|
+
if type(profile) is dict:
|
|
12
|
+
self.ports[port_name].set_initial_value(profile)
|
|
13
|
+
else:
|
|
14
|
+
self.ports[port_name].set_initial_value_from_array(profile)
|