Skip to content

Commit

Permalink
added stock hydro test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann-Temudjin committed May 31, 2024
1 parent 6e16230 commit 8fba186
Show file tree
Hide file tree
Showing 3 changed files with 263 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tests/models/components_for_test_stock_hydro_2_input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
study:
nodes:
- id: NE1
model: node
- id: NE2
model: node

components:
- id: DE1
model: demand
parameters:
- name: demand
type: constant
value: 50
- id: DE2
model: demand
parameters:
- name: demand
type: constant
value: 100
- id: PE1
model: generator
parameters:
- name: cost
type: constant
value: 10
- name: p_max
type: constant
value: 200
- id: PE2
model: generator
parameters:
- name: cost
type: constant
value: 10
- name: p_max
type: constant
value: 200
- id: HS
model: stock_final_level_input
parameters:
- name: p_max_in
type: constant
value: 50
- name: p_max_out
type: constant
value: 50
- name: capacity
type: constant
value: 100
- name: initial_level
type: constant
value: 10
- name: final_level
type: constant
value: 20


connections:
- component1: NE1
port_1: injection_port
component2: PE1
port_2: injection_port
- component1: NE1
port_1: injection_port
component2: DE1
port_2: injection_port
- component1: NE1
port_1: injection_port
component2: HS
port_2: flow_s1

- component1: NE2
port_1: injection_port
component2: PE2
port_2: injection_port
- component1: NE2
port_1: injection_port
component2: DE2
port_2: injection_port
- component1: NE2
port_1: injection_port
component2: HS
port_2: flow_s2
110 changes: 110 additions & 0 deletions tests/models/models_for_test_stock_hydro_2_input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# 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.

library:
id: basic
description: Basic library

port-types:
- id: flow
description: A port which transfers power flow
fields:
- name: flow
models:

- id: generator
description: A basic generator model
parameters:
- name: cost
time-dependent: false
scenario-dependent: false
- name: p_max
time-dependent: false
scenario-dependent: false
variables:
- name: generation
lower-bound: 0
upper-bound: p_max
ports:
- name: injection_port
type: flow
port-field-definitions:
- port: injection_port
field: flow
definition: generation
objective: expec(sum(cost * generation))

- id: node
description: A basic balancing node model
ports:
- name: injection_port
type: flow
binding-constraints:
- name: balance
expression: sum_connections(injection_port.flow) = 0

- id: demand
description: A basic fixed demand model
parameters:
- name: demand
time-dependent: true
scenario-dependent: true
ports:
- name: injection_port
type: flow
port-field-definitions:
- port: injection_port
field: flow
definition: -demand

- id: stock_final_level_input
description: A stock model
parameters:
- name: p_max_in
time-dependent: false
scenario-dependent: false
- name: p_max_out
time-dependent: false
scenario-dependent: false
- name: capacity
time-dependent: false
scenario-dependent: false
- name: initial_level
time-dependent: false
scenario-dependent: false
- name: final_level
time-dependent: false
scenario-dependent: false
variables:
- name: r
lower-bound: 0
upper-bound: capacity
- name: u1
lower-bound: -p_max_in
upper-bound: p_max_out
- name: u2
lower-bound: -p_max_in
upper-bound: p_max_out
ports:
- name: flow_s1
type: flow
- name: flow_s2
type: flow
port-field-definitions:
- port: flow_s1
field: flow
definition: u1
- port: flow_s2
field: flow
definition: u2
constraints:
- name: r_h
expression: r[t+1] = r[t] - u1[t] - u2[t]
- name: r0
expression: r[0] = initial_level
- name: rt
expression: r[t] = initial_level
69 changes: 69 additions & 0 deletions tests/models/test_stock_hydro_2_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 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

import pytest

from andromede.model.parsing import parse_yaml_library
from andromede.model.resolve_library import resolve_library
from andromede.simulation import OutputValues, TimeBlock, build_problem
from andromede.study.parsing import InputComponents, parse_yaml_components
from andromede.study.resolve_components import (
build_data_base,
build_network,
consistency_check,
resolve_components_and_cnx,
)


@pytest.fixture(scope="session")
def lib_models():
libs_path = Path(__file__).parent
lib_sc_file = libs_path / "models_for_test_stock_hydro_2_input.yml"

with lib_sc_file.open() as f:
input_lib_sc = parse_yaml_library(f)

lib_sc = resolve_library(input_lib_sc)
return lib_sc


def test_stock_hydro_2_input(data_dir: Path, lib_models: Path):
"""
Test of a hydro stock connected to 2 nodes with a electrical production and demand each
"""
components_path = Path(__file__)
compo_file = components_path.parent / "components_for_test_stock_hydro_2_input.yml"
input_component = parse_yaml_components(compo_file.open())

components_input = resolve_components_and_cnx(input_component, lib_models)
consistency_check(components_input.components, lib_models.models)

database = build_data_base(input_component, None)
network = build_network(components_input)

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

output = OutputValues(problem)
r_value = output.component("HS").var("r").value
generation1 = output.component("PE1").var("generation").value
generation2 = output.component("PE2").var("generation").value
print("generation")
print(generation1)
print(generation2)
print(r_value)
assert status == problem.solver.OPTIMAL
assert math.isclose(problem.solver.Objective().Value(), 1500)

0 comments on commit 8fba186

Please sign in to comment.