Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parameter to storage_value_default() function if v880+ + check values rule for v880+ #169

Closed
wants to merge 9 commits into from
23 changes: 13 additions & 10 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BUGFIXES :

NEW FEATURES :

* Complete function `deleteStudy()` with new parameter `simulation` to delete a simulation in an Antares study.
* Complete function `deleteStudy()` with new parameter **simulation** to delete a simulation in an Antares study.
* New parameter `geographic.trimming` in `updateGeneralSettings()`to activate or deactivate this general parameter.
* Add `importZipStudyWeb()` to allow the user to import a local study in Antares Web

Expand All @@ -53,28 +53,31 @@ NEW FEATURES :
* `setPlaylist()` optimized for the API mode
- returned an updated list of simulation parameters returned by the function `setSimulationPath()` and `setSimulationPathAPI()`
* `.createCluster()` uses data.table::fwrite() instead of utils::write.table() for optimization
* `createCluster()` parameter `list_pollutants` default value to NULL.
* `createBindingConstraint()` parameter `coefficients` must be alphabetically ordered.
* `createCluster()` parameter **list_pollutants** default value to NULL.
* `createBindingConstraint()` parameter **coefficients** must be alphabetically ordered.
* `.createCluster()` default matrix in API mode.
* `removeArea()` :
- control the existence of an area in a binding constraint coefficient before deletion
- no longer deletes a binding constraint
* `removeLink()` : control the existence of a link a in a binding constraint coefficient before deletion
* `removeCluster()` : control the existence of a cluster a in a binding constraint coefficient before deletion
* `createClusterST()` : add a control to check if a cluster exists before running actions.
* `editClusterST()` : add a control to check if a cluster exists before running actions.
* `createClusterST()` / `editClusterST()` :
- add a control to check if a cluster exists before running actions.
* If antaresVersion >= 8.8.0 :
- warning when **initialleveloptim** == FALSE and **initiallevel** different of 0.5. Switch to 0.5 in this case.
-`storage_values_default()` : Change **initiallevel** default value to 0.5 and add **enabled** to list of parameters with default value equal to TRUE.
* `.removeCluster()` : add a control to check if a cluster exists before running actions in st-storage mode.
* Update documentation for scenarioBuilder : user must enable/disable `custom-scenario` property in `generaldata.ini` by himself
* Update documentation for scenarioBuilder : user must enable/disable **custom-scenario** property in `generaldata.ini` by himself


BUGFIXES :

* Fix `filter_synthesis` and `filter_year_by_year` parameters of `editLink()` in API mode
* Fix `filter_synthesis` and **filter_year_by_year** parameters of `editLink()` in API mode
* Fix `setPlaylist()` works in API and local mode with weights.
* Fix `getPlaylist()` works in API and local mode with weights.
* Fix `createDSR()` in API mode : daily binding constraint takes 366 rows.
* Fix `createCluster()` and `editCluster()` parameter `list_pollutants` stop if Antares Version < 8.6.0
* `getJobs()` no longer returns duplicates and displays the two new columns `owner_id` and `owner_name`.
* Fix `createCluster()` and `editCluster()` parameter **list_pollutants** stop if Antares Version < 8.6.0
* `getJobs()` no longer returns duplicates and displays the two new columns **owner_id** and **owner_name**.
* Allow the user to set symbol or full name as argument series in `updateScenarioBuilder()`
* `scenarioBuilder()` matrix has the same row repeated if the area is not rand
* Fix `createLink()` to update opts in API mode.
Expand Down Expand Up @@ -104,7 +107,7 @@ BUGFIXES :
* `createArea()` integrate "st-storage".
* `removeArea()` integrate "st-storage".
* `writeInputTS()` integrate "mingen" data and dependency between "mod.txt" and "mingen.txt" data.
* `createCluster()` / `editCluster()` have new parameter `list_pollutants` for list of pollutants.
* `createCluster()` / `editCluster()` have new parameter **list_pollutants** for list of pollutants.


NEW FEATURES (Antares v8.6) :
Expand Down
88 changes: 62 additions & 26 deletions R/createClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
createClusterST <- function(area,
cluster_name,
group = "Other1",
storage_parameters = storage_values_default(),
storage_parameters = NULL,
PMAX_injection = NULL,
PMAX_withdrawal = NULL,
inflows = NULL,
Expand Down Expand Up @@ -130,20 +130,29 @@ createClusterST <- function(area,
stop("Cluster already exists. Edit it with editClusterST().")
}
}

# Default value for storage_parameters
if (is.null(storage_parameters)){
storage_parameters <- storage_values_default(opts = opts)
}

##
# check parameters (ini file)
##
assertthat::assert_that(inherits(storage_parameters, "list"))

# static name of list parameters
names_parameters <- names(storage_values_default())
names_parameters <- names(storage_values_default(opts = opts))

if(!all(names(storage_parameters) %in% names_parameters))
stop(append("Parameter 'st-storage' must be named with the following elements: ",
paste0(names_parameters, collapse= ", ")))

# check values parameters
.st_mandatory_params(list_values = storage_parameters)
# check values parameters
storage_parameters <- .st_mandatory_params(list_values = storage_parameters,
area = area,
cluster_name = cluster_name,
opts = opts)


# DATA parameters : default value + name txt file
Expand Down Expand Up @@ -284,34 +293,53 @@ createClusterST <- function(area,

# check parameters (`list`)
#' @return `list`
.st_mandatory_params <- function(list_values){
.st_mandatory_params <- function(list_values,
area,
cluster_name,
opts = antaresRead::simOptions()){
.is_ratio(list_values$efficiency,
"efficiency")

.check_capacity(list_values$reservoircapacity,
"reservoircapacity")
# if(!list_values$reservoircapacity >= 0)
# stop("reservoircapacity must be >= 0",
# call. = FALSE)

.is_ratio(list_values$initiallevel,
"initiallevel")

.check_capacity(list_values$withdrawalnominalcapacity,
"withdrawalnominalcapacity")
# if(!list_values$withdrawalnominalcapacity >= 0)
# stop("withdrawalnominalcapacity must be >= 0",
# call. = FALSE)

.check_capacity(list_values$injectionnominalcapacity,
"injectionnominalcapacity")
# if(!list_values$injectionnominalcapacity >= 0)
# stop("injectionnominalcapacity must be >= 0",
# call. = FALSE)

if(!is.null(list_values$initialleveloptim))
assertthat::assert_that(inherits(list_values$initialleveloptim,
"logical"))
assertthat::assert_that(inherits(list_values$initialleveloptim,
"logical"))
# Check 880 rule for storage_parameters
if (opts$antaresVersion >= 880){

if(!is.null(list_values$enabled))
assertthat::assert_that(inherits(list_values$enabled,
"logical"))
if(file.exists(file.path(opts$studyPath,"input","st-storage","clusters",area,"list.ini"))){
ini = readIni(pathIni = file.path("input","st-storage","clusters",area,"list"), opts = opts)
initialleveloptim_ini = ini[[cluster_name]][["initialleveloptim"]]
} else {
initialleveloptim_ini = FALSE
}
#TRUE IF TRUE, FALSE OTHERWISE
is_initialleveloptim_TRUE = any(list_values$initialleveloptim,
initialleveloptim_ini)


if ("initiallevel" %in% names(list_values) & list_values$initiallevel != 0.5){
if(!is_initialleveloptim_TRUE){
warning("`initiallevel` value will be replaced by 0.5 because `initialleveloptim` = FALSE.")
list_values$initiallevel <- 0.5
}
}
}
return(list_values)
}

.is_ratio <- function(x, mess){
Expand All @@ -334,18 +362,26 @@ createClusterST <- function(area,

#' Short Term Storage Property List
#'
#'
#' @template opts
#' @return a named list
#' @export
#'
#' @examples
#' \dontrun{
#'
#' storage_values_default()
storage_values_default <- function() {
list(efficiency = 1,
reservoircapacity = 0,
initiallevel = 0,
withdrawalnominalcapacity = 0,
injectionnominalcapacity = 0,
initialleveloptim = FALSE)
}

#' }
storage_values_default <- function(opts = antaresRead::simOptions()) {
lst_parameters <- list(efficiency = 1,
reservoircapacity = 0,
initiallevel = 0,
withdrawalnominalcapacity = 0,
injectionnominalcapacity = 0,
initialleveloptim = FALSE)

if (opts$antaresVersion >= 880){
lst_parameters$initiallevel <- 0.5
lst_parameters$enabled <- TRUE
}
return(lst_parameters)
}
7 changes: 5 additions & 2 deletions R/editClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ editClusterST <- function(area,
assertthat::assert_that(inherits(storage_parameters, "list"))

# static name of list parameters
names_parameters <- names(storage_values_default())
names_parameters <- names(storage_values_default(opts = opts))

if(!all(names(storage_parameters) %in% names_parameters))
stop(append("Parameter 'st-storage' must be named with the following elements: ",
paste0(names_parameters, collapse= ", ")))

# check values parameters
.st_mandatory_params(list_values = storage_parameters)
storage_parameters <- .st_mandatory_params(list_values = storage_parameters,
area = area,
cluster_name = cluster_name,
opts = opts)

# check list of parameters
params_cluster <- hyphenize_names(storage_parameters)
Expand Down
2 changes: 1 addition & 1 deletion man/createClusterST.Rd

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

11 changes: 10 additions & 1 deletion man/storage_values_default.Rd

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

Loading
Loading