diff --git a/CHANGELOG.md b/CHANGELOG.md index 4240797c8b..0dfdf833a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,17 +7,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### changed +- **21_trade** changed export share calculation to be done at region level in the model - **default.cfg** input data upgraded from rev4.117 to rev4.118, default for bioenergy demand and GHG prices changed from R32M46 to R34M410, `rcp4p5` used for SSP2-NPi2025 in line with MAGICC climate outcome and REMIND assumptions. +- **default.cfg** changed running magpie by default with optfile for specified solver settings (Tol_Optimality) - **script/start/test_runs.R** Test runs adjusted based on availability from coupled runs for R34M410. ### added -- +- **default.cfg** added option to set Tol_Optimality (GAMS solver setting) to a certain value (GAMS-default 1e-7, new MAgPIE-default 1e-8) +- **80_optimization** added writing of conopt opt files with using scalars from input ### removed -- +- **80_optimization** removed older optfile, that should be tried if no optimal solution can be found ### fixed -- +- **18_residues** fixed equation for cluster level production of crop residues in flexreg_apr16 realization ## [4.10.0] - 2025-04-03 diff --git a/config/default.cfg b/config/default.cfg index f2be8a9e02..7776f0afb7 100644 --- a/config/default.cfg +++ b/config/default.cfg @@ -597,8 +597,6 @@ cfg$gms$processing <- "substitution_may21" # def = substitution_may21 cfg$gms$c20_scp_type <- "sugar" # def = sugar # ***--------------------- 21_trade -------------------------------------- -# * (free_apr16): free trade without restrictions -# * (off): no trade at all # * (exo): exogenously prescribed trade # * (selfsuff_reduced): self-sufficiency based trade with trade costs related to exports # * (selfsuff_reduced_bilateral22): same as `selfsuff_reduced` but with bilateral trade flows @@ -2177,7 +2175,12 @@ cfg$gms$c80_nlp_solver <- "conopt4" # def = conopt4 # * 1: using optfile for specified solver settings # * 0: default settings (optfile will be ignored) -cfg$gms$s80_optfile <- 0 # def = 0 +cfg$gms$s80_optfile <- 1 # def = 1 + +# Solver setting Tol_Optimality (real): +# Optimality tolerance for reduced gradient when feasible. +# Range: [3.e-13, 1], Solver default: 1.e-7 +cfg$gms$s80_toloptimal <- 1.0e-8 # def = 1.0e-8 # * Optional second solve statement (0=off, 1=on) cfg$gms$s80_secondsolve <- 0 # def = 0 diff --git a/core/calculations.gms b/core/calculations.gms index 9063d06f87..e8c37db7e2 100644 --- a/core/calculations.gms +++ b/core/calculations.gms @@ -21,7 +21,6 @@ $batinclude "./modules/include.gms" preloop * to be done here because a file declaration cannot be inside a loop file dummy; dummy.pw=2000; put dummy; - ************************OPTIMIZATION PROCESS START****************************** * This section contains only sourcecode that is directly connected to the * optimization process. That means that everything on the following lines diff --git a/modules/18_residues/flexreg_apr16/declarations.gms b/modules/18_residues/flexreg_apr16/declarations.gms index e000474151..b4ce1a141c 100644 --- a/modules/18_residues/flexreg_apr16/declarations.gms +++ b/modules/18_residues/flexreg_apr16/declarations.gms @@ -18,19 +18,15 @@ positive variables ; equations - q18_prod_res_ag_reg(i,kcr,attributes) Production constraint of aboveground residues (mio. tDM) q18_prod_res_bg_reg(i,kcr,dm_nr) Production constraint of belowground residues (mio. tDM) - q18_res_field_balance(i,kcr,attributes) Calculation of the residues amount recycled to soils (mio. tDM) q18_res_field_burn(i,kcr,attributes) Fixing of the residues amount burned in a region in respective attribute units DM GJ Nr P K WM C (mio. tX) q18_translate(i,kres,attributes) Transformation of the multiple crop residues into supply balance crop redisues in respective attribute units DM GJ Nr P K WM C (mio. tX) - q18_prod_res_cell(j,kres) Allows for distribution of residues to cellular level (mio. tDM) - + q18_prod_res_reg(i,kres) Allows for distribution of residues to cellular level (mio. tDM) q18_res_recycling_nr(i) Nutrient recycling of reaactive nitrogen (mio. tNr) q18_res_recycling_pk(i,pk18) Nutrient recycling of phosphorus and potash (mio. tX) q18_cost_prod_res(i,kres) Production costs of harvesting crop residues (mio. USD17MER) - ; parameters @@ -52,7 +48,7 @@ parameters oq18_res_field_balance(t,i,kcr,attributes,type) Calculation of the residues amount recycled to soils (mio. tDM) oq18_res_field_burn(t,i,kcr,attributes,type) Fixing of the residues amount burned in a region in respective attribute units DM GJ Nr P K WM C (mio. tX) oq18_translate(t,i,kres,attributes,type) Transformation of the multiple crop residues into supply balance crop redisues in respective attribute units DM GJ Nr P K WM C (mio. tX) - oq18_prod_res_cell(t,j,kres,type) Allows for distribution of residues to cellular level (mio. tDM) + oq18_prod_res_reg(t,i,kres,type) Allows for distribution of residues to cellular level (mio. tDM) oq18_res_recycling_nr(t,i,type) Nutrient recycling of reaactive nitrogen (mio. tNr) oq18_res_recycling_pk(t,i,pk18,type) Nutrient recycling of phosphorus and potash (mio. tX) oq18_cost_prod_res(t,i,kres,type) Production costs of harvesting crop residues (mio. USD17MER) diff --git a/modules/18_residues/flexreg_apr16/equations.gms b/modules/18_residues/flexreg_apr16/equations.gms index e01b0d2072..7bf6de8aad 100644 --- a/modules/18_residues/flexreg_apr16/equations.gms +++ b/modules/18_residues/flexreg_apr16/equations.gms @@ -73,10 +73,12 @@ vm_prod_reg(i2,kres) * fm_attributes(attributes,kres); *' Amount produced at cellular level is flexible, can be distributed as it wants - q18_prod_res_cell(j2,kres).. - sum(cell(i2,j2), vm_prod_reg(i2,kres)) +*' and is just bound by the regional sum via + + q18_prod_res_reg(i2,kres).. + sum(cell(i2,j2), v18_prod_res(j2,kres)) =e= - v18_prod_res(j2,kres) ; + vm_prod_reg(i2,kres); *' Residues recycled to croplands in nutrients `vm_res_recycling(i2,"nr")` are diff --git a/modules/18_residues/flexreg_apr16/postsolve.gms b/modules/18_residues/flexreg_apr16/postsolve.gms index 0b0007332b..4633ea69e2 100644 --- a/modules/18_residues/flexreg_apr16/postsolve.gms +++ b/modules/18_residues/flexreg_apr16/postsolve.gms @@ -23,7 +23,7 @@ oq18_res_field_balance(t,i,kcr,attributes,"marginal") = q18_res_field_balance.m(i,kcr,attributes); oq18_res_field_burn(t,i,kcr,attributes,"marginal") = q18_res_field_burn.m(i,kcr,attributes); oq18_translate(t,i,kres,attributes,"marginal") = q18_translate.m(i,kres,attributes); - oq18_prod_res_cell(t,j,kres,"marginal") = q18_prod_res_cell.m(j,kres); + oq18_prod_res_reg(t,i,kres,"marginal") = q18_prod_res_reg.m(i,kres); oq18_res_recycling_nr(t,i,"marginal") = q18_res_recycling_nr.m(i); oq18_res_recycling_pk(t,i,pk18,"marginal") = q18_res_recycling_pk.m(i,pk18); oq18_cost_prod_res(t,i,kres,"marginal") = q18_cost_prod_res.m(i,kres); @@ -40,7 +40,7 @@ oq18_res_field_balance(t,i,kcr,attributes,"level") = q18_res_field_balance.l(i,kcr,attributes); oq18_res_field_burn(t,i,kcr,attributes,"level") = q18_res_field_burn.l(i,kcr,attributes); oq18_translate(t,i,kres,attributes,"level") = q18_translate.l(i,kres,attributes); - oq18_prod_res_cell(t,j,kres,"level") = q18_prod_res_cell.l(j,kres); + oq18_prod_res_reg(t,i,kres,"level") = q18_prod_res_reg.l(i,kres); oq18_res_recycling_nr(t,i,"level") = q18_res_recycling_nr.l(i); oq18_res_recycling_pk(t,i,pk18,"level") = q18_res_recycling_pk.l(i,pk18); oq18_cost_prod_res(t,i,kres,"level") = q18_cost_prod_res.l(i,kres); @@ -57,7 +57,7 @@ oq18_res_field_balance(t,i,kcr,attributes,"upper") = q18_res_field_balance.up(i,kcr,attributes); oq18_res_field_burn(t,i,kcr,attributes,"upper") = q18_res_field_burn.up(i,kcr,attributes); oq18_translate(t,i,kres,attributes,"upper") = q18_translate.up(i,kres,attributes); - oq18_prod_res_cell(t,j,kres,"upper") = q18_prod_res_cell.up(j,kres); + oq18_prod_res_reg(t,i,kres,"upper") = q18_prod_res_reg.up(i,kres); oq18_res_recycling_nr(t,i,"upper") = q18_res_recycling_nr.up(i); oq18_res_recycling_pk(t,i,pk18,"upper") = q18_res_recycling_pk.up(i,pk18); oq18_cost_prod_res(t,i,kres,"upper") = q18_cost_prod_res.up(i,kres); @@ -74,7 +74,7 @@ oq18_res_field_balance(t,i,kcr,attributes,"lower") = q18_res_field_balance.lo(i,kcr,attributes); oq18_res_field_burn(t,i,kcr,attributes,"lower") = q18_res_field_burn.lo(i,kcr,attributes); oq18_translate(t,i,kres,attributes,"lower") = q18_translate.lo(i,kres,attributes); - oq18_prod_res_cell(t,j,kres,"lower") = q18_prod_res_cell.lo(j,kres); + oq18_prod_res_reg(t,i,kres,"lower") = q18_prod_res_reg.lo(i,kres); oq18_res_recycling_nr(t,i,"lower") = q18_res_recycling_nr.lo(i); oq18_res_recycling_pk(t,i,pk18,"lower") = q18_res_recycling_pk.lo(i,pk18); oq18_cost_prod_res(t,i,kres,"lower") = q18_cost_prod_res.lo(i,kres); diff --git a/modules/21_trade/exo/not_used.txt b/modules/21_trade/exo/not_used.txt new file mode 100644 index 0000000000..4dd79412da --- /dev/null +++ b/modules/21_trade/exo/not_used.txt @@ -0,0 +1,2 @@ +name,type,reason +sm_fix_SSP2,input,not needed diff --git a/modules/21_trade/free_apr16/declarations.gms b/modules/21_trade/free_apr16/declarations.gms deleted file mode 100644 index 6654381530..0000000000 --- a/modules/21_trade/free_apr16/declarations.gms +++ /dev/null @@ -1,29 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -parameters - i21_trade_bal_reduction(t_all,k_trade) Trade balance reduction (1) - i21_trade_margin(h,k_trade) Trade margins (USD17MER per tDM) - i21_trade_tariff(h,k_trade) Trade tariffs (USD17MER per tDM) -; - -positive variables - vm_cost_trade(i) Regional trade costs (mio. USD17MER per yr) -; - -equations - q21_trade_glo(k_trade) Global production constraint (mio. tDM per yr) - q21_notrade(h,k_notrade) Superregional production constraint of non-tradable commodities (mio. tDM per yr) -; - -*#################### R SECTION START (OUTPUT DECLARATIONS) #################### -parameters - ov_cost_trade(t,i,type) Regional trade costs (mio. USD17MER per yr) - oq21_trade_glo(t,k_trade,type) Global production constraint (mio. tDM per yr) - oq21_notrade(t,h,k_notrade,type) Superregional production constraint of non-tradable commodities (mio. tDM per yr) -; -*##################### R SECTION END (OUTPUT DECLARATIONS) ##################### diff --git a/modules/21_trade/free_apr16/equations.gms b/modules/21_trade/free_apr16/equations.gms deleted file mode 100644 index 3926ac0232..0000000000 --- a/modules/21_trade/free_apr16/equations.gms +++ /dev/null @@ -1,18 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -*' @equations -*' For traded goods the only active constraint is that the global supply is larger or equal to demand. -*' This means that production can be freely allocated globally based on comparative advantages. - -q21_trade_glo(k_trade).. sum(i2 ,vm_prod_reg(i2,k_trade)) =g= sum(i2, vm_supply(i2,k_trade)); - -*' -*' For non-tradable commodites, the regional supply should be larger or equal to the regional demand. - - q21_notrade(h2,k_notrade).. - sum(supreg(h2,i2),vm_prod_reg(i2,k_notrade)) =g= sum(supreg(h2,i2), vm_supply(i2,k_notrade)); diff --git a/modules/21_trade/free_apr16/input.gms b/modules/21_trade/free_apr16/input.gms deleted file mode 100644 index 24f41963ec..0000000000 --- a/modules/21_trade/free_apr16/input.gms +++ /dev/null @@ -1,11 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -table f21_self_suff(t_all,h,kall) Superregional self-sufficiency rates (1) -$ondelim -$include "./modules/21_trade/input/f21_trade_self_suff.cs3" -$offdelim; diff --git a/modules/21_trade/free_apr16/postsolve.gms b/modules/21_trade/free_apr16/postsolve.gms deleted file mode 100644 index b405f11f5b..0000000000 --- a/modules/21_trade/free_apr16/postsolve.gms +++ /dev/null @@ -1,22 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - - -*#################### R SECTION START (OUTPUT DEFINITIONS) ##################### - ov_cost_trade(t,i,"marginal") = vm_cost_trade.m(i); - oq21_trade_glo(t,k_trade,"marginal") = q21_trade_glo.m(k_trade); - oq21_notrade(t,h,k_notrade,"marginal") = q21_notrade.m(h,k_notrade); - ov_cost_trade(t,i,"level") = vm_cost_trade.l(i); - oq21_trade_glo(t,k_trade,"level") = q21_trade_glo.l(k_trade); - oq21_notrade(t,h,k_notrade,"level") = q21_notrade.l(h,k_notrade); - ov_cost_trade(t,i,"upper") = vm_cost_trade.up(i); - oq21_trade_glo(t,k_trade,"upper") = q21_trade_glo.up(k_trade); - oq21_notrade(t,h,k_notrade,"upper") = q21_notrade.up(h,k_notrade); - ov_cost_trade(t,i,"lower") = vm_cost_trade.lo(i); - oq21_trade_glo(t,k_trade,"lower") = q21_trade_glo.lo(k_trade); - oq21_notrade(t,h,k_notrade,"lower") = q21_notrade.lo(h,k_notrade); -*##################### R SECTION END (OUTPUT DEFINITIONS) ###################### diff --git a/modules/21_trade/free_apr16/realization.gms b/modules/21_trade/free_apr16/realization.gms deleted file mode 100644 index 5d69350249..0000000000 --- a/modules/21_trade/free_apr16/realization.gms +++ /dev/null @@ -1,19 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -*' @description In this realization, agricultural trade is fully liberalized in all timesteps. - -*' @limitations This realization does not account for current trends in agricultural trade. - -*####################### R SECTION START (PHASES) ############################## -$Ifi "%phase%" == "sets" $include "./modules/21_trade/free_apr16/sets.gms" -$Ifi "%phase%" == "declarations" $include "./modules/21_trade/free_apr16/declarations.gms" -$Ifi "%phase%" == "input" $include "./modules/21_trade/free_apr16/input.gms" -$Ifi "%phase%" == "equations" $include "./modules/21_trade/free_apr16/equations.gms" -$Ifi "%phase%" == "preloop" $include "./modules/21_trade/free_apr16/preloop.gms" -$Ifi "%phase%" == "postsolve" $include "./modules/21_trade/free_apr16/postsolve.gms" -*######################## R SECTION END (PHASES) ############################### diff --git a/modules/21_trade/free_apr16/sets.gms b/modules/21_trade/free_apr16/sets.gms deleted file mode 100644 index 0a23e00b10..0000000000 --- a/modules/21_trade/free_apr16/sets.gms +++ /dev/null @@ -1,22 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -sets -*sets should be in sync with default trade realisation; currently selfsuff_reduced - k_notrade(kall) Production activities of non-tradable commodites - / oilpalm, foddr, pasture, res_cereals, res_fibrous, res_nonfibrous, begr,betr / -* oilpalm not traded, only its oil and oilcake due to FAOSTAT complications, and as trade is little -* foddr is not traded as too bulky -* pasture it not traded as too bulky -* begr and betr are not traded because biomass is traded in REMIND - k_trade(kall) Production activities of tradable commodities - / tece,maiz,trce,rice_pro,soybean,rapeseed,groundnut,sunflower,puls_pro, - potato,cassav_sp,sugr_cane,sugr_beet,others,cottn_pro, - oils,oilcakes,sugar,molasses,alcohol,ethanol,distillers_grain,brans,scp,fibres, - livst_rum, livst_pig,livst_chick, livst_egg, livst_milk, fish, wood, woodfuel / - -; diff --git a/modules/21_trade/input/files b/modules/21_trade/input/files index dbc4131c7f..5b70512a5d 100644 --- a/modules/21_trade/input/files +++ b/modules/21_trade/input/files @@ -1,6 +1,6 @@ * list of files that are required here f21_trade_self_suff.cs3 -f21_trade_export_share.cs3 +f21_trade_domestic_supply.cs3 f21_trade_balanceflow.cs3 f21_trade_margin.cs3 f21_trade_tariff.cs3 diff --git a/modules/21_trade/module.gms b/modules/21_trade/module.gms index ea081a3124..0e62aed9df 100644 --- a/modules/21_trade/module.gms +++ b/modules/21_trade/module.gms @@ -16,8 +16,6 @@ *' @authors Xiaoxi Wang, Anne Biewald, Christoph Schmitz, Markus Bonsch *###################### R SECTION START (MODULETYPES) ########################## $Ifi "%trade%" == "exo" $include "./modules/21_trade/exo/realization.gms" -$Ifi "%trade%" == "free_apr16" $include "./modules/21_trade/free_apr16/realization.gms" -$Ifi "%trade%" == "off" $include "./modules/21_trade/off/realization.gms" $Ifi "%trade%" == "selfsuff_reduced" $include "./modules/21_trade/selfsuff_reduced/realization.gms" $Ifi "%trade%" == "selfsuff_reduced_bilateral22" $include "./modules/21_trade/selfsuff_reduced_bilateral22/realization.gms" *###################### R SECTION END (MODULETYPES) ############################ diff --git a/modules/21_trade/off/declarations.gms b/modules/21_trade/off/declarations.gms deleted file mode 100644 index 834bc74db3..0000000000 --- a/modules/21_trade/off/declarations.gms +++ /dev/null @@ -1,21 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -positive variables - vm_cost_trade(i) Regional trade costs (mio. USD17MER per yr) -; - -equations - q21_notrade(h,kall) Superregional production constraint of non-tradable commodities (mio. tDM per yr) -; - -*#################### R SECTION START (OUTPUT DECLARATIONS) #################### -parameters - ov_cost_trade(t,i,type) Regional trade costs (mio. USD17MER per yr) - oq21_notrade(t,h,kall,type) Superregional production constraint of non-tradable commodities (mio. tDM per yr) -; -*##################### R SECTION END (OUTPUT DECLARATIONS) ##################### diff --git a/modules/21_trade/off/equations.gms b/modules/21_trade/off/equations.gms deleted file mode 100644 index a7f78a3132..0000000000 --- a/modules/21_trade/off/equations.gms +++ /dev/null @@ -1,13 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -*' @equations -*' For all commodites, the regional supply should be larger or equal to the -*' regional demand. - -q21_notrade(h2,kall).. - sum(supreg(h2,i2),vm_prod_reg(i2,kall)) =g= sum(supreg(h2,i2), vm_supply(i2,kall)); diff --git a/modules/21_trade/off/input.gms b/modules/21_trade/off/input.gms deleted file mode 100644 index e13b626af9..0000000000 --- a/modules/21_trade/off/input.gms +++ /dev/null @@ -1,16 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -table f21_trade_balance(t_all,h,kall) trade balance of positive exports and negative imports (mio. tDM per yr) -$ondelim -$include "./modules/21_trade/input/f21_trade_balance.cs3" -$offdelim; - -table f21_self_suff(t_all,h,kall) Superregional self-sufficiency rates (1) -$ondelim -$include "./modules/21_trade/input/f21_trade_self_suff.cs3" -$offdelim; diff --git a/modules/21_trade/off/postsolve.gms b/modules/21_trade/off/postsolve.gms deleted file mode 100644 index 3dfc56b519..0000000000 --- a/modules/21_trade/off/postsolve.gms +++ /dev/null @@ -1,18 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - - -*#################### R SECTION START (OUTPUT DEFINITIONS) ##################### - ov_cost_trade(t,i,"marginal") = vm_cost_trade.m(i); - oq21_notrade(t,h,kall,"marginal") = q21_notrade.m(h,kall); - ov_cost_trade(t,i,"level") = vm_cost_trade.l(i); - oq21_notrade(t,h,kall,"level") = q21_notrade.l(h,kall); - ov_cost_trade(t,i,"upper") = vm_cost_trade.up(i); - oq21_notrade(t,h,kall,"upper") = q21_notrade.up(h,kall); - ov_cost_trade(t,i,"lower") = vm_cost_trade.lo(i); - oq21_notrade(t,h,kall,"lower") = q21_notrade.lo(h,kall); -*##################### R SECTION END (OUTPUT DEFINITIONS) ###################### diff --git a/modules/21_trade/off/preloop.gms b/modules/21_trade/off/preloop.gms deleted file mode 100644 index e5db56cc6e..0000000000 --- a/modules/21_trade/off/preloop.gms +++ /dev/null @@ -1,9 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -*set vm_cost_trade zero in order to avoid a free variable -vm_cost_trade.fx(i) = 0; diff --git a/modules/21_trade/off/realization.gms b/modules/21_trade/off/realization.gms deleted file mode 100644 index 4a5f9f3fa0..0000000000 --- a/modules/21_trade/off/realization.gms +++ /dev/null @@ -1,19 +0,0 @@ -*** | (C) 2008-2025 Potsdam Institute for Climate Impact Research (PIK) -*** | authors, and contributors see CITATION.cff file. This file is part -*** | of MAgPIE and licensed under AGPL-3.0-or-later. Under Section 7 of -*** | AGPL-3.0, you are granted additional permissions described in the -*** | MAgPIE License Exception, version 1.0 (see LICENSE file). -*** | Contact: magpie@pik-potsdam.de - -*' @description In this realization, there is no agricultural trade, i.e. regions -*' are fully self-sufficient and dependent on domestic production. - -*' @limitations This realization does not account for current trends in agricultural trade. - -*####################### R SECTION START (PHASES) ############################## -$Ifi "%phase%" == "declarations" $include "./modules/21_trade/off/declarations.gms" -$Ifi "%phase%" == "input" $include "./modules/21_trade/off/input.gms" -$Ifi "%phase%" == "equations" $include "./modules/21_trade/off/equations.gms" -$Ifi "%phase%" == "preloop" $include "./modules/21_trade/off/preloop.gms" -$Ifi "%phase%" == "postsolve" $include "./modules/21_trade/off/postsolve.gms" -*######################## R SECTION END (PHASES) ############################### diff --git a/modules/21_trade/selfsuff_reduced/declarations.gms b/modules/21_trade/selfsuff_reduced/declarations.gms index 74732e2631..ccf11f6a03 100644 --- a/modules/21_trade/selfsuff_reduced/declarations.gms +++ b/modules/21_trade/selfsuff_reduced/declarations.gms @@ -7,8 +7,11 @@ parameters i21_trade_bal_reduction(t_all,k_trade) Trade balance reduction (1) + i21_exp_shr(t_all,h,k_trade) Trade export shr (1) i21_trade_margin(h,k_trade) Trade margins (USD17MER per tDM) i21_trade_tariff(h,k_trade) Trade tariffs (USD17MER per tDM) + i21_exports(t_all,h,k_trade) Total exports (tDM) + i21_exp_glo(t_all,k_trade) Total global exports (tDM) ; positive variables diff --git a/modules/21_trade/selfsuff_reduced/equations.gms b/modules/21_trade/selfsuff_reduced/equations.gms index a2a624e2a3..0c387ac850 100644 --- a/modules/21_trade/selfsuff_reduced/equations.gms +++ b/modules/21_trade/selfsuff_reduced/equations.gms @@ -55,7 +55,7 @@ q21_excess_supply(h2,k_trade).. v21_excess_prod(h2,k_trade) =e= - v21_excess_dem(k_trade)*sum(ct,f21_exp_shr(ct,h2,k_trade)); + v21_excess_dem(k_trade)*sum(ct,i21_exp_shr(ct,h2,k_trade)); * Trade costs are associated with exporting superregions. They are dependent on net exports, trade margin, and tariffs. diff --git a/modules/21_trade/selfsuff_reduced/input.gms b/modules/21_trade/selfsuff_reduced/input.gms index 7c7ef24511..6cfe28dffd 100644 --- a/modules/21_trade/selfsuff_reduced/input.gms +++ b/modules/21_trade/selfsuff_reduced/input.gms @@ -29,9 +29,9 @@ $ondelim $include "./modules/21_trade/input/f21_trade_self_suff.cs3" $offdelim; -table f21_exp_shr(t_all,h,kall) Superregional and crop-specific export share (1) +table f21_dom_supply(t_all,h,kall) Superregional domestic supply (mio. tDM per yr) $ondelim -$include "./modules/21_trade/input/f21_trade_export_share.cs3" +$include "./modules/21_trade/input/f21_trade_domestic_supply.cs3" $offdelim; table f21_trade_balanceflow(t_all,kall) Domestic balance flows (mio. tDM per yr) diff --git a/modules/21_trade/selfsuff_reduced/preloop.gms b/modules/21_trade/selfsuff_reduced/preloop.gms index a35770df1c..8a1bfb2f5c 100644 --- a/modules/21_trade/selfsuff_reduced/preloop.gms +++ b/modules/21_trade/selfsuff_reduced/preloop.gms @@ -5,8 +5,22 @@ *** | MAgPIE License Exception, version 1.0 (see LICENSE file). *** | Contact: magpie@pik-potsdam.de -i21_trade_bal_reduction(t_all,k_trade)=f21_trade_bal_reduction(t_all,"easytrade","%c21_trade_liberalization%"); + +*' Trade liberalization i.e. shift from self-sufficiency fixed pool to free pool begins +*' with sm_fix_SSP2 to keep values matching historical data until then. +loop(t_all, + if(m_year(t_all) <= sm_fix_SSP2, + i21_trade_bal_reduction(t_all,k_trade)=f21_trade_bal_reduction(t_all,"easytrade","l909090r808080"); + i21_trade_bal_reduction(t_all,k_hardtrade21)=f21_trade_bal_reduction(t_all,"hardtrade","l909090r808080"); + else + i21_trade_bal_reduction(t_all,k_trade)=f21_trade_bal_reduction(t_all,"easytrade","%c21_trade_liberalization%"); i21_trade_bal_reduction(t_all,k_hardtrade21)=f21_trade_bal_reduction(t_all,"hardtrade","%c21_trade_liberalization%"); + ); +); + +i21_exports(t_all,h,k_trade) = ((f21_self_suff(t_all,h,k_trade) * f21_dom_supply(t_all,h,k_trade)) - f21_dom_supply(t_all,h,k_trade))$(f21_self_suff(t_all,h,k_trade) > 1); +i21_exp_glo(t_all,k_trade) = sum(h, i21_exports(t_all,h,k_trade)); +i21_exp_shr(t_all,h,k_trade) = i21_exports(t_all,h,k_trade) / (i21_exp_glo(t_all,k_trade) + 0.001$(i21_exp_glo(t_all,k_trade) = 0)); i21_trade_margin(h,k_trade) = f21_trade_margin(h,k_trade); diff --git a/modules/21_trade/selfsuff_reduced/realization.gms b/modules/21_trade/selfsuff_reduced/realization.gms index 809c0ffba7..d506a989c4 100644 --- a/modules/21_trade/selfsuff_reduced/realization.gms +++ b/modules/21_trade/selfsuff_reduced/realization.gms @@ -9,7 +9,8 @@ *' together with regional demands, establish a baseline value for the production of traded products in the superregions. *' Production is then allowed to fluctuate freely within a band around this baseline value, *' only being enforced to maintain the condition of global production exceeding global demand. -*' The width of the production band is determined by the `i21_trade_bal_reduction` (ptb) factor. +*' The width of the production band is determined by the `i21_trade_bal_reduction` (ptb) factor, which differentiates +*' itself by SSP after the year prescribed by sm_fix_SSP2. *' *' Effectively, this factor splits the global demand into two pools: The `ptb` share of demand goes *' into a pool for which the origin of products is fixed by the self-sufficiency ratios and export shares. diff --git a/modules/21_trade/selfsuff_reduced_bilateral22/not_used.txt b/modules/21_trade/selfsuff_reduced_bilateral22/not_used.txt new file mode 100644 index 0000000000..4dd79412da --- /dev/null +++ b/modules/21_trade/selfsuff_reduced_bilateral22/not_used.txt @@ -0,0 +1,2 @@ +name,type,reason +sm_fix_SSP2,input,not needed diff --git a/modules/80_optimization/lp_nlp_apr17/input.gms b/modules/80_optimization/lp_nlp_apr17/input.gms index 3945d0c594..1486c3a2a0 100644 --- a/modules/80_optimization/lp_nlp_apr17/input.gms +++ b/modules/80_optimization/lp_nlp_apr17/input.gms @@ -6,16 +6,8 @@ *** | Contact: magpie@pik-potsdam.de scalars - s80_maxiter maximal solve iterations if modelstat is > 2 (1) / 30 / - s80_optfile switch to use specfied solver settings (1) / 0 / - s80_add_cplex add cplex optimization after conopt4 (1) / 0 / - s80_add_conopt3 add conopt3 optimization after conopt4 (1) / 0 / - s80_secondsolve second solve statement (binary) / 0 / + s80_maxiter maximal solve iterations if modelstat is > 2 (1) / 30 / + s80_optfile switch to use specfied solver settings (1) / 1 / + s80_secondsolve second solve statement (binary) / 0 / + s80_toloptimal value for CONOPT4 Tol_Optimality / 1e-08 / ; - - -$setglobal c80_nlp_solver conopt4 -* options: (conopt3): conopt3 -* (conopt4): conopt4 -* (conopt4+cplex): conopt4 followed by cplex with landdiff optimization -* (conopt4+conopt3): conopt4 followed by conopt3 diff --git a/modules/80_optimization/lp_nlp_apr17/solve.gms b/modules/80_optimization/lp_nlp_apr17/solve.gms index d9306a5dbd..a8a3db3dca 100644 --- a/modules/80_optimization/lp_nlp_apr17/solve.gms +++ b/modules/80_optimization/lp_nlp_apr17/solve.gms @@ -34,12 +34,12 @@ $elseif "%c80_nlp_solver%" == "conopt4+conopt3" s80_add_conopt3 = 1; $endif -$onecho > conopt4.opt -Lim_Variable = 1.e25 -$offecho +put optfile; +put 'Tol_Optimality = ', s80_toloptimal:12:11 /; +putclose optfile; $onecho > conopt4.op2 -Flg_Prep = FALSE +Lim_Variable = 1.e25 $offecho repeat( @@ -143,7 +143,7 @@ $batinclude "./modules/include.gms" nl_relax * if solve stopped with an error, try it again with CONOPT4 and OPTFILE if((magpie.modelstat = 13), - display "WARNING: Modelstat 13 | retry without Conopt4 pre-processing"; + display "WARNING: Modelstat 13 | Retry solve with CONOPT4 increasing largest allowable value"; option nlp = conopt4; magpie.optfile = 2 solve magpie USING nlp MINIMIZING vm_cost_glo; diff --git a/modules/80_optimization/nlp_apr17/input.gms b/modules/80_optimization/nlp_apr17/input.gms index 051075eec3..1486c3a2a0 100644 --- a/modules/80_optimization/nlp_apr17/input.gms +++ b/modules/80_optimization/nlp_apr17/input.gms @@ -7,6 +7,7 @@ scalars s80_maxiter maximal solve iterations if modelstat is > 2 (1) / 30 / - s80_optfile switch to use specfied solver settings (1) / 0 / - s80_secondsolve second solve statement (binary) / 0 / + s80_optfile switch to use specfied solver settings (1) / 1 / + s80_secondsolve second solve statement (binary) / 0 / + s80_toloptimal value for CONOPT4 Tol_Optimality / 1e-08 / ; diff --git a/modules/21_trade/free_apr16/preloop.gms b/modules/80_optimization/nlp_apr17/preloop.gms similarity index 80% rename from modules/21_trade/free_apr16/preloop.gms rename to modules/80_optimization/nlp_apr17/preloop.gms index e5db56cc6e..115c631cc6 100644 --- a/modules/21_trade/free_apr16/preloop.gms +++ b/modules/80_optimization/nlp_apr17/preloop.gms @@ -5,5 +5,5 @@ *** | MAgPIE License Exception, version 1.0 (see LICENSE file). *** | Contact: magpie@pik-potsdam.de -*set vm_cost_trade zero in order to avoid a free variable -vm_cost_trade.fx(i) = 0; +File optfile /conopt4.opt/; + diff --git a/modules/80_optimization/nlp_apr17/realization.gms b/modules/80_optimization/nlp_apr17/realization.gms index f4c3750a8a..dd35745758 100644 --- a/modules/80_optimization/nlp_apr17/realization.gms +++ b/modules/80_optimization/nlp_apr17/realization.gms @@ -14,5 +14,6 @@ *####################### R SECTION START (PHASES) ############################## $Ifi "%phase%" == "declarations" $include "./modules/80_optimization/nlp_apr17/declarations.gms" $Ifi "%phase%" == "input" $include "./modules/80_optimization/nlp_apr17/input.gms" +$Ifi "%phase%" == "preloop" $include "./modules/80_optimization/nlp_apr17/preloop.gms" $Ifi "%phase%" == "solve" $include "./modules/80_optimization/nlp_apr17/solve.gms" *######################## R SECTION END (PHASES) ############################### diff --git a/modules/80_optimization/nlp_apr17/solve.gms b/modules/80_optimization/nlp_apr17/solve.gms index ffdb6bfc0e..d9facfe83a 100644 --- a/modules/80_optimization/nlp_apr17/solve.gms +++ b/modules/80_optimization/nlp_apr17/solve.gms @@ -18,16 +18,12 @@ magpie.scaleopt = 1 ; magpie.solprint = 0 ; magpie.holdfixed = 1 ; -$onecho > conopt4.opt -Lim_Variable = 1.e25 -$offecho +put optfile; +put 'Tol_Optimality = ', s80_toloptimal:12:11 /; +putclose optfile; $onecho > conopt4.op2 -Flg_Prep = FALSE -$offecho - -$onecho > conopt4.op3 -Flg_NoDefc = TRUE +Lim_Variable = 1.e25 $offecho if(execerror > 0, @@ -62,14 +58,10 @@ if (magpie.modelstat > 2, option nlp = conopt4; magpie.optfile = 1; elseif s80_resolve_option = 3, - display "Modelstat > 2 | Retry solve with CONOPT4 w/o preprocessing"; + display "Modelstat > 2 | Retry solve with CONOPT4 increasing largest allowable value"; option nlp = conopt4; magpie.optfile = 2; elseif s80_resolve_option = 4, - display "Modelstat > 2 | Retry solve with CONOPT4 w/o search for definitional constraints"; - option nlp = conopt4; - magpie.optfile = 3; - elseif s80_resolve_option = 5, display "Modelstat > 2 | Retry solve with CONOPT3"; option nlp = conopt3; magpie.optfile = 0; @@ -94,7 +86,7 @@ if (magpie.modelstat > 2, * Otherwise, the repeat loop will never end. magpie.modelStat$(magpie.modelStat=NA) = 13; - s80_resolve_option$(s80_resolve_option >= 5) = 0; + s80_resolve_option$(s80_resolve_option >= 4) = 0; until (magpie.modelstat <= 2 or s80_counter >= s80_maxiter) ); diff --git a/modules/80_optimization/nlp_par/input.gms b/modules/80_optimization/nlp_par/input.gms index 39891d8b17..1486c3a2a0 100644 --- a/modules/80_optimization/nlp_par/input.gms +++ b/modules/80_optimization/nlp_par/input.gms @@ -6,7 +6,8 @@ *** | Contact: magpie@pik-potsdam.de scalars - s80_maxiter maximal solve iterations if modelstat is > 2 (1) / 30 / - s80_optfile switch to use specfied solver settings (1) / 0 / - s80_secondsolve second solve statement (binary) / 0 / + s80_maxiter maximal solve iterations if modelstat is > 2 (1) / 30 / + s80_optfile switch to use specfied solver settings (1) / 1 / + s80_secondsolve second solve statement (binary) / 0 / + s80_toloptimal value for CONOPT4 Tol_Optimality / 1e-08 / ; diff --git a/modules/80_optimization/nlp_par/solve.gms b/modules/80_optimization/nlp_par/solve.gms index 87be8fa8de..198a2c48eb 100644 --- a/modules/80_optimization/nlp_par/solve.gms +++ b/modules/80_optimization/nlp_par/solve.gms @@ -21,16 +21,12 @@ magpie.solprint = 0 ; magpie.holdfixed = 1 ; magpie.savepoint = 0; -$onecho > conopt4.opt -Lim_Variable = 1.e25 -$offecho +put optfile; +put 'Tol_Optimality = ', s80_toloptimal:12:11 /; +putclose optfile; $onecho > conopt4.op2 -Flg_Prep = FALSE -$offecho - -$onecho > conopt4.op3 -Flg_NoDefc = TRUE +Lim_Variable = 1.e25 $offecho h2(h) = no; @@ -111,14 +107,10 @@ repeat option nlp = conopt4; magpie.optfile = 1; elseif p80_resolve_option(h) = 3, - display "Modelstat > 2 | Retry solve with CONOPT4 w/o preprocessing"; + display "Modelstat > 2 | Retry solve with CONOPT4 increasing largest allowable value"; option nlp = conopt4; magpie.optfile = 2; elseif p80_resolve_option(h) = 4, - display "Modelstat > 2 | Retry solve with CONOPT4 w/o search for definitional constraints"; - option nlp = conopt4; - magpie.optfile = 3; - elseif p80_resolve_option(h) = 5, display "Modelstat > 2 | Retry solve with CONOPT3"; option nlp = conopt3; magpie.optfile = 0; @@ -131,7 +123,7 @@ repeat option nlp = conopt4; magpie.optfile = s80_optfile; - p80_resolve_option(h)$(p80_resolve_option(h) >= 5) = 0; + p80_resolve_option(h)$(p80_resolve_option(h) >= 4) = 0; ); h2(h) = no; i2(i) = no;