Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

NEW FEATURES :

* `createStudy()` initializes the study by updating the `generaldata.ini` file :
- the value of the `shedding-policy` parameter is changed to "accurate shave peaks"
- a new "compatibility" section is created with parameter `hydro-pmax` = "daily"
* `createArea()` initializes the `hydro.ini` file with a new parameter `overflow spilled cost difference` (for each area)
* `createClusterST()`/`editClusterST()` : Parameter `group` is now dynamic and have no restriction
* `createClusterST()`/`editClusterST()` :
- **New properties** (*efficiencywithdrawal*, *penalize-variation-injection*, *penalize-variation-withdrawal*, see list of properties according to study version of Antares with `storage_values_default()`)
- **New optional time series** (cost-injection, cost-withdrawal, cost-level, cost-variation-injection, cost-variation-withdrawal)


### Breaking changes :
- `createClusterST()` : For a study < *v9.2*, execution will be STOP if `group` is not included in list (see doc)
- `updateAdequacySettings()` : Two parameters (*enable-first-step*, *set-to-null-ntc-between-physical-out-for-first-step*) are `deprecated` and removed. Parameters are forced to `NULL` with study >= v9.2.
- `updateAdequacySettings()` : Two parameters (*enable-first-step*, *set-to-null-ntc-between-physical-out-for-first-step*) are **deprecated** and removed. Parameters are forced to `NULL` with study >= v9.2.


### DOC :
Expand Down
2 changes: 1 addition & 1 deletion R/createArea.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ createArea <- function(name,

# ini
if (file.exists(file.path(inputPath, "hydro", "hydro.ini"))) {
default_params <- get_default_hydro_ini_values()
default_params <- get_default_hydro_ini_values(opts = opts)
# Check area is not possible at this step
writeIniHydro(area = name, params = default_params, mode = "createArea", opts = opts)
}
Expand Down
25 changes: 22 additions & 3 deletions R/createStudy.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,31 @@ createStudy <- function(path, study_name = "my_study", antares_version = "8.2.0"
opts <- setSimulationPath(path = path)

# add specific directory and files according to version of study to create
if (antares_version >= as.numeric_version("8.1.0")) {
if (antares_version >= as.numeric_version("8.1.0"))
activateRES(opts = opts)
}

if (antares_version >= as.numeric_version("8.6.0")) {
if (antares_version >= as.numeric_version("8.6.0"))
activateST(opts = opts)

# update actual template for 'generaldata.ini' (>=9.2)
# as.numeric_version() is not efficient for 2 digits ...
if(is_new_version){
antares_version <- as.numeric(
as.character(antares_version))

if (antares_version >= 9.2){
updateOptimizationSettings(shedding.policy = "accurate shave peaks")

# add new section and initiate with value "daily" to keep legacy behavior
gen_data_file <- readIni("settings/generaldata")
new_section <- list(
"compatibility" = list("hydro-pmax" = "daily"))
gen_data_file <- append(gen_data_file, new_section)

writeIni(listData = gen_data_file,
pathIni = "settings/generaldata",
overwrite = TRUE)
}
}
return(invisible(opts))
}
Expand Down
2 changes: 1 addition & 1 deletion R/removeArea.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ removeArea <- function(name, opts = antaresRead::simOptions()) {
## Hydro
# ini
if (file.exists(file.path(inputPath, "hydro", "hydro.ini"))) {
default_params <- get_default_hydro_ini_values()
default_params <- get_default_hydro_ini_values(opts=opts)
empty_params <- sapply(names(default_params), FUN = function(n) default_params[[n]] <- NULL)
writeIniHydro(area = name, params = empty_params, mode = "removeArea", opts = opts)
}
Expand Down
14 changes: 11 additions & 3 deletions R/updateOptimizationSettings.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' @param solver.log true or false (available for version >= 8.8)
#' @param power.fluctuations free modulations, minimize excursions or minimize ramping
#' @param shedding.strategy share margins
#' @param shedding.policy shave peaks or minimize duration
#' @param shedding.policy shave peaks (accurate shave peaks for study >= v9.2)or minimize duration
#' @param unit.commitment.mode fast or accurate
#' @param number.of.cores.mode minimum, low, medium, high or maximum
#' @param renewable.generation.modelling aggregated or clusters
Expand Down Expand Up @@ -119,8 +119,16 @@ updateOptimizationSettings <- function(simplex.range = NULL,
)
if (!is.null(shedding.strategy))
assertthat::assert_that(shedding.strategy %in% c("share margins"))
if (!is.null(shedding.policy))
assertthat::assert_that(shedding.policy %in% c("shave peaks", "minimize duration"))
if (!is.null(shedding.policy)){
if(opts$antaresVersion>=920)
assertthat::assert_that(
shedding.policy %in%
c("accurate shave peaks", "minimize duration"))
else
assertthat::assert_that(
shedding.policy %in%
c("shave peaks", "minimize duration"))
}
if (!is.null(unit.commitment.mode))
assertthat::assert_that(unit.commitment.mode %in% c("fast", "accurate"))
if (!is.null(number.of.cores.mode))
Expand Down
14 changes: 12 additions & 2 deletions R/writeHydroValues.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ writeHydroValues <- function(area,


#' @title Get default hydro.ini values
get_default_hydro_ini_values <- function(){
#' @template opts-arg
get_default_hydro_ini_values <- function(opts){

default_hydro_params <- list(
"inter-daily-breakdown" = 1, #
Expand All @@ -144,6 +145,10 @@ get_default_hydro_ini_values <- function(){
"reservoir capacity" = 0
)

if(opts$antaresVersion>=920)
default_hydro_params <- append(default_hydro_params,
list("overflow spilled cost difference" = 1))

return(default_hydro_params)
}

Expand Down Expand Up @@ -303,6 +308,11 @@ writeIniHydro <- function(area, params, mode = "other", opts = antaresRead::simO
"reservoir capacity" = c("numeric", "integer", "NULL")
)

if(opts$antaresVersion>=920)
expected_params <- append(
expected_params,
list("overflow spilled cost difference" = c("numeric", "integer", "NULL")))

params_names <- names(params)
expected_params_names <- names(expected_params)

Expand Down Expand Up @@ -450,7 +460,7 @@ fill_empty_hydro_ini_file <- function(area, opts = antaresRead::simOptions()){

path_ini_hydro <- file.path("input", "hydro", "hydro.ini")
ini_hydro_data <- antaresRead::readIni(path_ini_hydro, opts = opts)
default_params <- get_default_hydro_ini_values()
default_params <- get_default_hydro_ini_values(opts = opts)
# use heuristic
if (is.null(ini_hydro_data[["use heuristic"]][[area]])) {
ini_hydro_data[["use heuristic"]][[area]] <- default_params[["use heuristic"]]
Expand Down
6 changes: 5 additions & 1 deletion man/get_default_hydro_ini_values.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/updateOptimizationSettings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 44 additions & 1 deletion tests/testthat/test-createArea.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sapply(studies, function(study) {
# Initialize hydro.ini values for a new area
test_that("Check if hydro.ini default values are initialized when creating an area", {

default_hydro_params <- get_default_hydro_ini_values()
default_hydro_params <- get_default_hydro_ini_values(opts=opts)

hydro_ini_path <- file.path("input", "hydro", "hydro.ini")
hydro_ini_data <- readIni(pathIni = hydro_ini_path, opts = opts)
Expand Down Expand Up @@ -521,3 +521,46 @@ test_that(".split_nodalOptimization_by_target() has the expected behaviour", {
expect_true(length(res[["toIniAreas"]]) == 1)
expect_true(names(res[["toIniAreas"]]) == "spilledenergycost")
})


# >= 920----
test_that("New HYDRO default parameter", {
suppressWarnings(
createStudy(path = tempdir(),
study_name = "test_area9.2",
antares_version = "9.2"))

# default area with st cluster
area_test = "al"
createArea(name = area_test)

hydro_ini_path <- file.path("input", "hydro", "hydro.ini")
hydro_ini_data <- readIni(pathIni = hydro_ini_path)

new_params_names <- "overflow spilled cost difference"

# test name + value
expect_true(new_params_names %in% names(hydro_ini_data))
expect_equal(names(hydro_ini_data[[new_params_names]]), "al")
expect_equal(hydro_ini_data[[new_params_names]][[area_test]], 1)



test_that("Remove area / check hydro params", {
area_test = "al2"
createArea(name = area_test)

removeArea(name = area_test)

hydro_ini_path <- file.path("input", "hydro", "hydro.ini")
hydro_ini_data <- readIni(pathIni = hydro_ini_path)
new_params_names <- "overflow spilled cost difference"

# test name + value
expect_true(new_params_names %in% names(hydro_ini_data))
expect_false(area_test %in% names(hydro_ini_data[[new_params_names]]))
})


deleteStudy()
})
26 changes: 26 additions & 0 deletions tests/testthat/test-createStudy.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

# create ----

## V9.2----
test_that("Init v9.2 version study", {
path <- file.path(tempdir(), "tests_v920")
suppressWarnings(
opts <- createStudy(path, antares_version = "9.2")
)
properties <- antaresRead:::readIniFile(file.path(path, "study.antares"))

# version
expect_identical(properties$antares$version, 9.2)

# test new values in generaldata
prop_gen <- readIni("settings/generaldata")

expect_equal(
prop_gen[["other preferences"]][["shedding-policy"]],
"accurate shave peaks"
)

expect_equal(
prop_gen[["compatibility"]][["hydro-pmax"]],
"daily"
)

unlink(path, recursive = TRUE)
})
## v9.0----
test_that("Create a new v9.0 study", {
path <- file.path(tempdir(), "tests_createStudy")
Expand Down
8 changes: 8 additions & 0 deletions vignettes/Antares_new_features_v920.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ current_study_opts <- simOptions()
current_study_opts$antaresVersion
```

Some minor changes to the creation of the study.

Initializes the study by updating the `generaldata.ini` file :

- the value of the `shedding-policy` parameter is changed to "accurate shave peaks"
- a new "compatibility" section is created with parameter `hydro-pmax` = "daily"

## Create area

Expand All @@ -57,6 +63,8 @@ createArea(name = "fr")
createArea(name = "it")
```

A new parameter `overflow spilled cost difference` in `hydro.ini` file (*input/hydro/hydro.ini*) is initiated (*default value = 1*).

## Short term storage

We can create new clusters, st-storage (from v8.6), with function `createClusterST()`. You can see function documentation with `?createClusterST`.
Expand Down