monee 2.2.0__tar.gz → 2.3.0__tar.gz
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.
- {monee-2.2.0/src/monee.egg-info → monee-2.3.0}/PKG-INFO +1 -1
- {monee-2.2.0 → monee-2.3.0}/pyproject.toml +1 -1
- {monee-2.2.0 → monee-2.3.0}/src/monee/__init__.py +4 -2
- {monee-2.2.0 → monee-2.3.0}/src/monee/express/__init__.py +86 -16
- {monee-2.2.0 → monee-2.3.0}/src/monee/io/from_pandapower.py +46 -23
- {monee-2.2.0 → monee-2.3.0}/src/monee/io/native.py +2 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/branch.py +44 -8
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/child.py +12 -8
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/core.py +48 -1
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/extension/islanding/el.py +5 -1
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/extension/linepack.py +22 -11
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/extension/ltc.py +20 -10
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/__init__.py +5 -2
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/bundles.py +43 -19
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/common.py +85 -6
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/milp/gas.py +1 -3
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/milp/heat.py +7 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/miqcqp/__init__.py +2 -1
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/miqcqp/convex/el.py +111 -26
- monee-2.3.0/src/monee/model/formulation/miqcqp/convex/gas.py +337 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/miqcqp/nonconvex/el.py +5 -2
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/miqcqp/nonconvex/heat.py +115 -19
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/nlp/gas.py +27 -17
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/nlp/heat.py +55 -16
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/registry.py +25 -2
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/grid.py +1 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/multi.py +138 -21
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/network.py +13 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/node.py +80 -29
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/core/hydraulics.py +5 -2
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/nonlinear/gf.py +21 -7
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/nonlinear/smooth.py +64 -5
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/nonlinear/wf.py +24 -13
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/storage.py +26 -33
- {monee-2.2.0 → monee-2.3.0}/src/monee/network/__init__.py +1 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/network/mes.py +808 -655
- {monee-2.2.0 → monee-2.3.0}/src/monee/problem/core.py +279 -26
- {monee-2.2.0 → monee-2.3.0}/src/monee/problem/economic_dispatch.py +48 -30
- {monee-2.2.0 → monee-2.3.0}/src/monee/problem/metric.py +8 -3
- {monee-2.2.0 → monee-2.3.0}/src/monee/problem/min_load_shedding.py +405 -267
- {monee-2.2.0 → monee-2.3.0}/src/monee/problem/utils.py +164 -31
- {monee-2.2.0 → monee-2.3.0}/src/monee/simulation/multi_period.py +290 -86
- {monee-2.2.0 → monee-2.3.0}/src/monee/simulation/stepper.py +3 -3
- {monee-2.2.0 → monee-2.3.0}/src/monee/simulation/timeseries.py +165 -40
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/casadi.py +274 -50
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/core.py +473 -128
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/dispatch.py +21 -13
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/gurobipy.py +145 -33
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/infeasibility/pyo.py +6 -5
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/pyo.py +109 -39
- {monee-2.2.0 → monee-2.3.0/src/monee.egg-info}/PKG-INFO +1 -1
- {monee-2.2.0 → monee-2.3.0}/src/monee.egg-info/SOURCES.txt +2 -1
- monee-2.3.0/tests/test_version.py +13 -0
- monee-2.2.0/src/monee/model/formulation/miqcqp/convex/gas.py +0 -118
- {monee-2.2.0 → monee-2.3.0}/LICENSE +0 -0
- {monee-2.2.0 → monee-2.3.0}/README.md +0 -0
- {monee-2.2.0 → monee-2.3.0}/setup.cfg +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/express/structures.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/io/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/io/_utils.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/io/from_cim.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/io/from_esdl.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/io/from_simbench.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/io/matpower.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/extension/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/extension/core.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/extension/islanding/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/extension/islanding/core.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/extension/islanding/gas.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/extension/islanding/water.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/core.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/milp/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/miqcqp/convex/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/miqcqp/nonconvex/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/miqcqp/nonconvex/gas.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/nlp/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/formulation/nlp/el.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/core/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/core/properties.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/islanding.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/linear/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/misoc/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/misoc/pf.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/nonlinear/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/nonlinear/ac.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/model/phys/nonlinear/hf.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/network/bench/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/network/bench/restoration.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/network/res.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/problem/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/simulation/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/simulation/core.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/simulation/result_utils.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/simulation/step_state.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/gekko.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/infeasibility/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/solver/infeasibility/apm.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/visualization/__init__.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/visualization/result_visualization.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee/visualization/visualization.py +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee.egg-info/dependency_links.txt +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee.egg-info/requires.txt +0 -0
- {monee-2.2.0 → monee-2.3.0}/src/monee.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: monee
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: Framework for calculating the steady-state energy flow and for solving optimization problems in coupled energy grids (gas, heat, electricity)
|
|
5
5
|
Author-email: Rico Schrage <rico.schrage@uol.de>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
__version__ = "2.3.0"
|
|
2
|
+
|
|
1
3
|
import monee.model as mm
|
|
2
4
|
import monee.solver as ms
|
|
3
5
|
import monee.problem as mp
|
|
@@ -231,7 +233,7 @@ def run_energy_flow_optimization(
|
|
|
231
233
|
result = run_energy_flow_optimization(my_network, my_problem, max_iter=1000, tol=1e-6)
|
|
232
234
|
"""
|
|
233
235
|
if copy:
|
|
234
|
-
net = net.
|
|
236
|
+
net = net._copy_for_solve()
|
|
235
237
|
return solve(net, optimization_problem, solver, **kwargs)
|
|
236
238
|
|
|
237
239
|
|
|
@@ -278,7 +280,7 @@ def solve_load_shedding_problem(
|
|
|
278
280
|
network (Network): The network to optimize, representing the system's topology and parameters.
|
|
279
281
|
demand_weight: Objective weight per shed demand unit.
|
|
280
282
|
generator_weight: Objective weight per shed generation unit.
|
|
281
|
-
weight_for_load: Optional callable ``weight_for_load(model)`` returning a per-load weight (None falls back to ``demand_weight``).
|
|
283
|
+
weight_for_load: Optional callable ``weight_for_load(model)`` returning a per-load weight, used as given and never rescaled by the priority floor (None falls back to ``demand_weight``).
|
|
282
284
|
bounds_vm (tuple): Per-unit voltage-magnitude bounds (min, max) for the electrical subsystem.
|
|
283
285
|
bounds_pressure (tuple): Per-unit pressure bounds (min, max) for the gas subsystem.
|
|
284
286
|
bounds_t (tuple): Per-unit temperature bounds (min, max) for the thermal subsystem.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
|
|
1
3
|
import monee.model as mm
|
|
2
4
|
from monee.model.extension.islanding import GridFormingGenerator, GridFormingSource
|
|
3
5
|
|
|
@@ -110,7 +112,7 @@ def create_el_branch(
|
|
|
110
112
|
|
|
111
113
|
|
|
112
114
|
def create_line(
|
|
113
|
-
network: mm.Network,
|
|
115
|
+
network: mm.Network, # NOSONAR
|
|
114
116
|
from_node_id,
|
|
115
117
|
to_node_id,
|
|
116
118
|
length_m,
|
|
@@ -123,10 +125,14 @@ def create_line(
|
|
|
123
125
|
on_off=1,
|
|
124
126
|
max_i_ka=None,
|
|
125
127
|
max_s_mva=None,
|
|
128
|
+
backup=False,
|
|
129
|
+
c_nf_per_m=0,
|
|
126
130
|
):
|
|
127
131
|
"""Add a :class:`PowerLine` between two buses; missing buses are auto-created.
|
|
128
132
|
``max_i_ka`` / ``max_s_mva`` set the thermal rating (model defaults apply
|
|
129
|
-
when omitted).
|
|
133
|
+
when omitted). ``backup=True`` marks a switchable line (e.g. a normally-open
|
|
134
|
+
tie with ``on_off=0``) that load shedding may close. ``c_nf_per_m`` is the
|
|
135
|
+
line capacitance in nF/m (charging susceptance)."""
|
|
130
136
|
rating_kwargs = {}
|
|
131
137
|
if max_i_ka is not None:
|
|
132
138
|
rating_kwargs["max_i_ka"] = max_i_ka
|
|
@@ -138,7 +144,9 @@ def create_line(
|
|
|
138
144
|
r_ohm_per_m,
|
|
139
145
|
x_ohm_per_m,
|
|
140
146
|
parallel,
|
|
147
|
+
backup=backup,
|
|
141
148
|
on_off=on_off,
|
|
149
|
+
c_nf_per_m=c_nf_per_m,
|
|
142
150
|
**rating_kwargs,
|
|
143
151
|
),
|
|
144
152
|
from_node_id=from_node_id,
|
|
@@ -239,6 +247,47 @@ def create_water_pipe(
|
|
|
239
247
|
)
|
|
240
248
|
|
|
241
249
|
|
|
250
|
+
def split_pipe(network: mm.Network, branch_id, n):
|
|
251
|
+
"""Replace the pipe *branch_id* by *n* equal segments in series, joined by
|
|
252
|
+
``n - 1`` new junctions on its grid. Each segment is a copy of the pipe's
|
|
253
|
+
model with ``length_m / n`` (diameter, roughness, insulation unchanged),
|
|
254
|
+
named ``<pipe name>.<i>``. Returns the ``n + 1`` node ids along the chain,
|
|
255
|
+
from the pipe's from-node to its to-node; ``n = 1`` leaves the pipe as is.
|
|
256
|
+
Works for water and gas pipes."""
|
|
257
|
+
if n < 1:
|
|
258
|
+
raise ValueError(f"split_pipe needs n >= 1 segments, got {n!r}.")
|
|
259
|
+
branch = network.branch_by_id(branch_id)
|
|
260
|
+
if n == 1:
|
|
261
|
+
return [branch.from_node_id, branch.to_node_id]
|
|
262
|
+
|
|
263
|
+
def name(i):
|
|
264
|
+
return None if branch.name is None else f"{branch.name}.{i}"
|
|
265
|
+
|
|
266
|
+
chain = [branch.from_node_id]
|
|
267
|
+
chain += [
|
|
268
|
+
network.node(mm.Junction(), grid=branch.grid, name=name(i)) for i in range(1, n)
|
|
269
|
+
]
|
|
270
|
+
chain.append(branch.to_node_id)
|
|
271
|
+
network.remove_branch(branch_id)
|
|
272
|
+
for i in range(n):
|
|
273
|
+
model = copy.deepcopy(branch.model)
|
|
274
|
+
model.length_m = branch.model.length_m / n
|
|
275
|
+
segment = network.branch_by_id(
|
|
276
|
+
network.branch(
|
|
277
|
+
model,
|
|
278
|
+
chain[i],
|
|
279
|
+
chain[i + 1],
|
|
280
|
+
formulation=branch.formulation,
|
|
281
|
+
constraints=list(branch.constraints),
|
|
282
|
+
grid=branch.grid,
|
|
283
|
+
name=name(i),
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
segment.formulation_pinned = branch.formulation_pinned
|
|
287
|
+
segment.active = branch.active
|
|
288
|
+
return chain
|
|
289
|
+
|
|
290
|
+
|
|
242
291
|
def create_el_child(
|
|
243
292
|
network: mm.Network,
|
|
244
293
|
model,
|
|
@@ -612,7 +661,16 @@ def create_heat_load(
|
|
|
612
661
|
|
|
613
662
|
Part load in one line: drive the stored ``q_mw_heat`` attribute; a nodal
|
|
614
663
|
heat load has no mass flow of its own, so the exchangers' constant-flow
|
|
615
|
-
vs variable-flow distinction does not apply.
|
|
664
|
+
vs variable-flow distinction does not apply.
|
|
665
|
+
|
|
666
|
+
The heat comes out of the junction's mixed stream (the nodal heat
|
|
667
|
+
balance), so every stream leaving the junction, the downstream supply
|
|
668
|
+
pipe included, leaves at the cooled temperature; a Sink on the same
|
|
669
|
+
junction drains water at that temperature and does not carry the heat
|
|
670
|
+
away separately. Along a supply line the temperature therefore drops at
|
|
671
|
+
every node-based consumer. A consumer that should cool only its own flow
|
|
672
|
+
is a branch from supply to return
|
|
673
|
+
(:func:`create_heat_exchanger` / :func:`create_passive_heat_exchanger`)."""
|
|
616
674
|
return create_water_child(
|
|
617
675
|
network,
|
|
618
676
|
mm.HeatLoad(q_mw=q_mw, **kwargs),
|
|
@@ -1142,15 +1200,24 @@ def create_trafo(
|
|
|
1142
1200
|
constraints=None,
|
|
1143
1201
|
grid=None,
|
|
1144
1202
|
name=None,
|
|
1203
|
+
max_i_ka=None,
|
|
1204
|
+
tap=1.0,
|
|
1145
1205
|
):
|
|
1146
|
-
"""Add a two-winding :class:`Trafo`. from-node = LV side, to-node = HV side.
|
|
1206
|
+
"""Add a two-winding :class:`Trafo`. from-node = LV side, to-node = HV side.
|
|
1207
|
+
``max_i_ka`` sets the current rating behind the loading (model default when
|
|
1208
|
+
omitted). ``tap`` is the off-nominal turns ratio at the from-node; see
|
|
1209
|
+
:class:`~monee.model.branch.Trafo`."""
|
|
1210
|
+
model = mm.Trafo(
|
|
1211
|
+
vk_percent=vk_percent,
|
|
1212
|
+
vkr_percent=vkr_percent,
|
|
1213
|
+
sn_trafo_mva=sn_trafo_mva,
|
|
1214
|
+
shift=shift,
|
|
1215
|
+
tap=tap,
|
|
1216
|
+
)
|
|
1217
|
+
if max_i_ka is not None:
|
|
1218
|
+
model.max_i_ka = max_i_ka
|
|
1147
1219
|
return network.branch(
|
|
1148
|
-
|
|
1149
|
-
vk_percent=vk_percent,
|
|
1150
|
-
vkr_percent=vkr_percent,
|
|
1151
|
-
sn_trafo_mva=sn_trafo_mva,
|
|
1152
|
-
shift=shift,
|
|
1153
|
-
),
|
|
1220
|
+
model,
|
|
1154
1221
|
from_node_id=from_node_id,
|
|
1155
1222
|
to_node_id=to_node_id,
|
|
1156
1223
|
constraints=constraints,
|
|
@@ -1242,12 +1309,15 @@ def create_water_ext_grid(
|
|
|
1242
1309
|
auto-creating a water junction if needed.
|
|
1243
1310
|
|
|
1244
1311
|
On a heat network this slack behaves as an unlimited backup heat plant:
|
|
1245
|
-
|
|
1246
|
-
sources elsewhere are compensated silently instead of
|
|
1247
|
-
Cap it with ``
|
|
1248
|
-
|
|
1249
|
-
``
|
|
1250
|
-
|
|
1312
|
+
with its temperature pinned it supplies whatever heat the island balance
|
|
1313
|
+
needs, so lost heat sources elsewhere are compensated silently instead of
|
|
1314
|
+
shedding heat load. Cap it with ``bounds_ext_heat_mw`` on the
|
|
1315
|
+
load-shedding or economic dispatch problem, or pass
|
|
1316
|
+
``pin_temperature=False``, when that is not the intended physics. On a
|
|
1317
|
+
closed loop (reference on the return) the heat is not carried by the
|
|
1318
|
+
exchanged mass flow, so ``max_import_kgs`` / ``max_export_kgs`` and the
|
|
1319
|
+
load-shedding ``bounds_ext_heat`` (kg/s) only limit it where the slack
|
|
1320
|
+
feeds the loop with mass (see the concepts/multi_energy page).
|
|
1251
1321
|
|
|
1252
1322
|
Args:
|
|
1253
1323
|
node_id: water junction to attach to; a missing node is auto-created.
|
|
@@ -89,6 +89,47 @@ def _register_branch(table, row, pair, seen, kinds, meta):
|
|
|
89
89
|
return bid
|
|
90
90
|
|
|
91
91
|
|
|
92
|
+
def _trafo_max_i_ka(net, row):
|
|
93
|
+
"""hv-side rated current in kA of a pandapower trafo row (``sn_mva``
|
|
94
|
+
times ``parallel`` and ``df``), or None without a usable rating."""
|
|
95
|
+
sn_mva = _coerce_positive_float(getattr(row, "sn_mva", None), default=None)
|
|
96
|
+
vn_kv = _coerce_positive_float(net.bus.at[row.hv_bus, "vn_kv"], default=None)
|
|
97
|
+
if sn_mva is None or vn_kv is None:
|
|
98
|
+
return None
|
|
99
|
+
parallel = _coerce_positive_int(getattr(row, "parallel", 1))
|
|
100
|
+
df = _coerce_positive_float(getattr(row, "df", 1.0))
|
|
101
|
+
return sn_mva * parallel * df / (math.sqrt(3) * vn_kv)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _trafo_and_impedance_overrides(net, pair_args, registry) -> dict:
|
|
105
|
+
"""Ratings of the trafos; an impedance only takes its branch slot.
|
|
106
|
+
``pair_args`` and ``registry`` are the trailing arguments of
|
|
107
|
+
:func:`_resolve_branch_pair` and :func:`_register_branch`."""
|
|
108
|
+
overrides = {}
|
|
109
|
+
# ppc branch order is line, trafo, trafo3w, impedance; trafo3w arms end on
|
|
110
|
+
# a unique star bus and never collide with these pairs, so counting
|
|
111
|
+
# impedances here keeps the parallel keys aligned with to_mpc.
|
|
112
|
+
for table, from_col, to_col in (
|
|
113
|
+
("trafo", "hv_bus", "lv_bus"),
|
|
114
|
+
("impedance", "from_bus", "to_bus"),
|
|
115
|
+
):
|
|
116
|
+
for row in _in_service_rows(net, table):
|
|
117
|
+
pair = _resolve_branch_pair(
|
|
118
|
+
getattr(row, from_col), getattr(row, to_col), *pair_args
|
|
119
|
+
)
|
|
120
|
+
if pair is None:
|
|
121
|
+
continue
|
|
122
|
+
bid = _register_branch(table, row, pair, *registry)
|
|
123
|
+
# to_mpc writes a 100 MVA placeholder RATE_A for a trafo without
|
|
124
|
+
# max_loading_percent; rate it at its sn_mva like pandapower's own
|
|
125
|
+
# loading_percent (and like the lines), in the hv (from-side)
|
|
126
|
+
# current basis.
|
|
127
|
+
rating = _trafo_max_i_ka(net, row) if table == "trafo" else None
|
|
128
|
+
if rating is not None:
|
|
129
|
+
overrides[bid] = rating
|
|
130
|
+
return overrides
|
|
131
|
+
|
|
132
|
+
|
|
92
133
|
def _pp_branch_max_i_ka_overrides(net, bus_to_node, monee_node_ids):
|
|
93
134
|
overrides = {}
|
|
94
135
|
kinds = {}
|
|
@@ -98,40 +139,22 @@ def _pp_branch_max_i_ka_overrides(net, bus_to_node, monee_node_ids):
|
|
|
98
139
|
if not hasattr(net, "bus"):
|
|
99
140
|
return overrides, kinds, meta
|
|
100
141
|
|
|
101
|
-
|
|
142
|
+
pair_args = (_live_bus_ids(net), bus_to_node, monee_node_ids)
|
|
143
|
+
registry = (seen, kinds, meta)
|
|
102
144
|
|
|
103
145
|
skipped_lines = []
|
|
104
146
|
# to_mpc drops out-of-service lines, so they consume no branch slot.
|
|
105
147
|
for row in _in_service_rows(net, "line"):
|
|
106
|
-
pair = _resolve_branch_pair(
|
|
107
|
-
row.from_bus, row.to_bus, live_buses, bus_to_node, monee_node_ids
|
|
108
|
-
)
|
|
148
|
+
pair = _resolve_branch_pair(row.from_bus, row.to_bus, *pair_args)
|
|
109
149
|
if pair is None:
|
|
110
150
|
skipped_lines.append(row.Index)
|
|
111
151
|
continue
|
|
112
|
-
bid = _register_branch("line", row, pair,
|
|
152
|
+
bid = _register_branch("line", row, pair, *registry)
|
|
113
153
|
max_i_ka = float(row.max_i_ka)
|
|
114
154
|
parallel = _coerce_positive_int(getattr(row, "parallel", 1))
|
|
115
155
|
df = _coerce_positive_float(getattr(row, "df", 1.0))
|
|
116
156
|
overrides[bid] = max_i_ka * parallel * df
|
|
117
|
-
|
|
118
|
-
# ppc branch order is line, trafo, trafo3w, impedance; trafo3w arms end on
|
|
119
|
-
# a unique star bus and never collide with these pairs, so counting
|
|
120
|
-
# impedances here keeps the parallel keys aligned with to_mpc.
|
|
121
|
-
for table, from_col, to_col in (
|
|
122
|
-
("trafo", "hv_bus", "lv_bus"),
|
|
123
|
-
("impedance", "from_bus", "to_bus"),
|
|
124
|
-
):
|
|
125
|
-
for row in _in_service_rows(net, table):
|
|
126
|
-
pair = _resolve_branch_pair(
|
|
127
|
-
getattr(row, from_col),
|
|
128
|
-
getattr(row, to_col),
|
|
129
|
-
live_buses,
|
|
130
|
-
bus_to_node,
|
|
131
|
-
monee_node_ids,
|
|
132
|
-
)
|
|
133
|
-
if pair is not None:
|
|
134
|
-
_register_branch(table, row, pair, seen, kinds, meta)
|
|
157
|
+
overrides.update(_trafo_and_impedance_overrides(net, pair_args, registry))
|
|
135
158
|
|
|
136
159
|
if skipped_lines:
|
|
137
160
|
warnings.warn(
|
|
@@ -489,6 +489,8 @@ def model_to_dict(model, include_solve_state=False):
|
|
|
489
489
|
"""
|
|
490
490
|
result = {}
|
|
491
491
|
for key, value in model.__dict__.items():
|
|
492
|
+
if key == "_solved_values" and not include_solve_state:
|
|
493
|
+
continue
|
|
492
494
|
if _encodable(value):
|
|
493
495
|
result[key] = _encode_value(value, include_solve_state)
|
|
494
496
|
elif not key.startswith("_"):
|
|
@@ -85,6 +85,12 @@ class PowerBranch(GenericPowerBranch, ABC):
|
|
|
85
85
|
|
|
86
86
|
@model
|
|
87
87
|
class PowerLine(PowerBranch):
|
|
88
|
+
"""Line or cable from per-metre data; ``c_nf_per_m`` is the operating
|
|
89
|
+
capacitance, split as half the charging susceptance onto each end (pi model)."""
|
|
90
|
+
|
|
91
|
+
# Networks saved before line charging existed restore without the attribute.
|
|
92
|
+
c_nf_per_m = 0
|
|
93
|
+
|
|
88
94
|
def __init__(
|
|
89
95
|
self,
|
|
90
96
|
length_m,
|
|
@@ -93,6 +99,7 @@ class PowerLine(PowerBranch):
|
|
|
93
99
|
parallel,
|
|
94
100
|
backup=False,
|
|
95
101
|
on_off=1,
|
|
102
|
+
c_nf_per_m=0,
|
|
96
103
|
**kwargs,
|
|
97
104
|
) -> None:
|
|
98
105
|
super().__init__(1, 0, backup=backup, on_off=on_off, **kwargs)
|
|
@@ -100,6 +107,7 @@ class PowerLine(PowerBranch):
|
|
|
100
107
|
self.r_ohm_per_m = r_ohm_per_m
|
|
101
108
|
self.x_ohm_per_m = x_ohm_per_m
|
|
102
109
|
self.parallel = parallel
|
|
110
|
+
self.c_nf_per_m = c_nf_per_m
|
|
103
111
|
|
|
104
112
|
def calc_r_x(self, grid: PowerGrid, from_node_model, to_node_model):
|
|
105
113
|
base_r = from_node_model.base_kv**2 / grid.sn_mva
|
|
@@ -107,13 +115,33 @@ class PowerLine(PowerBranch):
|
|
|
107
115
|
br_x_pu = self.x_ohm_per_m * self.length_m / base_r / self.parallel
|
|
108
116
|
return (br_r_pu, br_x_pu)
|
|
109
117
|
|
|
118
|
+
def calc_b_pu(self, grid: PowerGrid, from_node_model):
|
|
119
|
+
"""Charging susceptance at each end, per unit."""
|
|
120
|
+
base_r = from_node_model.base_kv**2 / grid.sn_mva
|
|
121
|
+
b_s_per_m = 2 * np.pi * grid.f_hz * self.c_nf_per_m * 1e-9
|
|
122
|
+
b_total_s = b_s_per_m * self.length_m * self.parallel
|
|
123
|
+
return b_total_s * base_r / 2
|
|
124
|
+
|
|
125
|
+
def equations(self, grid: PowerGrid, from_node_model, to_node_model, **kwargs):
|
|
126
|
+
self.b_fr_pu = self.b_to_pu = self.calc_b_pu(grid, from_node_model)
|
|
127
|
+
return super().equations(grid, from_node_model, to_node_model, **kwargs)
|
|
128
|
+
|
|
110
129
|
|
|
111
130
|
@model
|
|
112
131
|
class Trafo(PowerBranch):
|
|
132
|
+
"""Two-winding transformer whose rated voltages equal the bus ``base_kv``, so
|
|
133
|
+
its per-unit impedance is ``vk_percent / 100 * sn_mva / sn_trafo_mva``.
|
|
134
|
+
|
|
135
|
+
``tap`` is the off-nominal turns ratio at the from-node (an LV-side tap for
|
|
136
|
+
the usual from = LV wiring); the impedance sits on the to-node side. A
|
|
137
|
+
pandapower tap ``tap_pos`` with ``tap_step_percent`` on side ``s`` maps to
|
|
138
|
+
``tap = 1 + tap_pos * tap_step_percent / 100`` with the from-node on side ``s``.
|
|
139
|
+
"""
|
|
140
|
+
|
|
113
141
|
def __init__(
|
|
114
|
-
self, vk_percent=12.2, vkr_percent=0.25, sn_trafo_mva=160, shift=0
|
|
142
|
+
self, vk_percent=12.2, vkr_percent=0.25, sn_trafo_mva=160, shift=0, tap=1.0
|
|
115
143
|
) -> None:
|
|
116
|
-
super().__init__(
|
|
144
|
+
super().__init__(tap, shift)
|
|
117
145
|
if (
|
|
118
146
|
isinstance(vk_percent, (int, float))
|
|
119
147
|
and isinstance(vkr_percent, (int, float))
|
|
@@ -126,13 +154,11 @@ class Trafo(PowerBranch):
|
|
|
126
154
|
self.vk_percent = vk_percent
|
|
127
155
|
self.vkr_percent = vkr_percent
|
|
128
156
|
self.sn_trafo_mva = sn_trafo_mva
|
|
129
|
-
self.vn_trafo_lv = 1
|
|
130
157
|
|
|
131
|
-
def calc_r_x(self, grid: PowerGrid,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
x_sc = np.sign(z_sc) * np.sqrt((z_sc**2 - r_sc**2).astype(float))
|
|
158
|
+
def calc_r_x(self, grid: PowerGrid, from_node_model, to_node_model):
|
|
159
|
+
z_sc = self.vk_percent / 100.0 * grid.sn_mva / self.sn_trafo_mva
|
|
160
|
+
r_sc = self.vkr_percent / 100.0 * grid.sn_mva / self.sn_trafo_mva
|
|
161
|
+
x_sc = np.sign(z_sc) * np.sqrt(np.asarray(z_sc**2 - r_sc**2, dtype=float))
|
|
136
162
|
return (r_sc, x_sc)
|
|
137
163
|
|
|
138
164
|
|
|
@@ -326,6 +352,16 @@ class HeatExchanger(BranchModel):
|
|
|
326
352
|
self.t_from_pu = Var(1, min=0, max=2, name="t_from_pu")
|
|
327
353
|
self.t_to_pu = Var(1, min=0, max=2, name="t_to_pu")
|
|
328
354
|
|
|
355
|
+
def scale_duty(self, factor):
|
|
356
|
+
"""Scale the duty by *factor*: the setpoint, the design flow and the
|
|
357
|
+
warm-start seeds derived from them, so a part-load duty solves like a
|
|
358
|
+
heat exchanger built for it (``regulation`` scales the duty within one
|
|
359
|
+
solve instead)."""
|
|
360
|
+
self.q_mw_set = self.q_mw_set * factor
|
|
361
|
+
self.mass_flow_design_kgs = self.mass_flow_design_kgs * factor
|
|
362
|
+
self._q_design_mw = self._q_design_mw * factor
|
|
363
|
+
self._mass_flow_seed_kgs = self._mass_flow_seed_kgs * factor
|
|
364
|
+
|
|
329
365
|
def equations(self, grid: WaterGrid, from_node_model, to_node_model, **kwargs):
|
|
330
366
|
eqs = [
|
|
331
367
|
IntermediateEq(
|
|
@@ -260,14 +260,18 @@ class ExtHydrGrid(NoVarChildModel, GridFormingMixin):
|
|
|
260
260
|
``monee.express.create_gas_ext_grid`` is also an ``ExtHydrGrid`` (the name
|
|
261
261
|
refers to the shared hydraulic slack role, not to water specifically).
|
|
262
262
|
|
|
263
|
-
On a water loop this slack acts as an unlimited backup heat plant:
|
|
264
|
-
|
|
265
|
-
heat
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
on the
|
|
269
|
-
|
|
270
|
-
|
|
263
|
+
On a water loop this slack acts as an unlimited backup heat plant: with
|
|
264
|
+
its temperature pinned, its node's heat balance is the island's dropped
|
|
265
|
+
(heat-slack) one, so it supplies or absorbs whatever heat the balance
|
|
266
|
+
needs and a fuel-starved or deactivated heat source elsewhere is silently
|
|
267
|
+
compensated instead of causing curtailment. On a closed loop (reference
|
|
268
|
+
on the return) that heat is not carried by its mass flow, so only
|
|
269
|
+
``bounds_ext_heat_mw`` (MW, load-shedding and economic dispatch problems)
|
|
270
|
+
or ``pin_temperature=False`` limit it; ``max_import_kgs`` /
|
|
271
|
+
``max_export_kgs`` here and ``bounds_ext_heat`` (kg/s) on the
|
|
272
|
+
load-shedding problem cap the exchanged mass flow, which bounds the heat
|
|
273
|
+
only where the slack feeds the loop with mass. The concepts/multi_energy
|
|
274
|
+
docs page explains the semantics.
|
|
271
275
|
|
|
272
276
|
``cost`` prices the exchange in the economic dispatch objective: per MW of
|
|
273
277
|
higher heating value on a gas grid (import charged, export credited), per
|
|
@@ -284,6 +284,35 @@ class PostProcess:
|
|
|
284
284
|
new.value = self.value
|
|
285
285
|
return new
|
|
286
286
|
|
|
287
|
+
def _inputs(self) -> list[str]:
|
|
288
|
+
read = []
|
|
289
|
+
|
|
290
|
+
class _Probe:
|
|
291
|
+
def __getattr__(self, name):
|
|
292
|
+
read.append(name)
|
|
293
|
+
return 1.0
|
|
294
|
+
|
|
295
|
+
try:
|
|
296
|
+
self.fn(_Probe())
|
|
297
|
+
except Exception: # noqa: BLE001 - naming the inputs is best effort
|
|
298
|
+
pass
|
|
299
|
+
return list(dict.fromkeys(read))
|
|
300
|
+
|
|
301
|
+
def _not_an_expression(self, *_args):
|
|
302
|
+
raise TypeError(
|
|
303
|
+
"A PostProcess report cannot appear in a constraint or objective: it "
|
|
304
|
+
"is computed from the solved values after the solve and is not a "
|
|
305
|
+
"solver variable. Use the decision variable it is computed from "
|
|
306
|
+
f"instead: {', '.join(self._inputs()) or 'none found'} (for a "
|
|
307
|
+
"temperature in K, m.t_pu * t_ref_k). See the "
|
|
308
|
+
"how-to/temperature_floor docs page."
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
__lt__ = __le__ = __gt__ = __ge__ = _not_an_expression
|
|
312
|
+
__add__ = __radd__ = __sub__ = __rsub__ = _not_an_expression
|
|
313
|
+
__mul__ = __rmul__ = __truediv__ = __rtruediv__ = _not_an_expression
|
|
314
|
+
__neg__ = __pow__ = _not_an_expression
|
|
315
|
+
|
|
287
316
|
|
|
288
317
|
def store_unknown_kwargs(model, kwargs):
|
|
289
318
|
"""Warn about keywords no model attribute claims and return them unchanged.
|
|
@@ -657,7 +686,11 @@ class CompoundModel(GenericModel):
|
|
|
657
686
|
|
|
658
687
|
A compound's own attributes are only build-time seeds; without this hook
|
|
659
688
|
a timeseries or override written to the compound never reaches the model
|
|
660
|
-
that carries the equations.
|
|
689
|
+
that carries the equations. The timeseries driver calls it per step and
|
|
690
|
+
every solve calls it on its working copy before building the model, so
|
|
691
|
+
an implementation should push only what the compound changed since it
|
|
692
|
+
last wrote it, keeping a value set on the sub-component itself.
|
|
693
|
+
Default: no-op."""
|
|
661
694
|
|
|
662
695
|
|
|
663
696
|
class MultiGridCompoundModel(CompoundModel):
|
|
@@ -722,12 +755,26 @@ class Component(ABC):
|
|
|
722
755
|
|
|
723
756
|
@property
|
|
724
757
|
def tid(self):
|
|
758
|
+
"""Network-wide unique key, e.g. ``"child-3"``. ``id`` is unique per
|
|
759
|
+
category only (node 3 and child 3 can coexist; branch ids are
|
|
760
|
+
``(from, to, key)`` tuples), so select by ``tid`` or check the
|
|
761
|
+
category (``isinstance(component, mm.Child)``) along with ``id``."""
|
|
725
762
|
return f"{self.__class__.__name__}-{self.id}".lower()
|
|
726
763
|
|
|
727
764
|
@property
|
|
728
765
|
def nid(self):
|
|
729
766
|
return f"{self.model.__class__.__name__}-{self.id}".lower()
|
|
730
767
|
|
|
768
|
+
def set(self, **attrs):
|
|
769
|
+
"""Set model attributes and return the component. A compound then
|
|
770
|
+
pushes them onto its sub-components (:meth:`CompoundModel.sync`); a
|
|
771
|
+
plain attribute write on a compound model would not reach them."""
|
|
772
|
+
for name, value in attrs.items():
|
|
773
|
+
setattr(self.model, name, value)
|
|
774
|
+
if isinstance(self.model, CompoundModel):
|
|
775
|
+
self.model.sync()
|
|
776
|
+
return self
|
|
777
|
+
|
|
731
778
|
def equations(self, *args, **kwargs):
|
|
732
779
|
model_eqs = self.model.equations(*args, **kwargs)
|
|
733
780
|
form_eqs = (
|
|
@@ -276,8 +276,12 @@ class ElectricityIslandingMode(IslandingMode):
|
|
|
276
276
|
vm_min = getattr(node.grid, "vm_pu_min", 0.5)
|
|
277
277
|
vm_max = getattr(node.grid, "vm_pu_max", 1.5)
|
|
278
278
|
eqs = []
|
|
279
|
+
# A formulation-derived report (branch-flow: vm_pu = sqrt(W)) has been
|
|
280
|
+
# replaced by its backend expression here, which _is_decision_value
|
|
281
|
+
# cannot tell from a variable; gating W already pins it.
|
|
282
|
+
derived = getattr(getattr(node, "formulation", None), "derived_attrs", ())
|
|
279
283
|
vm = getattr(node.model, "vm_pu", None)
|
|
280
|
-
if _is_decision_value(vm):
|
|
284
|
+
if "vm_pu" not in derived and _is_decision_value(vm):
|
|
281
285
|
eqs.append(voltage_upper_bound_energized(vm, vm_max, e))
|
|
282
286
|
eqs.append(voltage_lower_bound_energized(vm, vm_min, e))
|
|
283
287
|
w = getattr(node.model, "vm_pu_squared", None)
|
|
@@ -2,7 +2,8 @@ r"""
|
|
|
2
2
|
Gas linepack extension.
|
|
3
3
|
|
|
4
4
|
Pipelines act as distributed storage: :math:`\text{linepack\_kg} = V_{pipe} \cdot \rho_{avg}` with
|
|
5
|
-
:math:`\rho = p \cdot M / (R \cdot T)
|
|
5
|
+
the real-gas :math:`\rho = p \cdot M / (Z \cdot R \cdot T)` at the pipe's mean pressure
|
|
6
|
+
(the exact steady isothermal mean under the NLP formulation). Between timesteps,
|
|
6
7
|
:math:`\text{net\_pack\_kgs}(t) \cdot \Delta t = \text{linepack\_kg}(t) - \text{linepack\_kg}(t-1)` - positive = charging.
|
|
7
8
|
Each endpoint junction sees :math:`+0.5 \cdot \text{net\_pack\_kgs}` (outflow-positive convention).
|
|
8
9
|
|
|
@@ -16,6 +17,7 @@ import math
|
|
|
16
17
|
from monee.model.branch import GasPipe
|
|
17
18
|
from monee.model.core import Var, set_initial_value
|
|
18
19
|
from monee.model.grid import GasGrid
|
|
20
|
+
from monee.model.phys.nonlinear.gf import gas_density
|
|
19
21
|
|
|
20
22
|
from .core import NetworkAspect
|
|
21
23
|
|
|
@@ -23,20 +25,26 @@ from .core import NetworkAspect
|
|
|
23
25
|
class GasLinepack(NetworkAspect):
|
|
24
26
|
"""Linepack extension. Injects ``linepack_kg`` and ``net_pack_kgs`` on every
|
|
25
27
|
GasPipe; auto-sizes initial/max from grid params. Per-pipe overrides via the
|
|
26
|
-
``overrides`` ``{branch_id: {"linepack_kg_initial": ..., "linepack_kg_max": ...}}``.
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
``overrides`` ``{branch_id: {"linepack_kg_initial": ..., "linepack_kg_max": ...}}``.
|
|
29
|
+
|
|
30
|
+
``first_step_steady_state=True`` pins ``net_pack_kgs = 0`` in the first
|
|
31
|
+
step instead of charging from ``linepack_kg_initial``, so step 0 is the
|
|
32
|
+
steady state of its inputs and the following steps start from that step's
|
|
33
|
+
solved linepack (the same anchor a separate steady solve would give), like
|
|
34
|
+
:class:`LumpedThermalCapacitance` does for heat."""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
overrides: dict[int, dict] | None = None,
|
|
39
|
+
first_step_steady_state: bool = False,
|
|
40
|
+
) -> None:
|
|
29
41
|
self._overrides: dict[int, dict] = overrides or {}
|
|
42
|
+
self._first_step_steady_state: bool = bool(first_step_steady_state)
|
|
30
43
|
self._pipe_volume: dict[int, float] = {}
|
|
31
44
|
self._initial_lp: dict[int, float] = {}
|
|
32
45
|
self._active_branches: set[int] = set()
|
|
33
46
|
self._timeseries_active: bool = False
|
|
34
47
|
|
|
35
|
-
@staticmethod
|
|
36
|
-
def _density(grid: GasGrid, pressure_pa: float) -> float:
|
|
37
|
-
"""Return gas density [kg/m^3] via the ideal-gas EoS."""
|
|
38
|
-
return pressure_pa * grid.molar_mass / (grid.universal_gas_constant * grid.t_k)
|
|
39
|
-
|
|
40
48
|
@staticmethod
|
|
41
49
|
def _nominal_pressure(grid: GasGrid) -> float:
|
|
42
50
|
"""Nominal ABSOLUTE operating pressure [Pa] (gauge + ambient)."""
|
|
@@ -76,8 +84,8 @@ class GasLinepack(NetworkAspect):
|
|
|
76
84
|
grid: GasGrid = branch.grid
|
|
77
85
|
v_pipe = math.pi / 4 * bm.diameter_m**2 * bm.length_m
|
|
78
86
|
|
|
79
|
-
rho_nominal =
|
|
80
|
-
rho_max =
|
|
87
|
+
rho_nominal = gas_density(grid, self._nominal_pressure(grid))
|
|
88
|
+
rho_max = gas_density(grid, self._max_pressure(grid))
|
|
81
89
|
auto_initial = v_pipe * rho_nominal
|
|
82
90
|
auto_max = v_pipe * rho_max
|
|
83
91
|
|
|
@@ -146,6 +154,9 @@ class GasLinepack(NetworkAspect):
|
|
|
146
154
|
continue
|
|
147
155
|
bm = branch.model
|
|
148
156
|
prev_lp = temporal_state.get(branch.id, "linepack_kg")
|
|
157
|
+
if prev_lp is None and self._first_step_steady_state:
|
|
158
|
+
eqs.append(bm.net_pack_kgs == 0)
|
|
159
|
+
continue
|
|
149
160
|
if prev_lp is None:
|
|
150
161
|
prev_lp = self._initial_lp[branch.id]
|
|
151
162
|
eqs.append(bm.net_pack_kgs * dt_s == bm.linepack_kg - prev_lp)
|