diff --git a/DESCRIPTION b/DESCRIPTION index 75c41f426..4532bfced 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,7 +25,7 @@ Imports: gdxdt, gdxrrw, ggplot2, - gms (>= 0.32.0), + gms (>= 0.32.1), goxygen (>= 1.4.4), gridExtra, gtools, @@ -36,7 +36,7 @@ Imports: knitr, lazyeval, lpjclass, - lucode2 (>= 0.36.0), + lucode2 (>= 0.47.8), luplot, luscale, lusweave, diff --git a/main.gms b/main.gms index 4294f8f27..58cd7c0f6 100755 --- a/main.gms +++ b/main.gms @@ -454,7 +454,7 @@ parameter *' * (2): parallel - all regions are run in parallel *' parameter - cm_iteration_max "number of iterations, if optimization is set to negishi or testOneRegi; is overwritten in Nash mode, except for cm_nash_autoconverge = 0" + cm_iteration_max "number of iterations, if optimization is set to negishi or testOneRegi; is overwritten in Nash mode, except if cm_nash_autoconverge is set to 0" ; cm_iteration_max = 1; !! def = 1 *' @@ -1621,12 +1621,14 @@ $setGlobal cm_CESMkup_ind standard !! def = standard $setGlobal cm_CESMkup_ind_data "" !! def = "" *** cm_fxIndUe "switch for fixing UE demand in industry to baseline level - no endogenous demand adjustment" -*** default cm_fxIndUe = off -> endogenous demand, cm_fxIndUe = on -> exogenous demand fixed to baseline/NPi level (read in from input_ref.gdx) -*** cm_fxIndUeReg indicates the regions under which the industry demand will be fixed -*** for example, cm_fxIndUe = on and cm_fxIndUeReg = SSA,NEU,CHA,IND,OAS,MEA,LAM gives a scenario where all non global north (non-OECD) industry demand is fixed to baseline -*** cm_fxIndUeReg = GLO fixes industry demand to baseline level everywhere -$setGlobal cm_fxIndUe off !! def = off -$setGlobal cm_fxIndUeReg "" !! def = "" +*** off: endogenous demand. +*** on: exogenous demand fixed to baseline/NPi level (read in from input_ref.gdx) +*** cm_fxIndUeReg "indicates the regions under which the industry demand will be fixed, requires cm_fxIndUe set to on" +*** examples: +*** SSA,NEU,CHA,IND,OAS,MEA,LAM: gives a scenario where all non global north (non-OECD) industry demand is fixed to baseline +*** GLO: fixes industry demand to baseline level everywhere +$setGlobal cm_fxIndUe off !! def = off !! regexp = off|on +$setGlobal cm_fxIndUeReg "" !! def = "" *** cm_ind_energy_limit Switch for setting upper limits on industry energy *** efficiency improvements. See ./modules/37_subsectors/datainput.gms for diff --git a/tests/testthat/test_01-manipulateConfig.R b/tests/testthat/test_01-manipulateConfig.R new file mode 100644 index 000000000..bffc87d84 --- /dev/null +++ b/tests/testthat/test_01-manipulateConfig.R @@ -0,0 +1,56 @@ +test_that("manipulate config with default configuration does not change main.gms", { + # copy main file and manipulate it based on default settings + cfg_init <- gms::readDefaultConfig("../..") + tmpfile <- tempfile(pattern = "main", tmpdir = "../..", fileext = ".gms") + file.copy("../../main.gms", tmpfile) + lucode2::manipulateConfig(tmpfile, cfg_init$gms) + cfg_after <- gms::readDefaultConfig("../..", basename(tmpfile)) + + # check diff + diffavailable <- ! Sys.which("diff") == "" + if (diffavailable) { + diffresult <- suppressWarnings(system(paste("diff -b ../../main.gms", tmpfile), intern = TRUE)) + # drop all sorts of comments until https://github.com/pik-piam/lucode2/issues/121 is fixed + drop <- c("^< \\*\\*\\*", "^> \\*\\*\\*", "^> \\*' \\*", "^< \\*' \\*", "^---$", "^[0-9,]+c[0-9,]+$") + for (d in drop) { + diffresult <- grep(d, diffresult, value = TRUE, invert = TRUE) + } + if (length(diffresult) > 0) { + warning("Applying manipulateConfig with the default configuration leads to this diff between main.gms and ", tmpfile, ":\n", + paste(diffresult, collapse = "\n")) + } + expect_equal(length(diffresult), 0) + } + + # check for switches missing in the new cfg + removedgms <- setdiff(names(cfg_init$gms), names(cfg_after$gms)) + if (length(removedgms) > 0) { + warning("These cfg$gms switches can't be found after manipulation of main.gms, see ", tmpfile, ".\n", + "Please file an issue in the gms package and try to adjust the code until the error goes away:\n", + paste("-", removedgms, collapse = "\n")) + } + expect_equal(length(removedgms), 0) + + # check for switches added to the new cfg + addedgms <- setdiff(names(cfg_after$gms), names(cfg_init$gms)) + if (length(addedgms) > 0) { + warning("These cfg$gms switches were somehow added by manipulateConfig to main.gms, see ", tmpfile, ".\n", + "Please file an issue in the gms package and try to adjust the code until the error goes away:\n", + paste("-", addedgms, collapse = "\n")) + } + expect_equal(length(addedgms), 0) + + # check for switches with different content between old and new cfg + joinednames <- intersect(names(cfg_after$gms), names(cfg_init$gms)) + contentdiff <- joinednames[! unlist(cfg_init$gms[joinednames]) == unlist(cfg_after$gms[joinednames])] + if (length(contentdiff) > 0) { + warning("After file manipulation, the following cfg$gms switches differ, see ", tmpfile, ":\n", + paste0("- ", contentdiff, ": ", unlist(cfg_init$gms[contentdiff]), " -> ", unlist(cfg_after$gms[contentdiff]), collapse = "\n")) + } + expect_equal(length(contentdiff), 0) + + # cleanup if no error found + if (length(addedgms) + length(removedgms) + length(contentdiff) + length(diffresult) == 0) { + file.remove(tmpfile) + } +})