From 1cc247354fd8c57123d09340e8e09c8812c3a9b2 Mon Sep 17 00:00:00 2001 From: Laura Marques Date: Sun, 21 Apr 2024 23:05:00 +0200 Subject: [PATCH] Added dist_frequency to params_siml --- R/run_biomee_f_bysite.R | 3 +++ data-raw/generate_biomee_driver_data_DBEN.R | 3 ++- src/biosphere_biomee.mod.f90 | 12 +++++------- src/params_siml_biomee.mod.f90 | 1 + src/sofun_r.f90 | 7 +++++-- src/wrappersc.c | 7 +++++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/R/run_biomee_f_bysite.R b/R/run_biomee_f_bysite.R index c29f9b5f..85319259 100644 --- a/R/run_biomee_f_bysite.R +++ b/R/run_biomee_f_bysite.R @@ -21,6 +21,8 @@ #' runs to recover N balance.} #' \item{do_reset_veg}{A logical value indicating whether reseting vegetation #' for disturbance runs.} +#' \item{dist_frequency}{Value indicating the frequency of the disturbance event (in years) +#' (e.g. 100 indicates a disturbance event occurs every 100 years, i.e., at a rate of 0.01)} #' \item{code_method_photosynth}{String specifying the method of photosynthesis #' used in the model, either "pmodel" or "gs_leuning".} #' \item{code_method_mortality}{String indicating the type of mortality in the @@ -514,6 +516,7 @@ run_biomee_f_bysite <- function( update_annualLAImax = as.logical(params_siml$update_annualLAImax), do_closedN_run = as.logical(params_siml$do_closedN_run), do_reset_veg = as.logical(params_siml$do_reset_veg), + dist_frequency = as.integer(params_siml$dist_frequency), code_method_photosynth= as.integer(code_method_photosynth), code_method_mortality = as.integer(code_method_mortality), diff --git a/data-raw/generate_biomee_driver_data_DBEN.R b/data-raw/generate_biomee_driver_data_DBEN.R index 677711a0..739e8d19 100644 --- a/data-raw/generate_biomee_driver_data_DBEN.R +++ b/data-raw/generate_biomee_driver_data_DBEN.R @@ -47,7 +47,8 @@ params_siml <- tibble( do_U_shaped_mortality = TRUE, update_annualLAImax = TRUE, do_closedN_run = TRUE, - do_reset_veg = FALSE, + do_reset_veg = FALSE, # TRUE + dist_frequency = 0, # 100, 75, 50, 25, 15, 10 method_photosynth = "gs_leuning", method_mortality = "dbh" ) diff --git a/src/biosphere_biomee.mod.f90 b/src/biosphere_biomee.mod.f90 index 9a2733d4..c7aba157 100644 --- a/src/biosphere_biomee.mod.f90 +++ b/src/biosphere_biomee.mod.f90 @@ -45,7 +45,6 @@ subroutine biosphere_annual(out_biosphere) integer :: year0 integer :: i integer :: idata - integer :: nfrequency integer, save :: simu_steps !, datalines integer, save :: iyears integer, save :: idays @@ -203,15 +202,14 @@ subroutine biosphere_annual(out_biosphere) if(myinterface%params_siml%do_reset_veg) then - if (iyears==myinterface%params_siml%spinupyears+31) then + if (iyears==myinterface%params_siml%spinupyears + 31) then call reset_vegn_initial(vegn) endif - nfrequency = 0 ! 100,75,50,25,15,10 - - if(nfrequency > 0) then - do i = myinterface%params_siml%spinupyears+31+nfrequency, & - myinterface%params_siml%spinupyears + myinterface%params_siml%nyeartrend, nfrequency + if(myinterface%params_siml%dist_frequency > 0) then + do i = myinterface%params_siml%spinupyears + 31 + myinterface%params_siml%dist_frequency, & + myinterface%params_siml%spinupyears + myinterface%params_siml%nyeartrend, & + myinterface%params_siml%dist_frequency if (iyears == i) call reset_vegn_initial(vegn) enddo diff --git a/src/params_siml_biomee.mod.f90 b/src/params_siml_biomee.mod.f90 index a1b6b8fc..db6f307b 100644 --- a/src/params_siml_biomee.mod.f90 +++ b/src/params_siml_biomee.mod.f90 @@ -28,6 +28,7 @@ module md_params_siml_biomee logical :: update_annualLAImax logical :: do_closedN_run logical :: do_reset_veg + integer :: dist_frequency character(len=30) :: method_photosynth character(len=30) :: method_mortality diff --git a/src/sofun_r.f90 b/src/sofun_r.f90 index 921fcbbb..8ddbb452 100644 --- a/src/sofun_r.f90 +++ b/src/sofun_r.f90 @@ -239,7 +239,8 @@ subroutine biomee_f( & do_U_shaped_mortality, & update_annualLAImax, & do_closedN_run, & - do_reset_veg, & + do_reset_veg, & + dist_frequency, & code_method_photosynth, & code_method_mortality, & longitude, & @@ -371,6 +372,7 @@ subroutine biomee_f( & logical(kind=c_bool), intent(in) :: update_annualLAImax logical(kind=c_bool), intent(in) :: do_closedN_run logical(kind=c_bool), intent(in) :: do_reset_veg + integer(kind=c_int), intent(in) :: dist_frequency integer(kind=c_int), intent(in) :: code_method_photosynth integer(kind=c_int), intent(in) :: code_method_mortality @@ -520,7 +522,8 @@ subroutine biomee_f( & myinterface%params_siml%do_U_shaped_mortality = do_U_shaped_mortality myinterface%params_siml%update_annualLAImax = update_annualLAImax myinterface%params_siml%do_closedN_run = do_closedN_run - myinterface%params_siml%do_reset_veg = do_reset_veg + myinterface%params_siml%do_reset_veg = do_reset_veg + myinterface%params_siml%dist_frequency = dist_frequency ! this needs to be consistent with translation to code in run_biomee_f_bysite.R if (code_method_photosynth == 1) then diff --git a/src/wrappersc.c b/src/wrappersc.c index 2942f0e1..cb94d8b9 100644 --- a/src/wrappersc.c +++ b/src/wrappersc.c @@ -121,7 +121,8 @@ void F77_NAME(biomee_f)( int *do_U_shaped_mortality, int *update_annualLAImax, int *do_closedN_run, - int *do_reset_veg, + int *do_reset_veg, + int *dist_frequency, int *code_method_photosynth, int *code_method_mortality, double *longitude, @@ -237,6 +238,7 @@ extern SEXP biomee_f_C( SEXP update_annualLAImax, SEXP do_closedN_run, SEXP do_reset_veg, + SEXP dist_frequency, SEXP code_method_photosynth, SEXP code_method_mortality, SEXP longitude, @@ -360,6 +362,7 @@ extern SEXP biomee_f_C( LOGICAL(update_annualLAImax), LOGICAL(do_closedN_run), LOGICAL(do_reset_veg), + INTEGER(dist_frequency), INTEGER(code_method_photosynth), INTEGER(code_method_mortality), REAL(longitude), @@ -542,7 +545,7 @@ extern SEXP biomee_f_C( ///////////////////////////////////////////////////////////// static const R_CallMethodDef CallEntries[] = { {"pmodel_f_C", (DL_FUNC) &pmodel_f_C, 23}, // Specify number of arguments to C wrapper as the last number here - {"biomee_f_C", (DL_FUNC) &biomee_f_C, 47}, // Number of the SEXP variables (not the output) + {"biomee_f_C", (DL_FUNC) &biomee_f_C, 48}, // Number of the SEXP variables (not the output) {NULL, NULL, 0} };