Skip to content

Commit

Permalink
- Last forcing year is repeated ad libitum in case nyeartrend is gr…
Browse files Browse the repository at this point in the history
…eater than the number of years in the forcing data.

- Update drivers doc
  • Loading branch information
marcadella committed Dec 11, 2024
1 parent 1dbfe71 commit 8d572ed
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
13 changes: 8 additions & 5 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
#' \describe{
#' \item{spinup}{A logical value indicating whether this simulation does spin-up.}
#' \item{spinupyears}{Number of spin-up years.}
#' \item{recycle}{Length of standard recycling period, in years.}
#' \item{recycle}{Length of the recycling period during spin-up, in years.}
#' \item{firstyeartrend}{First transient year (year AD).}
#' \item{nyeartrend}{Number of transient years. If greater than the forcing data, the last year is repeated.}
#' \item{steps_per_day}{Time resolution (day-1). Must be set to 1.}
#' \item{outdt}{An integer indicating the output periodicity.}
#' \item{ltre}{A logical value, \code{TRUE} if evergreen tree.}
#' \item{ltne}{A logical value, \code{TRUE} if evergreen tree and N-fixing.}
Expand Down Expand Up @@ -188,9 +191,9 @@
#' \describe{
#' \item{spinup}{Flag indicating whether this simulation does spin-up.}
#' \item{spinupyears}{Number of spin-up years.}
#' \item{recycle}{Length of standard recycling period (years).}
#' \item{firstyeartrend}{First transient year.}
#' \item{nyeartrend}{Number of transient years.}
#' \item{recycle}{Length of the recycling period during spin-up, in years.}
#' \item{firstyeartrend}{First transient year (year AD).}
#' \item{nyeartrend}{Number of transient years. If greater than the forcing data, the last year is repeated.}
#' \item{steps_per_day}{Time resolution (day-1).}
#' \item{do_U_shaped_mortality}{Flag indicating whether U-shaped
#' mortality is used.}
Expand Down Expand Up @@ -256,7 +259,7 @@
#' \item{phenotype}{Integer set to 0 for deciduous and 1 for evergreen.}
#' \item{pt}{Integer indicating the type of plant according to photosynthesis:
#' 0 for C3; 1 for C4}
#' \item{alpha_FR}{Fine root turnonver rate (year\eqn{^{-1}}).}
#' \item{alpha_FR}{Fine root turnover rate (year\eqn{^{-1}}).}
#' \item{rho_FR}{Material density of fine roots (kg C m\eqn{^{-3}}).}
#' \item{root_r}{Radius of the fine roots, in m.}
#' \item{root_zeta}{e-folding parameter of root vertical distribution, in m.}
Expand Down
4 changes: 1 addition & 3 deletions R/run_pmodel_f_bysite.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ run_pmodel_f_bysite <- function(

# predefine variables for CRAN check compliance
ccov <- temp <- rain <- vpd <- ppfd <- netrad <-
fsun <- snow <- co2 <- fapar <- patm <-
nyeartrend_forcing <- firstyeartrend_forcing <-
tmin <- tmax <- . <- NULL
fsun <- snow <- co2 <- fapar <- patm <- tmin <- tmax <- . <- NULL

# base state, always execute the call
continue <- TRUE
Expand Down
8 changes: 4 additions & 4 deletions man/biomee_gs_leuning_drivers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/p_model_drivers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions src/forcing_siterun_biomee.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ function getclimate( nt, ntstepsyear, forcing, climateyear_idx ) result ( out_cl
integer, intent(in) :: climateyear_idx

! local variables
integer :: idx_start, idx_end, it
integer :: idx_start, idx_end, it, forcing_years, idx

! function return variable
type(climate_type), dimension(ntstepsyear) :: out_climate

idx_start = (climateyear_idx - 1) * ntstepsyear + 1
forcing_years = size(forcing(:, 1)) / ntstepsyear
! If we are simulating more years than the forcing array contains,
! We repeat the last year of the forcing.
idx = MIN(climateyear_idx, forcing_years)

idx_start = (idx - 1) * ntstepsyear + 1
idx_end = idx_start + ntstepsyear - 1

! This is to read from ORNL file
Expand Down
28 changes: 21 additions & 7 deletions src/forcing_siterun_pmodel.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ function getclimate( nt, forcing, climateyear_idx, in_ppfd, in_netrad ) result (
logical, intent(in) :: in_netrad

! local variables
integer :: idx_start, idx_end
! integer, dimension(2) :: shape_forcing
integer :: idx_start, idx_end, forcing_years, idx

! function return variable
type( climate_type ), dimension(ndayyear) :: out_climate

idx_start = (climateyear_idx - 1) * ndayyear + 1
forcing_years = size(forcing(:, 1)) / ndayyear
! If we are simulating more years than the forcing array contains,
! We repeat the last year of the forcing.
idx = MIN(climateyear_idx, forcing_years)

idx_start = (idx - 1) * ndayyear + 1
idx_end = idx_start + ndayyear - 1

! Test if forcing dimensions are correct
Expand Down Expand Up @@ -113,11 +117,16 @@ function getco2( nt, forcing, forcingyear, firstyeartrend ) result( pco2 )

! local variables
integer :: readyear_idx
integer :: idx_start, idx_end
integer :: idx_start, idx_end, forcing_years, idx

readyear_idx = forcingyear - firstyeartrend + 1

idx_start = (readyear_idx - 1) * ndayyear + 1
forcing_years = size(forcing(:, 1)) / ndayyear
! If we are simulating more years than the forcing array contains,
! We repeat the last year of the forcing.
idx = MIN(readyear_idx, forcing_years)

idx_start = (idx - 1) * ndayyear + 1
idx_end = idx_start + ndayyear - 1

pco2 = sum(real(forcing(idx_start:idx_end, 8)))/ndayyear
Expand All @@ -138,9 +147,14 @@ function getfapar( nt, forcing, forcingyear_idx ) result( out_vegcover )
type( vegcover_type ), dimension(ndayyear) :: out_vegcover

! local variables
integer :: idx_start, idx_end
integer :: idx_start, idx_end, forcing_years, idx

forcing_years = size(forcing(:, 1)) / ndayyear
! If we are simulating more years than the forcing array contains,
! We repeat the last year of the forcing.
idx = MIN(forcingyear_idx, forcing_years)

idx_start = (forcingyear_idx - 1) * ndayyear + 1
idx_start = (idx - 1) * ndayyear + 1
idx_end = idx_start + ndayyear - 1

out_vegcover(:)%dfapar = real(forcing(idx_start:idx_end, 9))
Expand Down
12 changes: 6 additions & 6 deletions src/params_core.mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module md_params_core
real, parameter :: dummy = -9999.0 ! arbitrary dummy value

type outtype_steering
integer :: year
integer :: year ! current simulation year
integer :: climateyear ! year AD for which climate is read in (recycling during spinup or when climate is held const.)
integer :: climateyear_idx ! year index for which climate is read in.
integer :: forcingyear ! year AD for which forcings are read in (=firstyeartrend during spinup)
Expand Down Expand Up @@ -126,7 +126,7 @@ function get_steering( year, steering ) result( out_steering )
out_steering%add_ninorg = .false.
end if

if (year<=steering%spinupyears) then
if (year <= steering%spinupyears) then
! during spinup
out_steering%spinup = .true.
cycleyear = get_cycleyear( year, steering%spinupyears, steering%recycle )
Expand All @@ -139,7 +139,7 @@ function get_steering( year, steering ) result( out_steering )
out_steering%spinup = .false.
out_steering%climateyear_idx = year - steering%spinupyears
out_steering%climateyear = out_steering%climateyear_idx + steering%firstyeartrend - 1
out_steering%forcingyear = out_steering%climateyear
out_steering%forcingyear = out_steering%climateyear
out_steering%forcingyear_idx = out_steering%climateyear_idx
endif
out_steering%outyear = year + steering%firstyeartrend - steering%spinupyears - 1
Expand All @@ -150,21 +150,21 @@ function get_steering( year, steering ) result( out_steering )
out_steering%dofree_alloc = .false.
end if

if ( (year==spinupyr_soilequil_1 .or. year==spinupyr_soilequil_2 ) .and. year<=steering%spinupyears) then
if ( (year == spinupyr_soilequil_1 .or. year == spinupyr_soilequil_2) .and. year <= steering%spinupyears) then
out_steering%do_soilequil = .true.
else
out_steering%do_soilequil = .false.
end if

if ( year<=steering%spinupyears .and. ( year > ( spinupyr_soilequil_1 - steering%recycle ) .and. &
if ( year <= steering%spinupyears .and. ( year > ( spinupyr_soilequil_1 - steering%recycle ) .and. &
year <= spinupyr_soilequil_1 .or. year > ( spinupyr_soilequil_2 - steering%recycle ) .and. &
year <= spinupyr_soilequil_2 ) ) then
out_steering%average_soil = .true.
else
out_steering%average_soil = .false.
end if

if ( year<=steering%spinupyears .and. year <= spinupyr_soilequil_1 ) then
if ( year <= steering%spinupyears .and. year <= spinupyr_soilequil_1 ) then
out_steering%project_nmin = .true.
else
out_steering%project_nmin = .false.
Expand Down

0 comments on commit 8d572ed

Please sign in to comment.