Skip to content

Commit

Permalink
added renewable.generation.modelling argument to updateOptimizationSe…
Browse files Browse the repository at this point in the history
…ttings() function
  • Loading branch information
pvictor committed Aug 2, 2021
1 parent 93011c1 commit 03afff2
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 91 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: antaresEditObject
Type: Package
Title: Edit an 'Antares' Simulation
Version: 0.2.2
Version: 0.2.2.9000
Authors@R: c(
person("Veronique", "Bachelier", email = "[email protected]", role = c("aut", "cre")),
person("Frederic", "Breant", role = "aut"),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# antaresEditObject 0.2.2.9000

* `updateOptimizationSettings()` new argument `renewable.generation.modelling` that can take as value: `NULL`|`aggregated`|`cluster`.


# antaresEditObject 0.2.2

* New usage `getPlaylist` : V8 antares ponderation.
* New usage `setPlaylist` : V8 antares ponderation.


# antaresEditObject 0.2.1

* New function `copyOutput` : to copy antares output with extansion.
Expand All @@ -12,6 +18,7 @@
* New function `editArea` : to edit area
* New function `editBindingConstraint` : to edit Binding Constraint


# antaresEditObject 0.2.0

* New template in `createStudy()` for Antares version >= 7.1.0
Expand Down
217 changes: 127 additions & 90 deletions R/updateOptimizationSettings.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,86 @@
#' @param shedding.policy shave peaks 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 cluster
#' @param day.ahead.reserve.management global
#' @param opts
#' List of simulation parameters returned by the function
#' \code{antaresRead::setSimulationPath}
#'
#' @return An updated list containing various information about the simulation options.
#' @export
#'
#'
#' @importFrom utils modifyList
#' @importFrom assertthat assert_that
#' @importFrom antaresRead setSimulationPath
#'
# @examples
updateOptimizationSettings <- function(simplex.range = NULL,
transmission.capacities = NULL,
include.constraints = NULL,
include.hurdlecosts = NULL,
include.tc.min.stable.power = NULL,
include.tc.min.up.down.time = NULL,
include.dayahead = NULL,
include.strategicreserve = NULL,
include.spinningreserve = NULL,
include.primaryreserve = NULL,
include.exportmps = NULL,
power.fluctuations = NULL,
shedding.strategy = NULL,
shedding.policy = NULL,
unit.commitment.mode = NULL,
number.of.cores.mode = NULL,
day.ahead.reserve.management = NULL,
opts = antaresRead::simOptions()) {

transmission.capacities = NULL,
include.constraints = NULL,
include.hurdlecosts = NULL,
include.tc.min.stable.power = NULL,
include.tc.min.up.down.time = NULL,
include.dayahead = NULL,
include.strategicreserve = NULL,
include.spinningreserve = NULL,
include.primaryreserve = NULL,
include.exportmps = NULL,
power.fluctuations = NULL,
shedding.strategy = NULL,
shedding.policy = NULL,
unit.commitment.mode = NULL,
number.of.cores.mode = NULL,
renewable.generation.modelling = NULL,
day.ahead.reserve.management = NULL,
opts = antaresRead::simOptions()) {
assertthat::assert_that(class(opts) == "simOptions")

# check inputs
if(!is.null(simplex.range)) assertthat::assert_that(simplex.range %in% c("week", "day"))
if(!is.null(transmission.capacities)) assertthat::assert_that(transmission.capacities %in% c("true", "false", "infinite"))
if(!is.null(include.constraints)) assertthat::assert_that(include.constraints %in% c("true", "false"))
if(!is.null(include.hurdlecosts)) assertthat::assert_that(include.hurdlecosts %in% c("true", "false"))
if(!is.null(include.tc.min.stable.power)) assertthat::assert_that(include.tc.min.stable.power %in% c("true", "false"))
if(!is.null(include.tc.min.up.down.time)) assertthat::assert_that(include.tc.min.up.down.time %in% c("true", "false"))
if(!is.null(include.dayahead)) assertthat::assert_that(include.dayahead %in% c("true", "false"))
if(!is.null(include.strategicreserve)) assertthat::assert_that(include.strategicreserve %in% c("true", "false"))
if(!is.null(include.spinningreserve)) assertthat::assert_that(include.spinningreserve %in% c("true", "false"))
if(!is.null(include.primaryreserve)) assertthat::assert_that(include.primaryreserve %in% c("true", "false"))
if(!is.null(include.exportmps)) assertthat::assert_that(include.exportmps %in% c("true", "false"))

if(!is.null(power.fluctuations)) assertthat::assert_that(power.fluctuations %in% c("free modulations", "minimize excursions", "minimize ramping"))
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(unit.commitment.mode)) assertthat::assert_that(unit.commitment.mode %in% c("fast", "accurate"))
if(!is.null(number.of.cores.mode)) assertthat::assert_that(number.of.cores.mode %in% c("minimum", "low", "medium", "high", "maximum"))
if(!is.null(day.ahead.reserve.management)) assertthat::assert_that(day.ahead.reserve.management %in% c("global"))
# check inputs
if (!is.null(simplex.range))
assertthat::assert_that(simplex.range %in% c("week", "day"))
if (!is.null(transmission.capacities))
assertthat::assert_that(transmission.capacities %in% c("true", "false", "infinite"))
if (!is.null(include.constraints))
assertthat::assert_that(include.constraints %in% c("true", "false"))
if (!is.null(include.hurdlecosts))
assertthat::assert_that(include.hurdlecosts %in% c("true", "false"))
if (!is.null(include.tc.min.stable.power))
assertthat::assert_that(include.tc.min.stable.power %in% c("true", "false"))
if (!is.null(include.tc.min.up.down.time))
assertthat::assert_that(include.tc.min.up.down.time %in% c("true", "false"))
if (!is.null(include.dayahead))
assertthat::assert_that(include.dayahead %in% c("true", "false"))
if (!is.null(include.strategicreserve))
assertthat::assert_that(include.strategicreserve %in% c("true", "false"))
if (!is.null(include.spinningreserve))
assertthat::assert_that(include.spinningreserve %in% c("true", "false"))
if (!is.null(include.primaryreserve))
assertthat::assert_that(include.primaryreserve %in% c("true", "false"))
if (!is.null(include.exportmps))
assertthat::assert_that(include.exportmps %in% c("true", "false"))

if (!is.null(power.fluctuations))
assertthat::assert_that(
power.fluctuations %in% c("free modulations", "minimize excursions", "minimize ramping")
)
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(unit.commitment.mode))
assertthat::assert_that(unit.commitment.mode %in% c("fast", "accurate"))
if (!is.null(number.of.cores.mode))
assertthat::assert_that(number.of.cores.mode %in% c("minimum", "low", "medium", "high", "maximum"))
if (!is.null(renewable.generation.modelling))
assertthat::assert_that(renewable.generation.modelling %in% c("aggregated", "cluster"))
if (!is.null(day.ahead.reserve.management))
assertthat::assert_that(day.ahead.reserve.management %in% c("global"))


# read
generaldatapath <- file.path(opts$studyPath, "settings", "generaldata.ini")
generaldatapath <-
file.path(opts$studyPath, "settings", "generaldata.ini")
generaldata <- readIniFile(file = generaldatapath)

# update
Expand All @@ -82,51 +105,62 @@ updateOptimizationSettings <- function(simplex.range = NULL,
new_params_optimization <- list(
simplex.range = simplex.range,
transmission.capacities = transmission.capacities,
include.constraints = include.constraints,
include.constraints = include.constraints,
include.hurdlecosts = include.hurdlecosts,
include.tc.min.stable.power = include.tc.min.stable.power,
include.tc.min.stable.power = include.tc.min.stable.power,
include.tc.min.up.down.time = include.tc.min.up.down.time,
include.dayahead = include.dayahead,
include.strategicreserve = include.strategicreserve,
include.strategicreserve = include.strategicreserve,
include.spinningreserve = include.spinningreserve,
include.primaryreserve = include.primaryreserve,
include.exportmps = include.exportmps)
include.primaryreserve = include.primaryreserve,
include.exportmps = include.exportmps
)

new_params_optimization <- dropNulls(new_params_optimization)

new_params_others <- list(
power.fluctuations = power.fluctuations,
shedding.strategy = shedding.strategy,
shedding.policy = shedding.policy,
unit.commitment.mode = unit.commitment.mode,
number.of.cores.mode = number.of.cores.mode,
day.ahead.reserve.management = day.ahead.reserve.management)
shedding.policy = shedding.policy,
unit.commitment.mode = unit.commitment.mode,
number.of.cores.mode = number.of.cores.mode,
renewable.generation.modelling = renewable.generation.modelling,
day.ahead.reserve.management = day.ahead.reserve.management
)

new_params_others <- dropNulls(new_params_others)

for (i in seq_along(new_params_optimization)) {
new_params_optimization[i] <- as.character(new_params_optimization[i])
names(new_params_optimization)[i] <- dicoOptimizationSettings(names(new_params_optimization)[i])
new_params_optimization[i] <-
as.character(new_params_optimization[i])
names(new_params_optimization)[i] <-
dicoOptimizationSettings(names(new_params_optimization)[i])
}

for (i in seq_along(new_params_others)) {
new_params_others[i] <- as.character(new_params_others[i])
names(new_params_others)[i] <- dicoOptimizationSettings(names(new_params_others)[i])
names(new_params_others)[i] <-
dicoOptimizationSettings(names(new_params_others)[i])
}

l_optimization <- utils::modifyList(x = l_optimization, val = new_params_optimization)
l_others <- utils::modifyList(x = l_others, val = new_params_others)
l_optimization <-
utils::modifyList(x = l_optimization, val = new_params_optimization)
l_others <-
utils::modifyList(x = l_others, val = new_params_others)

generaldata$optimization <- l_optimization
generaldata$`other preferences` <- l_others


# write
writeIni(listData = generaldata, pathIni = generaldatapath, overwrite = TRUE)
writeIni(listData = generaldata,
pathIni = generaldatapath,
overwrite = TRUE)

# Maj simulation
suppressWarnings({
res <- antaresRead::setSimulationPath(path = opts$studyPath, simulation = "input")
res <-
antaresRead::setSimulationPath(path = opts$studyPath, simulation = "input")
})

invisible(res)
Expand All @@ -137,61 +171,64 @@ updateOptimizationSettings <- function(simplex.range = NULL,


#' Correspondence between arguments of \code{updateOptimizationSettings} and actual Antares parameters.
#'
#'
#' @param arg An argument from function \code{updateOptimizationSettings}.
#'
#' @return The corresponding Antares general parameter.
#'
#'
#' @export
#'
#' @examples
#'
#' @examples
#' dicoGeneralSettings("year.by.year") # "year-by-year"
dicoOptimizationSettings <- function(arg) {
if (length(arg) > 1)
if (length(arg) > 1)
stop("'arg' must be length one")


antares_params <- as.list(c(
"simplex-range",
"transmission-capacities",
"include-constraints",
"include-hurdlecosts",
"include-tc-minstablepower",
"include-tc-min-ud-time",
"include-dayahead",
"include-strategicreserve",
"include-spinningreserve",
"include-primaryreserve",
"include-exportmps",
"power-fluctuations",
"shedding-strategy",
"shedding-policy",
"unit-commitment-mode",
"number-of-cores-mode",
"day-ahead-reserve-management"))
antares_params <- as.list(
c(
"simplex-range",
"transmission-capacities",
"include-constraints",
"include-hurdlecosts",
"include-tc-minstablepower",
"include-tc-min-ud-time",
"include-dayahead",
"include-strategicreserve",
"include-spinningreserve",
"include-primaryreserve",
"include-exportmps",
"power-fluctuations",
"shedding-strategy",
"shedding-policy",
"unit-commitment-mode",
"number-of-cores-mode",
"renewable-generation-modelling",
"day-ahead-reserve-management"
)
)


names(antares_params) <- c(
"simplex.range",
"transmission.capacities",
"include.constraints",
"include.constraints",
"include.hurdlecosts",
"include.tc.min.stable.power",
"include.tc.min.stable.power",
"include.tc.min.up.down.time",
"include.dayahead",
"include.strategicreserve",
"include.strategicreserve",
"include.spinningreserve",
"include.primaryreserve",
"include.exportmps",
"include.primaryreserve",
"include.exportmps",
"power.fluctuations",
"shedding.strategy",
"shedding.policy",
"unit.commitment.mode",
"number.of.cores.mode",
"day.ahead.reserve.management")
"shedding.policy",
"unit.commitment.mode",
"number.of.cores.mode",
"renewable.generation.modelling",
"day.ahead.reserve.management"
)

antares_params[[arg]]
}



1 change: 1 addition & 0 deletions antaresEditObject.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ LaTeX: pdfLaTeX
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageCheckArgs: --no-manual
PackageRoxygenize: rd,collate,namespace
3 changes: 3 additions & 0 deletions man/updateOptimizationSettings.Rd

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

0 comments on commit 03afff2

Please sign in to comment.