Skip to content

Commit b678e2d

Browse files
committed
feat: expose initialization of soil (N, microb, water) pools to R (optional)
Previously, default initial values were derived inside of Fortran code. This has now been moved to R in case the user does not provide initial values for the soil pools. Bottom line: The default recovers former default initialization.
1 parent 48123aa commit b678e2d

5 files changed

Lines changed: 99 additions & 23 deletions

File tree

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
* Added optional parameter `init_cohort$init_cohort_age` to specify a corresponding
1818
initial age distribution in years (default = 0). Default ensures backwards compatibility.
1919
Age affects reproduction through `params_species$matural_age`
20-
* Added optional parameter to `init_cohort`, to enable specification of initial
20+
* Added optional parameter to `init_cohort`, to enable specification of initial plant
2121
nitrogen pools. Namely: `init_cohort_bl_n14`, `init_cohort_br_n14`,
2222
`init_cohort_bsw_n14`,`init_cohort_bHW_n14`,`init_cohort_seedC_n14`,
2323
`init_cohort_nsc_n14``. If not provided, default values ensure backwards compatibility.
24+
* Added optional parameter to `init_soil`, to enable specification of initial soil
25+
nitrogen pools. Namely: `init_fast_soil_N`, `init_slow_soil_N`, `init_pmicr_C`,
26+
`init_pmicr_d13C`, `init_pmicr_N`, `init_wcl1`, `init_wcl2`, `init_wcl3`, `init_N0_ecosystem`.
27+
If not provided, default values ensure backwards compatibility.
2428
* Added check that all `species$LMA` >= `params_tile$LMAmin`
2529
* P-model:
2630
* no changes

R/data.R

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,12 @@
316316
#' \item{init_cohort_bHW}{Initial biomass of heartwood, in kg C per individual.}
317317
#' \item{init_cohort_seedC}{Initial biomass of seed, in kg C per individual.}
318318
#' \item{init_cohort_nsc}{Initial non-structural biomass, in kg C per individual. (optional, defaults to value derived from br_max and bl_max)}
319-
#' \item{init_cohort_bl_n14}{Initial nitorgen in leaf, in kg N per individual. (optional, defaults to C biomass * CN-ratio)}
320-
#' \item{init_cohort_br_n14}{Initial nitorgen in fine root, in Ng C per individual. (optional, defaults to C biomass * CN-ratio)}
321-
#' \item{init_cohort_bsw_n14}{Initial nitorgen in sapwood, in kg N per individual. (optional, defaults to C biomass * CN-ratio)}
322-
#' \item{init_cohort_bHW_n14}{Initial nitorgen in heartwood, in kg N per individual. (optional, defaults to C biomass * CN-ratio)}
323-
#' \item{init_cohort_seedC_n14}{Initial nitorgen in seed, in kg N per individual. (optional, defaults to C biomass * CN-ratio)}
324-
#' \item{init_cohort_nsc_n14}{Initial non-structural biomass, in kg C per individual. (optional, defaults to value derived from br_max and bl_max)}
319+
#' \item{init_cohort_bl_n14}{Initial nitrogen in leaf, in kg N per individual. (optional, defaults to C biomass * CN-ratio)}
320+
#' \item{init_cohort_br_n14}{Initial nitrogen in fine root, in kg N per individual. (optional, defaults to C biomass * CN-ratio)}
321+
#' \item{init_cohort_bsw_n14}{Initial nitrogen in sapwood, in kg N per individual. (optional, defaults to C biomass * CN-ratio)}
322+
#' \item{init_cohort_bHW_n14}{Initial nitrogen in heartwood, in kg N per individual. (optional, defaults to C biomass * CN-ratio)}
323+
#' \item{init_cohort_seedC_n14}{Initial nitrogen in seed, in kg N per individual. (optional, defaults to C biomass * CN-ratio)}
324+
#' \item{init_cohort_nsc_n14}{Initial non-structural biomass, in kg N per individual. (optional, defaults to value derived from br_max and bl_max)}
325325
#' \item{lu_index}{Land use type this cohorts belongs to (given as index in init_lu aray). (optional)
326326
#' Default: 0 (attach to all LU types except thoses which do not accept vegetation -- cf init_lu.vegetated).}
327327
#' }}
@@ -332,6 +332,15 @@
332332
#' \item{init_slow_soil_C}{Initial slow soil carbon, in kg C m\eqn{^{-2}}.}
333333
#' \item{init_Nmineral}{Mineral nitrogen pool, in kg N m\eqn{^{-2}}.}
334334
#' \item{N_input}{Annual nitrogen input to soil N pool, in kg N m\eqn{^{-2}} yr\eqn{^{-1}}.}
335+
#' \item{init_fast_soil_N}{Initial fast soil nitrogen, in kg N m\eqn{^{-2}}. (optional, defaults to C biomass * CN-ratio)}
336+
#' \item{init_slow_soil_N}{Initial slow soil nitrogen, in kg N m\eqn{^{-2}}. (optional, defaults to C biomass * CN-ratio)}
337+
#' \item{init_pmicr_C}{Initial carbon in soil microbial biomass, in kg C m\eqn{^{-2}}. (optional, defaults to 0.0)}
338+
#' \item{init_pmicr_d13C}{Initial d13C signature in soil microbial biomass, in permil. (optional, defaults to -9999)}
339+
#' \item{init_pmicr_N}{Initial nitrogen in soil microbial biomass, in kg N m\eqn{^{-2}}. (optional, defaults to 0.0)}
340+
#' \item{init_wcl1}{Initial volumetric water content of soil layer 1, in m\eqn{^{3}m\eqn{^{-3}}. (optional, defaults to field capacity)}
341+
#' \item{init_wcl2}{Initial volumetric water content of soil layer 2, in m\eqn{^{3}m\eqn{^{-3}}. (optional, defaults to field capacity)}
342+
#' \item{init_wcl3}{Initial volumetric water content of soil layer 3, in m\eqn{^{3}m\eqn{^{-3}}. (optional, defaults to field capacity)}
343+
#' \item{init_N0_ecosystem}{Initial total amount of nitrogen in ecosystem (only used for nitrogen workaround), in kg N m\eqn{^{-2}}. (optional, defaults to sum of soil and plant pools.) Might not be needed.}
335344
#' }}
336345
#' \item{init_lu}{A data.frame of initial land unit (LU) specifications, including
337346
#' the following data:

R/run_biomee_f_bysite.R

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ run_biomee_f_bysite <- function(
246246
params_tile <- build_params_tile(params_tile)
247247
params_species <- build_params_species(params_species, params_tile)
248248
init_cohort <- build_init_cohort(init_cohort, params_species)
249-
init_soil <- build_init_soil(init_soil)
249+
init_soil <- build_init_soil(init_soil, init_cohort, params_tile)
250250
forcing <- build_forcing(forcing)
251251

252252
# Build LULUC parameters
@@ -658,8 +658,41 @@ build_init_cohort <- function(init_cohort, params_species){
658658
return(init_cohort)
659659
}
660660

661-
build_init_soil <- function(init_soil){
662-
#browser() # currently build_init_soil has no-effect
661+
build_init_soil <- function(init_soil, init_cohort, params_tile){
662+
if ('init_fast_soil_N' %nin% names(init_soil)) {
663+
init_soil$init_fast_soil_N = init_soil$init_fast_soil_C / params_tile$CN0metabolicL # former default
664+
}
665+
if ('init_slow_soil_N' %nin% names(init_soil)) {
666+
init_soil$init_slow_soil_N = init_soil$init_slow_soil_C / params_tile$CN0structuralL # former default
667+
}
668+
if ('init_pmicr_C' %nin% names(init_soil)) {
669+
init_soil$init_pmicr_C = 0.0 # former default
670+
}
671+
if ('init_pmicr_d13C' %nin% names(init_soil)) {
672+
init_soil$init_pmicr_d13C = -9999.0 # former default
673+
}
674+
if ('init_pmicr_N' %nin% names(init_soil)) {
675+
init_soil$init_pmicr_N = 0.0 # former default
676+
}
677+
if ('init_wcl1' %nin% names(init_soil)) {
678+
init_soil$init_wcl1 = params_tile$FLDCAP # former default
679+
}
680+
if ('init_wcl2' %nin% names(init_soil)) {
681+
init_soil$init_wcl2 = params_tile$FLDCAP # former default
682+
}
683+
if ('init_wcl3' %nin% names(init_soil)) {
684+
init_soil$init_wcl3 = params_tile$FLDCAP # former default
685+
}
686+
if ('init_N0_ecosystem' %nin% names(init_soil)) { # this is used for nitrogen workaround
687+
Ntot_soil <- init_soil$init_pmicr_N + init_soil$init_fast_soil_N + init_soil$init_slow_soil_N + init_soil$init_Nmineral # kgN/m2
688+
N_in_each_cohort <- with(init_cohort,
689+
init_cohort_nindivs * # tree/m2
690+
(init_cohort_nsc_n14 + init_cohort_bl_n14 + init_cohort_br_n14 + # kgN per tree
691+
init_cohort_bsw_n14 + init_cohort_bHW_n14 + init_cohort_seedC_n14))
692+
Ntot_plant <- sum(N_in_each_cohort)
693+
Ntot <- Ntot_soil + Ntot_plant
694+
init_soil$init_N0_ecosystem = Ntot # former default: sum of the initialized soil and plant pools
695+
}
663696
return(init_soil)
664697
}
665698

@@ -917,7 +950,16 @@ prepare_init_soil <- function(init_soil){
917950
"init_fast_soil_C",
918951
"init_slow_soil_C",
919952
"init_Nmineral",
920-
"N_input"
953+
"N_input",
954+
"init_fast_soil_N",
955+
"init_slow_soil_N",
956+
"init_pmicr_C",
957+
"init_pmicr_d13C",
958+
"init_pmicr_N",
959+
"init_wcl1",
960+
"init_wcl2",
961+
"init_wcl3",
962+
"init_N0_ecosystem"
921963
)
922964
}
923965

src/interface_in_biosphere_biomee.mod.f90

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module md_interface_in_biomee
1111
private
1212
public inputs, interface_in_biosphere_biomee, params_species_biomee, init_lu_biomee
1313

14-
!===== Soil water hydrualics
14+
!===== Soil water hydraulics
1515
integer, public, parameter :: MAX_LEVELS = 3 ! Soil layers, for soil water dynamics
1616
real, public, parameter :: thksl(MAX_LEVELS) = (/0.05, 0.45, 1.5/) ! m, thickness of soil layers
1717

@@ -22,7 +22,7 @@ module md_interface_in_biomee
2222
integer, public, parameter :: nvars_params_siml = 11
2323
integer, public, parameter :: nvars_site_info = 4
2424
integer, public, parameter :: nvars_params_tile = 20
25-
integer, public, parameter :: nvars_init_soil = 4
25+
integer, public, parameter :: nvars_init_soil = 13
2626
integer, public, parameter :: nvars_init_cohorts = 16
2727
integer, public, parameter :: nvars_params_species = 65
2828
integer, public, parameter :: nvars_init_lu = 5
@@ -215,6 +215,15 @@ module md_interface_in_biomee
215215
real :: init_slow_soil_C
216216
real :: init_Nmineral
217217
real :: N_input
218+
real :: init_fast_soil_N
219+
real :: init_slow_soil_N
220+
real :: init_pmicr_C
221+
real :: init_pmicr_d13C
222+
real :: init_pmicr_N
223+
real :: init_wcl1
224+
real :: init_wcl2
225+
real :: init_wcl3
226+
real :: init_N0_ecosystem
218227

219228
contains
220229

@@ -405,6 +414,16 @@ subroutine populate_init_soil(self, init_soil)
405414
self%init_slow_soil_C = real( init_soil(2) )
406415
self%init_Nmineral = real( init_soil(3) )
407416
self%N_input = real( init_soil(4) )
417+
self%init_fast_soil_N = real( init_soil(5) )
418+
self%init_slow_soil_N = real( init_soil(6) )
419+
self%init_pmicr_C = real( init_soil(7) )
420+
self%init_pmicr_d13C = real( init_soil(8) )
421+
self%init_pmicr_N = real( init_soil(9) )
422+
self%init_wcl1 = real( init_soil(10))
423+
self%init_wcl2 = real( init_soil(11))
424+
self%init_wcl3 = real( init_soil(12))
425+
self%init_N0_ecosystem = real( init_soil(13))
426+
408427
end subroutine populate_init_soil
409428

410429
subroutine populate_params_tile(self, params_tile)

src/vegetation_tile_biomee.mod.f90

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ module md_vegetation_tile_biomee
119119
real :: N_P2S_yr ! N turnover (plant to soil) (kg N m-2 yr-1)
120120

121121
!===== Memory
122-
real :: previousN ! weighted annual available N
123122
real :: initialN0 ! initial available N (kg N m-2)
124123

125124
!===== Fast fluxes, kg m-2 timestep-1
@@ -225,7 +224,7 @@ pure real function soilwater(self)
225224
!---------------------------------------------------------------
226225
class(vegn_tile_type), intent(in) :: self
227226

228-
soilwater = SUM(self%wcl(:)*thksl(:)*1000.0)
227+
soilwater = SUM(self%wcl(:)*thksl(:)*1000.0) ! in m*1000 = m3/m2 *1000 = kg/m2
229228

230229
end function soilwater
231230

@@ -1079,20 +1078,23 @@ subroutine initialize_vegn_tile( self, lu_index )
10791078
! Initial Soil pools and environmental conditions
10801079
self%psoil_fs%c12 = inputs%init_soil%init_fast_soil_C ! fast soil carbon pool, (kg C/m2)
10811080
self%psoil_sl%c12 = inputs%init_soil%init_slow_soil_C ! slow soil carbon pool, (kg C/m2)
1082-
self%psoil_fs%n14 = self%psoil_fs%c12 / inputs%params_tile%CN0metabolicL ! fast soil nitrogen pool, (kg N/m2)
1083-
self%psoil_sl%n14 = self%psoil_sl%c12 / inputs%params_tile%CN0structuralL ! slow soil nitrogen pool, (kg N/m2)
1081+
self%psoil_fs%n14 = inputs%init_soil%init_fast_soil_N ! fast soil nitrogen pool, (kg N/m2)
1082+
self%psoil_sl%n14 = inputs%init_soil%init_slow_soil_N ! slow soil nitrogen pool, (kg N/m2)
10841083
self%inorg%n14 = inputs%init_soil%init_Nmineral ! Mineral nitrogen pool, (kg N/m2)
1085-
self%previousN = self%inorg%n14
10861084

10871085
! debug: adding microbial biomass initialisation
1088-
self%pmicr = orgpool() ! to do: add to: inputs%init_soil%xxxxx
1086+
self%pmicr = orgpool(inputs%init_soil%init_pmicr_C, &
1087+
inputs%init_soil%init_pmicr_d13C, &
1088+
inputs%init_soil%init_pmicr_N)
10891089

1090-
! Initialize soil volumetric water conent with field capacity (maximum soil moisture to start with)
1091-
self%wcl = inputs%params_tile%FLDCAP
1090+
! Initialize soil volumetric water content
1091+
self%wcl = (/inputs%init_soil%init_wcl1, inputs%init_soil%init_wcl2, inputs%init_soil%init_wcl3/)
10921092

1093-
call self%aggregate_cohorts()
1093+
! Initialize initialN0, that is used for nitrogen workaround: keep the N in the system constant at this value
1094+
self%initialN0 = inputs%init_soil%init_N0_ecosystem
10941095

1095-
self%initialN0 = self%totN
1096+
!call self%aggregate_cohorts()
1097+
!self%initialN0 = self%totN
10961098

10971099
end subroutine initialize_vegn_tile
10981100

0 commit comments

Comments
 (0)