Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ NEW FEATURES :
* `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)
* `createArea()` initializes the `hydro.ini` file with a new parameter `overflow spilled cost difference`

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

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()
})