Skip to content

Commit

Permalink
added two test for stock pipeline and test and model for gas stock
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann-Temudjin committed May 17, 2024
1 parent 651ca02 commit 14bc1e5
Show file tree
Hide file tree
Showing 3 changed files with 367 additions and 6 deletions.
81 changes: 80 additions & 1 deletion src/andromede/libs/standard_sc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,71 @@ library:
expression: f_from = f_from_p - f_from_m
- name: max0_to
expression: f_to = f_to_p - f_to_m
- name: r_h
- name: r_t1
expression: r[t+1] = r[t] + f_from - f_to
- name: r0
expression: r[0] = initial_level
- name: rt
expression: r[t] = initial_level
binding-constraints:
- name: FlowFromPos
expression: sum_connections(flow_from_pos.flow) = f_from_p
- name: FlowToPos
expression: sum_connections(flow_to_pos.flow) = f_to_p

- id: link_with_storage_2
description: A link with energy storage without flow_from/to_pos
parameters:
- name: f_from_max
time-dependent: false
scenario-dependent: false
- name: f_to_max
time-dependent: false
scenario-dependent: false
- name: capacity
time-dependent: false
scenario-dependent: false
- name: initial_level
time-dependent: false
scenario-dependent: false
variables:
- name: r
lower-bound: 0
upper-bound: capacity
- name: f_from
lower-bound: -f_from_max
upper-bound: f_from_max
- name: f_to
lower-bound: -f_to_max
upper-bound: f_to_max
- name: f_from_p
lower-bound: 0
- name: f_from_m
lower-bound: 0
- name: f_to_p
lower-bound: 0
- name: f_to_m
lower-bound: 0
ports:
- name: flow_from
type: flow
- name: flow_to
type: flow
port-field-definitions:
- port: flow_from
field: flow
definition: -f_from
- port: flow_to
field: flow
definition: f_to
constraints:
- name: r_t1
expression: r[t+1] = r[t] + f_from - f_to
- name: r0
expression: r[0] = initial_level
- name: rt
expression: r[t] = initial_level

- id: stock_final_level
description: A stock model
parameters:
Expand Down Expand Up @@ -130,6 +187,28 @@ library:
- name: flow_in
expression: sum_connections(flow_c.flow) = u_in

- id: repartition_key
description: A repartition key
parameters:
- name: alpha
time-dependent: false
scenario-dependent: false
variables:
- name: input
lower-bound: 0
ports:
- name: input_port
type: flow
- name: output_port
type: flow
port-field-definitions:
- port: input_port
field: flow
definition: -input
- port: output_port
field: flow
definition: input * alpha

- id: convertor
description: A basic convertor model
parameters:
Expand Down
138 changes: 138 additions & 0 deletions tests/models/test_gas_stock_elec_compressor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

import math
from pathlib import Path

from andromede.simulation import OutputValues, TimeBlock, build_problem
from andromede.study import (
ConstantData,
DataBase,
Network,
Node,
PortRef,
create_component,
)


def test_gas_stock_elec_compressor(data_dir: Path, lib: Path, lib_sc: Path):
"""
Test of a pipeline with stock capacity
for the following test we have two gaz production and two gaz demands,
One of each on each sides of a pipeline that has a storage capacity
gaz_prod_1 and gaz_demand_1 are on the input side of the pipeline
gaz_prod_2 and gaz_demand_2 are on the output side of the pipeline
we have the following values:
gaz production 1:
- p_max = 200
- cost = 30
gaz production 2:
- p_max = 50
- cost = 10
gaz demand 1:
- demand = 100
gaz demand 2:
- demand = 100
pipeline:
- f_from_max = 50
- f_to_max = 50
- capacity = 100
- initial_level = 20
"""
gen_model = lib.models["generator"]
node_model = lib.models["node"]
demand_model = lib.models["demand"]
stock_final_model = lib_sc.models["stock_final_level"]
convertor_model = lib_sc.models["convertor"]

gaz_node = Node(model=node_model, id="g")
elec_node = Node(model=node_model, id="e")
gaz_prod = create_component(model=gen_model, id="pg")
elec_prod = create_component(model=gen_model, id="pe")
gaz_demand = create_component(model=demand_model, id="dg")
elec_demand = create_component(model=demand_model, id="de")
gas_stock = create_component(model=stock_final_model, id="sg")
electrolyzer = create_component(model=convertor_model, id="ez")
compressor = create_component(model=convertor_model, id="cp")

database = DataBase()
database.add_data("dg", "demand", ConstantData(100))
database.add_data("de", "demand", ConstantData(10))

database.add_data("pg", "p_max", ConstantData(300))
database.add_data("pg", "cost", ConstantData(10))
database.add_data("pe", "p_max", ConstantData(200))
database.add_data("pe", "cost", ConstantData(10))

database.add_data("sg", "p_max_in", ConstantData(100))
database.add_data("sg", "p_max_out", ConstantData(50))
database.add_data("sg", "capacity", ConstantData(100))
database.add_data("sg", "initial_level", ConstantData(10))
database.add_data("sg", "final_level", ConstantData(90))

database.add_data("ez", "alpha", ConstantData(0.5))

database.add_data("cp", "alpha", ConstantData(0.7))

network = Network("test")
network.add_node(gaz_node)
network.add_node(elec_node)
network.add_component(gaz_prod)
network.add_component(elec_prod)
network.add_component(gaz_demand)
network.add_component(elec_demand)
network.add_component(gas_stock)
network.add_component(compressor)
network.add_component(electrolyzer)

network.connect(
PortRef(gaz_node, "injection_port"), PortRef(gaz_demand, "injection_port")
)
network.connect(PortRef(gaz_node, "injection_port"), PortRef(gas_stock, "flow_s"))
network.connect(
PortRef(gaz_node, "injection_port"), PortRef(electrolyzer, "output_port")
)
network.connect(
PortRef(gaz_node, "injection_port"), PortRef(gaz_prod, "injection_port")
)

network.connect(PortRef(gas_stock, "flow_c"), PortRef(compressor, "output_port"))

network.connect(
PortRef(elec_node, "injection_port"), PortRef(elec_demand, "injection_port")
)
network.connect(
PortRef(elec_prod, "injection_port"), PortRef(elec_node, "injection_port")
)
network.connect(
PortRef(elec_node, "injection_port"), PortRef(electrolyzer, "input_port")
)
network.connect(
PortRef(elec_node, "injection_port"), PortRef(compressor, "input_port")
)
scenarios = 1
problem = build_problem(network, database, TimeBlock(1, [0]), scenarios)
status = problem.solver.Solve()

output = OutputValues(problem)
r_value = output.component("sg").var("r").value
generation1 = output.component("pg").var("generation").value
generation2 = output.component("pe").var("generation").value
print("generation")
print(generation1)
print(generation2)
print(r_value)
assert status == problem.solver.OPTIMAL
assert math.isclose(problem.solver.Objective().Value(), 1100)

assert math.isclose(r_value, 100)
Loading

0 comments on commit 14bc1e5

Please sign in to comment.