-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
to test see tests/unittests/data/components_for_thermal_cluster.yml
- Loading branch information
1 parent
336336d
commit 24c0bfc
Showing
4 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# 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 argparse | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from andromede.model.library import Library | ||
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 import DataBase | ||
from andromede.study.parsing import parse_yaml_components | ||
from andromede.study.resolve_components import ( | ||
NetworkComponents, | ||
build_data_base, | ||
build_network, | ||
consistency_check, | ||
resolve_components_and_cnx, | ||
) | ||
|
||
|
||
class AntaresTimeSeriesImportError(Exception): | ||
pass | ||
|
||
|
||
def input_models(model_path: Path) -> Library: | ||
with model_path.open() as lib: | ||
return resolve_library(parse_yaml_library(lib)) | ||
|
||
|
||
def input_database(study_path: Path, timeseries_path: Optional[Path]) -> DataBase: | ||
with study_path.open() as comp: | ||
return build_data_base(parse_yaml_components(comp), timeseries_path) | ||
|
||
|
||
def input_components(study_path: Path, model: Library) -> NetworkComponents: | ||
with study_path.open() as comp: | ||
return resolve_components_and_cnx(parse_yaml_components(comp), model) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--model", type=Path, help="path to the model file, *.yml", required=True | ||
) | ||
parser.add_argument( | ||
"--study", type=Path, help="path to the study file, *.yml", required=True | ||
) | ||
parser.add_argument( | ||
"--timeseries", type=Path, help="path to the timeseries repertory" | ||
) | ||
parser.add_argument( | ||
"--duration", type=int, help="duration of the simulation", default=1 | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
models = input_models(args.model) | ||
components = input_components(args.study, models) | ||
consistency_check(components.components, models.models) | ||
|
||
try: | ||
database = input_database(args.study, args.timeseries) | ||
except UnboundLocalError: | ||
raise AntaresTimeSeriesImportError( | ||
"An error occurred while importing time series. Did you correctly use the '--timeseries' parameter ?" | ||
) | ||
network = build_network(components) | ||
|
||
scenarios = 1 | ||
timeblock = TimeBlock(1, list(range(args.duration))) | ||
problem = build_problem(network, database, timeblock, scenarios) | ||
|
||
status = problem.solver.Solve() | ||
print(status) | ||
print(problem.solver.Objective().Value()) | ||
|
||
output = OutputValues(problem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# 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. | ||
|
||
|
||
#test file for command line execution | ||
#run : | ||
#$ python src/andromede/main/main.py --model tests/unittests/data/lib_2.yml --study tests/unittests/data/components_for_thermal_cluster.yml --duration 3 --timeseries tests/unittests/data/ | ||
#expected value : | ||
#> 0 | ||
#> 72000 | ||
|
||
study: | ||
nodes: | ||
- id: N | ||
model: node | ||
|
||
components: | ||
- id: G | ||
model: thermal-cluster-dhd | ||
parameters: | ||
- name: cost | ||
type: constant | ||
value: 100 | ||
- name: p_min | ||
type: constant | ||
value: 100 | ||
- name: p_max | ||
type: constant | ||
value: 500 | ||
- name: d_min_up | ||
type: constant | ||
value: 3 | ||
- name: d_min_down | ||
type: constant | ||
value: 3 | ||
- name: nb_units_max | ||
type: constant | ||
value: 1 | ||
- name: nb_failures | ||
type: constant | ||
value: 0 | ||
- id: D | ||
model: demand | ||
parameters: | ||
- name: demand | ||
type: timeseries | ||
timeseries: demand-ts_2 | ||
- id: S | ||
model: spillage | ||
parameters: | ||
- name: cost | ||
type: constant | ||
value: 10 | ||
|
||
connections: | ||
- component1: N | ||
port_1: injection_port | ||
component2: D | ||
port_2: injection_port | ||
|
||
- component1: N | ||
port_1: injection_port | ||
component2: G | ||
port_2: injection_port | ||
|
||
- component1: N | ||
port_1: injection_port | ||
component2: S | ||
port_2: injection_port | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
500 | ||
0 | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# 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. | ||
library: | ||
id: basic | ||
description: Basic library | ||
|
||
port-types: | ||
- id: flow | ||
description: A port which transfers power flow | ||
fields: | ||
- name: flow | ||
|
||
models: | ||
|
||
|
||
- 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: spillage | ||
description: A basic spillage model | ||
parameters: | ||
- name: cost | ||
time-dependent: false | ||
scenario-dependent: false | ||
variables: | ||
- name: spillage | ||
lower-bound: 0 | ||
ports: | ||
- name: injection_port | ||
type: flow | ||
port-field-definitions: | ||
- port: injection_port | ||
field: flow | ||
definition: -spillage | ||
objective: expec(sum(cost * spillage)) | ||
|
||
- 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: thermal-cluster-dhd | ||
parameters: | ||
- name: p_max | ||
- name: p_min | ||
- name: cost | ||
- name: d_min_up | ||
- name: d_min_down | ||
- name: nb_units_max | ||
- name: nb_failures | ||
variables: | ||
- name: nb_units_on | ||
lower-bound: 0 | ||
upper-bound: nb_units_max | ||
variable-type: integer | ||
- name: nb_starting | ||
lower-bound: 0 | ||
upper-bound: nb_units_max | ||
variable-type: integer | ||
- name: nb_stoping | ||
lower-bound: 0 | ||
upper-bound: nb_units_max | ||
variable-type: integer | ||
- name: production | ||
lower-bound: 0 | ||
upper-bound: nb_units_max * p_max | ||
ports: | ||
- name: injection_port | ||
type: flow | ||
port-field-definitions: | ||
- port: injection_port | ||
field: flow | ||
definition: production | ||
constraints: | ||
- name: max production | ||
expression: production <= nb_units_on * p_max | ||
- name: min production | ||
expression: production >= nb_units_on * p_min | ||
- name: on units variation | ||
expression: nb_units_on = nb_units_on[-1] + nb_starting - nb_stoping | ||
- name: starting time | ||
expression: sum(nb_starting[-d_min_up + 1 .. 0]) <= nb_units_on | ||
- name: stoping time | ||
expression: sum(nb_stoping[-d_min_down + 1 .. 0]) <= nb_units_max - nb_units_on | ||
objective: expec(sum(cost * production)) |