Skip to content

Commit d76ba85

Browse files
createArea() updated with new default parameters + tests (#215)
* createArea() updated with new default parameters + tests * newmd updated with hydraulic part * createStudy() updated with new init parameters + tests * updateOptimizationSettings() updated with new default value * vignette updated
1 parent 0a195bc commit d76ba85

File tree

11 files changed

+137
-14
lines changed

11 files changed

+137
-14
lines changed

NEWS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55

66
NEW FEATURES :
77

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

17+
1318
### Breaking changes :
1419
- `createClusterST()` : For a study < *v9.2*, execution will be STOP if `group` is not included in list (see doc)
15-
- `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.
20+
- `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.
1621

1722

1823
### DOC :

R/createArea.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ createArea <- function(name,
224224

225225
# ini
226226
if (file.exists(file.path(inputPath, "hydro", "hydro.ini"))) {
227-
default_params <- get_default_hydro_ini_values()
227+
default_params <- get_default_hydro_ini_values(opts = opts)
228228
# Check area is not possible at this step
229229
writeIniHydro(area = name, params = default_params, mode = "createArea", opts = opts)
230230
}

R/createStudy.R

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,31 @@ createStudy <- function(path, study_name = "my_study", antares_version = "8.2.0"
109109
opts <- setSimulationPath(path = path)
110110

111111
# add specific directory and files according to version of study to create
112-
if (antares_version >= as.numeric_version("8.1.0")) {
112+
if (antares_version >= as.numeric_version("8.1.0"))
113113
activateRES(opts = opts)
114-
}
115114

116-
if (antares_version >= as.numeric_version("8.6.0")) {
115+
if (antares_version >= as.numeric_version("8.6.0"))
117116
activateST(opts = opts)
117+
118+
# update actual template for 'generaldata.ini' (>=9.2)
119+
# as.numeric_version() is not efficient for 2 digits ...
120+
if(is_new_version){
121+
antares_version <- as.numeric(
122+
as.character(antares_version))
123+
124+
if (antares_version >= 9.2){
125+
updateOptimizationSettings(shedding.policy = "accurate shave peaks")
126+
127+
# add new section and initiate with value "daily" to keep legacy behavior
128+
gen_data_file <- readIni("settings/generaldata")
129+
new_section <- list(
130+
"compatibility" = list("hydro-pmax" = "daily"))
131+
gen_data_file <- append(gen_data_file, new_section)
132+
133+
writeIni(listData = gen_data_file,
134+
pathIni = "settings/generaldata",
135+
overwrite = TRUE)
136+
}
118137
}
119138
return(invisible(opts))
120139
}

R/removeArea.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ removeArea <- function(name, opts = antaresRead::simOptions()) {
7676
## Hydro
7777
# ini
7878
if (file.exists(file.path(inputPath, "hydro", "hydro.ini"))) {
79-
default_params <- get_default_hydro_ini_values()
79+
default_params <- get_default_hydro_ini_values(opts=opts)
8080
empty_params <- sapply(names(default_params), FUN = function(n) default_params[[n]] <- NULL)
8181
writeIniHydro(area = name, params = empty_params, mode = "removeArea", opts = opts)
8282
}

R/updateOptimizationSettings.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' @param solver.log true or false (available for version >= 8.8)
2121
#' @param power.fluctuations free modulations, minimize excursions or minimize ramping
2222
#' @param shedding.strategy share margins
23-
#' @param shedding.policy shave peaks or minimize duration
23+
#' @param shedding.policy shave peaks (accurate shave peaks for study >= v9.2)or minimize duration
2424
#' @param unit.commitment.mode fast or accurate
2525
#' @param number.of.cores.mode minimum, low, medium, high or maximum
2626
#' @param renewable.generation.modelling aggregated or clusters
@@ -119,8 +119,16 @@ updateOptimizationSettings <- function(simplex.range = NULL,
119119
)
120120
if (!is.null(shedding.strategy))
121121
assertthat::assert_that(shedding.strategy %in% c("share margins"))
122-
if (!is.null(shedding.policy))
123-
assertthat::assert_that(shedding.policy %in% c("shave peaks", "minimize duration"))
122+
if (!is.null(shedding.policy)){
123+
if(opts$antaresVersion>=920)
124+
assertthat::assert_that(
125+
shedding.policy %in%
126+
c("accurate shave peaks", "minimize duration"))
127+
else
128+
assertthat::assert_that(
129+
shedding.policy %in%
130+
c("shave peaks", "minimize duration"))
131+
}
124132
if (!is.null(unit.commitment.mode))
125133
assertthat::assert_that(unit.commitment.mode %in% c("fast", "accurate"))
126134
if (!is.null(number.of.cores.mode))

R/writeHydroValues.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ writeHydroValues <- function(area,
124124

125125

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

129130
default_hydro_params <- list(
130131
"inter-daily-breakdown" = 1, #
@@ -144,6 +145,10 @@ get_default_hydro_ini_values <- function(){
144145
"reservoir capacity" = 0
145146
)
146147

148+
if(opts$antaresVersion>=920)
149+
default_hydro_params <- append(default_hydro_params,
150+
list("overflow spilled cost difference" = 1))
151+
147152
return(default_hydro_params)
148153
}
149154

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

311+
if(opts$antaresVersion>=920)
312+
expected_params <- append(
313+
expected_params,
314+
list("overflow spilled cost difference" = c("numeric", "integer", "NULL")))
315+
306316
params_names <- names(params)
307317
expected_params_names <- names(expected_params)
308318

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

451461
path_ini_hydro <- file.path("input", "hydro", "hydro.ini")
452462
ini_hydro_data <- antaresRead::readIni(path_ini_hydro, opts = opts)
453-
default_params <- get_default_hydro_ini_values()
463+
default_params <- get_default_hydro_ini_values(opts = opts)
454464
# use heuristic
455465
if (is.null(ini_hydro_data[["use heuristic"]][[area]])) {
456466
ini_hydro_data[["use heuristic"]][[area]] <- default_params[["use heuristic"]]

man/get_default_hydro_ini_values.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/updateOptimizationSettings.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-createArea.R

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ sapply(studies, function(study) {
7171
# Initialize hydro.ini values for a new area
7272
test_that("Check if hydro.ini default values are initialized when creating an area", {
7373

74-
default_hydro_params <- get_default_hydro_ini_values()
74+
default_hydro_params <- get_default_hydro_ini_values(opts=opts)
7575

7676
hydro_ini_path <- file.path("input", "hydro", "hydro.ini")
7777
hydro_ini_data <- readIni(pathIni = hydro_ini_path, opts = opts)
@@ -521,3 +521,46 @@ test_that(".split_nodalOptimization_by_target() has the expected behaviour", {
521521
expect_true(length(res[["toIniAreas"]]) == 1)
522522
expect_true(names(res[["toIniAreas"]]) == "spilledenergycost")
523523
})
524+
525+
526+
# >= 920----
527+
test_that("New HYDRO default parameter", {
528+
suppressWarnings(
529+
createStudy(path = tempdir(),
530+
study_name = "test_area9.2",
531+
antares_version = "9.2"))
532+
533+
# default area with st cluster
534+
area_test = "al"
535+
createArea(name = area_test)
536+
537+
hydro_ini_path <- file.path("input", "hydro", "hydro.ini")
538+
hydro_ini_data <- readIni(pathIni = hydro_ini_path)
539+
540+
new_params_names <- "overflow spilled cost difference"
541+
542+
# test name + value
543+
expect_true(new_params_names %in% names(hydro_ini_data))
544+
expect_equal(names(hydro_ini_data[[new_params_names]]), "al")
545+
expect_equal(hydro_ini_data[[new_params_names]][[area_test]], 1)
546+
547+
548+
549+
test_that("Remove area / check hydro params", {
550+
area_test = "al2"
551+
createArea(name = area_test)
552+
553+
removeArea(name = area_test)
554+
555+
hydro_ini_path <- file.path("input", "hydro", "hydro.ini")
556+
hydro_ini_data <- readIni(pathIni = hydro_ini_path)
557+
new_params_names <- "overflow spilled cost difference"
558+
559+
# test name + value
560+
expect_true(new_params_names %in% names(hydro_ini_data))
561+
expect_false(area_test %in% names(hydro_ini_data[[new_params_names]]))
562+
})
563+
564+
565+
deleteStudy()
566+
})

tests/testthat/test-createStudy.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
# create ----
44

5+
## V9.2----
6+
test_that("Init v9.2 version study", {
7+
path <- file.path(tempdir(), "tests_v920")
8+
suppressWarnings(
9+
opts <- createStudy(path, antares_version = "9.2")
10+
)
11+
properties <- antaresRead:::readIniFile(file.path(path, "study.antares"))
12+
13+
# version
14+
expect_identical(properties$antares$version, 9.2)
15+
16+
# test new values in generaldata
17+
prop_gen <- readIni("settings/generaldata")
18+
19+
expect_equal(
20+
prop_gen[["other preferences"]][["shedding-policy"]],
21+
"accurate shave peaks"
22+
)
23+
24+
expect_equal(
25+
prop_gen[["compatibility"]][["hydro-pmax"]],
26+
"daily"
27+
)
28+
29+
unlink(path, recursive = TRUE)
30+
})
531
## v9.0----
632
test_that("Create a new v9.0 study", {
733
path <- file.path(tempdir(), "tests_createStudy")

0 commit comments

Comments
 (0)