Skip to content

Commit

Permalink
PST test case
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Leclerc <[email protected]>
  • Loading branch information
sylvlecl committed Feb 12, 2024
1 parent 76988c2 commit e32a924
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions tests/andromede/test_ac_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,80 @@
],
)

"""
Flow on the line is proportional to angle difference between extremities,
and inverse of impedance.
"""
AC_LINK_WITH_LIMIT = model(
id="LINK",
parameters=[
float_parameter("reactance", IndexingStructure(False, False)),
float_parameter("flow_limit", IndexingStructure(False, False)),
],
variables=[float_variable("flow", -param("flow_limit"), param("flow_limit"))],
ports=[
ModelPort(port_type=AC_PORT, port_name="port1"),
ModelPort(port_type=AC_PORT, port_name="port2"),
],
port_fields_definitions=[
PortFieldDefinition(
port_field=PortFieldId("port1", "flow"),
definition=-var("flow"),
),
PortFieldDefinition(
port_field=PortFieldId("port2", "flow"),
definition=var("flow"),
),
],
binding_constraints=[
Constraint(
name="AC flow",
expression=var("flow")
== 1
/ param("reactance")
* (port_field("port1", "angle") - port_field("port2", "angle")),
)
],
)

"""
Flow on the line is proportional to angle difference between extremities,
and inverse of impedance.
A shift angle is applied on side 1, allowing to control the flow.
"""
AC_LINK_WITH_PST = model(
id="LINK_WITH_PST",
parameters=[float_parameter("reactance", IndexingStructure(False, False))],
variables=[float_variable("flow"), float_variable("shift")],
ports=[
ModelPort(port_type=AC_PORT, port_name="port1"),
ModelPort(port_type=AC_PORT, port_name="port2"),
],
port_fields_definitions=[
PortFieldDefinition(
port_field=PortFieldId("port1", "flow"),
definition=-var("flow"),
),
PortFieldDefinition(
port_field=PortFieldId("port2", "flow"),
definition=var("flow"),
),
],
binding_constraints=[
Constraint(
name="AC flow",
expression=var("flow")
== 1
/ param("reactance")
* (
port_field("port1", "angle")
+ var("shift")
- port_field("port2", "angle")
),
)
],
)


def test_ac_network_no_links():
database = DataBase()
Expand Down Expand Up @@ -242,3 +316,70 @@ def test_parallel_ac_links():
assert OutputValues(problem).component("L2").var("flow").value == pytest.approx(
-33.33, abs=0.01
)


def test_parallel_ac_links_with_pst():
"""
2 parallel links constrained by a flow limit of 50 MW.
The PST allows to balance the flow between the 2 links.
"""
database = DataBase()
database.add_data("D", "demand", ConstantData(100))

database.add_data("G", "p_max", ConstantData(100))
database.add_data("G", "cost", ConstantData(35))

database.add_data("L", "reactance", ConstantData(1))
database.add_data("L", "flow_limit", ConstantData(50))
database.add_data("T", "reactance", ConstantData(2))
database.add_data("T", "flow_limit", ConstantData(50))

node1 = Node(model=AC_NODE_MODEL, id="1")
node2 = Node(model=AC_NODE_MODEL, id="2")
demand = create_component(
model=DEMAND_MODEL,
id="D",
)
gen = create_component(
model=GENERATOR_MODEL,
id="G",
)
link1 = create_component(
model=AC_LINK_WITH_LIMIT,
id="L",
)
link2 = create_component(
model=AC_LINK_WITH_PST,
id="T",
)

network = Network("test")
network.add_node(node1)
network.add_node(node2)
network.add_component(demand)
network.add_component(gen)
network.add_component(link1)
network.add_component(link2)
network.connect(PortRef(demand, "balance_port"), PortRef(node1, "injections"))
network.connect(PortRef(gen, "balance_port"), PortRef(node2, "injections"))
network.connect(PortRef(link1, "port1"), PortRef(node1, "links"))
network.connect(PortRef(link1, "port2"), PortRef(node2, "links"))
network.connect(PortRef(link2, "port1"), PortRef(node1, "links"))
network.connect(PortRef(link2, "port2"), PortRef(node2, "links"))

scenarios = 1
problem = build_problem(network, database, TimeBlock(1, [0]), scenarios)
status = problem.solver.Solve()

assert status == problem.solver.OPTIMAL
assert problem.solver.Objective().Value() == 3500

assert OutputValues(problem).component("L").var("flow").value == pytest.approx(
-50, abs=0.01
)
assert OutputValues(problem).component("T").var("flow").value == pytest.approx(
-50, abs=0.01
)
assert OutputValues(problem).component("T").var("shift").value == pytest.approx(
-50, abs=0.01
)

0 comments on commit e32a924

Please sign in to comment.