Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e658fcb
residues interfaces changed to hand over kcr and w information
k4rst3ns Jun 21, 2023
71466f9
update old 59_som realizations to new interfaces
k4rst3ns Jul 29, 2023
3cfd75e
add new 59_som realization (threepool_may23) - complication error free
k4rst3ns Jul 29, 2023
0b0245e
Merge branch 'magpiemodel:master' into f_socmodel
k4rst3ns Oct 19, 2023
5bc6d47
add new residue realization
k4rst3ns Jan 9, 2024
243b878
Merge branch 'f_socmodel' of github.com:k4rst3ns/magpie into f_socmodel
k4rst3ns Jan 9, 2024
c6d3854
Merge remote-tracking branch 'origin/develop' into f_socmodel
k4rst3ns Jan 23, 2024
caf0177
Merge remote-tracking branch 'origin/develop' into f_socmodel
k4rst3ns Jan 23, 2024
93a6839
Merge remote-tracking branch 'origin/develop' into f_socmodel
k4rst3ns Mar 25, 2024
d41d9bd
threepool SOM update
k4rst3ns Apr 9, 2024
546f024
Merge remote-tracking branch 'origin/develop' into f_socmodel
k4rst3ns Apr 9, 2024
2e6bf81
bugfix wrong production call for residues (now irrigation type specific)
k4rst3ns Apr 18, 2024
46af8c7
Merge remote-tracking branch 'origin/develop' into f_socmodel
k4rst3ns Jun 7, 2024
0ec49ee
update test setup
k4rst3ns Jun 9, 2024
2fbe080
Merge remote-tracking branch 'pat/f_pForest' into f_socmodel
k4rst3ns Jun 9, 2024
3255cad
bugfix residues for the moment and soc
k4rst3ns Jun 17, 2024
67ad123
update input
k4rst3ns Jul 21, 2024
8f7a63b
:qMerge remote-tracking branch 'magpiemodel/develop' into f_socmodel
k4rst3ns Jan 22, 2025
8814d53
changes in residues
k4rst3ns Mar 14, 2025
3dc781d
Merge remote-tracking branch 'magpiemodel/develop' into f_socmodel
k4rst3ns Mar 14, 2025
d3b523b
bugfix residues
k4rst3ns Mar 20, 2025
82d3656
small bugfix + switch to set Tol_Optimality
k4rst3ns Apr 4, 2025
e9f73c8
Merge remote-tracking branch 'origin/develop' into f_resSpike
k4rst3ns Apr 4, 2025
3d3b25f
new residue realization to test
k4rst3ns Apr 4, 2025
44bc8bd
Merge remote-tracking branch 'magpiemodel/develop' into f_socmodel
k4rst3ns Apr 4, 2025
73904dc
Merge remote-tracking branch 'origin/develop' into f_resSpike
k4rst3ns Apr 7, 2025
14787e0
add config entry for setting Tol_Optimality solver setting dynamically
k4rst3ns Apr 7, 2025
822dbde
Update config/default.cfg
k4rst3ns Apr 8, 2025
7a7d1b3
Update modules/80_optimization/nlp_apr17/input.gms
k4rst3ns Apr 8, 2025
2a66f84
rename residue production equation from q18_prod_res_cell to q18_prod…
k4rst3ns Apr 9, 2025
e9ddb59
Merge remote-tracking branch 'karstens/f_resSpike' into f_resSpike
k4rst3ns Apr 9, 2025
faf30e2
update s80_resolve_option cascade
k4rst3ns Apr 9, 2025
ba0d01e
Merge remote-tracking branch 'magpiemodel/develop' into f_socmodel
k4rst3ns Apr 10, 2025
e51972a
new realization for residues - default as copy
k4rst3ns Apr 10, 2025
f5dfafd
new implementation for disaggregated residues
k4rst3ns Apr 10, 2025
edc3190
update realization less uncontrained variables in residues
k4rst3ns Apr 11, 2025
71f3c3e
Merge remote-tracking branch 'origin/f_resSpike' into f_socmodel
k4rst3ns Apr 11, 2025
e57b03a
bring config back to develop
k4rst3ns Apr 11, 2025
3f9e560
small bugfix of set for bg residue eq
k4rst3ns Apr 11, 2025
75c6bbf
bugfix declaration in residues default realization
k4rst3ns Apr 11, 2025
89da683
remove old realizations
k4rst3ns Apr 11, 2025
bb04cb6
change from all attributes to dm_cnr and change some pos variables to…
k4rst3ns Apr 11, 2025
c4195e0
bugfix wrong sets + other small mistakes
k4rst3ns Apr 11, 2025
c13dff2
update auto-generated part
k4rst3ns Apr 11, 2025
60b170c
rename threepool realization from som module, create new one on clust…
k4rst3ns Apr 15, 2025
14ba9a1
vm_prod_kcr_w back to positive variable, reduce residue reccycling eq…
k4rst3ns Apr 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions config/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ cfg$gms$c17_prod_init <- "on" # default = on
# ***--------------------- 18_residues -----------------------------------
# * (flexreg_apr16): detailed residue calculations
# * (off): off
cfg$gms$residues <- "flexreg_apr16" # def = flexreg_apr16
cfg$gms$residues <- "disaggRes_apr25" # def = flexreg_apr16

# * residue on field burning
# * options: phaseout - phaseout of residue burning to minimum burn share (0-10%)
Expand Down Expand Up @@ -1827,6 +1827,7 @@ cfg$gms$s58_fix_peatland <- 2020 # def = 2020
# * (static_jan19): static soil carbon loss for cropland
# * (cellpool_jan23): dynamic soil organic matter pool on cellular level
# * with updated, regionalized stock change factors (IPCC guidelines 2019)
# cfg$gms$som <- "threepool_may23"
cfg$gms$som <- "cellpool_jan23" # def = cellpool_jan23

# * static realization switch
Expand Down Expand Up @@ -2177,7 +2178,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
Expand Down
1 change: 1 addition & 0 deletions core/calculations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $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;

File optfile /conopt4.opt/;

************************OPTIMIZATION PROCESS START******************************
* This section contains only sourcecode that is directly connected to the
Expand Down
Binary file not shown.
75 changes: 75 additions & 0 deletions modules/18_residues/disaggRes_apr25/declarations.gms
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
*** | (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
v18_prod_res(j,kres) Cellular production of residues (mio. tDM)
vm_res_biomass_ag(i,kcr,w,dm_cnr) Production of aboveground residues in each region (mio. tDM)
vm_res_biomass_bg(i,kcr,w,dm_cnr) Production of belowground residues in each region (mio. tDM)
vm_res_ag_burn(i,kcr,w,dm_cnr) Residues burned on fields in respective attribute units DM GJ Nr P K WM C (mio. tX)
vm_res_recycling(i,kcr,w,dm_cnr) Residues recycled to croplands in respective nutrients Nr P K units (mio. tX)
vm_cost_prod_kres(i,kres) Production costs of harvesting crop residues (mio. USD17MER per yr)
v18_res_ag_removal_clust(j,kcr,w,dm_cnr) Removal of crop residues in respective attribute units DM GJ Nr P K WM C (mio. tX)
v18_res_ag_recycling_clust(j,kcr,w,dm_cnr) Recylcing of crop residues to soils in respective attribute units DM GJ Nr P K WM C (mio. tX)
;

variables
v18_res_biomass_ag_clust(j,kcr,w,dm_cnr) Production of aboveground residues in each cluster (mio. tDM)
v18_res_biomass_bg_clust(j,kcr,w,dm_cnr) Production of belowground residues in each cluster (mio. tDM)
v18_res_ag_burn_clust(j,kcr,w,dm_cnr) Residues burned on fields in respective attribute units DM GJ Nr P K WM C in each cluster (mio. tX)
v18_res_recycling_clust(j,kcr,w,dm_cnr) Residues recycled to croplands in respective nutrients Nr P K units in each cluster (mio. tX)
;

equations
q18_prod_res_ag_clust(j,kcr,w,dm_cnr) Production constraint of aboveground residues (mio. tDM)
q18_sumreg_res_biomass_ag(i,kcr,w,dm_cnr) Regional above-ground residue biomass (mio. tX per yr)
q18_prod_res_bg_clust(j,kcr,w,dm_cnr) Production constraint of belowground residues (mio. tDM)
q18_sumreg_res_biomass_bg(i,kcr,w,dm_cnr) Regional below-ground residue biomass (mio. tX per yr)
q18_res_field_balance_clust(j,kcr,w,dm_cnr) Calculation of the residues amount recycled to soils (mio. tDM)
q18_res_field_burn_clust(j,kcr,w,dm_cnr) Fixing of the residues amount burned in a cluster in respective attribute units DM GJ Nr P K WM C (mio. tX)
q18_sumreg_res_biomass_burn(i,kcr,w,dm_cnr) Regional burned residue biomass (mio. tX per yr)
q18_translate(j,kres,dm_cnr) 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(i,kres) Allows for distribution of residues to cellular level (mio. tDM)
q18_res_recycling_cnr_clust(j,kcr,w,cnr) Nutrient recycling of carbon and reaactive nitrogen (mio. tX)
q18_sumreg_res_recycling(i,kcr,w,cnr) Regional recycled residue biomass (mio. tX per yr)
q18_cost_prod_res(i,kres) Production costs of harvesting crop residues (mio. USD17MER)
;

parameters
i18_res_use_burn(t_all,dev18,kcr) Share of residues burned on field (1)
;

*#################### R SECTION START (OUTPUT DECLARATIONS) ####################
parameters
ov18_prod_res(t,j,kres,type) Cellular production of residues (mio. tDM)
ov_res_biomass_ag(t,i,kcr,w,dm_cnr,type) Production of aboveground residues in each region (mio. tDM)
ov_res_biomass_bg(t,i,kcr,w,dm_cnr,type) Production of belowground residues in each region (mio. tDM)
ov_res_ag_burn(t,i,kcr,w,dm_cnr,type) Residues burned on fields in respective attribute units DM GJ Nr P K WM C (mio. tX)
ov_res_recycling(t,i,kcr,w,dm_cnr,type) Residues recycled to croplands in respective nutrients Nr P K units (mio. tX)
ov_cost_prod_kres(t,i,kres,type) Production costs of harvesting crop residues (mio. USD17MER per yr)
ov18_res_ag_removal_clust(t,j,kcr,w,dm_cnr,type) Removal of crop residues in respective attribute units DM GJ Nr P K WM C (mio. tX)
ov18_res_ag_recycling_clust(t,j,kcr,w,dm_cnr,type) Recylcing of crop residues to soils in respective attribute units DM GJ Nr P K WM C (mio. tX)
ov18_res_biomass_ag_clust(t,j,kcr,w,dm_cnr,type) Production of aboveground residues in each cluster (mio. tDM)
ov18_res_biomass_bg_clust(t,j,kcr,w,dm_cnr,type) Production of belowground residues in each cluster (mio. tDM)
ov18_res_ag_burn_clust(t,j,kcr,w,dm_cnr,type) Residues burned on fields in respective attribute units DM GJ Nr P K WM C in each cluster (mio. tX)
ov18_res_recycling_clust(t,j,kcr,w,dm_cnr,type) Residues recycled to croplands in respective nutrients Nr P K units in each cluster (mio. tX)
oq18_prod_res_ag_clust(t,j,kcr,w,dm_cnr,type) Production constraint of aboveground residues (mio. tDM)
oq18_sumreg_res_biomass_ag(t,i,kcr,w,dm_cnr,type) Regional above-ground residue biomass (mio. tX per yr)
oq18_prod_res_bg_clust(t,j,kcr,w,dm_cnr,type) Production constraint of belowground residues (mio. tDM)
oq18_sumreg_res_biomass_bg(t,i,kcr,w,dm_cnr,type) Regional below-ground residue biomass (mio. tX per yr)
oq18_res_field_balance_clust(t,j,kcr,w,dm_cnr,type) Calculation of the residues amount recycled to soils (mio. tDM)
oq18_res_field_burn_clust(t,j,kcr,w,dm_cnr,type) Fixing of the residues amount burned in a cluster in respective attribute units DM GJ Nr P K WM C (mio. tX)
oq18_sumreg_res_biomass_burn(t,i,kcr,w,dm_cnr,type) Regional burned residue biomass (mio. tX per yr)
oq18_translate(t,j,kres,dm_cnr,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,i,kres,type) Allows for distribution of residues to cellular level (mio. tDM)
oq18_res_recycling_cnr_clust(t,j,kcr,w,cnr,type) Nutrient recycling of carbon and reaactive nitrogen (mio. tX)
oq18_sumreg_res_recycling(t,i,kcr,w,cnr,type) Regional recycled residue biomass (mio. tX per yr)
oq18_cost_prod_res(t,i,kres,type) Production costs of harvesting crop residues (mio. USD17MER)
;
*##################### R SECTION END (OUTPUT DECLARATIONS) #####################

*** EOF declarations.gms ***
126 changes: 126 additions & 0 deletions modules/18_residues/disaggRes_apr25/equations.gms
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
*** | (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

*' The AG crop residue biomass `vm_res_biomass_ag` is calculated as a function
*' of harvested area `vm_area` and production `vm_prod_reg`. `f18_cgf` contains
*' slope and intercept parameters of the CGFs.

q18_sumreg_res_biomass_ag(i2,kcr,w,dm_cnr) ..
vm_res_biomass_ag(i2,kcr,w,dm_cnr) =e=
sum(cell(i2,j2), v18_res_biomass_ag_clust(j2,kcr,w,dm_cnr));


q18_prod_res_ag_clust(j2,kcr,w,dm_cnr) ..
v18_res_biomass_ag_clust(j2,kcr,w,dm_cnr)
=e=
(vm_area(j2,kcr,w) * sum((ct, cell(i2,j2)), f18_multicropping(ct,i2)) * f18_cgf("intercept",kcr)
+ vm_prod_kcr_w(j2,kcr,w) * f18_cgf("slope",kcr))
* f18_attributes_residue_ag(dm_cnr,kcr);

*' The BG crop residue biomass `vm_res_biomass_bg` is calculated as a function of
*' total aboveground biomass.


q18_prod_res_bg_clust(j2,kcr,w,dm_cnr) ..
v18_res_biomass_bg_clust(j2,kcr,w,dm_cnr)
=e=
(vm_prod_kcr_w(j2,kcr,w) +
v18_res_biomass_ag_clust(j2,kcr,w,"dm")) * f18_cgf("bg_to_ag",kcr)
* f18_attributes_residue_bg(dm_cnr,kcr);

q18_sumreg_res_biomass_bg(i2,kcr,w,dm_cnr) ..
vm_res_biomass_bg(i2,kcr,w,dm_cnr) =e=
sum(cell(i2,j2), v18_res_biomass_bg_clust(j2,kcr,w,dm_cnr));

*' In contrast to AG biomass, AG production `vm_res_biomass_ag(i,kcr,dm_cnr)`
*' is defined as the part of residues which is removed from the field. The
*' difference between biomass and production is either burned on field or
*' remains on the fields (either incorporated in soils or not) and decays.
*' The field balance equations ensures that the production of AG residues
*' `vm_res_biomass_ag(i,kcr,dm_cnr)` is properly assigned to different uses:
*' removal, on-field burning and recycling of AG residues.

q18_res_field_balance_clust(j2,kcr,w,dm_cnr) ..
v18_res_biomass_ag_clust(j2,kcr,w,dm_cnr)
=e=
v18_res_ag_removal_clust(j2,kcr,w,dm_cnr)
+ v18_res_ag_burn_clust(j2,kcr,w,dm_cnr)
+ v18_res_ag_recycling_clust(j2,kcr,w,dm_cnr);

*' The amount of residues burned on fields in a region `vm_res_ag_burn` is
*' determined by the share (ic18_res_use_min_shr) of AG residue biomass.
*' Based on @smil_nitrogen_1999, residue burning is fixed to 15% of total AG
*' crop residue dry matter in developed and 25% in developing regions for each
*' crop. For future time steps, these rates are scenario dependent, and either
*' kept constant or reduced to 10% and 0% in 2050.

q18_res_field_burn_clust(j2,kcr,w,dm_cnr) ..
v18_res_ag_burn_clust(j2,kcr,w,dm_cnr)
=e=
sum((cell(i2,j2),ct), im_development_state(ct,i2) * i18_res_use_burn(ct,"high_income",kcr)
+ (1-im_development_state(ct,i2)) * i18_res_use_burn(ct,"low_income",kcr))
* v18_res_biomass_ag_clust(j2,kcr,w,dm_cnr);

q18_sumreg_res_biomass_burn(i2,kcr,w,dm_cnr) ..
vm_res_ag_burn(i2,kcr,w,dm_cnr) =e=
sum(cell(i2,j2), v18_res_ag_burn_clust(j2,kcr,w,dm_cnr));

*' While the residue biomass is estiamted with a crop-specific nutrient
*' composition (which is required for consistent nutrient budgets), the
*' removed residues are assumed to have homogeneous properties
*' (to reduce the number of commodities in MAgPIE) within three crop residue
*' groups (cereal straw, fibrous residues that cannot be digested
*' by monogastrics, and non-fibrous residues that can be digested).
*' The following constraint, in combination with the field balance equation,
*' guarantees that mass balances are not violated while a homogeneous
*' good is extracted from heterogeneous goods.

q18_translate(j2,kres,dm_cnr)..
sum((kres_kcr(kres,kcr),w), v18_res_ag_removal_clust(j2,kcr,w,dm_cnr))
=e=
v18_prod_res(j2,kres) * fm_attributes(dm_cnr,kres);

*' sum to the regional amount of residues produced for the regional interface

q18_prod_res_cell(i2,kres)..
sum(cell(i2,j2), v18_prod_res(j2,kres))
=e=
vm_prod_reg(i2,kres) ;

*' Residues recycled to croplands in nutrients `vm_res_recycling(i2,"nr")` are
*' calcualted based on the amount of AG residues left on field for recycling, the
*' nutrients coming from burned residues, and on biomass that is left in
*' BG residues. They are calculated to be transmitted to the nitrogen budget
*' module [50_nr_soil_budget].

q18_res_recycling_cnr_clust(j2,kcr,w,cnr) ..
v18_res_recycling_clust(j2,kcr,w,cnr)
=e=
v18_res_ag_recycling_clust(j2,kcr,w,cnr)
+ v18_res_ag_burn_clust(j2,kcr,w,cnr)*(1-f18_res_combust_eff(kcr))
+ v18_res_biomass_bg_clust(j2,kcr,w,cnr)
;

q18_sumreg_res_recycling(i2,kcr,w,cnr) ..
vm_res_recycling(i2,kcr,w,cnr) =e=
sum(cell(i2,j2), v18_res_recycling_clust(j2,kcr,w,cnr));

*' Costs of residue harvest are based on straw baling and hauling from
*' Budynski, Stephanie. 2020. Straw Manufacturing in Alberta (@budynski_straw_2020),
*' using the lower range of the US costs.

q18_cost_prod_res(i2,kres) ..
vm_cost_prod_kres(i2,kres)
=e=
vm_prod_reg(i2,kres) * fm_attributes("wm",kres) * f18_fac_req_kres(kres);

*' Trade of AG residues is not considered, so that all produced AG residues have
*' to be assigned to uses within the respective world region.

*** EOF constraints.gms ***
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ $include "./modules/18_residues/input/f18_attributes_residue_ag.csv"
$offdelim;


table f18_attributes_residue_bg(dm_nr,kve) Nutrient content of belowground crop residues in reactive nitorgen and carbon units Nr C (X per DM)
table f18_attributes_residue_bg(dm_cnr,kve) Nutrient content of belowground crop residues in reactive nitorgen and carbon units Nr C (X per DM)
$ondelim
$include "./modules/18_residues/input/f18_attributes_residue_bg.csv"
$offdelim;

table f18_cgf(cgf,kve) Crop growth functions for all vegetation types containing slope intercept and belowground to aboveground ratio (1)
$ondelim
$include "./modules/18_residues/flexcluster_jul23/input/f18_cgf.csv"
$include "./modules/18_residues/disaggRes_apr25/input/f18_cgf.csv"
$offdelim;

table f18_res_use_burn(t_all,burn_scen18,dev18,kcr) Minimum and maximum burn share use for residues developing over time (1)
$ondelim
$include "./modules/18_residues/flexcluster_jul23/input/f18_res_use_burn.cs3"
$include "./modules/18_residues/disaggRes_apr25/input/f18_res_use_burn.cs3"
$offdelim;

parameter f18_res_combust_eff(kve) Combustion efficiency of residue burning (1)
Expand All @@ -44,7 +44,7 @@ $offdelim
parameter f18_fac_req_kres(kres) Factor requirements (USD17MER per tDM)
/
$ondelim
$include "./modules/18_residues/flexcluster_jul23/input/f18_fac_req_kres.csv"
$include "./modules/18_residues/disaggRes_apr25/input/f18_fac_req_kres.csv"
$offdelim
/;

Expand Down
Loading