Skip to content

Commit

Permalink
Merge branch 'master' into release/cran064
Browse files Browse the repository at this point in the history
  • Loading branch information
berthetclement authored May 24, 2024
2 parents c76fa6b + f13f052 commit ff55f01
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 3 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr

2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# antaresEditObject 0.6.4

BREAKING CHANGES :
Expand All @@ -9,6 +10,7 @@ BUGFIXES :
* `editArea()` : not delete one of the two economic options if only one must be edited
* Avoid data deletion in API mode for `editArea()`


# antaresEditObject 0.6.3

NEW FEATURES :
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-createArea.R
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,4 @@ test_that(".split_nodalOptimization_by_target() has the expected behaviour", {
expect_true(length(res[["toIniAreas"]]) == 1)
expect_true(names(res[["toIniAreas"]]) == "spilledenergycost")
})

120 changes: 120 additions & 0 deletions tests/testthat/test-createCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,126 @@ test_that("removeCluster() : cluster is not removed if it is referenced in a bin
})


# Delete expected files ----
test_that("removeCluster(): check if the expected files are deleted", {

st_test <- paste0("my_study_820_", paste0(sample(letters,5),collapse = ""))
suppressWarnings(opts <- createStudy(path = pathstd, study_name = st_test, antares_version = "8.2.0"))

## Areas
area <- "zone1"
createArea(name = area, opts = simOptions())

## Clusters
clusters <- c("nuclear", "gas", "coal")
nb_clusters <- length(clusters)
my_clusters <- expand.grid("area" = area, "cluster_name" = clusters)
apply(my_clusters[,c("area","cluster_name")],
MARGIN = 1,
FUN = function(row){
createCluster(area = as.character(row[1]),
cluster_name = as.character(row[2]),
add_prefix = TRUE,
opts = simOptions()
)
}
)

suppressWarnings(opts <- setSimulationPath(path = opts$studyPath, simulation = "input"))

all_clusters <- readClusterDesc(opts = simOptions())
expect_true(nrow(all_clusters) == nb_clusters)

i <- 0
preproPath <- file.path(opts$inputPath, "thermal", "prepro")
seriesPath <- file.path(opts$inputPath, "thermal", "series")
# remove N-1 first clusters
for (cluster in clusters[-length(clusters)]) {
i <- i + 1
suppressWarnings(removeCluster(area = area, cluster_name = cluster, add_prefix = TRUE, opts = simOptions()))
all_clusters <- readClusterDesc(opts = simOptions())
expect_true(nrow(all_clusters) == nb_clusters - i)
expect_false(dir.exists(file.path(preproPath, area, paste0(area, "_", cluster))))
expect_false(dir.exists(file.path(seriesPath, area, paste0(area, "_", cluster))))
expect_true(dir.exists(file.path(preproPath, area)))
expect_true(dir.exists(file.path(seriesPath, area)))
}

all_clusters <- readClusterDesc(opts = simOptions())
expect_true(nrow(all_clusters) == 1)

# last cluster
suppressWarnings(removeCluster(area = area, cluster_name = clusters[length(clusters)], add_prefix = TRUE, opts = simOptions()))
suppressWarnings(all_clusters <- readClusterDesc(opts = simOptions()))
expect_true(nrow(all_clusters) == 0)
# Remove area directory when removing last cluster of the area
expect_false(dir.exists(file.path(preproPath, area)))
expect_false(dir.exists(file.path(seriesPath, area)))

unlink(x = opts$studyPath, recursive = TRUE)
})


# Cluster in binding constraint not removed ----
test_that("removeCluster() : cluster is not removed if it is referenced in a binding constraint", {

ant_version <- "8.2.0"
st_test <- paste0("my_study_820_", paste0(sample(letters,5),collapse = ""))
suppressWarnings(opts <- createStudy(path = pathstd, study_name = st_test, antares_version = ant_version))

nb_areas <- 5
ids_areas <- seq(1,nb_areas)
my_areas <- paste0("zone",ids_areas)

clusters <- c("nuclear", "gas", "coal")
my_clusters <- expand.grid("area" = my_areas, "cluster_name" = clusters)
my_clusters$cluster_name_prefixed <- paste0(my_clusters$area, "_", my_clusters$cluster_name)
my_clusters$cluster_name_binding <- paste0(my_clusters$area, ".", my_clusters$cluster_name_prefixed)
lst_clusters <- split(my_clusters[,c("cluster_name_binding")], my_clusters$cluster_name)

# Areas
lapply(my_areas, FUN = function(area){createArea(name = area, opts = simOptions())})

# Clusters
apply(my_clusters[,c("area","cluster_name")],
MARGIN = 1,
FUN = function(row){
createCluster(area = as.character(row[1]),
cluster_name = as.character(row[2]),
add_prefix = TRUE,
opts = simOptions()
)
}
)

suppressWarnings(opts <- setSimulationPath(path = opts$studyPath, simulation = "input"))

nb_cols_per_matrix <- 3
nb_hours_per_year <- 8784
nb_values_per_matrix <- nb_hours_per_year * nb_cols_per_matrix
for (cluster in names(lst_clusters)) {
names_coefs_bc <- lst_clusters[[cluster]]
coefs <- seq_len(length(names_coefs_bc))
names(coefs) <- names_coefs_bc
createBindingConstraint(name = paste0("bc_",cluster),
timeStep = "hourly",
operator = "less",
coefficients = coefs,
values = matrix(rep(0,nb_values_per_matrix), ncol = nb_cols_per_matrix),
opts = opts
)
}

suppressWarnings(opts <- setSimulationPath(path = opts$studyPath, simulation = "input"))

expect_error(removeCluster(area = "zone1", cluster_name = "nuclear", add_prefix = TRUE, opts = opts), regexp = "Can not remove the cluster")
removeBindingConstraint(name = "bc_nuclear", opts = opts)
expect_no_error(removeCluster(area = "zone1", cluster_name = "nuclear", add_prefix = TRUE, opts = opts))

unlink(x = opts$studyPath, recursive = TRUE)
})


# Delete expected files ----
test_that("removeCluster(): check if the expected files are deleted", {

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-createDSR.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


# context("Function createDSR")
#
#
Expand Down Expand Up @@ -138,3 +137,4 @@
# unlink(x = file.path(pathstd, "test_case"), recursive = TRUE)
#
# })

2 changes: 1 addition & 1 deletion tests/testthat/test-createPSP.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


# context("Function createPSP")
#
#
Expand Down Expand Up @@ -176,3 +175,4 @@
# unlink(x = file.path(pathstd, "test_case"), recursive = TRUE)
#
# })

0 comments on commit ff55f01

Please sign in to comment.