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
echo/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.3.0"
|
echo/configuration.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""Enumerations of possible configurations for echo model components."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Units(Enum):
|
|
7
|
+
"""Enumeration object containing units in which the optimisation is undertaken."""
|
|
8
|
+
|
|
9
|
+
NA = 0
|
|
10
|
+
"""Used for initialisation but optimisation will fail if units not set prior to execution."""
|
|
11
|
+
KW = 1
|
|
12
|
+
"""Instantaneous electrical real power kW"""
|
|
13
|
+
CO2 = 2
|
|
14
|
+
"""Instantaneous CO2e emissions (in kg)"""
|
|
15
|
+
KWT = 3
|
|
16
|
+
"""Instantaneous thermal power"""
|
|
17
|
+
JPS = 4
|
|
18
|
+
"""Joules per second"""
|
|
19
|
+
KWh = 5
|
|
20
|
+
"""Electrical energy kWh"""
|
|
21
|
+
KVA = 6
|
|
22
|
+
"""Instantaneous electrical apparent power kVA """
|
|
23
|
+
KVAR = 7
|
|
24
|
+
"""Instantaneous electrical reactive power kVAR """
|
|
25
|
+
LPS = 8
|
|
26
|
+
"""Liquid commodity flow in litres per second """
|
|
27
|
+
CMS = 9
|
|
28
|
+
"""Gas or liquid commodity flow in Cubic meters per second """
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Flows(Enum):
|
|
32
|
+
"""Enumeration object defining the direction of commodity flow supported by the Port."""
|
|
33
|
+
|
|
34
|
+
NA = 0
|
|
35
|
+
"""flow direction for the port is not defined"""
|
|
36
|
+
Import = 1
|
|
37
|
+
"""the port supports only import"""
|
|
38
|
+
Export = 2
|
|
39
|
+
"""the port supports only export"""
|
|
40
|
+
Both = 3
|
|
41
|
+
"""the port supports two-way flow (import and export)"""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class FlowConstraint(Enum):
|
|
45
|
+
"""Enumeration object defining the type (format) of constraint at the Port."""
|
|
46
|
+
|
|
47
|
+
NA = 0
|
|
48
|
+
"""Constraint type is not specified for this port"""
|
|
49
|
+
NoConstraint = 1
|
|
50
|
+
"""No constraint on flow at this port"""
|
|
51
|
+
Fixed = 2
|
|
52
|
+
"""A fixed constraint exists"""
|
|
53
|
+
Series = 3
|
|
54
|
+
"""A time series (time varying) constraint exists"""
|
|
55
|
+
InRange = 4
|
|
56
|
+
"""A lower bound constraint and upper bound constraint exist at this port"""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class OptimisationType(Enum):
|
|
60
|
+
"""Enumeration object defining the type Port value variable in optimisation context."""
|
|
61
|
+
|
|
62
|
+
NA = 0
|
|
63
|
+
"""Value type is not specified for this port"""
|
|
64
|
+
Parameter = 1
|
|
65
|
+
"""The port value variable is fixed"""
|
|
66
|
+
Variable = 2
|
|
67
|
+
"""The port variable is variable/optimisable"""
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class TransformRule(Enum):
|
|
71
|
+
"""Enumeration object defining to which component of the Port value the Transformation Rule applies"""
|
|
72
|
+
|
|
73
|
+
NA = 0
|
|
74
|
+
"""Not specified for this Port"""
|
|
75
|
+
Both = 1
|
|
76
|
+
"""The transformation applies to both pos and neg components of the port variable"""
|
|
77
|
+
Pos = 2
|
|
78
|
+
"""The transformation applies to only the positive component of the port variable"""
|
|
79
|
+
Neg = 3
|
|
80
|
+
"""The transformation applies to only the negative component of the port variable"""
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ExpansionType(Enum):
|
|
84
|
+
"""Enumeration object defining the type of Expansion"""
|
|
85
|
+
|
|
86
|
+
NA = 0
|
|
87
|
+
"""Not specified"""
|
|
88
|
+
Storage = 1
|
|
89
|
+
"""Energy storage expansion"""
|
|
90
|
+
Generation = 2
|
|
91
|
+
"""Energy generation expansion"""
|
|
92
|
+
Edge = 3
|
|
93
|
+
"""Energy throughput (Edge capacity) expansion"""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class NodeType(Enum):
|
|
97
|
+
"""Enumeration of Node types"""
|
|
98
|
+
|
|
99
|
+
ElectricalFlex = "electrical_flex"
|
|
100
|
+
ElectricalTellegen = "elec_tellegen"
|
|
101
|
+
MultiCommodityTellegen = "multi_commodity_tellegen"
|
|
102
|
+
Battery = "battery"
|
|
103
|
+
ElectricalLoad = "load"
|
|
104
|
+
ElectricalGeneration = "elec_gen"
|
|
105
|
+
Solar = "solar"
|
|
106
|
+
"""Solar generator (PV) Node"""
|
|
107
|
+
EV = "ev"
|
|
108
|
+
V0GEV = "v0g_ev"
|
|
109
|
+
V1GEV = "v1g_ev"
|
|
110
|
+
V2GEV = "v2g_ev"
|
|
111
|
+
Inverter = "inverter"
|
|
112
|
+
"""DC/AC inverter Node"""
|
|
113
|
+
Chiller = "chiller"
|
|
114
|
+
GasBoiler = "gas_boiler"
|
|
115
|
+
ControlledElectricalLoad = "cload_elec"
|
|
116
|
+
ControlledElectricalGen = "cgen_elec"
|
|
117
|
+
FixedElectrical = "fixed_elec"
|
|
118
|
+
FixedGas = "fixed_gas"
|
|
119
|
+
CarbonAggregation = "carbon_agg"
|
|
120
|
+
"""CO2 aggregation Node"""
|
|
121
|
+
HeatPump = "heatpump"
|
|
122
|
+
"""Heat water pump Node"""
|
|
123
|
+
FlexWithEmissions = "flex_with_emissions"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class Resource(Enum):
|
|
127
|
+
"""Enumeration object defining the types of Energy Resources (Commodities)"""
|
|
128
|
+
|
|
129
|
+
Electricity = 0
|
|
130
|
+
"""Electricity"""
|
|
131
|
+
Gas = 1
|
|
132
|
+
"""Gas"""
|
|
133
|
+
Thermal = 2
|
|
134
|
+
"""Thermal"""
|
|
135
|
+
CO2 = 3
|
|
136
|
+
"""CO2 (emissions)"""
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class TariffType(Enum):
|
|
140
|
+
"""Tariff types"""
|
|
141
|
+
|
|
142
|
+
ImportTariff = "import tariff"
|
|
143
|
+
ExportTariff = "export tariff"
|
|
144
|
+
ImportDemandTariff = "import demand tariff"
|
|
145
|
+
ExportDemandTariff = "export demand tariff"
|
|
146
|
+
ThroughputCost = "throughput cost"
|
|
147
|
+
PeakPosPower = "peak positive power"
|
|
148
|
+
PeakNegPower = "peak negative power"
|
|
149
|
+
QuadraticPower = "quadratic power"
|
|
150
|
+
ContingencyPositive = "contingency positive"
|
|
151
|
+
ContingencyNegative = "contingency negative"
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class Resets(Enum):
|
|
155
|
+
"""How often something resets"""
|
|
156
|
+
|
|
157
|
+
minute = "minute"
|
|
158
|
+
hourly = "hourly"
|
|
159
|
+
daily = "daily"
|
|
160
|
+
weekly = "weekly"
|
|
161
|
+
yearly = "annually"
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class EVChargeMode(Enum):
|
|
165
|
+
"""Enumeration of EV class charging modes"""
|
|
166
|
+
|
|
167
|
+
V0G = "V0G"
|
|
168
|
+
V1G = "V1G"
|
|
169
|
+
V2G = "V2G"
|
|
170
|
+
DemandProfile = "demand_profile"
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class EVChargeStatus(Enum):
|
|
174
|
+
"""Feasibility of EV charging."""
|
|
175
|
+
|
|
176
|
+
Feasible = "feasible"
|
|
177
|
+
Infeasible = "Infeasible"
|
|
178
|
+
TimeOfDayInfeasibleConvenienceFeasible = "time of day infeasible, convenience feasible"
|
echo/constants.py
ADDED
echo/exceptions.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class ConfigurationError(Exception):
|
|
2
|
+
pass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class OptimiserResultError(Exception):
|
|
6
|
+
"""Raised when a particular termination condition is not met when running an optimisation"""
|
|
7
|
+
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def validate(statement: bool, message: str) -> None:
|
|
12
|
+
"""Similar to assert but will NOT be optimised out by bytecode conversions (see bandit warning B101)"""
|
|
13
|
+
if statement:
|
|
14
|
+
return
|
|
15
|
+
|
|
16
|
+
raise ConfigurationError(message)
|
echo/functional.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
from collections.abc import Iterable, Mapping
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def is_list(
|
|
6
|
+
obj: typing.Any, # noqa ANN401
|
|
7
|
+
scalars: tuple = (Mapping, str),
|
|
8
|
+
iters: tuple[type[typing.Iterable]] = (Iterable,),
|
|
9
|
+
) -> bool: # noqa ANN004
|
|
10
|
+
"""Return true if the object is iterable.
|
|
11
|
+
|
|
12
|
+
Note:
|
|
13
|
+
Returns false if object is a mapping or string.
|
|
14
|
+
|
|
15
|
+
Taken from
|
|
16
|
+
https://github.com/celery/kombu/blob/v5.0.2/kombu/utils/functional.py
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2015-2016 Ask Solem & contributors. All rights reserved.
|
|
19
|
+
Copyright (c) 2012-2014 GoPivotal Inc & contributors. All rights reserved.
|
|
20
|
+
Copyright (c) 2009-2012, Ask Solem & contributors. All rights reserved.
|
|
21
|
+
|
|
22
|
+
Redistribution and use in source and binary forms, with or without
|
|
23
|
+
modification, are permitted provided that the following conditions are met:
|
|
24
|
+
|
|
25
|
+
* Redistributions of source code must retain the above copyright
|
|
26
|
+
notice, this list of conditions and the following disclaimer.
|
|
27
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
28
|
+
notice, this list of conditions and the following disclaimer in the
|
|
29
|
+
documentation and/or other materials provided with the distribution.
|
|
30
|
+
* Neither the name of Ask Solem nor the
|
|
31
|
+
names of its contributors may be used to endorse or promote products
|
|
32
|
+
derived from this software without specific prior written permission.
|
|
33
|
+
|
|
34
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
35
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
36
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
37
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Ask Solem OR CONTRIBUTORS
|
|
38
|
+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
39
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
40
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
41
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
42
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
43
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
44
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
45
|
+
"""
|
|
46
|
+
return isinstance(obj, iters) and not isinstance(obj, scalars or ())
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def maybe_list(obj: typing.Any, scalars: tuple = (Mapping, str)) -> list: # noqa ANN004
|
|
50
|
+
"""Return list of one element if ``l`` is a scalar.
|
|
51
|
+
|
|
52
|
+
Taken from
|
|
53
|
+
https://github.com/celery/kombu/blob/v5.0.2/kombu/utils/functional.py
|
|
54
|
+
|
|
55
|
+
Copyright (c) 2015-2016 Ask Solem & contributors. All rights reserved.
|
|
56
|
+
Copyright (c) 2012-2014 GoPivotal Inc & contributors. All rights reserved.
|
|
57
|
+
Copyright (c) 2009-2012, Ask Solem & contributors. All rights reserved.
|
|
58
|
+
|
|
59
|
+
Redistribution and use in source and binary forms, with or without
|
|
60
|
+
modification, are permitted provided that the following conditions are met:
|
|
61
|
+
|
|
62
|
+
* Redistributions of source code must retain the above copyright
|
|
63
|
+
notice, this list of conditions and the following disclaimer.
|
|
64
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
65
|
+
notice, this list of conditions and the following disclaimer in the
|
|
66
|
+
documentation and/or other materials provided with the distribution.
|
|
67
|
+
* Neither the name of Ask Solem nor the
|
|
68
|
+
names of its contributors may be used to endorse or promote products
|
|
69
|
+
derived from this software without specific prior written permission.
|
|
70
|
+
|
|
71
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
72
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
73
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
74
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Ask Solem OR CONTRIBUTORS
|
|
75
|
+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
76
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
77
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
78
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
79
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
80
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
81
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
82
|
+
"""
|
|
83
|
+
return obj if obj is None or is_list(obj, scalars) else [obj]
|
echo/models/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from echo.models.agnostic.aggregation import AggregationNode
|
|
2
|
+
from echo.models.agnostic.base import (
|
|
3
|
+
Demand,
|
|
4
|
+
FixedPort,
|
|
5
|
+
Sink,
|
|
6
|
+
Source,
|
|
7
|
+
)
|
|
8
|
+
from echo.models.agnostic.bounded import BoundedLoad, BoundedPort
|
|
9
|
+
from echo.models.agnostic.controlled import (
|
|
10
|
+
ControlledGen,
|
|
11
|
+
ControlledLoad,
|
|
12
|
+
ControlledLoadOrGen,
|
|
13
|
+
)
|
|
14
|
+
from echo.models.agnostic.flex import FlexPort, FlexSink, FlexSource, OffOrConstrainedPort
|
|
15
|
+
from echo.models.agnostic.input_output import InputOutputNode
|
|
16
|
+
from echo.models.agnostic.storage import MobileStorage, Storage
|
|
17
|
+
from echo.models.agnostic.tellegen import (
|
|
18
|
+
MultiCommodityTellegenNode,
|
|
19
|
+
PartitionedMultiCommodityTellegenNode,
|
|
20
|
+
TellegenNode,
|
|
21
|
+
ThreeWayValveNode,
|
|
22
|
+
)
|
|
23
|
+
from echo.models.agnostic.time_delay import TimeDelayNode
|
|
24
|
+
from echo.models.agnostic.time_varying import TimeVaryingPiecewiseIONode
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"AggregationNode",
|
|
28
|
+
"BoundedLoad",
|
|
29
|
+
"BoundedPort",
|
|
30
|
+
"ControlledGen",
|
|
31
|
+
"ControlledLoad",
|
|
32
|
+
"ControlledLoadOrGen",
|
|
33
|
+
"Demand",
|
|
34
|
+
"FixedPort",
|
|
35
|
+
"FlexPort",
|
|
36
|
+
"FlexSink",
|
|
37
|
+
"FlexSource",
|
|
38
|
+
"InputOutputNode",
|
|
39
|
+
"MobileStorage",
|
|
40
|
+
"MultiCommodityTellegenNode",
|
|
41
|
+
"OffOrConstrainedPort",
|
|
42
|
+
"PartitionedMultiCommodityTellegenNode",
|
|
43
|
+
"Sink",
|
|
44
|
+
"Source",
|
|
45
|
+
"Storage",
|
|
46
|
+
"TellegenNode",
|
|
47
|
+
"TimeDelayNode",
|
|
48
|
+
"TimeVaryingPiecewiseIONode",
|
|
49
|
+
"ThreeWayValveNode",
|
|
50
|
+
]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import pyomo.environ as en
|
|
3
|
+
from attrs import define, field
|
|
4
|
+
from pyomo.core.expr import EqualityExpression
|
|
5
|
+
|
|
6
|
+
from echo.configuration import Units
|
|
7
|
+
from echo.exceptions import ConfigurationError
|
|
8
|
+
from echo.models.agnostic.flex import FlexSink
|
|
9
|
+
from echo.models.base import Node, Port
|
|
10
|
+
from echo.models.scenario import EchoConcreteModel
|
|
11
|
+
from echo.validators import ports_have_same_units_validator, ports_match_nominal_units_validator
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@define
|
|
15
|
+
class AggregationNode(Node):
|
|
16
|
+
"""Arbitrary commodity aggregation node.
|
|
17
|
+
|
|
18
|
+
This node has an additional variable, 'total', which equals the sum of all ports defined on the node.
|
|
19
|
+
port_units attribute is used for validation, all ports must be the same commodity.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
port_units: Units = field(kw_only=True)
|
|
23
|
+
ports: dict[str, Port] = field(
|
|
24
|
+
factory=dict, validator=[ports_have_same_units_validator, ports_match_nominal_units_validator]
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# aggregator_unit_check = root_validator(allow_reuse=True)(node_unit_validator)
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def total(self) -> None:
|
|
31
|
+
return "total_value_" + self.node_name
|
|
32
|
+
|
|
33
|
+
def verify_node(self) -> None:
|
|
34
|
+
super().verify_node()
|
|
35
|
+
|
|
36
|
+
def add_port(self, name: str, port: FlexSink | None = None) -> None:
|
|
37
|
+
if port is None:
|
|
38
|
+
port = FlexSink()
|
|
39
|
+
|
|
40
|
+
if self.ports.get(name) is None:
|
|
41
|
+
if port.units == Units.NA:
|
|
42
|
+
port.units = self.port_units
|
|
43
|
+
if port.units != self.port_units:
|
|
44
|
+
raise ValueError(
|
|
45
|
+
f"All ports on Aggregation node must match the node units {self.port_units}."
|
|
46
|
+
f"Received new port with units {port.units} for node {self.node_name}"
|
|
47
|
+
)
|
|
48
|
+
self.ports[name] = port
|
|
49
|
+
else:
|
|
50
|
+
raise ConfigurationError(f"Port with name {name} is already defined on node {self.node_name}")
|
|
51
|
+
|
|
52
|
+
def add_node_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame) -> None:
|
|
53
|
+
super().add_node_to_model(model, profile)
|
|
54
|
+
# Create a variable for the total value
|
|
55
|
+
setattr(model, self.total, en.Var(model.Expansion, model.Time, initialize=0, domain=en.Reals))
|
|
56
|
+
|
|
57
|
+
def apply_node_constraints(self, model: EchoConcreteModel) -> None:
|
|
58
|
+
def sum_rule(model: EchoConcreteModel, p: int, t: int) -> EqualityExpression:
|
|
59
|
+
a = 0
|
|
60
|
+
for port in self.ports.values():
|
|
61
|
+
a += getattr(model, port.port_name)[p, t]
|
|
62
|
+
return getattr(model, self.total)[p, t] == a
|
|
63
|
+
|
|
64
|
+
setattr(model, "total_sum_con_" + self.node_name, en.Constraint(model.Expansion, model.Time, rule=sum_rule))
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from attrs import define, field
|
|
3
|
+
|
|
4
|
+
from echo.configuration import FlowConstraint, Flows, OptimisationType
|
|
5
|
+
from echo.models.base import Port
|
|
6
|
+
from echo.utils import (
|
|
7
|
+
TimeExpandableType,
|
|
8
|
+
)
|
|
9
|
+
from echo.validators import (
|
|
10
|
+
nonnegative_load_validator,
|
|
11
|
+
nonpositive_generation_validator,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@define
|
|
16
|
+
class FixedPort(Port):
|
|
17
|
+
"""Fixed port (parameter), can either import or export."""
|
|
18
|
+
|
|
19
|
+
flows: Flows = Flows.Both
|
|
20
|
+
import_constraint: FlowConstraint = FlowConstraint.NoConstraint
|
|
21
|
+
export_constraint: FlowConstraint = FlowConstraint.NoConstraint
|
|
22
|
+
flow_type: OptimisationType = OptimisationType.Parameter
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@define
|
|
26
|
+
class Source(Port):
|
|
27
|
+
"""A fixed source of a commodity."""
|
|
28
|
+
|
|
29
|
+
flows: Flows = Flows.Export
|
|
30
|
+
export_constraint: FlowConstraint = FlowConstraint.NoConstraint
|
|
31
|
+
flow_type: OptimisationType = OptimisationType.Parameter
|
|
32
|
+
initial_value: dict[tuple[int, int], float] | float = field(default=0, validator=nonpositive_generation_validator)
|
|
33
|
+
|
|
34
|
+
def add_source_profile(self, source_values: dict) -> None:
|
|
35
|
+
self.set_initial_value(source_values)
|
|
36
|
+
|
|
37
|
+
def add_source_profile_from_array(
|
|
38
|
+
self,
|
|
39
|
+
source_values: list[float] | np.ndarray,
|
|
40
|
+
expansion_periods: int = 1,
|
|
41
|
+
time_periods: int | None = None,
|
|
42
|
+
) -> None:
|
|
43
|
+
self.set_initial_value_from_array(
|
|
44
|
+
array=source_values, expansion_periods=expansion_periods, time_periods=time_periods
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@define
|
|
49
|
+
class Sink(Port):
|
|
50
|
+
"""A fixed sink for a commodity."""
|
|
51
|
+
|
|
52
|
+
flows: Flows = Flows.Import
|
|
53
|
+
import_constraint: FlowConstraint = FlowConstraint.NoConstraint
|
|
54
|
+
flow_type: OptimisationType = OptimisationType.Parameter
|
|
55
|
+
|
|
56
|
+
initial_value: dict[tuple[int, int], float] | float = field(default=0, validator=nonnegative_load_validator)
|
|
57
|
+
|
|
58
|
+
def add_sink_profile(self, sink_values: dict[tuple[int, int], float]) -> None:
|
|
59
|
+
self.set_initial_value(sink_values)
|
|
60
|
+
|
|
61
|
+
def add_sink_profile_from_array(
|
|
62
|
+
self,
|
|
63
|
+
sink_values: list[float] | np.ndarray,
|
|
64
|
+
expansion_periods: int = 1,
|
|
65
|
+
time_periods: int | None = None,
|
|
66
|
+
) -> None:
|
|
67
|
+
|
|
68
|
+
self.set_initial_value_from_array(
|
|
69
|
+
array=sink_values, expansion_periods=expansion_periods, time_periods=time_periods
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@define
|
|
74
|
+
class Demand(Sink):
|
|
75
|
+
def add_demand_profile(self, demand: dict) -> None:
|
|
76
|
+
self.set_initial_value(demand)
|
|
77
|
+
|
|
78
|
+
def add_demand_profile_from_array(
|
|
79
|
+
self,
|
|
80
|
+
demand: TimeExpandableType,
|
|
81
|
+
expansion_periods: int = 1,
|
|
82
|
+
time_periods: int | None = None,
|
|
83
|
+
) -> None:
|
|
84
|
+
self.set_initial_value_from_array(array=demand, expansion_periods=expansion_periods, time_periods=time_periods)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from attrs import define, field
|
|
3
|
+
|
|
4
|
+
from echo.configuration import FlowConstraint
|
|
5
|
+
from echo.models.agnostic.flex import FlexPort
|
|
6
|
+
from echo.models.scenario import EchoConcreteModel
|
|
7
|
+
from echo.utils import (
|
|
8
|
+
generate_array_constraint,
|
|
9
|
+
set_var_bounds_from_dict,
|
|
10
|
+
)
|
|
11
|
+
from echo.validators import (
|
|
12
|
+
ArrayType,
|
|
13
|
+
bound_order_validator,
|
|
14
|
+
nonnegative_load_validator,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@define
|
|
19
|
+
class BoundedPort(FlexPort):
|
|
20
|
+
"""A flex port with an upper and lower bound"""
|
|
21
|
+
|
|
22
|
+
upper_bound: ArrayType | float = field(kw_only=True, validator=bound_order_validator)
|
|
23
|
+
lower_bound: ArrayType | float = field(kw_only=True, validator=bound_order_validator)
|
|
24
|
+
|
|
25
|
+
def add_port_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame) -> None:
|
|
26
|
+
super().add_port_to_model(model, profile)
|
|
27
|
+
# Set bounds on our port variable
|
|
28
|
+
ub_dict = generate_array_constraint(self.upper_bound, time_periods=len(model.Time), expansion_periods=1)
|
|
29
|
+
lb_dict = generate_array_constraint(self.lower_bound, time_periods=len(model.Time), expansion_periods=1)
|
|
30
|
+
set_var_bounds_from_dict(model=model, var_name=self.port_name, ub=ub_dict, lb=lb_dict)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@define
|
|
34
|
+
class BoundedLoad(BoundedPort):
|
|
35
|
+
"""A port where the load has to be within a max and min value which is specified at each timestep."""
|
|
36
|
+
|
|
37
|
+
import_constraint: FlowConstraint = FlowConstraint.NoConstraint
|
|
38
|
+
|
|
39
|
+
upper_bound: ArrayType | float = field(kw_only=True, validator=[nonnegative_load_validator, bound_order_validator])
|
|
40
|
+
lower_bound: ArrayType | float = field(kw_only=True, validator=[nonnegative_load_validator, bound_order_validator])
|
|
41
|
+
|
|
42
|
+
def add_port_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame) -> None:
|
|
43
|
+
super().add_port_to_model(model, profile)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import attrs
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import pyomo.environ as en
|
|
4
|
+
from attrs import define, field
|
|
5
|
+
from pyomo.core.expr import InequalityExpression
|
|
6
|
+
|
|
7
|
+
from echo.configuration import Flows, Units
|
|
8
|
+
from echo.models.agnostic.flex import FlexPort
|
|
9
|
+
from echo.models.scenario import EchoConcreteModel
|
|
10
|
+
from echo.utils import (
|
|
11
|
+
set_float_var_bounds,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@define
|
|
16
|
+
class ControlledLoadOrGen(FlexPort):
|
|
17
|
+
"""
|
|
18
|
+
A controlled load or generation has a max/min power, as well as a max/min utilisation.
|
|
19
|
+
Min utilisation is the ratio between the minimum energy consumed/generated,
|
|
20
|
+
and the maximum energy that could be consumed/generated if the load operated at max power.
|
|
21
|
+
Max utilisation is the ratio between the maximum energy consumed/generated,
|
|
22
|
+
and the maximum energy that could be consumed/generated if the load operated at max power.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
min_utilisation: float | None = field(default=None)
|
|
26
|
+
max_utilisation: float | None = field(default=None)
|
|
27
|
+
max_power: float | None = field(default=None)
|
|
28
|
+
min_power: float | None = field(default=None)
|
|
29
|
+
units: Units = field(default=Units.KW)
|
|
30
|
+
|
|
31
|
+
def add_port_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame) -> None:
|
|
32
|
+
super().add_port_to_model(model, profile)
|
|
33
|
+
|
|
34
|
+
# Set bounds using min and max power
|
|
35
|
+
set_float_var_bounds(model=model, var_name=self.port_name, ub=self.max_power, lb=self.min_power)
|
|
36
|
+
|
|
37
|
+
if self.min_utilisation is not None and self.max_power is not None:
|
|
38
|
+
min_utilisation: float = self.min_utilisation
|
|
39
|
+
max_power: float = self.max_power
|
|
40
|
+
|
|
41
|
+
def sum_of_energy_must_be_greater_than_min(model: EchoConcreteModel) -> InequalityExpression:
|
|
42
|
+
return (
|
|
43
|
+
sum(
|
|
44
|
+
getattr(model, self.port_name)[p, i] * model.scenario_settings.interval_duration / 60.0
|
|
45
|
+
for p in model.Expansion
|
|
46
|
+
for i in model.Time
|
|
47
|
+
)
|
|
48
|
+
>= min_utilisation
|
|
49
|
+
* max_power
|
|
50
|
+
* model.scenario_settings.interval_duration
|
|
51
|
+
* model.scenario_settings.number_of_intervals
|
|
52
|
+
/ 60.0
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
setattr(
|
|
56
|
+
model,
|
|
57
|
+
f"cons_{self.port_name}_min_utilisation_req",
|
|
58
|
+
en.Constraint(rule=sum_of_energy_must_be_greater_than_min),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
if self.max_utilisation is not None and self.max_power is not None:
|
|
62
|
+
max_utilisation: float = self.max_utilisation
|
|
63
|
+
max_power = self.max_power
|
|
64
|
+
|
|
65
|
+
def sum_of_energy_must_be_less_than_max(model: EchoConcreteModel) -> InequalityExpression:
|
|
66
|
+
return (
|
|
67
|
+
sum(
|
|
68
|
+
getattr(model, self.port_name)[p, i] * model.scenario_settings.interval_duration / 60.0
|
|
69
|
+
for p in model.Expansion
|
|
70
|
+
for i in model.Time
|
|
71
|
+
)
|
|
72
|
+
<= max_utilisation
|
|
73
|
+
* max_power
|
|
74
|
+
* model.scenario_settings.interval_duration
|
|
75
|
+
* model.scenario_settings.number_of_intervals
|
|
76
|
+
/ 60.0
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
setattr(
|
|
80
|
+
model,
|
|
81
|
+
f"cons_{self.port_name}_max_utilisation_req",
|
|
82
|
+
en.Constraint(rule=sum_of_energy_must_be_less_than_max),
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@define
|
|
87
|
+
class ControlledLoad(ControlledLoadOrGen):
|
|
88
|
+
max_power: float = field(kw_only=True, validator=attrs.validators.ge(0))
|
|
89
|
+
min_power: float = field(kw_only=True, validator=attrs.validators.ge(0))
|
|
90
|
+
flows = Flows.Import
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@define
|
|
94
|
+
class ControlledGen(ControlledLoadOrGen):
|
|
95
|
+
max_power: float = field(kw_only=True, validator=attrs.validators.le(0))
|
|
96
|
+
min_power: float = field(kw_only=True, validator=attrs.validators.le(0))
|
|
97
|
+
flows = Flows.Export
|