From 5daf8be00ad162cf0300c6ca2d4b7e8da46083b5 Mon Sep 17 00:00:00 2001
From: David Klein <dklein@pik-potsdam.de>
Date: Fri, 3 Apr 2020 17:00:04 +0200
Subject: [PATCH] Change the reference scenario (for calculating the BECCS
 bound, see previous commit) from input_ref.gdx to the values of the own
 previous nash iteration.

---
 modules/30_biomass/magpie_40/bounds.gms       |  6 --
 modules/30_biomass/magpie_40/datainput.gms    | 55 +++++++++----------
 modules/30_biomass/magpie_40/declarations.gms |  8 +--
 modules/30_biomass/magpie_40/equations.gms    |  2 +-
 modules/30_biomass/magpie_40/postsolve.gms    | 25 +++++++++
 modules/30_biomass/magpie_40/presolve.gms     | 28 ++++++++++
 modules/30_biomass/magpie_40/realization.gms  |  2 +
 scripts/output/comparison/compareScenarios.R  | 18 +++---
 8 files changed, 96 insertions(+), 48 deletions(-)
 create mode 100644 modules/30_biomass/magpie_40/postsolve.gms
 create mode 100644 modules/30_biomass/magpie_40/presolve.gms

diff --git a/modules/30_biomass/magpie_40/bounds.gms b/modules/30_biomass/magpie_40/bounds.gms
index b64fdf3..c33ee73 100644
--- a/modules/30_biomass/magpie_40/bounds.gms
+++ b/modules/30_biomass/magpie_40/bounds.gms
@@ -9,12 +9,6 @@
 *** Bounds on pedem
 *** -------------------------------------------------------------
 
-*** To prevent RUS and MEA from demanding high amounts of biomass 
-*** just because of their capacity to store negative emissions a
-*** general rule for all regions is applied that limits the PE 
-*** demand of BECCS technologies in policy runs to 30% of the total 
-*** PE of the baseline scenario (see q30_limitTeBio)
-
 *** -------------------------------------------------------------
 *** Bounds on 1st generation biomass annual production
 *** -------------------------------------------------------------
diff --git a/modules/30_biomass/magpie_40/datainput.gms b/modules/30_biomass/magpie_40/datainput.gms
index cedf619..f8a0534 100644
--- a/modules/30_biomass/magpie_40/datainput.gms
+++ b/modules/30_biomass/magpie_40/datainput.gms
@@ -89,36 +89,35 @@ display i30_bioen_price_a, i30_bioen_price_b;
 *** Bounds on pedem
 *** -------------------------------------------------------------
 
-*** To prevent regions with large carbon sequestration potentials
-*** from demanding high amounts of biomass with CCS to generate
-*** negative emissions rather than requiring it for energy production
-*** this general rule for all regions is applied that limits the PE 
+*** To prevent RUS and MEA from demanding high amounts of biomass 
+*** just because of their capacity to store negative emissions a
+*** general rule for all regions is applied that limits the PE 
 *** demand of BECCS technologies in policy runs to 30% of the total 
 *** PE of the baseline scenario (see q30_limitTeBio)
 
-if(cm_emiscen ne 1,
-Execute_Loadpoint 'input_ref' v30_pedem_BAU=vm_demPe;
-Execute_Loadpoint 'input_ref' v30_seprod_BAU=vm_prodSe;
-
-p30_pedem_BAU(ttot,regi) =
-  sum(pe2se(enty,enty2,te)$(sameas(enty,"peoil") OR sameas(enty,"pecoal") OR sameas(enty,"pegas") OR sameas(enty,"pebiolc") OR sameas(enty,"pebios") OR sameas(enty,"pebioil")),
-    v30_pedem_BAU.l(ttot,regi,enty,enty2,te)
-  ) 
-  + sum(entySe,
-      sum(te,
-          v30_seprod_BAU.l(ttot,regi,"pegeo",entySe,te)
-        + v30_seprod_BAU.l(ttot,regi,"pehyd",entySe,te)
-        + v30_seprod_BAU.l(ttot,regi,"pewin",entySe,te)
-        + v30_seprod_BAU.l(ttot,regi,"pesol",entySe,te)
-        + v30_seprod_BAU.l(ttot,regi,"peur",entySe,te)
-      )
-    ) * 100/40  !!! substitution method
-;
-
-p30_pedemBio_BAU(ttot,regi) =
-  sum(pe2se(enty,enty2,te)$(sameas(enty,"pebiolc") OR sameas(enty,"pebios") OR sameas(enty,"pebioil")),
-    v30_pedem_BAU.l(ttot,regi,enty,enty2,te)
-  );
-);
+***if(cm_emiscen ne 1,
+***Execute_Loadpoint 'input_ref' v30_pedem_BAU=vm_demPe;
+***Execute_Loadpoint 'input_ref' v30_seprod_BAU=vm_prodSe;
+***
+***p30_pedem_BAU(ttot,regi) =
+***  sum(pe2se(enty,enty2,te)$(sameas(enty,"peoil") OR sameas(enty,"pecoal") OR sameas(enty,"pegas") OR sameas(enty,"pebiolc") OR sameas(enty,"pebios") OR sameas(enty,"pebioil")),
+***    v30_pedem_BAU.l(ttot,regi,enty,enty2,te)
+***  ) 
+***  + sum(entySe,
+***      sum(te,
+***          v30_seprod_BAU.l(ttot,regi,"pegeo",entySe,te)
+***        + v30_seprod_BAU.l(ttot,regi,"pehyd",entySe,te)
+***        + v30_seprod_BAU.l(ttot,regi,"pewin",entySe,te)
+***        + v30_seprod_BAU.l(ttot,regi,"pesol",entySe,te)
+***        + v30_seprod_BAU.l(ttot,regi,"peur",entySe,te)
+***      )
+***    ) * 100/40  !!! substitution method
+***;
+***
+***p30_pedemBio_BAU(ttot,regi) =
+***  sum(pe2se(enty,enty2,te)$(sameas(enty,"pebiolc") OR sameas(enty,"pebios") OR sameas(enty,"pebioil")),
+***    v30_pedem_BAU.l(ttot,regi,enty,enty2,te)
+***  );
+***);
 
 *** EOF ./modules/30_biomass/magpie_40/datainput.gms
diff --git a/modules/30_biomass/magpie_40/declarations.gms b/modules/30_biomass/magpie_40/declarations.gms
index fa4ac10..8d1153a 100644
--- a/modules/30_biomass/magpie_40/declarations.gms
+++ b/modules/30_biomass/magpie_40/declarations.gms
@@ -20,8 +20,8 @@ p30_max200_path(tall)                           "Time path of global maximal peb
 p30_maxprod_residue(ttot,all_regi)              "Maximal potential of residues enhanced by demand of biotr [TWa]"
 p30_pebiolc_pricemag(tall,all_regi)             "Prices for lignocellulosic purpose grown bioenergy from MAgPIE [T$US/TWa]"
 p30_pebiolc_demandmag(tall,all_regi)            "Production of lignocellulosic purpose grown bioenergy from MAgPIE [TWa]"
-p30_pedem_BAU(ttot,all_regi)                    "Primary energy demand imported from reference gdx [TWa]"
-p30_pedemBio_BAU(ttot,all_regi)                 "Primary bioenergy demand imported from reference gdx [TWa]"
+p30_demPe(ttot,all_regi)                        "Primary energy demand imported from gdx or previous iteration [TWa]"
+***p30_pedemBio_BAU(ttot,all_regi)                 "Primary bioenergy demand imported from reference gdx [TWa]"
 
 
 *** Shift factor calculation
@@ -52,8 +52,8 @@ Positive variable
 v30_priceshift(ttot,all_regi)      "Regional translation factor that shifts emulator prices to better fit actual MAgPIE prices [-]"
 v30_pricemult(ttot,all_regi)       "Regional multiplication factor that sclaes emulator prices to better fit actual MAgPIE prices [-]"
 v30_multcost(ttot,all_regi)        "Cost markup factor for deviations from demand of last coupling iteration [-]"
-v30_pedem_BAU(tall,all_regi,all_enty,all_enty,all_te)    "Primary energy demand imported from refernce gdx [TWa]"
-v30_seprod_BAU(tall,all_regi,all_enty,all_enty,all_te)   "Secondary energy production imported from reference gdx [TWa]"
+***v30_pedem_BAU(tall,all_regi,all_enty,all_enty,all_te)    "Primary energy demand imported from refernce gdx [TWa]"
+***v30_seprod_BAU(tall,all_regi,all_enty,all_enty,all_te)   "Secondary energy production imported from reference gdx [TWa]"
 
 ;
 
diff --git a/modules/30_biomass/magpie_40/equations.gms b/modules/30_biomass/magpie_40/equations.gms
index a262240..4687b7e 100644
--- a/modules/30_biomass/magpie_40/equations.gms
+++ b/modules/30_biomass/magpie_40/equations.gms
@@ -113,7 +113,7 @@ q30_limitXpBio(t,regi)..
 q30_limitTeBio(t,regi)$(cm_emiscen ne 1)..
         sum(pe2se(enty,enty2,teBio)$(teCCS(teBio)), vm_demPe(t,regi,enty,enty2,teBio))
         =l=
-        max (0.35 * p30_pedem_BAU(t,regi), 1.30 * p30_pedemBio_BAU(t,regi));
+        0.5 * p30_demPe(t,regi);
          
 		 
 *** EOF ./modules/30_biomass/magpie_4/equations.gms
diff --git a/modules/30_biomass/magpie_40/postsolve.gms b/modules/30_biomass/magpie_40/postsolve.gms
new file mode 100644
index 0000000..1032673
--- /dev/null
+++ b/modules/30_biomass/magpie_40/postsolve.gms
@@ -0,0 +1,25 @@
+*** |  (C) 2006-2019 Potsdam Institute for Climate Impact Research (PIK)
+*** |  authors, and contributors see CITATION.cff file. This file is part
+*** |  of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of
+*** |  AGPL-3.0, you are granted additional permissions described in the
+*** |  REMIND License Exception, version 1.0 (see LICENSE file).
+*** |  Contact: remind@pik-potsdam.de
+
+*** SOF ./modules/30_biomass/magpie_40/postsolve.gm
+
+p30_demPe(ttot,regi) =
+  sum(pe2se(enty,enty2,te)$(sameas(enty,"peoil") OR sameas(enty,"pecoal") OR sameas(enty,"pegas") OR sameas(enty,"pebiolc") OR sameas(enty,"pebios") OR sameas(enty,"pebioil")),
+    vm_demPe.l(ttot,regi,enty,enty2,te)
+  ) 
+  + sum(entySe,
+      sum(te,
+          vm_prodSe.l(ttot,regi,"pegeo",entySe,te)
+        + vm_prodSe.l(ttot,regi,"pehyd",entySe,te)
+        + vm_prodSe.l(ttot,regi,"pewin",entySe,te)
+        + vm_prodSe.l(ttot,regi,"pesol",entySe,te)
+        + vm_prodSe.l(ttot,regi,"peur",entySe,te)
+      )
+    ) * 100/40  !!! substitution method
+;
+
+*** EOF ./modules/30_biomass/magpie_40/postsolve.gms
diff --git a/modules/30_biomass/magpie_40/presolve.gms b/modules/30_biomass/magpie_40/presolve.gms
new file mode 100644
index 0000000..4a8ccf0
--- /dev/null
+++ b/modules/30_biomass/magpie_40/presolve.gms
@@ -0,0 +1,28 @@
+*** |  (C) 2006-2019 Potsdam Institute for Climate Impact Research (PIK)
+*** |  authors, and contributors see CITATION.cff file. This file is part
+*** |  of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of
+*** |  AGPL-3.0, you are granted additional permissions described in the
+*** |  REMIND License Exception, version 1.0 (see LICENSE file).
+*** |  Contact: remind@pik-potsdam.de
+
+*** SOF ./modules/30_biomass/magpie_40/presolve.gms
+
+*** save level value of all taxes
+
+p30_demPe(ttot,regi) =
+  sum(pe2se(enty,enty2,te)$(sameas(enty,"peoil") OR sameas(enty,"pecoal") OR sameas(enty,"pegas") OR sameas(enty,"pebiolc") OR sameas(enty,"pebios") OR sameas(enty,"pebioil")),
+    vm_demPe.l(ttot,regi,enty,enty2,te)
+  ) 
+  + sum(entySe,
+      sum(te,
+          vm_prodSe.l(ttot,regi,"pegeo",entySe,te)
+        + vm_prodSe.l(ttot,regi,"pehyd",entySe,te)
+        + vm_prodSe.l(ttot,regi,"pewin",entySe,te)
+        + vm_prodSe.l(ttot,regi,"pesol",entySe,te)
+        + vm_prodSe.l(ttot,regi,"peur",entySe,te)
+      )
+    ) * 100/40  !!! substitution method
+;
+
+
+*** EOF ./modules/30_biomass/magpie_40/presolve.gms
diff --git a/modules/30_biomass/magpie_40/realization.gms b/modules/30_biomass/magpie_40/realization.gms
index 67b8c48..450aa7c 100644
--- a/modules/30_biomass/magpie_40/realization.gms
+++ b/modules/30_biomass/magpie_40/realization.gms
@@ -17,6 +17,8 @@ $Ifi "%phase%" == "datainput" $include "./modules/30_biomass/magpie_40/datainput
 $Ifi "%phase%" == "equations" $include "./modules/30_biomass/magpie_40/equations.gms"
 $Ifi "%phase%" == "preloop" $include "./modules/30_biomass/magpie_40/preloop.gms"
 $Ifi "%phase%" == "bounds" $include "./modules/30_biomass/magpie_40/bounds.gms"
+$Ifi "%phase%" == "presolve" $include "./modules/30_biomass/magpie_40/presolve.gms"
+$Ifi "%phase%" == "postsolve" $include "./modules/30_biomass/magpie_40/postsolve.gms"
 $Ifi "%phase%" == "output" $include "./modules/30_biomass/magpie_40/output.gms"
 *######################## R SECTION END (PHASES) ###############################
 *** EOF ./modules/30_biomass/magpie_linear.gms
diff --git a/scripts/output/comparison/compareScenarios.R b/scripts/output/comparison/compareScenarios.R
index 6d484c0..887f5d6 100644
--- a/scripts/output/comparison/compareScenarios.R
+++ b/scripts/output/comparison/compareScenarios.R
@@ -15,16 +15,16 @@ if (exists("outputdirs")) {
 } else {
   # This is the case if this script was called directly via Rscript
   listofruns <- list( 
-      #list(period = "both",  set = "cpl-Base",       dirs = c("C_SDP-Base-rem-5",       "C_SSP1-Base-rem-5",       "C_SSP2-Base-rem-5",       "C_SSP5-Base-rem-5")),
-      #list(period = "both",  set = "cpl-PkBudg900",  dirs = c("C_SDP-PkBudg900-rem-5",  "C_SSP1-PkBudg900-rem-5",  "C_SSP2-PkBudg900-rem-5",  "C_SSP5-PkBudg900-rem-5")),
-      #list(period = "both",  set = "cpl-PkBudg1100", dirs = c("C_SDP-PkBudg1100-rem-5", "C_SSP1-PkBudg1100-rem-5", "C_SSP2-PkBudg1100-rem-5", "C_SSP5-PkBudg1100-rem-5")),
-      #list(period = "both",  set = "cpl-PkBudg1300", dirs = c("C_SDP-PkBudg1300-rem-5", "C_SSP1-PkBudg1300-rem-5", "C_SSP2-PkBudg1300-rem-5", "C_SSP5-PkBudg1300-rem-5")),
-      #list(period = "both",  set = "cpl-NPi",        dirs = c("C_SDP-NPi-rem-5",        "C_SSP1-NPi-rem-5",        "C_SSP2-NPi-rem-5",        "C_SSP5-NPi-rem-5")),
+      list(period = "both",  set = "cpl-Base",       dirs = c("C_SDP-Base-rem-5",       "C_SSP1-Base-rem-5",       "C_SSP2-Base-rem-5",       "C_SSP5-Base-rem-5")),
+      list(period = "both",  set = "cpl-PkBudg900",  dirs = c("C_SDP-PkBudg900-rem-5",  "C_SSP1-PkBudg900-rem-5",  "C_SSP2-PkBudg900-rem-5",  "C_SSP5-PkBudg900-rem-5")),
+      list(period = "both",  set = "cpl-PkBudg1100", dirs = c("C_SDP-PkBudg1100-rem-5", "C_SSP1-PkBudg1100-rem-5", "C_SSP2-PkBudg1100-rem-5", "C_SSP5-PkBudg1100-rem-5")),
+      list(period = "both",  set = "cpl-PkBudg1300", dirs = c("C_SDP-PkBudg1300-rem-5", "C_SSP1-PkBudg1300-rem-5", "C_SSP2-PkBudg1300-rem-5", "C_SSP5-PkBudg1300-rem-5")),
+      list(period = "both",  set = "cpl-NPi",        dirs = c("C_SDP-NPi-rem-5",        "C_SSP1-NPi-rem-5",        "C_SSP2-NPi-rem-5",        "C_SSP5-NPi-rem-5")),
       
-      #list(period = "both",  set = "cpl-SDP",  dirs = c("C_SDP-Base-rem-5",  "C_SDP-NPi-rem-5",  "C_SDP-PkBudg1300-rem-5",  "C_SDP-PkBudg1100-rem-5",  "C_SDP-PkBudg1000-rem-5")),
-      #list(period = "both",  set = "cpl-SSP1", dirs = c("C_SSP1-Base-rem-5", "C_SSP1-NPi-rem-5", "C_SSP1-PkBudg1300-rem-5", "C_SSP1-PkBudg1100-rem-5", "C_SSP1-PkBudg900-rem-5")),
-      list(period = "both",  set = "cpl-SSP2", dirs = c("C_SSP2-Base-rem-5", "C_SSP2-NPi-rem-5", "C_SSP2-PkBudg1300-rem-5", "C_SSP2-PkBudg1100-rem-5", "C_SSP2-PkBudg900-rem-5")), #, "C_SSP2-NDC-rem-5"
-      #list(period = "both",  set = "cpl-SSP5", dirs = c("C_SSP5-Base-rem-5", "C_SSP5-NPi-rem-5", "C_SSP5-PkBudg1300-rem-5", "C_SSP5-PkBudg1100-rem-5", "C_SSP5-PkBudg900-rem-5")),
+      list(period = "both",  set = "cpl-SDP",  dirs = c("C_SDP-Base-rem-5",  "C_SDP-NPi-rem-5",  "C_SDP-PkBudg1300-rem-5",  "C_SDP-PkBudg1100-rem-5",  "C_SDP-PkBudg1000-rem-5")),
+      list(period = "both",  set = "cpl-SSP1", dirs = c("C_SSP1-Base-rem-5", "C_SSP1-NPi-rem-5", "C_SSP1-PkBudg1300-rem-5", "C_SSP1-PkBudg1100-rem-5", "C_SSP1-PkBudg900-rem-5")),
+      list(period = "both",  set = "cpl-SSP2", dirs = c("C_SSP2-Base-rem-5", "C_SSP2-NPi-rem-5", "C_SSP2-PkBudg1300-rem-5", "C_SSP2-PkBudg1100-rem-5", "C_SSP2-PkBudg900-rem-5", "C_SSP2-NDC-rem-5")), #
+      list(period = "both",  set = "cpl-SSP5", dirs = c("C_SSP5-Base-rem-5", "C_SSP5-NPi-rem-5", "C_SSP5-PkBudg1300-rem-5", "C_SSP5-PkBudg1100-rem-5", "C_SSP5-PkBudg900-rem-5")),
       
       #list(period = "both",  set = "cpl-PkBudg900-plant-vgl",  dirs = c("C_SDP-PkBudg900-plant-rem-5", "C_SDP-PkBudg900-rem-5", "C_SSP2-PkBudg900-plant-rem-5", "C_SSP2-PkBudg900-rem-5")),
       #list(period = "both",  set = "cpl-PkBudg900-plant",      dirs = c("C_SDP-PkBudg900-plant-rem-5",  "C_SSP1-PkBudg900-plant-rem-5",  "C_SSP2-PkBudg900-plant-rem-5",  "C_SSP5-PkBudg900-plant-rem-5")),
-- 
GitLab