From 8225de7f09d2600104a083299b0b8c2141236075 Mon Sep 17 00:00:00 2001
From: David Klein <dklein@pik-potsdam.de>
Date: Thu, 19 Dec 2019 16:58:08 +0100
Subject: [PATCH] *refactoring* Deleted q30_pebiolc_price_base and
 vm_pebiolc_price_shifted since it was a remainder of old implementations and
 had no function anymore.

---
 core/declarations.gms                         |  1 -
 core/preloop.gms                              |  1 -
 modules/21_tax/on/equations.gms               |  2 +-
 modules/21_tax/on/postsolve.gms               |  2 +-
 modules/21_tax/on/presolve.gms                |  2 +-
 modules/30_biomass/magpie_40/declarations.gms |  1 -
 modules/30_biomass/magpie_40/equations.gms    | 48 +++++++++----------
 modules/30_biomass/magpie_40/preloop.gms      |  4 +-
 8 files changed, 27 insertions(+), 34 deletions(-)

diff --git a/core/declarations.gms b/core/declarations.gms
index ff9472f..46911c4 100644
--- a/core/declarations.gms
+++ b/core/declarations.gms
@@ -302,7 +302,6 @@ vm_prodFe(ttot,all_regi,all_enty,all_enty,all_te)    "fe production. [TWa]"
 v_costFu(ttot,all_regi)                              "fuel costs"
 vm_costFuEx(ttot,all_regi,all_enty)                  "fuel costs from exhaustible energy [tril$US]"
 vm_pebiolc_price(ttot,all_regi)                      "bioenergy price according to MAgPIE supply curves"
-vm_pebiolc_price_shifted(ttot,all_regi)              "bioenergy price according to shifted MAgPIE supply curves, required only for calculation of the bioenergy tax"
 
 v_costOM(ttot,all_regi)                              "o&m costs"
 v_costInv(ttot,all_regi)                             "investment costs"
diff --git a/core/preloop.gms b/core/preloop.gms
index 49bf48e..32b254d 100644
--- a/core/preloop.gms
+++ b/core/preloop.gms
@@ -70,7 +70,6 @@ vm_capDistr.l(t,regi,te,rlf)          = 0;
 vm_cap.l(t,regi,te,rlf)              = 0;
 vm_fuExtr.l(ttot,regi,"pebiolc","1")$(ttot.val ge 2005)  = 0;
 vm_pebiolc_price.l(ttot,regi)$(ttot.val ge 2005)         = 0;
-vm_pebiolc_price_shifted.l(ttot,regi)$(ttot.val ge 2005) = 0;
   
 *** overwrite default targets with gdx values if wanted
 Execute_Loadpoint 'input' p_emi_budget1_gdx = sm_budgetCO2eqGlob;
diff --git a/modules/21_tax/on/equations.gms b/modules/21_tax/on/equations.gms
index 5baf7ad..d56a841 100644
--- a/modules/21_tax/on/equations.gms
+++ b/modules/21_tax/on/equations.gms
@@ -163,7 +163,7 @@ v21_taxrevSO2(t,regi) =g= p21_tau_so2_tax(t,regi) * vm_emiTe(t,regi,"so2")
 *'  Documentation of overall tax approach is above at q21_taxrev.
 ***---------------------------------------------------------------------------
 q21_taxrevBio(t,regi)$(t.val ge max(2010,cm_startyear))..
-v21_taxrevBio(t,regi) =g= v21_tau_bio(t) * vm_fuExtr(t,regi,"pebiolc","1") * vm_pebiolc_price_shifted(t,regi) 
+v21_taxrevBio(t,regi) =g= v21_tau_bio(t) * vm_fuExtr(t,regi,"pebiolc","1") * vm_pebiolc_price(t,regi) 
                           - p21_taxrevBio0(t,regi);
 						  
 ***---------------------------------------------------------------------------
diff --git a/modules/21_tax/on/postsolve.gms b/modules/21_tax/on/postsolve.gms
index 6b31e9d..75f2c5f 100644
--- a/modules/21_tax/on/postsolve.gms
+++ b/modules/21_tax/on/postsolve.gms
@@ -39,7 +39,7 @@ p21_taxrevPE2SE0(ttot,regi) = SUM(pe2se(enty,enty2,te),
                                   ); 
 p21_taxrevXport0(ttot,regi) = SUM(tradePe(enty), p21_tau_XpRes_tax(ttot,regi,enty) * vm_Xport.l(ttot,regi,enty));
 p21_taxrevSO20(ttot,regi) = p21_tau_so2_tax(ttot,regi) * vm_emiTe.l(ttot,regi,"so2");
-p21_taxrevBio0(ttot,regi) = v21_tau_bio.l(ttot) * vm_fuExtr.l(ttot,regi,"pebiolc","1") * vm_pebiolc_price_shifted.l(ttot,regi);
+p21_taxrevBio0(ttot,regi) = v21_tau_bio.l(ttot) * vm_fuExtr.l(ttot,regi,"pebiolc","1") * vm_pebiolc_price.l(ttot,regi);
 p21_implicitDiscRate0(ttot,regi) = sum(ppfKap(in),  p21_implicitDiscRateMarg(ttot,regi,in)  * vm_cesIO.l(ttot,regi,in) );
 ***DK: for reporting only
 p21_tau_bioenergy_tax(t) = v21_tau_bio.l(t);
diff --git a/modules/21_tax/on/presolve.gms b/modules/21_tax/on/presolve.gms
index 40ec921..9d3df36 100644
--- a/modules/21_tax/on/presolve.gms
+++ b/modules/21_tax/on/presolve.gms
@@ -40,7 +40,7 @@ p21_taxrevPE2SE0(ttot,regi) = SUM(pe2se(enty,enty2,te),
                                   ); 
 p21_taxrevXport0(ttot,regi) = SUM(tradePe(enty), p21_tau_XpRes_tax(ttot,regi,enty) * vm_Xport.l(ttot,regi,enty));
 p21_taxrevSO20(ttot,regi) = p21_tau_so2_tax(ttot,regi) * vm_emiTe.l(ttot,regi,"so2");
-p21_taxrevBio0(ttot,regi) = v21_tau_bio.l(ttot) * vm_fuExtr.l(ttot,regi,"pebiolc","1")*vm_pebiolc_price_shifted.l(ttot,regi);
+p21_taxrevBio0(ttot,regi) = v21_tau_bio.l(ttot) * vm_fuExtr.l(ttot,regi,"pebiolc","1")*vm_pebiolc_price.l(ttot,regi);
 p21_implicitDiscRate0(ttot,regi) = sum(ppfKap(in),  p21_implicitDiscRateMarg(ttot,regi,in)  * vm_cesIO.l(ttot,regi,in) );
 
 *** EOF ./modules/21_tax/on/presolve.gms
diff --git a/modules/30_biomass/magpie_40/declarations.gms b/modules/30_biomass/magpie_40/declarations.gms
index 1784e83..ac44c9c 100644
--- a/modules/30_biomass/magpie_40/declarations.gms
+++ b/modules/30_biomass/magpie_40/declarations.gms
@@ -58,7 +58,6 @@ v30_multcost(ttot,all_regi)        "cost markup factor for deviations from deman
 equations
 q30_costFuBio(ttot,all_regi)             "total costs of bioenergy production"
 q30_pebiolc_price(ttot,all_regi)         "MAgPIE emulator: calculates the price of pebiolc according to MAgPIE supply curves"
-q30_pebiolc_price_base(ttot,all_regi)    "MAgPIE emulator: calculates the price of pebiolc according to MAgPIE supply curves"
 q30_pebiolc_costs(ttot,all_regi)         "MAgPIE emulator: calculates the costs of pebiolc according to MAgPIE supply curves"
 q30_priceshift                           "calculates shift factor by minimizing least squares of price differences between MAgPIE output and MAgPIE emulator"
 q30_limitXpBio(ttot,all_regi)            "only purpose grown bioenergy may be exported, no residues"
diff --git a/modules/30_biomass/magpie_40/equations.gms b/modules/30_biomass/magpie_40/equations.gms
index e0463af..a3a96f8 100644
--- a/modules/30_biomass/magpie_40/equations.gms
+++ b/modules/30_biomass/magpie_40/equations.gms
@@ -13,10 +13,11 @@
 *' 
 *' **Total fuel costs for biomass**  
 *' The first part, summing over *peren2rlf30*, represents costs for biomass with fixed prices.
-*' The second part that includes *v30_pebiolc_costs* represents costs for biomass with continous supply curves from MAgPIE.
-*' In coupled runs *v30_multcost* is a cost markup factor improving the optimization performance by penalizing
-*' (too) large jumps in the demand in between two coupling iterations. It converges to 1 and therefore does not affect the outcome.
-*' The last part, containing *pm_costsTradePeFinancial*, represents additional tradecosts (only for purpose grown lignocellulosic biomass).
+*' The second part that includes *v30_pebiolc_costs* represents costs for biomass with continous 
+*' supply curves from MAgPIE. In coupled runs *v30_multcost* is a cost markup factor improving 
+*' the optimization performance by penalizing (too) large jumps in the demand between two coupling 
+*' iterations. It converges to 1 and therefore does not affect the outcome. The last part, containing 
+*' *pm_costsTradePeFinancial*, represents additional tradecosts (only for purpose grown lignocellulosic biomass).
 
 q30_costFuBio(ttot,regi)$(ttot.val ge cm_startyear).. 
          vm_costFuBio(ttot,regi)
@@ -28,21 +29,13 @@ $if %cm_MAgPIE_coupling% == "off" (v30_pebiolc_costs(ttot,regi))
          + 
          sum(peren2cont30(enty,rlf), vm_fuExtr(ttot,regi,enty,rlf) * pm_costsTradePeFinancial(regi,"use",enty));
 
-*' **Calculate cost markup factor for coupled runs**  
-*' It penalizes large jumps from the previous coupling iteration and converges to 1, as the difference between *vm_fuExtr* and 
-*' *p30_pebiolc_demandmag* vanish when the coupling converges over iterations.
-q30_costAdj(ttot,regi)$(ttot.val ge cm_startyear)..
-         v30_multcost(ttot,regi)
-         =e=
-         power((vm_fuExtr(ttot,regi,"pebiolc","1")-p30_pebiolc_demandmag(ttot,regi))/ (p30_pebiolc_demandmag(ttot,regi) + 0.15),2) * 0.4 + 1
-;
-
 ***---------------------------------------------------------------------------
 ***                      MAgPIE EMULATOR
 ***---------------------------------------------------------------------------
 
-*' **Caclulate bioenergy price according to MAgPIE supply curves**  
-*' The equation is mainly used by shift factor calculation in the preloop. In main solve it is only required for bioenergy tax.
+*' **Caclulate bioenergy prices according to MAgPIE supply curves**  
+*' The equation is used by shift factor calculation in the preloop stage. In the main solve stage the price is only used to apply
+*' the bioenergy tax.
 
 q30_pebiolc_price(ttot,regi)$(ttot.val ge cm_startyear)..
          vm_pebiolc_price(ttot,regi)
@@ -52,16 +45,6 @@ q30_pebiolc_price(ttot,regi)$(ttot.val ge cm_startyear)..
        + i30_bioen_price_b(ttot,regi) * (vm_fuExtr(ttot,regi,"pebiolc","1") + sm_eps) )
        * v30_pricemult(ttot,regi);
 
-*' **Calculate bioenergy price according to shifted MAgPIE supply curves**  
-*' Required only to calculate the bioenergy tax. For historic reasons there exist both *vm_pebiolc_price_shifted* and 
-*' *vm_pebiolc_price*. Could be refactored some time.
-
-q30_pebiolc_price_base(ttot,regi)$(ttot.val ge cm_startyear)..
-         vm_pebiolc_price_shifted(ttot,regi)
-         =e=
-         vm_pebiolc_price(ttot,regi)
-;
-
 *' **MAgPIE EMULATOR**  
 *' Calculates bioenergy costs of purpose grown lignocellulosic biomass by integrating the linear price supply curve.
 *' It contains optional shift and scaling of supply curves in coupled runs. 
@@ -96,6 +79,21 @@ q30_priceshift$(s30_switch_shiftcalc eq 1)..
          )
 ;
 
+***---------------------------------------------------------------------------
+***                      COUPLING CONVERGENCE
+***---------------------------------------------------------------------------
+
+*' **Calculate cost markup factor for coupled runs**  
+*' It penalizes deviations in the demand for purpose grown bioenergy from the previous coupling iteration 
+*' by increasing the costs proportional to the deviation. The scaling factor converges to 1, as the 
+*' difference between *vm_fuExtr* and *p30_pebiolc_demandmag* vanishes when the coupling converges over 
+*' iterations.
+q30_costAdj(ttot,regi)$(ttot.val ge cm_startyear)..
+         v30_multcost(ttot,regi)
+         =e=
+         power((vm_fuExtr(ttot,regi,"pebiolc","1")-p30_pebiolc_demandmag(ttot,regi))/ (p30_pebiolc_demandmag(ttot,regi) + 0.15),2) * 0.4 + 1
+;
+
 ***---------------------------------------------------------------------------
 ***          Definition of resource constraints for biomass
 ***---------------------------------------------------------------------------
diff --git a/modules/30_biomass/magpie_40/preloop.gms b/modules/30_biomass/magpie_40/preloop.gms
index ed365c6..1e77ded 100644
--- a/modules/30_biomass/magpie_40/preloop.gms
+++ b/modules/30_biomass/magpie_40/preloop.gms
@@ -77,9 +77,7 @@ $endif
 ***------------ Step 3: calculate bioenergy costs -------------
 *** The costs are calculated applying the regular cost equation. 
 *** This equation integrates the shifted (!) price supply curve over the demand.
-*** Since the price shift factor is required for this it has been calcualted before (see above).
-*** There is no cost shift factor (anymore) since there is no cost emulator (anymore), 
-*** because the costs are calculated by integrating the shifted price supply curve.
+*** It requires the price shift factor to be calcualted before (see above).
 
 solve model_biopresolve_c using cns; !!! nothing has to be optimized here, just pure calculation
 
-- 
GitLab