diff --git a/README_FYM_fixes.md b/README_FYM_fixes.md new file mode 100644 index 0000000000..0f01e8e74b --- /dev/null +++ b/README_FYM_fixes.md @@ -0,0 +1,166 @@ +# eCLM_FYM — correctness fixes before production runs + +Branch: `eCLM_FYM_fixes` (branched from `eCLM_FYM`) +All changes are marked in the source with `tboas-fix`. + +Verified: RELEASE and DEBUG builds complete and link (GCC 13, OpenMPI, netCDF 4.9.2, +PnetCDF 1.12.3). + +--- + +## 1. CropType restart state (`src/clm5/biogeochem/CropType.F90`) + +The 12 patch variables added for winter-cereal cold hardening and perennial crop +age were never written to the restart file. They initialise to `spval` (~1e36) +and `huge(1)`, so any restart during hardening or during a perennial's growing +season fed garbage into + + rateh = Hparam*(10-tcrown)*(lt50-lt50max) (CNPhenologyMod:~3324) + fsurv = 2**(-(|tcrown|/|lt50|)**4) + idpp = dayspyr*(kyr-yrop) + jday - idop (CNPhenologyMod:~1802, ~3675) + +`yrop` is an integer, so `kyr - huge(1)` overflowed. + +`yrop`, `lt50`, `wdd`, `rateh`, `rated`, `rates`, `rater`, `fsurv`, `accfsurv`, +`countfsurv`, `ck` and `tcrown` are now restarted. Reading a pre-fix restart file +is handled: `yrop` falls back to the current year and the hardening state falls +back to the values `CropPhenology` assigns at planting (`lt50=-5`, `fsurv=1`, +`accfsurv=1`, `countfsurv=1`, rates `=0`). Both fallbacks log on `masterproc`. + +**This is the fix that matters most for spinup**, because a long spinup is by +definition a restart chain. + +## 2. Manure nitrogen was counted twice + +`manunitro(ivt(p))` was applied in full as immediately-available mineral N +*and* used again, multiplied by `manure_CN_ratio`, to size a pulse of organic +carbon that carried no nitrogen at all. + +Now, when `use_cfert = .true.`: + +* `manure_nh4_frac` (new, default **0.25**) of the manure N goes to the mineral + pool on the existing fertiliser schedule — the ammoniacal fraction. +* the remaining `(1 - manure_nh4_frac)` enters the litter pools as organic N + together with the manure C, at exactly `manure_CN_ratio`, and is mineralised + by the decomposition cascade. This is the DNDC/DayCent convention. +* the manure C is sized from the **organic** N only, so no nitrogen is used twice. +* the `manure_freq_years` / `manure_apply_month` gate now applies to the mineral + part as well. Previously the gate only governed the carbon, so manure N was + applied every year even in years when no manure carbon was. + +With `use_cfert = .false.` the behaviour is unchanged: `manunitro` is treated +purely as mineral fertiliser N, exactly as in stock CLM5. + +Typical `manure_nh4_frac`: ~0.25 solid farmyard manure, ~0.5–0.6 cattle/pig slurry. + +New patch flux `fertN_patch` (history field `Norg_FERT`, gN/m²/s, inactive by +default) mirrors the existing `fertC_patch` / `Corg_FERT`, and is restarted. + +## 3. Mass-conservation checks restored + +`CNBalanceCheckMod` had its abort thresholds hardcoded to `100` gC and gN +m⁻² per timestep — roughly a season of NPP, i.e. the check was off. They are +back at the CLM5 default `1e-7`, now via `cn_balance_tol_c` / `cn_balance_tol_n` +so a tolerance can be widened *deliberately and visibly* while debugging. Any +value above `1e-6` prints a "do not use for production" warning at startup. + +The underlying imbalance is also fixed. `covercrop_switch_ivt` set +`xsmrpool_patch(p) = 0`, and `xsmrpool` is inside `totc_patch` — so that +statement destroyed carbon (or created it, when the pool held a respiration +debt) with no matching flux. It now moves into `xsmrpool_loss_patch`, which is +also inside `totc_patch`, and `CNCStateUpdate1Mod` releases it through +`xsmrpool_to_atm` — a flux the C balance already counts as an output. A branch +was added there so the pool still drains when `dribble_crophrv_xsmrpool_2atm` +is off, which is the default. + +The manure C and N balance terms are now aggregated over active patches only, +matching how `CNCSoilFert` actually applies them. + +## 4. Out-of-bounds write on the PFT table (`pftconMod.F90`) + +`set_is_pft_known_to_model` marked literal indices `27, 28, 55, 56, 59, 60, 65, +66, 78, 79`. `mxpft = 78` and the array is allocated `(0:mxpft)`, so **index 79 +was out of bounds** — trapped in DEBUG, silent heap corruption in RELEASE. And +per `expected_pftnames`, `covercrop_1`/`covercrop_2` are at 77/78, not 78/79, so +the cover-crop pair was off by one and `covercrop_1` was never marked. + +The list is now resolved by name (`nwbarley`, `nirrig_wbarley`, `npotatoes`, +`nirrig_potatoes`, `nrapeseed`, `nirrig_rapeseed`, `nsugarbeet`, +`nirrig_sugarbeet`, `ncovercrop_1`, `ncovercrop_2`) using the same idiom already +used for `apple` and `covercrop_1`, so it survives a change of parameter file. +Each resolved index is range-checked against `[npcropmin, mxpft]` and echoed to +the log with the PFT name found there. + +> Please confirm this name list is what was intended. It was reverse-engineered +> from the literal indices against `expected_pftnames`. + +## 5. Uninitialised landunit index (`CNVegCarbonStateType.F90`) + +In the AD-spinup reseed block, `lun%itype(l)` was read one statement *before* +`l = patch%landunit(i)` was assigned, so it used the previous loop iteration's +value. `l = patch%landunit(i)` now comes first. Confirmed with gfortran: the +pre-fix file emits `'l' may be used uninitialized` at that line; the fixed file +does not. + +`deadstemc_soy` / `deadstemc_storage_soy` / `deadstemn_soy` are also now included +in the x10 / ÷10 AAD-spinup rescaling applied to `deadstemc` / `deadstemn`, since +they are compared against those pools. + +## 6. Per-patch debug writes + +15 `write(iulog,*)` statements in `dynHarvestMod`, `dynCovercropFileMod`, +`CNPhenologyMod` and `CNBalanceCheckMod` fired once per patch, from every MPI +rank, with no `masterproc` guard — on rotation dates that is O(10⁵) lines per +rank at 1 km, and the `coldtolerance` and `cbalance warning` traces fired every +timestep. + +They are now behind `debug_covercrop`, a `logical, parameter` in `clm_varctl` +(default `.false.`), so the compiler removes them entirely. Set it to `.true.` +and rebuild for single-point debugging. + +--- + +## New namelist variables (`&cfert_inparm`) + +| Variable | Type | Default | Meaning | +|---|---|---|---| +| `manure_nh4_frac` | real | 0.25 | Ammoniacal fraction of applied manure N. The rest becomes organic N in litter. Range-checked to [0,1]. | +| `cn_balance_tol_c` | real | 1e-7 | C mass-conservation abort threshold, gC/m²/timestep. | +| `cn_balance_tol_n` | real | 1e-7 | N mass-conservation abort threshold, gN/m²/timestep. | + +The Python namelist generator does not need to know about these; the Fortran +defaults apply when they are absent from `lnd_in`. + +## Also worth setting, unchanged by this branch + +`use_grainproduct = .true.`. It defaults to `.false.`, and when false +`grainc_to_food` is routed into `litfall` (`CNVegCarbonFluxType:~4367`) — the +harvested grain never leaves the domain and is eventually respired back, which +biases cropland NEE/NBP. + +## 7. Calendar-date manure application + +`manure_apply_month > 0` never worked: the gate sat inside the leaf-emergence +onset block, which fires on a single timestep once per season, so a fixed +calendar date essentially never coincided with it and the manure was silently +never applied. Only `manure_apply_month = 0` was functional. + +The date-driven case is now handled at the top of the crop patch loop, where it +is reached every timestep, and the onset path is restricted to +`manure_apply_month == 0` so the two cannot both fire. Only the organic C and N +are date-driven; the ammoniacal fraction stays on the standard fertiliser +schedule, metered from onset over `ndays_on`, since that is plant-available N. +The `manure_freq_years` gate now applies to the ammoniacal N on both paths. + +Because the new block sits before the perennial branch, fruit-tree patches also +receive manure for the first time -- `FruitTreePhenology` writes no `fertC` / +`fertN` of its own, so with `manure_apply_month = 0` perennials still get none. + +## Not addressed here + +* The single-timestep manure C pulse (`fertC = manureC / dtrad`) is kept, as + requested. It is numerically violent; if the balance check trips at a manure + application date, spreading it over `ndays_on` is the first thing to try. +* In `CNNStateUpdate1Mod`, the perennial-woody branch skips + `livestemn_to_litter` while `CNPhenologyMod` may still route that flux into + the litter pools. If the N balance trips on fruit-tree patches, look there. diff --git a/README_covercrop_changes.md b/README_covercrop_changes.md new file mode 100644 index 0000000000..4ed27f9795 --- /dev/null +++ b/README_covercrop_changes.md @@ -0,0 +1,257 @@ +# eCLM Cover-Cropping Implementation — Source Code Changes + +**Branch:** `eCLM_FYM` on fork `tboas/eCLM` +**Base:** HPSCTerrSys/clm5_0 +**Author:** T. Boas +**Date:** July 2026 + +--- + +## Overview + +This document describes all source code changes introduced to implement +optional, file-driven cover-crop rotation in eCLM (CLM5). The implementation +is fully backward compatible: with `use_covercropping = .false.` (default), +the model behaves identically to the unmodified CLM5. + +--- + +## Design Goals + +1. **Backward compatibility** — old parameter files (79 PFTs) and old namelists + work unchanged when `use_covercropping = .false.` +2. **File-driven rotation** — crop sequence defined externally via a transient + land-use file, not hardcoded in the source +3. **Spatial** — works for point cases and regional/global domains identically +4. **Timing** — PFT switch happens immediately after cash crop harvest, within + the same calendar year, enabling fall planting of winter crops and cover crops +5. **Separate param file** — cover-crop PFT physiology in a dedicated param file, + keeping the standard param file untouched + +--- + +## New Namelist Parameters + +Added to `&clm_inparm` in `lnd_in`: + +| Parameter | Type | Default | Description | +|---|---|---|---| +| `use_covercropping` | logical | `.false.` | Enable cover-crop rotation | +| `covercrop_paramfile` | character(256) | `' '` | Param file containing `covercrop_1/2` PFTs and `covercrop` flag array | +| `transient_landuse_file` | character(256) | `' '` | NetCDF file defining `PCT_CFT(time, cft, lndgrid)` crop rotation sequence | + +--- + +## Transient Land-Use File Format + +Required when `use_covercropping = .true.`: + +``` +dimensions: + time = N (number of years in rotation) + cft = 64 (number of crop functional types, must match model) + lndgrid = M (number of gridcells; 1 for point cases) + +variables: + int YEAR(time) -- calendar year for each time slice + real PCT_CFT(time, cft, lndgrid) -- CFT fractions 0-100% + real PCT_CROP(time, lndgrid) -- total crop area fraction +``` + +Each year, one CFT has 100% and all others have 0%. +The CFT index maps to CLM5 PFT index as: `PFT_index = CFT_index + cft_lb` +where `cft_lb = natpft_ub + 1 = 15`. + +--- + +## Files Modified + +### 1. `src/clm5/main/clm_varctl.F90` + +**What changed:** Added two new public character variables. + +```fortran +! Added after: logical, public :: use_covercropping = .false. +character(len=256), public :: transient_landuse_file = ' ' +character(len=fname_len), public :: covercrop_paramfile = ' ' +``` + +--- + +### 2. `src/clm5/main/controlMod.F90` + +**What changed:** Added both new variables to the `clm_inparm` namelist and +added MPI broadcasts so all tasks receive the values. + +```fortran +! Added to namelist declarations: +namelist /clm_inparm/ covercrop_paramfile +namelist /clm_inparm/ transient_landuse_file + +! Added to MPI broadcast section (after use_covercropping broadcast): +call mpi_bcast(covercrop_paramfile, len(covercrop_paramfile), MPI_CHARACTER, 0, mpicom, ier) +call mpi_bcast(transient_landuse_file, len(transient_landuse_file), MPI_CHARACTER, 0, mpicom, ier) +``` + +--- + +### 3. `src/clm5/main/pftconMod.F90` + +**What changed:** Replaced the covercrop flag read block so that: +- With `use_covercropping = .false.`: `covercrop(:) = 0`, nothing read from any file +- With `use_covercropping = .true.`: opens `covercrop_paramfile` separately and reads + the `covercrop` flag array from there; aborts clearly if file not set + +**Before:** +```fortran +!Cover crop flag read-in +if (use_covercropping) then + call ncd_io('covercrop', this%covercrop, 'read', ncid, readvar=readv) + if (.not. readv) call endrun(...) +else + this%covercrop(:) = 0._r8 +end if +``` + +**After:** +```fortran +!Cover crop flag read-in --- tboas +! Default: zero array — backward compatible with standard 79-PFT param file. +this%covercrop(:) = 0._r8 +if (use_covercropping) then + if (trim(covercrop_paramfile) == '' ...) call endrun(clear error message) + block + ! Open covercrop_paramfile separately + call ncd_pio_openfile(ncid_cc, covercrop_paramfile, 0) + call ncd_io('covercrop', this%covercrop, 'read', ncid_cc, readvar=readv) + if (.not. readv) call endrun(...) + call ncd_pio_closefile(ncid_cc) + end block +end if +``` + +**Key point:** The standard `paramfile` (79 PFTs) is never touched for covercrop +reads. Only the separate `covercrop_paramfile` (81 PFTs with `covercrop_1/2`) is +opened when the flag is on. + +--- + +### 4. `src/clm5/biogeochem/dynHarvestMod.F90` + +**What changed:** +- Added `use dynCovercropFileMod, only: covercrop_switch_ivt` +- Removed hardcoded cash crop rotation (`nswheat`, `nsugarbeet`, + `ncovercrop_1/2` logic with fixed DOY thresholds) +- `covercropping_update_patch` now delegates entirely to `covercrop_switch_ivt` +- Moved from phenology path → transient land-use/harvest update path + (called from `dynSubgridDriverMod` after harvest) + +**Before (hardcoded):** +```fortran +cashcrop1 = nswheat +cashcrop2 = nsugarbeet +if (harvdate(p) >= 150 .and. ivt(p) == cashcrop1) then + ivt(p) = covercrop1 + ... +else if (harvdate(p) <= 170 .and. ivt(p) == covercrop1) then + ivt(p) = cashcrop2 + ... +! etc — fixed wheat/sugarbeet/covercrop sequence +``` + +**After (file-driven):** +```fortran +! Only act on patches flagged as cover-crop rotation members +if (covercrop(ivt(p)) /= 1) return +! Only switch after harvest has occurred this season +if (harvdate(p) <= 0) return +! Delegate to file-driven rotation in dynCovercropFileMod +call covercrop_switch_ivt(p, crop_inst, cnveg_state_inst) +``` + +--- + +### 5. `src/clm5/dyn_subgrid/dynSubgridDriverMod.F90` + +**What changed:** Added init and interp calls for the new `dynCovercropFileMod`. + +```fortran +! Added use statement: +use dynCovercropFileMod, only: dyncovercrop_init, dyncovercrop_interp + +! In dynSubgrid_init, after dynHarvest_init: +if (use_covercropping) call dyncovercrop_init(bounds_proc) + +! In dynSubgrid_driver, after dyncrop_interp: +if (use_covercropping) call dyncovercrop_interp(bounds_proc) +``` + +--- + +### 6. `src/clm5/dyn_subgrid/dynCovercropFileMod.F90` *(NEW FILE)* + +New module implementing the file-driven rotation. Three public subroutines: + +#### `dyncovercrop_init(bounds)` +- Called once at startup from `dynSubgridDriverMod` +- Opens `transient_landuse_file` +- Validates `cft` dimension matches model +- Allocates `pct_cft_cur(begg:endg, cft_size)` and `pct_cft_next(begg:endg, cft_size)` +- Calls `dyncovercrop_interp` to load first two time slices +- Aborts clearly if `transient_landuse_file` not set + +#### `dyncovercrop_interp(bounds)` +- Called every timestep from `dynSubgridDriverMod` +- Updates `pct_cft_cur` and `pct_cft_next` for current model year +- Uses `dyn_var_time_uninterp_type` (same infrastructure as `dyncropFileMod`) +- `pct_cft_next` holds the NEXT year's crop fractions — used for post-harvest + planting decisions (winter crops planted in fall of current year) + +#### `covercrop_switch_ivt(p, crop_inst, cnveg_state_inst)` +- Called per-patch from `covercropping_update_patch` after harvest +- Finds dominant CFT in `pct_cft_next` for this gridcell `g = patch%gridcell(p)` +- Converts CFT index to global PFT index: `new_ivt = cft_lb + best_cft - 1` +- Only switches if new PFT differs from current +- Resets `croplive`, `cropplant`, `idop` so new PFT starts fresh +- Sets `use_grainproduct = .false.` for cover crops, `.true.` for cash crops + +--- + +### 7. `src/clm5/CMakeLists.txt` + +Added new module to build system: + +```cmake +dyn_subgrid/dynCovercropFileMod.F90 +``` + +--- + +## Cover-Crop Param File + +The `covercrop_paramfile` must contain: +- `pft` dimension = 81 (79 standard + covercrop_1 + covercrop_2) +- `pftname` array with `covercrop_1` at index 77, `covercrop_2` at index 78 +- `covercrop(pft)` integer flag array: `1` for all PFTs that participate in + rotation (cash crops + cover crops), `0` for all others +- Full physiology for covercrop_1 and covercrop_2 PFTs + +File used for DE-RuS Selhausen: +``` +/p/project1/cjicg41/jicg4180/clm5_params.c171117_boas_cc34_on_mod5_hybgdd950_apple_perennial_0.nc +``` + +--- + +## Backward Compatibility Matrix + +| Scenario | Behaviour | +|---|---| +| `use_covercropping = .false.` (default) | Identical to unmodified CLM5. No files read, `covercrop(:)=0`, rotation logic skipped entirely | +| Old 79-PFT param file + flag off | Works unchanged | +| `use_covercropping = .true.`, no `covercrop_paramfile` | Clean `endrun` with message pointing to missing namelist key | +| `use_covercropping = .true.`, no `transient_landuse_file` | Clean `endrun` with message pointing to missing namelist key | +| `use_covercropping = .true.`, both files set | Full file-driven rotation active | + +--- + diff --git a/REVIEW_FYM_vs_master.md b/REVIEW_FYM_vs_master.md new file mode 100644 index 0000000000..48bda02871 --- /dev/null +++ b/REVIEW_FYM_vs_master.md @@ -0,0 +1,133 @@ +# eCLM_FYM vs. master: functional review of `src/clm5` + +** AI GENERATED ** + +- Branch: `eCLM_FYM_fixes_merged_with_master` at `e79767641a` +- Compared with: `master` at `e113460a91` +- Date: 2026-09-29 + +The line numbers below refer to the branch at `e79767641a`. + +Whitespace, blank-line and file-mode artefacts were already cleaned up +before this review. See the commits "remove whitespace" and "src: mode +changes of several files". + +## Summary + +**With all FYM switches off (`use_cfert`, `use_covercropping`, +`use_fruittree`), the branch does not behave like master.** + +The new features themselves are mostly switched properly, but several +crop changes apply to every crop run, and a few look like bugs. + +## A. Changes to default crop runs that have no switch + +All of these are in `src/clm5/biogeochem/CNPhenologyMod.F90` unless noted. + +1. **Winter cereals use a different model.** For winter wheat, and for + winter barley and rapeseed when active: + - `vernalization_2` (Lu et al. 2017) replaces master's + `vernalization` (:2751). The old routine is now dead code. + - a new `coldtolerance` routine runs in phase 2 and moves leaf C + and N to litter as frost damage (:2791) + - seeding adds `frootc_xfer = 0.1` (:2431, :2485) + - on 1 January, a living winter crop now gets `cropplant = .true.` + where master sets `.false.` (:2350) + - new rule: after day 170, a winter wheat patch that isn't growing + is reset to "not planted" (:2357) +2. **Maize and sugarcane maturity changed.** At normal planting, + `gddmaturity = hybgdd` replaces master's climate-adjusted `max(950, + min(gdd820*0.85, hybgdd))` formula (:2540). This affects every + maize patch. +3. **Probable bug: soybean matures immediately.** The soybean + `gddmaturity` rule at normal planting is commented out (:2533). The + value then stays at the 0 it was reset to while unplanted, so `hui + >= gddmaturity` is true right away. Temperate soybean exists in + default CLM5 runs. A single-point run with soybean would confirm + it. +4. **Tropical soybean lost its special handling.** It is still an + active PFT, but no longer gets the soybean maturity rule or the + stem-allocation exception in both `NutrientCompetition*Mod` + (e.g. `NutrientCompetitionFlexibleCNMod.F90:1838`). +5. **Six more crop types become active PFTs.** `pftconMod.F90:1413` + marks barley, winter barley, winter rye, potatoes, rapeseed and + sugar beet (plus irrigated versions) as "known to model". In master + these areas are merged into the standard CLM5 crops. With real + surface data, the patch structure changes, and in turn items 1 and + 2 apply to these crops. Sugar beet and potato also get `gddmaturity + = hybgdd` (:2547, :2603). +6. **The N balance check is 10,000x stricter.** In master the run + aborts when `|col_errnb| > 1e-3`. In the branch the threshold is + `cn_balance_tol_n`, default `1e-7` + (`CNBalanceCheckMod.F90:379`). The comment in `clm_varctl.F90` says + the defaults are "the stock CLM5 values", but that's only true for + C. Runs that pass on master could abort here. + +## B. Changes that are properly switched off by default + +- **Manure (`use_cfert`)** is clean. With it off, `fert` is computed + exactly as in master, and `CNCSoilFert` returns early. +- **Cover crops (`use_covercropping`)**: `dynCovercropFileMod`, + `covercropping_update` and the rotation dates are all behind the + switch. With it off, `ncovercrop_1/2 = 0`, which never matches a + crop patch. +- **Fruit trees (`use_fruittree`)**: with it off, `perennial = 0` for + every PFT. That disables all the `perennial(ivt)==1` branches in + about 10 modules (allocation, state updates, pruning, orchard + rotation, respiration, FUN, gap mortality) and `FruitTreePhenology` + itself. +- **Tree allometry**: `taper` and `nstem` fall back to master's + hard-coded values (200 or 10 for shrubs, and 0.1) when they're + missing from the parameter file. + +## C. Bugs to verify + +- **`CNVegCarbonStateType.F90:1473`** (Restart, reseeding block): the + loop runs over `i` but tests `patch%itype(p)`, where `p` is a + leftover value from an earlier loop. Also, non-woody PFTs no longer + get `deadstemc = 0`. This only matters with `reseed_dead_plants = + .true.`. +- **`CNRotationToColumn`** (`CNPhenologyMod.F90`): its final loop adds + `pwood_harvestc` for *all* active patches. `CNLitterToColumn` has + already added it for pruned fruit trees, so pruning wood harvest + appears to be counted twice when fruit trees are on. It adds 0 in + default runs. + +## D. Cosmetic changes with no effect on results + +- **Deleted comments.** + - `CNNDynamicsMod.F90`: apart from the new `CNCSoilFert`, the whole + diff consists of master's comments being deleted. It could be + rebuilt as master plus that one routine, which removes about 250 + lines from the diff. + - `clm_varctl.F90`: the argument comments of `clm_varctl_set` were + deleted as well. +- **`controlMod.F90`**: + - `covercrop_paramfile` and `transient_landuse_file` are each + declared twice in `clm_inparm` (:228-231). + - The comment "this broadcast was lost" (:620) describes a bug that + existed only on the FYM branch. Master already broadcasts + `use_grainproduct`, so the comment can go. +- **`TemperatureType.F90`**: a `T24` accumulator is defined but never + used. +- **`PatchType.F90`**: comments were renamed from citrus to apple and + from tropical soybean to cover crop. These are only true when the + switches are on. +- **Commented-out code**: examples are the old `vernalization` and + `coldtolerance` calls in `CNPhenologyMod.F90` (2735-2765), the + `fun_cn_flex_c` writes in `CNFUNMod.F90` (1233-1253), + `CNVegCarbonStateType.F90` (958-965) and `CNVegStateType.F90` + (531-544). + +## Recommendation + +If this is heading toward master, the rule should be that **all +switches off means identical to master**: + +- **Put behind a switch:** A1, A2, A5 and the sugar beet/potato + part. They could be tied to the FYM crop-calendar setup or get their + own switch. +- **Restore master's behaviour:** A3 and A4, and change the + `cn_balance_tol_n` default to `1e-3` (A6). +- **Start with A3 and A6:** they're small, clear-cut fixes, and A3 + probably also affects FYM results that have soybean patches. diff --git a/docs/Case_setup_FYM_branch.md b/docs/Case_setup_FYM_branch.md new file mode 100644 index 0000000000..4ab1eb088b --- /dev/null +++ b/docs/Case_setup_FYM_branch.md @@ -0,0 +1,277 @@ +# Setting up a case on `eCLM_FYM_fixes` + +A working-level guide to building this branch and running a case two ways: +unchanged, as a drop-in replacement for an existing single-crop setup, and +then with the branch's own functionality — prognostic crop rotation and +organic-fertiliser (FYM) carbon routing — enabled. Written for someone who +already runs eCLM/CLM5 cases; it does not re-explain CIME/CTSM case +mechanics. For what each feature actually does and why, see +[`eCLM_FYM_branch_guide.md`](eCLM_FYM_branch_guide.md) in this same +directory — this document is the "how", that one is the "what". + +## 0. Prerequisites + +- A working single-crop eCLM/CLM5 case at your target site or domain, already + building and running on `master` or an earlier branch. This tutorial + extends that case; it does not build one from scratch. +- Build toolchain: GCC 13 / gfortran, OpenMPI (`mpicc`/`mpifort`), + netCDF-C/Fortran, PnetCDF, LAPACK. If any of `gfortran`, `mpifort`, + `nc-config`, `nf-config`, `pnetcdf-config` are missing, install via your + system's package manager before proceeding. +- The reference parameter file in [`params/`](params/) alongside this + document, or your own parameter file built on the same PFT ordering (see + §3 below for why the ordering matters and how to check it). + +## 1. Build + +This branch adds public module entities (new namelist variables in +`clm_varctl.F90`, extended arrays in `pftconMod.F90`). A build directory left +over from an earlier branch will use stale `.mod` files and fail or silently +misbehave — always rebuild from a clean build directory when switching onto +this branch for the first time: + +```bash +git checkout eCLM_FYM_fixes +git log --oneline -3 # sanity check you're where you think you are + +rm -rf /* +# re-run your normal cmake configure step, then: +cmake --build --parallel 8 +cmake --install --prefix +``` + +## 2. Part A — backward-compatible run + +Before touching any of this branch's new functionality, confirm the build +itself is sound by running your existing single-crop case unchanged. This +isolates build/toolchain problems from feature-specific ones later. + +```fortran +&clm_inparm + use_covercropping = .false. + use_fruittree = .false. + use_cfert = .false. + paramfile = '.nc' +/ +``` + +Both flags default to `.false.`, so an existing `lnd_in` that never mentions +them is already in this state — you can run it as-is. Two things to expect +that are specific to this branch, not failures: + +- **`CropType.F90` restart fallback.** This branch restarts 12 crop state + variables (`yrop`, `lt50`, `wdd`, and others) that earlier code left + un-restarted. If you're initializing from a restart file written before + this branch existed, those fields are absent and the run falls back to + planting-time defaults — logged once per masterproc, not an error. Confirm + it appears once, not repeatedly: + ```bash + grep -iE 'fallback|yrop|lt50' /logs/*.comp_lnd.log | head + ``` +- **`taper`/`nstem` fallback**, if your parameter file predates this branch's + optional handling of those fields — same pattern, logged once: + ```bash + grep -iE 'taper|nstem' /logs/*.comp_lnd.log | head + ``` + +If this run reproduces your pre-branch results (bit-for-bit, or within +expected tolerance if your case has an inherent source of run-to-run +variation), the build is sound and any issue you hit later is +feature-specific, not a build problem. + +## 3. Part B1 — crop rotation + +### Prepare the rotation file + +Use [`tools/make_rotation_landuse.py`](tools/make_rotation_landuse.py) in +this directory. First, find the exact crop names in the parameter file your +case will use — **read them from the file itself, never assume a fixed +index table**. PFT/CFT index-to-name mappings are not guaranteed stable +across parameter files, and hardcoded indices have caused real, silent bugs +in this branch's own history: + +```bash +python3 tools/make_rotation_landuse.py --paramfile .nc --list-crops +``` + +Edit the `ROTATION` and `DOMAIN` blocks at the top of the script using the +exact names printed above, then build: + +```bash +python3 tools/make_rotation_landuse.py --paramfile .nc -o .nc +``` + +Convention to keep straight while editing `ROTATION`: **year N is the crop +harvested in year N.** A winter crop entered for 2015 is sown in autumn +2014, not 2015 — the entry still goes under `2015` in the list. + +### Set the namelist flags + +```fortran +&clm_inparm + use_fruittree = .true. + use_covercropping = .true. + paramfile = '.nc' + covercrop_paramfile = '.nc' + transient_landuse_file = '.nc' +/ +``` + +`paramfile` and `covercrop_paramfile` **must point to the same file** — the +cover-crop flag array and the `covercrop_1`/`covercrop_2` entries are read +from `covercrop_paramfile` specifically, and a mismatch here silently reads +crop parameters and cover-crop flags from two different sources. Both flags +default to `.false.`, so an existing case is unaffected until you set them. + +### Request diagnostics + +Add to `hist_fincl1`: + +``` +IVT, CPHASE, GDDPLANT, GRAINC +``` + +`IVT` is the rotation itself (active crop PFT index) and is only registered +when `use_covercropping = .true.` — requesting it otherwise aborts the run +at initialization. + +### Run + +Submission is otherwise unchanged. Two requirements specific to a rotation +run: + +- Atmospheric forcing must cover the full rotation period — cyclic forcing + is not supported. +- The transient land-use file must span the simulated years. + +The first simulated year inherits its crop from the restart file, not from +the rotation logic — treat it as spin-up when checking results. + +### Verify + +Switching events are written to the land component log: + +```bash +grep CCROT /*.comp_lnd.log +``` + +Expect one switching event per crop transition in the prescribed sequence; a +much larger count indicates a configuration problem (often a rotation file +that doesn't span the run, or a mismatched `paramfile`/`covercrop_paramfile` +pair). Cross-check the simulated sequence against what you prescribed: + +```bash +ncdump -v IVT .clm2.h0.*.nc +``` + +## 4. Part B2 — organic fertiliser (FYM) carbon + +In the default model, manure nitrogen enters the mineral nitrogen pool +directly with no associated carbon — farmyard manure has no effect on soil +organic carbon. This branch routes it as both a carbon and a nitrogen input. + +### Namelist + +```fortran +&clm_inparm + use_cfert = .true. +/ +&cfert_inparm + manure_CN_ratio = 25.0 + manure_fmet = 0.60 + manure_fcel = 0.30 + manure_flig = 0.10 + manure_injection_depth = 0.0 + manure_freq_years = 1 + manure_nh4_frac = 0.25 + manure_apply_month = 0 + manure_apply_day = 1 + cn_balance_tol_c = 1.0e-7 + cn_balance_tol_n = 1.0e-7 +/ +``` + +Values above are the defaults; `cfert_inparm` is optional — omit it entirely +and these are used. `use_cfert` defaults to `.false.`, so an existing case is +unaffected until set. + +**What `manunitro` means now.** The per-crop-PFT rate in the parameter file +is *total* manure nitrogen. Only `(1 - manure_nh4_frac)` of it is immediately +mineral; the rest enters the litter pools as organic nitrogen alongside +carbon at `manure_CN_ratio`: + +``` +manureC = (1 - manure_nh4_frac) * manunitro * 1000 * manure_CN_ratio +mineral N = manunitro * 1000 * manure_nh4_frac +organic N = manunitro * 1000 * (1 - manure_nh4_frac) +``` + +`manure_nh4_frac ≈ 0.25` for solid FYM, `≈ 0.55` for slurry. + +**The calibration tradeoff.** At a fixed `manure_CN_ratio`, `manunitro` can +reproduce a target carbon input or a target total-nitrogen input, but not +both independently — moving one moves the other. If your target carbon input +(from a soil-carbon comparison) implies an unrealistic total nitrogen rate, +`manure_CN_ratio` is the correct lever, not `manunitro`: + +``` +manure_CN_ratio = C_org_target / (N_tot * (1 - manure_nh4_frac)) +``` + +Worked example: 20 t/ha solid FYM applied, target carbon input 108 gC/m²/yr, +`manure_nh4_frac = 0.25`. Solving forward at `manure_CN_ratio = 25`: +`manunitro = 108 / 25 / 0.75 / 1000 = 0.00576` → total N = 57.6 kgN/ha, +mineral N = 14.4 kgN/ha, organic N = 43.2 kgN/ha. Sanity-check the resulting +total N against an independent estimate for your site (typical FYM carries +roughly 5 kgN per tonne fresh mass) before committing to a value. + +**Timing.** The full amount applies within a single timestep. +`manure_apply_month = 0` applies at the onset of crop growth (gated by the +same `manure_freq_years` interval as ammoniacal N); a non-zero month/day +applies on that fixed calendar date instead, independent of onset timing. +`manure_freq_years` sets the application interval for biennial or less +frequent amendment. + +**Vertical placement.** `manure_injection_depth = 0.0` puts carbon in the +surface layer only (surface spreading). A positive depth distributes it over +soil layers down to that depth (incorporation). + +**Balance checks are live**, not effectively disabled — tolerances default +to `1e-7`, not the historical `100`. A run that used to complete under the +old, effectively-disabled tolerance may now abort. If it aborts specifically +on a manure application date, the correct fix is spreading the pulse over +the crop's `ndays_on` window rather than widening `cn_balance_tol_c`/`_n` — +widening the tolerance defeats the purpose of tightening it in the first +place. + +### Diagnostics + +`Corg_FERT` (gC m⁻² s⁻¹) and `Norg_FERT` reports the applied organic +carbon/nitrogen flux and are registered when `use_cfert` is set. Add them to +`hist_fincl1` and confirm one spike per application year, at the expected +date and magnitude: + +```bash +grep -i 'balance' /logs/*.comp_lnd.log | head +``` + +## 5. Running both together + +Rotation and organic fertiliser are independent flags and combine directly — +set both blocks above in the same `lnd_in`. This is the realistic +configuration for a real farm management sequence: a prescribed crop +rotation with periodic FYM application, rather than either in isolation. +There is no separate "combined" namelist group to configure. + +## 6. Reverting to a single-crop configuration + +Set `use_covercropping = .false.` and `use_fruittree = .false.` and supply +the legacy parameter file. No other change is required — the rotation code +paths are not entered, matching Part A above. + +## 7. Verification checklist + +Beyond the feature-specific checks above, before trusting results from a new case on this branch: + +use_grainproduct is actually active on every rank. This branch fixed a dropped MPI broadcast that previously left it .false. on every rank but 0. If you're comparing against results generated before this fix, expect a real difference: harvested grain carbon now leaves the litter pool instead of returning to it on every rank, not just rank 0. +PFT/CFT indices, if you or a script hardcode any crop-PFT index rather than resolving it from pftname (as make_rotation_landuse.py does) — check it against the actual parameter file in use. This has been the single most common source of silent, wrong-answer bugs in this branch diff --git a/docs/index_eCLM_FYM_implementation_matrix.html b/docs/index_eCLM_FYM_implementation_matrix.html new file mode 100644 index 0000000000..47e78a149f --- /dev/null +++ b/docs/index_eCLM_FYM_implementation_matrix.html @@ -0,0 +1,525 @@ + + + + + +eCLM_FYM Implementation Map + + + + + + + + +
+ +
+
Model development · branch eCLM_FYM_fixes
+

Organic fertiliser carbon and prognostic crop rotation in eCLM

+

Two coupled developments on the CLM5 crop model: manure carbon and nitrogen routed + through the litter and mineral pools rather than entering as nitrogen alone, and a + calendar-driven rotation that switches crop type between seasons and admits winter cover + crops. This page maps what the code does and which namelist options control it.

+
tboas/eCLM · eCLM_FYM_fixes · point sites Dikopshof, Hoosfield, Selhausen + regional DE009
+
+ +
+

Where the manure goes

+

Click any box for the detail. The switches change what is active, exactly as the + namelist does — turn use_cfert off and the whole amendment branch goes dark.

+ +
+ + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + manunitro × 1000 + split by nh4_frac + immediate + C:N = 25 + × CN ratio + fmet / fcel / flig + + + Application gatemanure_apply_month + + Manure N ratemanunitro (gN m⁻² yr⁻¹) + + N speciationmanure_nh4_frac + + Ammoniacalmineral N + + Organic N1 − nh4_frac + + Manure carbonCorg_FERT + + SMINNuptake · N₂O + + Litter NLITR1–3 N + + Litter C poolsLITR1 / LITR2 / LITR3 + + Soil organic matterTOTSOMC + + N₂ONIT + DENIT + + Crop rotationPCT_CFTPCT_CFT_WINTERplanting event + + +
+ +
+

Pick a box

+
the map
+

Every arrow here is a mass transfer in the code. The dashed green arrow is + the coupling people usually miss: manure is released on a planting event, so a + crop that never plants receives no manure — even when every manure namelist value is correct.

+
+
+
+ +
+ Delivered ≠ nominal. The rate reaching the soil is three quarters of + manunitro × 1000 × manure_CN_ratio. Verified against Dikopshof: nominal 144 + gC m⁻² yr⁻¹ produced a measured Corg_FERT of 4.032258 × 10⁻⁵ gC m⁻² s⁻¹ over a + 31-day month — exactly 108 gC m⁻² yr⁻¹, the Herbst target. +
+
+ +
+

Delivered rate

+

What a given manunitro actually puts into the soil, and the nitrogen that + rides with it.

+
+
+ + +
+
+ + +
+
+ + +
+
+
100.0
gC m⁻² yr⁻¹ delivered
+
53.3
kg N ha⁻¹ yr⁻¹ total
+
13.3
kg N ha⁻¹ mineral
+
40.0
kg N ha⁻¹ organic
+
+
+
+ The site targets are 108 (Dikopshof), 300 (Hoosfield) and 100 (Selhausen) gC m⁻² yr⁻¹. + Holding carbon at those values fixes the nitrogen that comes with it, and the two cannot + both be matched at a fixed C:N — at Selhausen the implied 53 kg N ha⁻¹ is well under the + ~125 kg N ha⁻¹ a 25 t ha⁻¹ application would carry. The honest lever there is + manure_CN_ratio, not manunitro. +
+
+ +
+

The rotation year

+

Three calendar decisions govern which crop stands on the patch. The switch is by date, + not by phenology, which is why a late-harvested summer crop can push its successor into the + following year.

+ +
+
+
31 Mar
+
1 Apr
+
1 Sep
+
+
+ JFMAMJ + JASOND +
+
+ +
+
+
31 Mar
+
+

Terminate a standing cover crop

+

If the crop on the patch is not this year's crop in the rotation file, it is a cover + crop. It is forced through harvest by zeroing gddmaturity and + huigrain — the same idiom as the cold-kill path in CNPhenologyMod. + itype is deliberately left alone so that residue is partitioned with the + cover crop's lf_flab / fcel / flig.

+
+
+
+
1 Apr
+
+

Switch to this year's crop

+

itype becomes pct_cft_cur. CropPhenology then + plants it inside its own min/max planting window. A crop whose window has already closed + waits until the next one opens — which is how a year can end with no harvest at all.

+
+
+
+
1 Sep
+
+

Look ahead to next year

+

If the patch is bare, next year's crop (pct_cft_next) is inspected and + adopted only when it is autumn-sown — min_NH_planting_date > 0700. A + spring-sown successor is left for the following April. A summer crop still standing is + left to finish.

+
+
+
+
+ +
+

Namelist reference

+

Every option the two developments add, with the values used for the manuscript runs.

+
+ + + + + + + + + + + + + + + + + + + + + +
OptionValue usedGroupWhat it does
use_cfert.true. / .false.carbonMaster switch for the organic amendment. Off makes the case a control.
manure_CN_ratio25.0carbonCarbon added per unit organic manure N. Sets the C input for a given N rate.
manure_nh4_frac0.25nitrogenFraction entering as ammoniacal N, available immediately; the rest is organic.
manure_fmet0.60carbonMetabolic share of manure C → LITR1.
manure_fcel0.30carbonCellulose share → LITR2.
manure_flig0.10carbonLignin share → LITR3. The three must sum to one.
manure_injection_depth0.0carbonDepth of incorporation; zero is surface application.
manure_apply_month0carbon0 applies at the planting event; a real month applies on that calendar date instead, decoupling manure from the crop.
manure_apply_day1carbonDay within the application month.
manure_freq_years1carbonApplication interval in years.
use_covercropping.true.rotationEnables the calendar rotation switch and the winter cover-crop slot.
transient_landuse_file*_landuse.ncrotationPer-year crop sequence. PCT_CFT is the main slot, PCT_CFT_WINTER the cover crop.
covercrop_paramfileclm5_params_*.ncrotationParameters for the cover-crop PFTs (77, 78).
use_fruittree.true.rotationEnables the perennial fruit-tree crop types.
use_grainproduct.true.carbonSends harvested grain to a product pool instead of returning it to litter.
cn_balance_tol_c1e-7carbonCarbon balance tolerance, now namelist-controlled — was hardcoded at 100, i.e. effectively disabled.
cn_balance_tol_n1e-7nitrogenNitrogen balance tolerance.
+
+
+ +
+

Defects found and fixed

+

Correctness fixes made while getting these runs to a publishable state. Several were + silent — the model ran and produced plausible output while doing the wrong thing.

+
+ + + + + + + + + + + + +
ModuleDefectWhy it mattered
pftconModPFT index resolved by hardcoded literal, one out of boundsOut-of-bounds write at index 79 — silent heap corruption in RELEASE builds. Resolution now by name.
CropType12 crop state variables not written to restartCold-hardening state lost on every restart; now written, with a fallback for old files.
controlModuse_grainproduct broadcast droppedOnly rank 0 saw the correct value, so harvested grain returned to litter on every other rank.
CNPhenologyModmanure_apply_month gate invertedAny non-zero value silently applied no manure at all.
CNVeg*StateTypeAD-spinup reseed used l before assignmentRescaling applied to the wrong column; deadstem pools were also missing from the rescale.
dynCovercropFileModCover-crop switch zeroed xsmrpoolMass was destroyed at every switch; now moved to a loss pool with a paired drain.
rotation terminationUnguarded branch on PFT switchKilled every two-crop rotation without an intervening cover crop — control runs included.
CNBalanceCheckModTolerance hardcoded at 100The balance check could not fail. Now namelist-controlled at 1e-7 and passing at regional scale.
+
+
+ +
eCLM_FYM_fixes · Dikopshof · Hoosfield · Selhausen · DE009
+
+ + + + diff --git a/docs/params/clm5_params_eCLM_FYM_reference.nc b/docs/params/clm5_params_eCLM_FYM_reference.nc new file mode 100644 index 0000000000..618611ffcb Binary files /dev/null and b/docs/params/clm5_params_eCLM_FYM_reference.nc differ diff --git a/docs/params/clm5_params_manunitro0006_default.nc b/docs/params/clm5_params_manunitro0006_default.nc new file mode 100644 index 0000000000..69f9fdc08f Binary files /dev/null and b/docs/params/clm5_params_manunitro0006_default.nc differ diff --git a/docs/params/variables.txt b/docs/params/variables.txt new file mode 100644 index 0000000000..023ed22a5e --- /dev/null +++ b/docs/params/variables.txt @@ -0,0 +1,109 @@ +cat > variables.txt < variables.txt <.nc --list-crops + + # 2. Edit the ROTATION and DOMAIN blocks below using those exact names. + + # 3. Build the file: + python3 make_rotation_landuse.py --paramfile .nc -o .nc + +`.nc` must be the SAME file passed as both `paramfile` and +`covercrop_paramfile` in the case's lnd_in — the CFT ordering has to match +what the running executable actually reads. +""" +import argparse +import sys + +import numpy as np +import netCDF4 as nc + + +# ============================================================================= +# 1. ROTATION — edit this. One entry per simulated year. +# +# year : calendar year. Per this branch's convention, "year N is the +# crop harvested in year N" — a winter crop entered for 2015 is +# sown in autumn 2014, not 2015. +# main : the main (current-year) crop, harvested that year. +# winter : optional winter cover crop sown in autumn of that year, or +# None to leave the winter slot empty (bare overwinter, or a +# spring crop sown directly in the following year). +# +# Names must match `pftname` entries in --paramfile exactly (case and +# spacing included) — run with --list-crops first to get them right. +# ============================================================================= +ROTATION = [ + # year, main crop, winter cover crop + (2011, "irrigated_winter_wheat", None), + (2012, "winter_barley", "covercrop_1"), + (2013, "sugarbeet", None), + (2014, "winter_wheat", "covercrop_2"), + (2015, "winter_rye", None), +] + +# ============================================================================= +# 2. DOMAIN — edit this to match your case's domain/surface file. +# One (lon, lat) pair per gridcell; a 1x1 point case has exactly one. +# ============================================================================= +LON = [6.30] # degrees east +LAT = [50.87] # degrees north +# ============================================================================= + + +def resolve_cft_index(pftnames_clean, crop_name): + """Resolve a crop name to its CFT index (PFT index - 15) by looking it up + in the parameter file's own pftname array. Never hardcode this mapping — + it is not stable across parameter files.""" + try: + pft_idx = pftnames_clean.index(crop_name) + except ValueError: + raise SystemExit( + f"'{crop_name}' not found in pftname.\n" + f"Run with --list-crops to see the exact names available in " + f"this parameter file." + ) + cft_idx = pft_idx - 15 + if cft_idx < 0: + raise SystemExit( + f"'{crop_name}' resolved to PFT index {pft_idx}, which is not a " + f"crop PFT (CFT indices start at PFT 15). Check the name — this " + f"looks like a non-crop PFT." + ) + return pft_idx, cft_idx + + +def load_pftnames(paramfile): + with nc.Dataset(paramfile) as p: + if "pftname" not in p.variables: + raise SystemExit(f"'pftname' not found in {paramfile} — is this " + f"a CLM5/eCLM parameter file?") + raw = nc.chartostring(p["pftname"][:]) + return [str(n).strip() for n in raw] + + +def list_crops(paramfile): + names = load_pftnames(paramfile) + print(f"{'PFT idx':>7} {'CFT idx':>7} name") + for pft_idx, name in enumerate(names): + if not name: + continue + cft_idx = pft_idx - 15 + tag = f"{cft_idx:7d}" if cft_idx >= 0 else " -" + print(f"{pft_idx:7d} {tag} {name}") + + +def build(paramfile, out_path): + pftnames = load_pftnames(paramfile) + n_cft = len(pftnames) - 15 # CFTs occupy PFT indices 15..mxpft + if n_cft <= 0: + raise SystemExit(f"{paramfile}: fewer than 16 PFT entries — does " + f"not look like a crop-enabled parameter file.") + + years = [r[0] for r in ROTATION] + if len(set(years)) != len(years): + raise SystemExit("ROTATION has duplicate years — one entry per year.") + n_time = len(years) + n_grid = len(LON) + if len(LAT) != n_grid: + raise SystemExit("LON and LAT must be the same length.") + + pct_cft = np.zeros((n_time, n_cft, n_grid), dtype="f8") + pct_cft_winter = np.zeros((n_time, n_cft, n_grid), dtype="f8") + have_winter = np.zeros(n_time, dtype=bool) + + print("Resolving rotation against", paramfile) + for t, (year, main_crop, winter_crop) in enumerate(ROTATION): + main_pft, main_cft = resolve_cft_index(pftnames, main_crop) + pct_cft[t, main_cft, :] = 100.0 + line = f" {year}: {main_crop} (PFT {main_pft} -> CFT {main_cft})" + if winter_crop is not None: + win_pft, win_cft = resolve_cft_index(pftnames, winter_crop) + pct_cft_winter[t, win_cft, :] = 100.0 + have_winter[t] = True + line += f" + {winter_crop} (PFT {win_pft} -> CFT {win_cft})" + print(line) + + with nc.Dataset(out_path, "w", format="NETCDF4_CLASSIC") as d: + d.createDimension("time", n_time) + d.createDimension("cft", n_cft) + d.createDimension("lndgrid", n_grid) + + v_year = d.createVariable("YEAR", "i4", ("time",)) + v_year[:] = years + v_year.long_name = "calendar year of each time slice" + + # LONGXY/LATIXY follow the conventional landuse.timeseries layout; + # drop them if your surface/domain-matching pathway doesn't expect + # them on this file. + v_lon = d.createVariable("LONGXY", "f8", ("lndgrid",)) + v_lon[:] = LON + v_lon.units = "degrees_east" + + v_lat = d.createVariable("LATIXY", "f8", ("lndgrid",)) + v_lat[:] = LAT + v_lat.units = "degrees_north" + + v_main = d.createVariable("PCT_CFT", "f8", ("time", "cft", "lndgrid")) + v_main[:] = pct_cft + v_main.long_name = "percent crop functional type, main crop" + v_main.units = "percent of the crop landunit" + + if have_winter.any(): + v_win = d.createVariable("PCT_CFT_WINTER", "f8", + ("time", "cft", "lndgrid")) + v_win[:] = pct_cft_winter + v_win.long_name = "percent crop functional type, winter cover crop" + v_win.units = "percent of the crop landunit" + else: + print(" (no winter cover crops in ROTATION - PCT_CFT_WINTER " + "omitted)") + + d.history = ("Generated by make_rotation_landuse.py for " + "eCLM_FYM_fixes; CFT indices resolved from pftname " + "in " + paramfile) + d.rotation_source_paramfile = paramfile + + print(f"\nWrote {out_path}: {n_time} years ({years[0]}-{years[-1]}), " + f"{int(have_winter.sum())}/{n_time} with a winter cover crop.") + + +def main(): + ap = argparse.ArgumentParser(description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + ap.add_argument("--paramfile", required=True, + help="parameter file whose pftname array defines the CFT " + "ordering (must match paramfile/covercrop_paramfile " + "in the case's lnd_in)") + ap.add_argument("--list-crops", action="store_true", + help="print every named PFT/CFT in --paramfile and exit " + "(use this to get exact names for the ROTATION list)") + ap.add_argument("-o", "--out", dest="out_path", + help="output transient land-use file (required unless " + "--list-crops)") + args = ap.parse_args() + + if args.list_crops: + list_crops(args.paramfile) + return + if not args.out_path: + ap.error("-o/--out is required unless --list-crops is given") + build(args.paramfile, args.out_path) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/src/clm5/CMakeLists.txt b/src/clm5/CMakeLists.txt index a2446ece0b..d6cdb963e5 100644 --- a/src/clm5/CMakeLists.txt +++ b/src/clm5/CMakeLists.txt @@ -174,6 +174,7 @@ target_sources(${PROJECT_NAME} dyn_subgrid/dynColumnTemplateMod.F90 dyn_subgrid/dynConsBiogeophysMod.F90 dyn_subgrid/dyncropFileMod.F90 + dyn_subgrid/dynCovercropFileMod.F90 dyn_subgrid/dynEDMod.F90 dyn_subgrid/dynFileMod.F90 dyn_subgrid/dynInitColumnsMod.F90 diff --git a/src/clm5/biogeochem/CNBalanceCheckMod.F90 b/src/clm5/biogeochem/CNBalanceCheckMod.F90 index 8f123cf442..d0688971f5 100644 --- a/src/clm5/biogeochem/CNBalanceCheckMod.F90 +++ b/src/clm5/biogeochem/CNBalanceCheckMod.F90 @@ -11,6 +11,9 @@ module CNBalanceCheckMod use decompMod , only : bounds_type use abortutils , only : endrun use clm_varctl , only : iulog, use_nitrif_denitrif + use clm_varctl , only : use_crop, use_cfert ! tboas: use_cfert for organic C balance + use clm_varctl , only : debug_covercrop ! tboas-fix + use clm_varctl , only : cn_balance_tol_c, cn_balance_tol_n ! tboas-fix use clm_time_manager , only : get_step_size use CNVegNitrogenFluxType , only : cnveg_nitrogenflux_type use CNVegNitrogenStateType , only : cnveg_nitrogenstate_type @@ -20,6 +23,7 @@ module CNBalanceCheckMod use SoilBiogeochemCarbonfluxType , only : soilbiogeochem_carbonflux_type use ColumnType , only : col use GridcellType , only : grc + use PatchType , only : patch ! tboas: needed for wtcol in fertC balance use CNSharedParamsMod , only : use_fun ! @@ -134,6 +138,8 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, & real(r8) :: dt ! radiation time step (seconds) real(r8) :: col_cinputs real(r8) :: col_coutputs + real(r8) :: col_fertc ! tboas-fix: column-aggregated manure C input (gC/m2/s) + integer :: pi, p ! tboas-fix: patch loop indices real(r8) :: col_errcb(bounds%begc:bounds%endc) !----------------------------------------------------------------------- @@ -147,6 +153,7 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, & col_fire_closs => cnveg_carbonflux_inst%fire_closs_col , & ! Input: [real(r8) (:) ] (gC/m2/s) total column-level fire C loss col_hrv_xsmrpool_to_atm => cnveg_carbonflux_inst%hrv_xsmrpool_to_atm_col , & ! Input: [real(r8) (:) ] (gC/m2/s) excess MR pool harvest mortality col_xsmrpool_to_atm => cnveg_carbonflux_inst%xsmrpool_to_atm_col , & ! Input: [real(r8) (:) ] (gC/m2/s) excess MR pool crop harvest loss to atm + fertC_patch => cnveg_carbonflux_inst%fertC_patch , & ! Input: [real(r8) (:) ] (gC/m2/s) organic C fertilizer from manure (tboas) som_c_leached => soilbiogeochem_carbonflux_inst%som_c_leached_col , & ! Input: [real(r8) (:) ] (gC/m2/s) total SOM C loss from vertical transport totcolc => cnveg_carbonstate_inst%totc_col & ! Input: [real(r8) (:) ] (gC/m2) total column carbon, incl veg and cpool @@ -164,6 +171,18 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, & ! calculate total column-level inputs col_cinputs = gpp(c) + ! tboas: add manure C input, which reaches the litter pools via CNCSoilFert. + ! tboas-fix: aggregate exactly as CNCSoilFert does (active patches only). + ! The previous sum() included inactive patches, so the balance term and + ! the flux actually applied could disagree. + col_fertc = 0._r8 + if (use_crop .and. use_cfert) then + do pi = 1, col%npatches(c) + p = col%patchi(c) + pi - 1 + if (patch%active(p)) col_fertc = col_fertc + fertC_patch(p) * patch%wtcol(p) + end do + col_cinputs = col_cinputs + col_fertc + end if ! calculate total column-level outputs ! er = ar + hr, col_fire_closs includes patch-level fire losses @@ -187,11 +206,18 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, & (col_endcb(c) - col_begcb(c)) ! check for significant errors - if (abs(col_errcb(c)) > 1e-7_r8) then + ! tboas-fix: threshold restored to the CLM5 default (1e-7 gC/m2/timestep), + ! now via a namelist knob. It had been hardcoded to 100 gC/m2/timestep -- + ! about a season of NPP -- which disabled the check rather than fixing the + ! underlying imbalance (xsmrpool was being zeroed on crop-rotation switches + ! without an accounting flux; see dynCovercropFileMod::covercrop_switch_ivt). + if (abs(col_errcb(c)) > cn_balance_tol_c) then err_found = .true. err_index = c end if - if (abs(col_errcb(c)) > 1e-8_r8) then + ! tboas-fix: this warning fired for every column on every timestep from + ! every rank with no masterproc guard. Kept for single-point debugging only. + if (debug_covercrop .and. abs(col_errcb(c)) > 1e-8_r8) then write(iulog,*) 'cbalance warning',c,col_errcb(c),col_endcb(c) end if @@ -208,6 +234,15 @@ subroutine CBalanceCheck(this, bounds, num_soilc, filter_soilc, & write(iulog,*)'delta store = ',col_endcb(c)-col_begcb(c) write(iulog,*)'--- Inputs ---' write(iulog,*)'gpp = ',gpp(c)*dt + ! tboas-fix: recompute over active patches only, matching the balance term + col_fertc = 0._r8 + if (use_crop .and. use_cfert) then + do pi = 1, col%npatches(c) + p = col%patchi(c) + pi - 1 + if (patch%active(p)) col_fertc = col_fertc + fertC_patch(p) * patch%wtcol(p) + end do + end if + write(iulog,*)'Corg_FERT (manure C) = ',col_fertc*dt write(iulog,*)'--- Outputs ---' write(iulog,*)'er = ',er(c)*dt write(iulog,*)'col_fire_closs = ',col_fire_closs(c)*dt @@ -249,6 +284,8 @@ subroutine NBalanceCheck(this, bounds, num_soilc, filter_soilc, & real(r8):: dt ! radiation time step (seconds) real(r8):: col_ninputs(bounds%begc:bounds%endc) real(r8):: col_noutputs(bounds%begc:bounds%endc) + real(r8):: col_fertn ! tboas-fix: column-aggregated organic manure N input (gN/m2/s) + integer :: pi, p ! tboas-fix: patch loop indices real(r8):: col_errnb(bounds%begc:bounds%endc) !----------------------------------------------------------------------- @@ -271,6 +308,7 @@ subroutine NBalanceCheck(this, bounds, num_soilc, filter_soilc, & col_fire_nloss => cnveg_nitrogenflux_inst%fire_nloss_col , & ! Input: [real(r8) (:) ] (gN/m2/s) total column-level fire N loss wood_harvestn => cnveg_nitrogenflux_inst%wood_harvestn_col , & ! Input: [real(r8) (:) ] (gN/m2/s) wood harvest (to product pools) grainn_to_cropprodn => cnveg_nitrogenflux_inst%grainn_to_cropprodn_col , & ! Input: [real(r8) (:) ] (gN/m2/s) grain N to 1-year crop product pool + fertN_patch => cnveg_nitrogenflux_inst%fertN_patch , & ! Input: [real(r8) (:) ] (gN/m2/s) organic N applied with manure (tboas-fix) totcoln => cnveg_nitrogenstate_inst%totn_col & ! Input: [real(r8) (:) ] (gN/m2) total column nitrogen, incl veg ) @@ -296,6 +334,19 @@ subroutine NBalanceCheck(this, bounds, num_soilc, filter_soilc, & col_ninputs(c) = col_ninputs(c) + fert_to_sminn(c) + soyfixn_to_sminn(c) end if + ! tboas-fix: the organic N applied with farmyard manure enters the litter + ! pools directly (CNNDynamicsMod::CNCSoilFert) rather than through the + ! mineral pool, so it is an external input that the balance must know + ! about. Aggregate exactly as CNCSoilFert does: active patches only. + col_fertn = 0._r8 + if (use_crop .and. use_cfert) then + do pi = 1, col%npatches(c) + p = col%patchi(c) + pi - 1 + if (patch%active(p)) col_fertn = col_fertn + fertN_patch(p) * patch%wtcol(p) + end do + col_ninputs(c) = col_ninputs(c) + col_fertn + end if + ! calculate total column-level outputs col_noutputs(c) = denit(c) + col_fire_nloss(c) @@ -322,12 +373,17 @@ subroutine NBalanceCheck(this, bounds, num_soilc, filter_soilc, & col_errnb(c) = (col_ninputs(c) - col_noutputs(c))*dt - & (col_endnb(c) - col_begnb(c)) - if (abs(col_errnb(c)) > 1e-3_r8) then + ! tboas-fix: threshold restored to the CLM5 default (1e-7 gN/m2/timestep), + ! now via a namelist knob. It had been hardcoded to 100 gN/m2/timestep, + ! which disabled the check entirely. + if (abs(col_errnb(c)) > cn_balance_tol_n) then err_found = .true. err_index = c end if - if (abs(col_errnb(c)) > 1e-7_r8) then + ! tboas-fix: guarded; this fired for every column, every timestep, on + ! every rank once the threshold above was loosened. + if (debug_covercrop .and. abs(col_errnb(c)) > cn_balance_tol_n) then write(iulog,*) 'nbalance warning',c,col_errnb(c),col_endnb(c) write(iulog,*)'inputs,ffix,nfix,ndep = ',ffix_to_sminn(c)*dt,nfix_to_sminn(c)*dt,ndep_to_sminn(c)*dt write(iulog,*)'outputs,lch,roff,dnit = ',smin_no3_leached(c)*dt, smin_no3_runoff(c)*dt,f_n2o_nit(c)*dt @@ -347,6 +403,15 @@ subroutine NBalanceCheck(this, bounds, num_soilc, filter_soilc, & write(iulog,*)'net flux = ',(col_ninputs(c)-col_noutputs(c))*dt write(iulog,*)'inputs,ffix,nfix,ndep = ',ffix_to_sminn(c)*dt,nfix_to_sminn(c)*dt,ndep_to_sminn(c)*dt write(iulog,*)'outputs,ffix,nfix,ndep = ',smin_no3_leached(c)*dt, smin_no3_runoff(c)*dt,f_n2o_nit(c)*dt + ! tboas-fix: the organic manure N input, aggregated as in CNCSoilFert + col_fertn = 0._r8 + if (use_crop .and. use_cfert) then + do pi = 1, col%npatches(c) + p = col%patchi(c) + pi - 1 + if (patch%active(p)) col_fertn = col_fertn + fertN_patch(p) * patch%wtcol(p) + end do + end if + write(iulog,*)'Norg_FERT (manure org N) = ',col_fertn*dt diff --git a/src/clm5/biogeochem/CNCIsoFluxMod.F90 b/src/clm5/biogeochem/CNCIsoFluxMod.F90 index a92ab44e47..ee392f3a5e 100644 --- a/src/clm5/biogeochem/CNCIsoFluxMod.F90 +++ b/src/clm5/biogeochem/CNCIsoFluxMod.F90 @@ -20,6 +20,7 @@ module CNCIsoFluxMod use PatchType , only : patch use clm_varctl , only : use_crop use clm_varctl , only : use_grainproduct + use pftconMod , only : is_covercrop ! tboas ! implicit none private @@ -414,6 +415,17 @@ subroutine CIsoFlux1(num_soilc, filter_soilc, num_soilp, filter_soilp, & iso_cnveg_cs%totvegc_patch , cnveg_cs%totvegc_patch, & num_soilp , filter_soilp, 1._r8, 0, isotope) + call CIsoFluxCalc(& + iso_cnveg_cf%crop_seedc_to_froot_patch , cnveg_cf%crop_seedc_to_froot_patch, & + iso_cnveg_cs%totvegc_patch , cnveg_cs%totvegc_patch, & + num_soilp , filter_soilp, 1._r8, 0, isotope) + + call CIsoFluxCalc(& + iso_cnveg_cf%crop_seedc_to_deadstem_patch , cnveg_cf%crop_seedc_to_deadstem_patch, & + iso_cnveg_cs%totvegc_patch , cnveg_cs%totvegc_patch, & + num_soilp , filter_soilp, 1._r8, 0, isotope) + + call CIsoFluxCalc(& iso_cnveg_cf%grain_curmr_patch , cnveg_cf%grain_curmr_patch, & iso_cnveg_cs%cpool_patch , cnveg_cs%cpool_patch, & @@ -462,6 +474,8 @@ subroutine CIsoFlux1(num_soilc, filter_soilc, num_soilp, filter_soilp, & if (use_grainproduct) then do fp = 1,num_soilp p = filter_soilp(fp) + ! tboas: cover crops contribute no crop product + if (is_covercrop(patch%itype(p))) cycle iso_cnveg_cf%grainc_to_cropprodc_patch(p) = iso_cnveg_cf%grainc_to_food_patch(p) iso_cnveg_cf%grain_mr_patch(p) = iso_cnveg_cf%grain_xsmr_patch(p) + iso_cnveg_cf%grain_curmr_patch(p) end do @@ -1233,8 +1247,8 @@ subroutine CNCIsoLitterToColumn (num_soilc, filter_soilc, & phenology_c_to_litr_lig_c(c,j) = phenology_c_to_litr_lig_c(c,j) & + livestemc_to_litter(p) * lf_flig(ivt(p)) * wtcol(p) * leaf_prof(p,j) - if (.not. use_grainproduct) then - ! grain litter carbon fluxes + if (.not. use_grainproduct .or. is_covercrop(ivt(p))) then + ! grain litter carbon fluxes --- tboas phenology_c_to_litr_met_c(c,j) = phenology_c_to_litr_met_c(c,j) & + grainc_to_food(p) * lf_flab(ivt(p)) * wtcol(p) * leaf_prof(p,j) phenology_c_to_litr_cel_c(c,j) = phenology_c_to_litr_cel_c(c,j) & diff --git a/src/clm5/biogeochem/CNCStateUpdate1Mod.F90 b/src/clm5/biogeochem/CNCStateUpdate1Mod.F90 index e1da2f354f..5a9bcb3a1f 100644 --- a/src/clm5/biogeochem/CNCStateUpdate1Mod.F90 +++ b/src/clm5/biogeochem/CNCStateUpdate1Mod.F90 @@ -174,6 +174,8 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & woody => pftcon%woody , & ! Input: binary flag for woody lifeform (1=woody, 0=not woody) + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types (1=perennial, 0= not perennial) + mulch_pruning => pftcon%mulch_pruning , & ! Input: binary flag for mulching or exporting pruning material (1=mulching, 0=exporting) cascade_donor_pool => decomp_cascade_con%cascade_donor_pool , & ! Input: [integer (:) ] which pool is C taken from for a given decomposition step cascade_receiver_pool => decomp_cascade_con%cascade_receiver_pool , & ! Input: [integer (:) ] which pool is C added to for a given decomposition step @@ -268,10 +270,15 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops ! lines here for consistency; the transfer terms are zero + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + cs_veg%grainc_patch(p) = cs_veg%grainc_patch(p) + cf_veg%grainc_xfer_to_grainc_patch(p)*dt + cs_veg%grainc_xfer_patch(p) = cs_veg%grainc_xfer_patch(p) - cf_veg%grainc_xfer_to_grainc_patch(p)*dt + else cs_veg%livestemc_patch(p) = cs_veg%livestemc_patch(p) + cf_veg%livestemc_xfer_to_livestemc_patch(p)*dt cs_veg%livestemc_xfer_patch(p) = cs_veg%livestemc_xfer_patch(p) - cf_veg%livestemc_xfer_to_livestemc_patch(p)*dt cs_veg%grainc_patch(p) = cs_veg%grainc_patch(p) + cf_veg%grainc_xfer_to_grainc_patch(p)*dt cs_veg%grainc_xfer_patch(p) = cs_veg%grainc_xfer_patch(p) - cf_veg%grainc_xfer_to_grainc_patch(p)*dt + end if end if ! phenology: litterfall fluxes @@ -286,12 +293,27 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & cs_veg%deadcrootc_patch(p) = cs_veg%deadcrootc_patch(p) + cf_veg%livecrootc_to_deadcrootc_patch(p)*dt end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + cs_veg%grainc_patch(p) = cs_veg%grainc_patch(p) & + - (cf_veg%grainc_to_food_patch(p) + cf_veg%grainc_to_seed_patch(p))*dt + cs_veg%cropseedc_deficit_patch(p) = cs_veg%cropseedc_deficit_patch(p) & + - cf_veg%crop_seedc_to_leaf_patch(p) * dt & + - cf_veg%crop_seedc_to_froot_patch(p) * dt & !(added by O.Dombrowski) + - cf_veg%crop_seedc_to_deadstem_patch(p) * dt & !(added by O.Dombrowski) + + cf_veg%grainc_to_seed_patch(p) * dt + if (mulch_pruning(ivt(p)) == 1._r8) then + ! update stem biomass after pruning + cs_veg%deadstemc_patch(p) = cs_veg%deadstemc_patch(p) - cf_veg%prunec_to_litter_patch(p)*dt + cs_veg%deadstemc_storage_patch(p) = cs_veg%deadstemc_storage_patch(p) - cf_veg%prunec_storage_to_litter_patch(p)*dt + end if + else cs_veg%livestemc_patch(p) = cs_veg%livestemc_patch(p) - cf_veg%livestemc_to_litter_patch(p)*dt cs_veg%grainc_patch(p) = cs_veg%grainc_patch(p) & - (cf_veg%grainc_to_food_patch(p) + cf_veg%grainc_to_seed_patch(p))*dt cs_veg%cropseedc_deficit_patch(p) = cs_veg%cropseedc_deficit_patch(p) & - cf_veg%crop_seedc_to_leaf_patch(p) * dt & + cf_veg%grainc_to_seed_patch(p) * dt + end if end if check_cpool = cs_veg%cpool_patch(p)- cf_veg%psnsun_to_cpool_patch(p)*dt-cf_veg%psnshade_to_cpool_patch(p)*dt @@ -302,13 +324,18 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_to_xsmrpool_patch(p)*dt cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%leaf_curmr_patch(p)*dt cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%froot_curmr_patch(p)*dt - If (woody(ivt(p)) == 1._r8) then + if (woody(ivt(p)) == 1._r8) then cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%livestem_curmr_patch(p)*dt cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%livecroot_curmr_patch(p)*dt end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%grain_curmr_patch(p)*dt + + else cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%livestem_curmr_patch(p)*dt cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%grain_curmr_patch(p)*dt + end if end if @@ -371,11 +398,18 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & cs_veg%deadcrootc_storage_patch(p) = cs_veg%deadcrootc_storage_patch(p) + cf_veg%cpool_to_deadcrootc_storage_patch(p)*dt end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops - if (carbon_resp_opt == 1) then + if (carbon_resp_opt == 1 .and. perennial(ivt(p)) == 0._r8) then !(perennial flag added by O.Dombrowski) cf_veg%cpool_to_livestemc_patch(p) = cf_veg%cpool_to_livestemc_patch(p) - cf_veg%cpool_to_livestemc_resp_patch(p) cf_veg%cpool_to_livestemc_storage_patch(p) = cf_veg%cpool_to_livestemc_storage_patch(p) - & cf_veg%cpool_to_livestemc_storage_resp_patch(p) end if + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_to_grainc_patch(p)*dt + cs_veg%grainc_patch(p) = cs_veg%grainc_patch(p) + cf_veg%cpool_to_grainc_patch(p)*dt + cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_to_grainc_storage_patch(p)*dt + cs_veg%grainc_storage_patch(p) = cs_veg%grainc_storage_patch(p) + cf_veg%cpool_to_grainc_storage_patch(p)*dt + + else cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_to_livestemc_patch(p)*dt cs_veg%livestemc_patch(p) = cs_veg%livestemc_patch(p) + cf_veg%cpool_to_livestemc_patch(p)*dt cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_to_livestemc_storage_patch(p)*dt @@ -384,6 +418,7 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & cs_veg%grainc_patch(p) = cs_veg%grainc_patch(p) + cf_veg%cpool_to_grainc_patch(p)*dt cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_to_grainc_storage_patch(p)*dt cs_veg%grainc_storage_patch(p) = cs_veg%grainc_storage_patch(p) + cf_veg%cpool_to_grainc_storage_patch(p)*dt + end if end if ! growth respiration fluxes for current growth @@ -397,8 +432,12 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_deadcroot_gr_patch(p)*dt end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_grain_gr_patch(p)*dt + else cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_livestem_gr_patch(p)*dt cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_grain_gr_patch(p)*dt + end if end if ! growth respiration for transfer growth @@ -411,8 +450,12 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & cs_veg%gresp_xfer_patch(p) = cs_veg%gresp_xfer_patch(p) - cf_veg%transfer_deadcroot_gr_patch(p)*dt end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + cs_veg%gresp_xfer_patch(p) = cs_veg%gresp_xfer_patch(p) - cf_veg%transfer_grain_gr_patch(p)*dt + else cs_veg%gresp_xfer_patch(p) = cs_veg%gresp_xfer_patch(p) - cf_veg%transfer_livestem_gr_patch(p)*dt cs_veg%gresp_xfer_patch(p) = cs_veg%gresp_xfer_patch(p) - cf_veg%transfer_grain_gr_patch(p)*dt + end if end if ! growth respiration at time of storage @@ -426,10 +469,14 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_deadcroot_storage_gr_patch(p)*dt end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_grain_storage_gr_patch(p)*dt + else cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_livestem_storage_gr_patch(p)*dt cs_veg%cpool_patch(p) = cs_veg%cpool_patch(p) - cf_veg%cpool_grain_storage_gr_patch(p)*dt + end if end if ! growth respiration stored for release during transfer growth @@ -454,16 +501,25 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & cs_veg%gresp_xfer_patch(p) = cs_veg%gresp_xfer_patch(p) + cf_veg%gresp_storage_to_xfer_patch(p)*dt end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + cs_veg%grainc_storage_patch(p) = cs_veg%grainc_storage_patch(p) - cf_veg%grainc_storage_to_xfer_patch(p)*dt + cs_veg%grainc_xfer_patch(p) = cs_veg%grainc_xfer_patch(p) + cf_veg%grainc_storage_to_xfer_patch(p)*dt + else ! lines here for consistency; the transfer terms are zero cs_veg%livestemc_storage_patch(p) = cs_veg%livestemc_storage_patch(p) - cf_veg%livestemc_storage_to_xfer_patch(p)*dt cs_veg%livestemc_xfer_patch(p) = cs_veg%livestemc_xfer_patch(p) + cf_veg%livestemc_storage_to_xfer_patch(p)*dt cs_veg%grainc_storage_patch(p) = cs_veg%grainc_storage_patch(p) - cf_veg%grainc_storage_to_xfer_patch(p)*dt cs_veg%grainc_xfer_patch(p) = cs_veg%grainc_xfer_patch(p) + cf_veg%grainc_storage_to_xfer_patch(p)*dt end if + end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1._r8) then + cs_veg%xsmrpool_patch(p) = cs_veg%xsmrpool_patch(p) - cf_veg%grain_xsmr_patch(p)*dt + else cs_veg%xsmrpool_patch(p) = cs_veg%xsmrpool_patch(p) - cf_veg%livestem_xsmr_patch(p)*dt cs_veg%xsmrpool_patch(p) = cs_veg%xsmrpool_patch(p) - cf_veg%grain_xsmr_patch(p)*dt + end if if (harvdate(p) < 999) then ! beginning at harvest, send to atm ! TODO (mv, 11-02-2014) the following lines are why the cf_veg is ! an intent(inout) @@ -500,6 +556,18 @@ subroutine CStateUpdate1( num_soilc, filter_soilc, num_soilp, filter_soilp, & ! update xsmrpool loss state cs_veg%xsmrpool_loss_patch(p) = cs_veg%xsmrpool_loss_patch(p) - cf_veg%xsmrpool_to_atm_patch(p) * dt + else if ( cs_veg%xsmrpool_loss_patch(p) /= 0._r8 ) then + ! tboas-fix: a crop-rotation switch deposits the outgoing crop's + ! xsmrpool into xsmrpool_loss (dynCovercropFileMod::covercrop_switch_ivt). + ! With dribbling off, nothing else drains that pool, so the carbon + ! would be stranded. Release it immediately, matching the + ! non-dribbling behaviour used at harvest above. Note the flux is + ! accumulated, not assigned, because the harvest branch may already + ! have written to it in this timestep, and it may legitimately be + ! negative when the previous crop ended with a respiration debt. + cf_veg%xsmrpool_to_atm_patch(p) = cf_veg%xsmrpool_to_atm_patch(p) + & + cs_veg%xsmrpool_loss_patch(p) / dt + cs_veg%xsmrpool_loss_patch(p) = 0._r8 end if end if diff --git a/src/clm5/biogeochem/CNDriverMod.F90 b/src/clm5/biogeochem/CNDriverMod.F90 index 94bc3f3554..67110d8a65 100644 --- a/src/clm5/biogeochem/CNDriverMod.F90 +++ b/src/clm5/biogeochem/CNDriverMod.F90 @@ -12,6 +12,7 @@ module CNDriverMod use perf_mod , only : t_startf, t_stopf use clm_varctl , only : use_century_decomp, use_nitrif_denitrif, use_nguardrail use clm_varctl , only : use_crop + use clm_varctl , only : use_cfert ! tboas: organic C fertilizer flag use CNSharedParamsMod , only : use_fun use CNVegStateType , only : cnveg_state_type use CNVegCarbonStateType , only : cnveg_carbonstate_type @@ -105,7 +106,8 @@ subroutine CNDriverNoLeaching(bounds, use clm_varpar , only: nlevdecomp, ndecomp_cascade_transitions, ndecomp_pools use subgridAveMod , only: p2c, p2c_2d use CropType , only: crop_type - use CNNDynamicsMod , only: CNNDeposition,CNNFixation, CNNFert, CNSoyfix,CNFreeLivingFixation + use CNNDynamicsMod , only: CNNDeposition,CNNFixation, CNNFert, CNSoyfix,CNFreeLivingFixation, & + CNCSoilFert ! tboas: organic C fertilizer routing use CNMRespMod , only: CNMResp use CNFUNMod , only: CNFUNInit !, CNFUN use CNPhenologyMod , only: CNPhenology @@ -352,11 +354,12 @@ subroutine CNDriverNoLeaching(bounds, filter_soilp, num_pcropp, filter_pcropp, & doalb, waterstate_inst, temperature_inst, atm2lnd_inst, & crop_inst, canopystate_inst, soilstate_inst, dgvs_inst, & - cnveg_state_inst, cnveg_carbonstate_inst, cnveg_carbonflux_inst, & + cnveg_state_inst, soilbiogeochem_state_inst, cnveg_carbonstate_inst, cnveg_carbonflux_inst, & cnveg_nitrogenstate_inst, cnveg_nitrogenflux_inst, & c13_cnveg_carbonstate_inst, c14_cnveg_carbonstate_inst, & leaf_prof_patch=soilbiogeochem_state_inst%leaf_prof_patch(begp:endp,1:nlevdecomp_full), & froot_prof_patch=soilbiogeochem_state_inst%froot_prof_patch(begp:endp,1:nlevdecomp_full), & + stem_prof_patch=soilbiogeochem_state_inst%stem_prof_patch(begp:endp,1:nlevdecomp_full), & phase=1) call t_stopf('CNPhenology_phase1') @@ -447,25 +450,32 @@ subroutine CNDriverNoLeaching(bounds, filter_soilp, num_pcropp, filter_pcropp, & doalb, waterstate_inst, temperature_inst, atm2lnd_inst, & crop_inst, canopystate_inst, soilstate_inst, dgvs_inst, & - cnveg_state_inst, cnveg_carbonstate_inst, cnveg_carbonflux_inst, & + cnveg_state_inst,soilbiogeochem_state_inst, cnveg_carbonstate_inst, cnveg_carbonflux_inst, & cnveg_nitrogenstate_inst, cnveg_nitrogenflux_inst, & c13_cnveg_carbonstate_inst, c14_cnveg_carbonstate_inst, & leaf_prof_patch=soilbiogeochem_state_inst%leaf_prof_patch(begp:endp,1:nlevdecomp_full), & froot_prof_patch=soilbiogeochem_state_inst%froot_prof_patch(begp:endp,1:nlevdecomp_full), & + stem_prof_patch=soilbiogeochem_state_inst%stem_prof_patch(begp:endp,1:nlevdecomp_full), & phase=1) end if call CNPhenology (bounds, num_soilc, filter_soilc, num_soilp, & filter_soilp, num_pcropp, filter_pcropp, & doalb, waterstate_inst, temperature_inst, atm2lnd_inst, & crop_inst, canopystate_inst, soilstate_inst, dgvs_inst, & - cnveg_state_inst, cnveg_carbonstate_inst, cnveg_carbonflux_inst, & + cnveg_state_inst, soilbiogeochem_state_inst,cnveg_carbonstate_inst, cnveg_carbonflux_inst, & cnveg_nitrogenstate_inst, cnveg_nitrogenflux_inst, & c13_cnveg_carbonstate_inst, c14_cnveg_carbonstate_inst, & leaf_prof_patch=soilbiogeochem_state_inst%leaf_prof_patch(begp:endp,1:nlevdecomp_full), & froot_prof_patch=soilbiogeochem_state_inst%froot_prof_patch(begp:endp,1:nlevdecomp_full), & + stem_prof_patch=soilbiogeochem_state_inst%stem_prof_patch(begp:endp,1:nlevdecomp_full), & phase=2) call t_stopf('CNPhenology') + ! tboas: route manure organic C into litter pools AFTER CNPhenology to avoid overwrite + if (use_cfert) then + call CNCSoilFert(bounds, num_soilc, filter_soilc, cnveg_carbonflux_inst, & + cnveg_nitrogenflux_inst) + end if !-------------------------------------------- ! Growth respiration diff --git a/src/clm5/biogeochem/CNFUNMod.F90 b/src/clm5/biogeochem/CNFUNMod.F90 index f1adee8f6b..da140b40c5 100644 --- a/src/clm5/biogeochem/CNFUNMod.F90 +++ b/src/clm5/biogeochem/CNFUNMod.F90 @@ -510,6 +510,7 @@ subroutine CNFUN(bounds,num_soilc, filter_soilc,num_soilp& ! -deciduous leaf habit (0 or 1) stress_decid => pftcon%stress_decid , & ! Input: binary flag for stress ! -deciduous leaf habit (0 or 1) + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types (0 or 1) a_fix => pftcon%a_fix , & ! Input: A BNF parameter b_fix => pftcon%b_fix , & ! Input: A BNF parameter c_fix => pftcon%c_fix , & ! Input: A BNF parameter @@ -1194,7 +1195,7 @@ subroutine CNFUN(bounds,num_soilc, filter_soilc,num_soilp& ! Calculate appropriate degree of retranslocation !------------------------------------------------------------------------------- - if(leafc(p).gt.0.0_r8.and.litterfall_n_step(p,istp)* fixerfrac>0.0_r8.and.ivt(p) 0.0_r8.and. (ivt(p) pftcon%leafcn , & ! Input: leaf C:N (gC/gN) frootcn => pftcon%frootcn , & ! Input: fine root C:N (gC/gN) livewdcn => pftcon%livewdcn , & ! Input: live wood (phloem and ray parenchyma) C:N (gC/gN) + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types (1=perennial, 0=not perennial) laisun => canopystate_inst%laisun_patch , & ! Input: [real(r8) (:)] sunlit projected leaf area index laisha => canopystate_inst%laisha_patch , & ! Input: [real(r8) (:)] shaded projected leaf area index @@ -147,6 +148,14 @@ subroutine CNGResp(num_soilp, filter_soilp, cnveg_carbonflux_inst, canopystate_i respfact_livestem_storage = 1.0_r8 if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + cpool_grain_gr(p) = cpool_to_grainc(p) * grperc(ivt(p)) + + cpool_grain_storage_gr(p) = cpool_to_grainc_storage(p) * grperc(ivt(p)) * grpnow(ivt(p)) + + transfer_grain_gr(p) = grainc_xfer_to_grainc(p) * grperc(ivt(p)) * (1._r8 - grpnow(ivt(p))) + + else cpool_livestem_gr(p) = cpool_to_livestemc(p) * grperc(ivt(p)) * respfact_livestem cpool_livestem_storage_gr(p) = cpool_to_livestemc_storage(p) * grperc(ivt(p)) * grpnow(ivt(p)) * & @@ -160,6 +169,7 @@ subroutine CNGResp(num_soilp, filter_soilp, cnveg_carbonflux_inst, canopystate_i cpool_grain_storage_gr(p) = cpool_to_grainc_storage(p) * grperc(ivt(p)) * grpnow(ivt(p)) transfer_grain_gr(p) = grainc_xfer_to_grainc(p) * grperc(ivt(p)) * (1._r8 - grpnow(ivt(p))) + end if end if ! leaf and fine root growth respiration diff --git a/src/clm5/biogeochem/CNGapMortalityMod.F90 b/src/clm5/biogeochem/CNGapMortalityMod.F90 index 939d4b52eb..2bd6380c62 100644 --- a/src/clm5/biogeochem/CNGapMortalityMod.F90 +++ b/src/clm5/biogeochem/CNGapMortalityMod.F90 @@ -129,6 +129,7 @@ subroutine CNGapMortality (bounds, num_soilc, filter_soilc, num_soilp, filter_so ivt => patch%itype , & ! Input: [integer (:) ] patch vegetation type woody => pftcon%woody , & ! Input: binary flag for woody lifeform + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types greffic => dgvs_inst%greffic_patch , & ! Input: [real(r8) (:) ] heatstress => dgvs_inst%heatstress_patch , & ! Input: [real(r8) (:) ] @@ -235,7 +236,7 @@ subroutine CNGapMortality (bounds, num_soilc, filter_soilc, num_soilp, filter_so cnveg_nitrogenflux_inst%m_deadcrootn_to_litter_patch(p) = cnveg_nitrogenstate_inst%deadcrootn_patch(p) * m end if - if (ivt(p) < npcropmin) then + if (ivt(p) < npcropmin .or. perennial(ivt(p)) == 1._r8) then ! perennial flag added by O.Dombrowski cnveg_nitrogenflux_inst%m_retransn_to_litter_patch(p) = cnveg_nitrogenstate_inst%retransn_patch(p) * m end if diff --git a/src/clm5/biogeochem/CNMRespMod.F90 b/src/clm5/biogeochem/CNMRespMod.F90 index 3a7052d0bb..a1db547d6c 100644 --- a/src/clm5/biogeochem/CNMRespMod.F90 +++ b/src/clm5/biogeochem/CNMRespMod.F90 @@ -177,6 +177,7 @@ subroutine CNMResp(bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, & woody => pftcon%woody , & ! Input: binary flag for woody lifeform (1=woody, 0=not woody) + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types (1=perennial, 0= not perennial) frac_veg_nosno => canopystate_inst%frac_veg_nosno_patch , & ! Input: [integer (:) ] fraction of vegetation not covered by snow (0 OR 1) [-] laisun => canopystate_inst%laisun_patch , & ! Input: [real(r8) (:) ] sunlit projected leaf area index laisha => canopystate_inst%laisha_patch , & ! Input: [real(r8) (:) ] shaded projected leaf area index @@ -264,6 +265,9 @@ subroutine CNMResp(bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, & if (woody(ivt(p)) == 1) then livestem_mr(p) = livestemn(p)*br*tc livecroot_mr(p) = livecrootn(p)*br_root*tc + if (perennial(ivt(p)) == 1._r8) then ! (added by O.Dombrowski) + grain_mr(p) = grainn(p)*br*tc + end if else if (ivt(p) >= npcropmin) then livestem_mr(p) = livestemn(p)*br*tc grain_mr(p) = grainn(p)*br*tc diff --git a/src/clm5/biogeochem/CNNDynamicsMod.F90 b/src/clm5/biogeochem/CNNDynamicsMod.F90 index b8796912a2..5531d9fa84 100644 --- a/src/clm5/biogeochem/CNNDynamicsMod.F90 +++ b/src/clm5/biogeochem/CNNDynamicsMod.F90 @@ -9,7 +9,13 @@ module CNNDynamicsMod use shr_kind_mod , only : r8 => shr_kind_r8 use decompMod , only : bounds_type use clm_varcon , only : dzsoi_decomp, zisoi + use clm_varpar , only : nlevdecomp + use clm_varctl , only : manure_fmet, manure_fcel, manure_flig, & + manure_injection_depth ! tboas: cfert_inparm params + use clm_varctl , only : manure_freq_years, manure_apply_month, & + manure_apply_day ! tboas: timing/frequency params use clm_varctl , only : use_nitrif_denitrif, use_vertsoilc, nfix_timeconst + use clm_varctl , only : use_cfert, use_crop ! tboas: use_cfert for organic C fert use subgridAveMod , only : p2c use atm2lndType , only : atm2lnd_type use CNVegStateType , only : cnveg_state_type @@ -34,6 +40,7 @@ module CNNDynamicsMod public :: CNNDeposition ! Update N deposition rate from atm forcing public :: CNNFixation ! Update N Fixation rate public :: CNNFert ! Update N fertilizer for crops + public :: CNCSoilFert ! tboas: route organic C fertilizer into litter pools public :: CNSoyfix ! N Fixation for soybeans public :: CNFreeLivingFixation ! N free living fixation @@ -44,6 +51,9 @@ module CNNDynamicsMod real(r8) :: freelivfix_slope_wET ! slope of line of free living fixation with annual ET end type params_type type(params_type) :: params_inst + ! tboas: litter partitioning fractions for manure C (metabolic / cellulose / lignin) + ! Based on typical farmyard manure composition (10% lignin, ~60% metabolic, ~30% cellulose) + ! tboas: manure_fmet/fcel/flig and manure_injection_depth imported from clm_varctl via use statement below !----------------------------------------------------------------------- contains @@ -63,22 +73,17 @@ subroutine CNNDynamicsReadNML( NLFilename ) use shr_log_mod , only : errMsg => shr_log_errMsg use abortutils , only : endrun ! - ! !ARGUMENTS: - character(len=*), intent(in) :: NLFilename ! Namelist filename + character(len=*), intent(in) :: NLFilename ! - ! !LOCAL VARIABLES: - integer :: ierr ! error code - integer :: unitn ! unit for namelist file + integer :: ierr, unitn character(len=*), parameter :: subname = 'CNNDynamicsReadNML' character(len=*), parameter :: nmlname = 'mineral_nitrogen_dynamics' !----------------------------------------------------------------------- - real(r8) :: freelivfix_intercept ! intercept of line of free living fixation with annual ET - real(r8) :: freelivfix_slope_wET ! slope of line of free living fixation with annual ET + real(r8) :: freelivfix_intercept + real(r8) :: freelivfix_slope_wET namelist /mineral_nitrogen_dynamics/ freelivfix_slope_wET, freelivfix_intercept - ! Initialize options to default values, in case they are not specified in - ! the namelist freelivfix_intercept = 0.0117_r8 @@ -117,30 +122,18 @@ end subroutine CNNDynamicsReadNML subroutine CNNDeposition( bounds, & atm2lnd_inst, soilbiogeochem_nitrogenflux_inst ) ! - ! !DESCRIPTION: - ! On the radiation time step, update the nitrogen deposition rate - ! from atmospheric forcing. For now it is assumed that all the atmospheric - ! N deposition goes to the soil mineral N pool. - ! This could be updated later to divide the inputs between mineral N absorbed - ! directly into the canopy and mineral N entering the soil pool. - ! - ! !USES: - use CNSharedParamsMod , only: use_fun - ! !ARGUMENTS: type(bounds_type) , intent(in) :: bounds type(atm2lnd_type) , intent(in) :: atm2lnd_inst type(soilbiogeochem_nitrogenflux_type) , intent(inout) :: soilbiogeochem_nitrogenflux_inst ! - ! !LOCAL VARIABLES: - integer :: g,c ! indices + integer :: g,c !----------------------------------------------------------------------- associate( & - forc_ndep => atm2lnd_inst%forc_ndep_grc , & ! Input: [real(r8) (:)] nitrogen deposition rate (gN/m2/s) - ndep_to_sminn => soilbiogeochem_nitrogenflux_inst%ndep_to_sminn_col & ! Output: [real(r8) (:)] atmospheric N deposition to soil mineral N (gN/m2/s) + forc_ndep => atm2lnd_inst%forc_ndep_grc , & + ndep_to_sminn => soilbiogeochem_nitrogenflux_inst%ndep_to_sminn_col & ) - ! Loop through columns do c = bounds%begc, bounds%endc g = col%gridcell(c) ndep_to_sminn(c) = forc_ndep(g) @@ -160,22 +153,20 @@ subroutine CNFreeLivingFixation(num_soilc, filter_soilc, & use shr_sys_mod , only : shr_sys_flush use clm_varcon , only : secspday, spval - integer , intent(in) :: num_soilc ! number of soil columns in filter - integer , intent(in) :: filter_soilc(:) ! filter for soil columns + integer , intent(in) :: num_soilc + integer , intent(in) :: filter_soilc(:) type(soilbiogeochem_nitrogenflux_type) , intent(inout) :: soilbiogeochem_nitrogenflux_inst type(waterflux_type) , intent(inout) :: waterflux_inst ! - ! !LOCAL VARIABLES: - integer :: c,fc !indices - real(r8) :: dayspyr !days per year - real(r8) :: secs_per_year !seconds per year + integer :: c,fc + real(r8) :: dayspyr, secs_per_year associate( & - AnnET => waterflux_inst%AnnET, & ! Input: [real(:) ] : Annual average ET flux mmH20/s - freelivfix_slope => params_inst%freelivfix_slope_wET, & ! Input: [real ] : slope of fixation with ET - freelivfix_inter => params_inst%freelivfix_intercept, & ! Input: [real ] : intercept of fixation with ET - ffix_to_sminn => soilbiogeochem_nitrogenflux_inst%ffix_to_sminn_col & ! Output: [real(:) ] : free living N fixation to soil mineral N (gN/m2/s) + AnnET => waterflux_inst%AnnET , & + freelivfix_slope => params_inst%freelivfix_slope_wET , & + freelivfix_inter => params_inst%freelivfix_intercept , & + ffix_to_sminn => soilbiogeochem_nitrogenflux_inst%ffix_to_sminn_col & ) dayspyr = get_days_per_year() @@ -183,7 +174,7 @@ subroutine CNFreeLivingFixation(num_soilc, filter_soilc, & do fc = 1,num_soilc c = filter_soilc(fc) - ffix_to_sminn(c) = (freelivfix_slope*(max(0._r8,AnnET(c))*secs_per_year) + freelivfix_inter )/secs_per_year !(units g N m-2 s-1) + ffix_to_sminn(c) = (freelivfix_slope*(max(0._r8,AnnET(c))*secs_per_year) + freelivfix_inter)/secs_per_year end do @@ -193,47 +184,32 @@ end subroutine CNFreeLivingFixation !----------------------------------------------------------------------- subroutine CNNFixation(num_soilc, filter_soilc, & cnveg_carbonflux_inst, soilbiogeochem_nitrogenflux_inst) - ! - ! !DESCRIPTION: - ! On the radiation time step, update the nitrogen fixation rate - ! as a function of annual total NPP. This rate gets updated once per year. - ! All N fixation goes to the soil mineral N pool. - ! - ! !USES: use clm_time_manager , only : get_days_per_year, get_step_size use shr_sys_mod , only : shr_sys_flush use clm_varcon , only : secspday, spval use CNSharedParamsMod , only: use_fun - ! - ! !ARGUMENTS: - integer , intent(in) :: num_soilc ! number of soil columns in filter - integer , intent(in) :: filter_soilc(:) ! filter for soil columns + integer , intent(in) :: num_soilc + integer , intent(in) :: filter_soilc(:) type(cnveg_carbonflux_type) , intent(inout) :: cnveg_carbonflux_inst type(soilbiogeochem_nitrogenflux_type) , intent(inout) :: soilbiogeochem_nitrogenflux_inst ! - ! !LOCAL VARIABLES: - integer :: c,fc ! indices - real(r8) :: t ! temporary - real(r8) :: dayspyr ! days per year + integer :: c,fc + real(r8) :: t, dayspyr !----------------------------------------------------------------------- associate( & - cannsum_npp => cnveg_carbonflux_inst%annsum_npp_col , & ! Input: [real(r8) (:)] nitrogen deposition rate (gN/m2/s) - col_lag_npp => cnveg_carbonflux_inst%lag_npp_col , & ! Input: [real(r8) (:)] (gC/m2/s) lagged net primary production - - nfix_to_sminn => soilbiogeochem_nitrogenflux_inst%nfix_to_sminn_col & ! Output: [real(r8) (:)] symbiotic/asymbiotic N fixation to soil mineral N (gN/m2/s) + cannsum_npp => cnveg_carbonflux_inst%annsum_npp_col , & + col_lag_npp => cnveg_carbonflux_inst%lag_npp_col , & + nfix_to_sminn => soilbiogeochem_nitrogenflux_inst%nfix_to_sminn_col & ) dayspyr = get_days_per_year() if ( nfix_timeconst > 0._r8 .and. nfix_timeconst < 500._r8 ) then - ! use exponential relaxation with time constant nfix_timeconst for NPP - NFIX relation - ! Loop through columns do fc = 1,num_soilc c = filter_soilc(fc) if (col_lag_npp(c) /= spval) then - ! need to put npp in units of gC/m^2/year here first t = (1.8_r8 * (1._r8 - exp(-0.003_r8 * col_lag_npp(c)*(secspday * dayspyr))))/(secspday * dayspyr) nfix_to_sminn(c) = max(0._r8,t) else @@ -241,7 +217,6 @@ subroutine CNNFixation(num_soilc, filter_soilc, & endif end do else - ! use annual-mean values for NPP-NFIX relation do fc = 1,num_soilc c = filter_soilc(fc) @@ -261,57 +236,156 @@ end subroutine CNNFixation subroutine CNNFert(bounds, num_soilc, filter_soilc, & cnveg_nitrogenflux_inst, soilbiogeochem_nitrogenflux_inst) ! - ! !DESCRIPTION: - ! On the radiation time step, update the nitrogen fertilizer for crops - ! All fertilizer goes into the soil mineral N pool. - ! - ! !USES: - ! - ! !ARGUMENTS: type(bounds_type) , intent(in) :: bounds - integer , intent(in) :: num_soilc ! number of soil columns in filter - integer , intent(in) :: filter_soilc(:) ! filter for soil columns + integer , intent(in) :: num_soilc + integer , intent(in) :: filter_soilc(:) type(cnveg_nitrogenflux_type) , intent(in) :: cnveg_nitrogenflux_inst type(soilbiogeochem_nitrogenflux_type) , intent(inout) :: soilbiogeochem_nitrogenflux_inst ! - ! !LOCAL VARIABLES: - integer :: c,fc ! indices + integer :: c,fc !----------------------------------------------------------------------- associate( & - fert => cnveg_nitrogenflux_inst%fert_patch , & ! Input: [real(r8) (:)] nitrogen fertilizer rate (gN/m2/s) - fert_to_sminn => soilbiogeochem_nitrogenflux_inst%fert_to_sminn_col & ! Output: [real(r8) (:)] + fert => cnveg_nitrogenflux_inst%fert_patch , & + fert_to_sminn => soilbiogeochem_nitrogenflux_inst%fert_to_sminn_col & ) call p2c(bounds, num_soilc, filter_soilc, & fert(bounds%begp:bounds%endp), & fert_to_sminn(bounds%begc:bounds%endc)) + end associate + end subroutine CNNFert + + !----------------------------------------------------------------------- + subroutine CNCSoilFert(bounds, num_soilc, filter_soilc, cnveg_carbonflux_inst, & + cnveg_nitrogenflux_inst) + ! + ! !DESCRIPTION: tboas + ! Route patch-level organic C fertilizer (fertC_patch) from manure application + ! into the surface litter pools at column level. + ! Manure C is partitioned between metabolic, cellulose, and lignin litter pools + ! using fixed fractions (manure_fmet / manure_fcel / manure_flig). + ! Only active when use_cfert = .true. and use_crop = .true. + ! + ! phenology_c_to_litr_*_col live in cnveg_carbonflux_type (not soilbiogeochem). + ! Inputs are at patch level (gC/m2/s); outputs enter at column level, + ! surface decomp layer (j=1) only. + ! + type(bounds_type) , intent(in) :: bounds + integer , intent(in) :: num_soilc + integer , intent(in) :: filter_soilc(:) + type(cnveg_carbonflux_type) , intent(inout) :: cnveg_carbonflux_inst + type(cnveg_nitrogenflux_type), intent(inout) :: cnveg_nitrogenflux_inst ! tboas-fix + ! + ! LOCAL VARIABLES + integer :: fc, c, pi, p + real(r8) :: fertC_col ! column-level sum of fertC_patch (area-weighted, gC/m2/s) + real(r8) :: fertN_col ! tboas-fix: organic manure N accompanying fertC_col (gN/m2/s) + !----------------------------------------------------------------------- + + if (.not. use_cfert .or. .not. use_crop) return + + associate( & + fertC_patch => cnveg_carbonflux_inst%fertC_patch , & ! Input: patch-level organic C fert flux (gC/m2/s) + fertN_patch => cnveg_nitrogenflux_inst%fertN_patch , & ! Input: patch-level organic N fert flux (gN/m2/s) tboas-fix + wtcol => patch%wtcol , & ! Input: patch weight on column + phenology_c_to_litr_met_c => cnveg_carbonflux_inst%phenology_c_to_litr_met_c_col , & ! Output: litter metabolic pool (gC/m3/s) + phenology_c_to_litr_cel_c => cnveg_carbonflux_inst%phenology_c_to_litr_cel_c_col , & ! Output: litter cellulose pool (gC/m3/s) + phenology_c_to_litr_lig_c => cnveg_carbonflux_inst%phenology_c_to_litr_lig_c_col , & ! Output: litter lignin pool (gC/m3/s) + ! tboas-fix: the manure N that travels with the manure C + phenology_n_to_litr_met_n => cnveg_nitrogenflux_inst%phenology_n_to_litr_met_n_col , & ! Output: litter metabolic pool (gN/m3/s) + phenology_n_to_litr_cel_n => cnveg_nitrogenflux_inst%phenology_n_to_litr_cel_n_col , & ! Output: litter cellulose pool (gN/m3/s) + phenology_n_to_litr_lig_n => cnveg_nitrogenflux_inst%phenology_n_to_litr_lig_n_col & ! Output: litter lignin pool (gN/m3/s) + ) + + do fc = 1, num_soilc + c = filter_soilc(fc) + fertC_col = 0.0_r8 + fertN_col = 0.0_r8 + + ! Aggregate patch-level fertC/fertN to column (area-weighted) + do pi = 1, col%npatches(c) + p = col%patchi(c) + pi - 1 + if (patch%active(p)) then + fertC_col = fertC_col + fertC_patch(p) * wtcol(p) + fertN_col = fertN_col + fertN_patch(p) * wtcol(p) ! tboas-fix + end if + end do + + ! Route into surface litter pools (layer j=1), volumetric units gC/m3/s + ! tboas: distribute manure C over layers down to manure_injection_depth + ! If manure_injection_depth=0 (default), apply to surface layer only (j=1) + ! tboas-fix: the organic manure N travels with the manure C, so the litter + ! pools receive both at manure_CN_ratio and the N is mineralised by the + ! decomposition cascade rather than being injected into the mineral pool a + ! second time (which is what the pre-fix code effectively did). + + if (manure_injection_depth <= 0.0_r8) then + phenology_c_to_litr_met_c(c,1) = phenology_c_to_litr_met_c(c,1) + & + fertC_col * manure_fmet / dzsoi_decomp(1) + phenology_c_to_litr_cel_c(c,1) = phenology_c_to_litr_cel_c(c,1) + & + fertC_col * manure_fcel / dzsoi_decomp(1) + phenology_c_to_litr_lig_c(c,1) = phenology_c_to_litr_lig_c(c,1) + & + fertC_col * manure_flig / dzsoi_decomp(1) + phenology_n_to_litr_met_n(c,1) = phenology_n_to_litr_met_n(c,1) + & + fertN_col * manure_fmet / dzsoi_decomp(1) + phenology_n_to_litr_cel_n(c,1) = phenology_n_to_litr_cel_n(c,1) + & + fertN_col * manure_fcel / dzsoi_decomp(1) + phenology_n_to_litr_lig_n(c,1) = phenology_n_to_litr_lig_n(c,1) + & + fertN_col * manure_flig / dzsoi_decomp(1) + else + ! Distribute proportionally over layers within injection depth + ! Weight by dzsoi_decomp so total flux integrates to fertC_col [gC/m2/s] + block + integer :: j + real(r8) :: depth_top, layer_wt, total_wt + total_wt = 0.0_r8 + depth_top = 0.0_r8 + do j = 1, nlevdecomp + if (depth_top >= manure_injection_depth) exit + total_wt = total_wt + dzsoi_decomp(j) + depth_top = depth_top + dzsoi_decomp(j) + end do + if (total_wt <= 0.0_r8) total_wt = dzsoi_decomp(1) ! guard + depth_top = 0.0_r8 + do j = 1, nlevdecomp + if (depth_top >= manure_injection_depth) exit + layer_wt = dzsoi_decomp(j) / total_wt + phenology_c_to_litr_met_c(c,j) = phenology_c_to_litr_met_c(c,j) + & + fertC_col * manure_fmet * layer_wt / dzsoi_decomp(j) + phenology_c_to_litr_cel_c(c,j) = phenology_c_to_litr_cel_c(c,j) + & + fertC_col * manure_fcel * layer_wt / dzsoi_decomp(j) + phenology_c_to_litr_lig_c(c,j) = phenology_c_to_litr_lig_c(c,j) + & + fertC_col * manure_flig * layer_wt / dzsoi_decomp(j) + phenology_n_to_litr_met_n(c,j) = phenology_n_to_litr_met_n(c,j) + & + fertN_col * manure_fmet * layer_wt / dzsoi_decomp(j) + phenology_n_to_litr_cel_n(c,j) = phenology_n_to_litr_cel_n(c,j) + & + fertN_col * manure_fcel * layer_wt / dzsoi_decomp(j) + phenology_n_to_litr_lig_n(c,j) = phenology_n_to_litr_lig_n(c,j) + & + fertN_col * manure_flig * layer_wt / dzsoi_decomp(j) + depth_top = depth_top + dzsoi_decomp(j) + end do + end block + end if + + end do end associate - end subroutine CNNFert + end subroutine CNCSoilFert !----------------------------------------------------------------------- subroutine CNSoyfix (bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, & waterstate_inst, crop_inst, cnveg_state_inst, cnveg_nitrogenflux_inst , & soilbiogeochem_state_inst, soilbiogeochem_nitrogenstate_inst, soilbiogeochem_nitrogenflux_inst) ! - ! !DESCRIPTION: - ! This routine handles the fixation of nitrogen for soybeans based on - ! the EPICPHASE model M. Cabelguenne et al., Agricultural systems 60: 175-196, 1999 - ! N-fixation is based on soil moisture, plant growth phase, and availibility of - ! nitrogen in the soil root zone. - ! - ! !USES: - use pftconMod, only : ntmp_soybean, nirrig_tmp_soybean - use pftconMod, only : ntrp_soybean, nirrig_trp_soybean + use pftconMod, only : ntmp_soybean, nirrig_tmp_soybean, ntrp_soybean, nirrig_trp_soybean ! - ! !ARGUMENTS: type(bounds_type) , intent(in) :: bounds - integer , intent(in) :: num_soilc ! number of soil columns in filter - integer , intent(in) :: filter_soilc(:) ! filter for soil columns - integer , intent(in) :: num_soilp ! number of soil patches in filter - integer , intent(in) :: filter_soilp(:) ! filter for soil patches + integer , intent(in) :: num_soilc + integer , intent(in) :: filter_soilc(:) + integer , intent(in) :: num_soilp + integer , intent(in) :: filter_soilp(:) type(waterstate_type) , intent(in) :: waterstate_inst type(crop_type) , intent(in) :: crop_inst type(cnveg_state_type) , intent(in) :: cnveg_state_inst @@ -320,10 +394,9 @@ subroutine CNSoyfix (bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, & type(soilbiogeochem_nitrogenstate_type) , intent(in) :: soilbiogeochem_nitrogenstate_inst type(soilbiogeochem_nitrogenflux_type) , intent(inout) :: soilbiogeochem_nitrogenflux_inst ! - ! !LOCAL VARIABLES: integer :: fp,p,c - real(r8):: fxw,fxn,fxg,fxr ! soil water factor, nitrogen factor, growth stage factor - real(r8):: soy_ndemand ! difference between nitrogen supply and demand + real(r8) :: fxw,fxn,fxg,fxr + real(r8) :: soy_ndemand real(r8):: GDDfrac real(r8):: sminnthreshold1, sminnthreshold2 real(r8):: GDDfracthreshold1, GDDfracthreshold2 @@ -331,20 +404,15 @@ subroutine CNSoyfix (bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, & !----------------------------------------------------------------------- associate( & - wf => waterstate_inst%wf_col , & ! Input: [real(r8) (:) ] soil water as frac. of whc for top 0.5 m - - hui => crop_inst%gddplant_patch , & ! Input: [real(r8) (:) ] gdd since planting (gddplant) - croplive => crop_inst%croplive_patch , & ! Input: [logical (:) ] true if planted and not harvested - - gddmaturity => cnveg_state_inst%gddmaturity_patch , & ! Input: [real(r8) (:) ] gdd needed to harvest - - plant_ndemand => cnveg_nitrogenflux_inst%plant_ndemand_patch , & ! Input: [real(r8) (:) ] N flux required to support initial GPP (gN/m2/s) - soyfixn => cnveg_nitrogenflux_inst%soyfixn_patch , & ! Output: [real(r8) (:) ] nitrogen fixed to each soybean crop - - fpg => soilbiogeochem_state_inst%fpg_col , & ! Input: [real(r8) (:) ] fraction of potential gpp (no units) - - sminn => soilbiogeochem_nitrogenstate_inst%sminn_col , & ! Input: [real(r8) (:) ] (kgN/m2) soil mineral N - soyfixn_to_sminn => soilbiogeochem_nitrogenflux_inst%soyfixn_to_sminn_col & ! Output: [real(r8) (:) ] + wf => waterstate_inst%wf_col , & + hui => crop_inst%gddplant_patch , & + croplive => crop_inst%croplive_patch , & + gddmaturity => cnveg_state_inst%gddmaturity_patch , & + plant_ndemand => cnveg_nitrogenflux_inst%plant_ndemand_patch , & + soyfixn => cnveg_nitrogenflux_inst%soyfixn_patch , & + fpg => soilbiogeochem_state_inst%fpg_col , & + sminn => soilbiogeochem_nitrogenstate_inst%sminn_col , & + soyfixn_to_sminn => soilbiogeochem_nitrogenflux_inst%soyfixn_to_sminn_col & ) sminnthreshold1 = 30._r8 @@ -358,7 +426,6 @@ subroutine CNSoyfix (bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, & p = filter_soilp(fp) c = patch%column(p) - ! if soybean currently growing then calculate fixation if (croplive(p) .and. & (patch%itype(p) == ntmp_soybean .or. & @@ -366,20 +433,15 @@ subroutine CNSoyfix (bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, & patch%itype(p) == ntrp_soybean .or. & patch%itype(p) == nirrig_trp_soybean) ) then - ! difference between supply and demand if (fpg(c) < 1._r8) then soy_ndemand = 0._r8 soy_ndemand = plant_ndemand(p) - plant_ndemand(p)*fpg(c) - ! fixation depends on nitrogen, soil water, and growth stage - - ! soil water factor fxw = 0._r8 fxw = wf(c)/0.85_r8 - ! soil nitrogen factor (Beth says: CHECK UNITS) if (sminn(c) > sminnthreshold1) then fxn = 0._r8 @@ -389,12 +451,6 @@ subroutine CNSoyfix (bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, & fxn = 1._r8 end if - ! growth stage factor - ! slevis: to replace GDDfrac, assume... - ! Beth's crit_offset_gdd_def is similar to my gddmaturity - ! Beth's ac_gdd (base 5C) similar to my hui=gddplant (base 10 - ! for soy) - ! Ranges below are not firm. Are they lit. based or tuning based? GDDfrac = hui(p) / gddmaturity(p) @@ -406,24 +462,23 @@ subroutine CNSoyfix (bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, & fxg = 1._r8 else if (GDDfrac > GDDfracthreshold3 .and. GDDfrac <= GDDfracthreshold4) then fxg = 3.75_r8 - 5._r8 * GDDfrac - else ! GDDfrac > GDDfracthreshold4 + else fxg = 0._r8 end if - ! calculate the nitrogen fixed by the soybean fxr = min(1._r8, fxw, fxn) * fxg fxr = max(0._r8, fxr) soyfixn(p) = fxr * soy_ndemand soyfixn(p) = min(soyfixn(p), soy_ndemand) - else ! if nitrogen demand met, no fixation + else soyfixn(p) = 0._r8 end if - else ! if not live soybean, no fixation + else soyfixn(p) = 0._r8 diff --git a/src/clm5/biogeochem/CNNStateUpdate1Mod.F90 b/src/clm5/biogeochem/CNNStateUpdate1Mod.F90 index 6c1d112029..fa896e1126 100644 --- a/src/clm5/biogeochem/CNNStateUpdate1Mod.F90 +++ b/src/clm5/biogeochem/CNNStateUpdate1Mod.F90 @@ -113,6 +113,8 @@ subroutine NStateUpdate1(num_soilc, filter_soilc, num_soilp, filter_soilp, & woody => pftcon%woody , & ! Input: binary flag for woody lifeform (1=woody, 0=not woody) + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types (1=perennial, 0= not perennial) + mulch_pruning => pftcon%mulch_pruning , & ! Input: binary flag for exporting of mulching of pruning material (1=mulching, 0=exporting) nf_veg => cnveg_nitrogenflux_inst , & ! Input: ns_veg => cnveg_nitrogenstate_inst , & ! Output: nf_soil => soilbiogeochem_nitrogenflux_inst & ! Output: @@ -167,10 +169,16 @@ subroutine NStateUpdate1(num_soilc, filter_soilc, num_soilp, filter_soilp, & if (ivt(p) >= npcropmin) then ! skip 2 generic crops ! lines here for consistency; the transfer terms are zero + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + ns_veg%grainn_patch(p) = ns_veg%grainn_patch(p) + nf_veg%grainn_xfer_to_grainn_patch(p)*dt + ns_veg%grainn_xfer_patch(p) = ns_veg%grainn_xfer_patch(p) - nf_veg%grainn_xfer_to_grainn_patch(p)*dt + + else ns_veg%livestemn_patch(p) = ns_veg%livestemn_patch(p) + nf_veg%livestemn_xfer_to_livestemn_patch(p)*dt ns_veg%livestemn_xfer_patch(p) = ns_veg%livestemn_xfer_patch(p) - nf_veg%livestemn_xfer_to_livestemn_patch(p)*dt ns_veg%grainn_patch(p) = ns_veg%grainn_patch(p) + nf_veg%grainn_xfer_to_grainn_patch(p)*dt ns_veg%grainn_xfer_patch(p) = ns_veg%grainn_xfer_patch(p) - nf_veg%grainn_xfer_to_grainn_patch(p)*dt + end if end if ! phenology: litterfall and retranslocation fluxes @@ -191,6 +199,22 @@ subroutine NStateUpdate1(num_soilc, filter_soilc, num_soilp, filter_soilp, & ns_veg%retransn_patch(p) = ns_veg%retransn_patch(p) + nf_veg%livecrootn_to_retransn_patch(p)*dt end if if (ivt(p) >= npcropmin) then ! Beth adds retrans from froot + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + ns_veg%frootn_patch(p) = ns_veg%frootn_patch(p) - nf_veg%frootn_to_retransn_patch(p)*dt + ns_veg%retransn_patch(p) = ns_veg%retransn_patch(p) + nf_veg%frootn_to_retransn_patch(p)*dt + ns_veg%grainn_patch(p) = ns_veg%grainn_patch(p) & + - (nf_veg%grainn_to_food_patch(p) + nf_veg%grainn_to_seed_patch(p))*dt + ns_veg%cropseedn_deficit_patch(p) = ns_veg%cropseedn_deficit_patch(p) & + - nf_veg%crop_seedn_to_leaf_patch(p) * dt & + - nf_veg%crop_seedn_to_froot_patch(p) * dt & ! added by (O.Dombrowski) + - nf_veg%crop_seedn_to_deadstem_patch(p) * dt & ! added by (O.Dombrowski) + + nf_veg%grainn_to_seed_patch(p) * dt + if (mulch_pruning(ivt(p)) == 1._r8) then + ! update stem N after pruning + ns_veg%deadstemn_patch(p) = ns_veg%deadstemn_patch(p) - nf_veg%prunen_to_litter_patch(p)*dt + ns_veg%deadstemn_storage_patch(p) = ns_veg%deadstemn_storage_patch(p) - nf_veg%prunen_storage_to_litter_patch(p)*dt + end if + else ns_veg%frootn_patch(p) = ns_veg%frootn_patch(p) - nf_veg%frootn_to_retransn_patch(p)*dt ns_veg%retransn_patch(p) = ns_veg%retransn_patch(p) + nf_veg%frootn_to_retransn_patch(p)*dt ns_veg%livestemn_patch(p) = ns_veg%livestemn_patch(p) - nf_veg%livestemn_to_litter_patch(p)*dt @@ -201,6 +225,7 @@ subroutine NStateUpdate1(num_soilc, filter_soilc, num_soilp, filter_soilp, & ns_veg%cropseedn_deficit_patch(p) = ns_veg%cropseedn_deficit_patch(p) & - nf_veg%crop_seedn_to_leaf_patch(p) * dt & + nf_veg%grainn_to_seed_patch(p) * dt + end if end if ! uptake from soil mineral N pool @@ -243,6 +268,13 @@ subroutine NStateUpdate1(num_soilc, filter_soilc, num_soilp, filter_soilp, & end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + ns_veg%npool_patch(p) = ns_veg%npool_patch(p) - nf_veg%npool_to_grainn_patch(p)*dt + ns_veg%grainn_patch(p) = ns_veg%grainn_patch(p) + nf_veg%npool_to_grainn_patch(p)*dt + ns_veg%npool_patch(p) = ns_veg%npool_patch(p) - nf_veg%npool_to_grainn_storage_patch(p)*dt + ns_veg%grainn_storage_patch(p) = ns_veg%grainn_storage_patch(p) + nf_veg%npool_to_grainn_storage_patch(p)*dt + + else ns_veg%npool_patch(p) = ns_veg%npool_patch(p) - nf_veg%npool_to_livestemn_patch(p)*dt ns_veg%livestemn_patch(p) = ns_veg%livestemn_patch(p) + nf_veg%npool_to_livestemn_patch(p)*dt ns_veg%npool_patch(p) = ns_veg%npool_patch(p) - nf_veg%npool_to_livestemn_storage_patch(p)*dt @@ -251,6 +283,7 @@ subroutine NStateUpdate1(num_soilc, filter_soilc, num_soilp, filter_soilp, & ns_veg%grainn_patch(p) = ns_veg%grainn_patch(p) + nf_veg%npool_to_grainn_patch(p)*dt ns_veg%npool_patch(p) = ns_veg%npool_patch(p) - nf_veg%npool_to_grainn_storage_patch(p)*dt ns_veg%grainn_storage_patch(p) = ns_veg%grainn_storage_patch(p) + nf_veg%npool_to_grainn_storage_patch(p)*dt + end if end if ! move storage pools into transfer pools @@ -271,11 +304,16 @@ subroutine NStateUpdate1(num_soilc, filter_soilc, num_soilp, filter_soilp, & end if if (ivt(p) >= npcropmin) then ! skip 2 generic crops + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1.0_r8) then ! (added by O.Dombrowski) + ns_veg%grainn_storage_patch(p) = ns_veg%grainn_storage_patch(p) - nf_veg%grainn_storage_to_xfer_patch(p)*dt + ns_veg%grainn_xfer_patch(p) = ns_veg%grainn_xfer_patch(p) + nf_veg%grainn_storage_to_xfer_patch(p)*dt ! lines here for consistency; the transfer terms are zero + else ns_veg%livestemn_storage_patch(p) = ns_veg%livestemn_storage_patch(p) - nf_veg%livestemn_storage_to_xfer_patch(p)*dt ns_veg%livestemn_xfer_patch(p) = ns_veg%livestemn_xfer_patch(p) + nf_veg%livestemn_storage_to_xfer_patch(p)*dt ns_veg%grainn_storage_patch(p) = ns_veg%grainn_storage_patch(p) - nf_veg%grainn_storage_to_xfer_patch(p)*dt ns_veg%grainn_xfer_patch(p) = ns_veg%grainn_xfer_patch(p) + nf_veg%grainn_storage_to_xfer_patch(p)*dt + end if end if end do diff --git a/src/clm5/biogeochem/CNPhenologyMod.F90 b/src/clm5/biogeochem/CNPhenologyMod.F90 index 9d66373085..a2136b84bc 100644 --- a/src/clm5/biogeochem/CNPhenologyMod.F90 +++ b/src/clm5/biogeochem/CNPhenologyMod.F90 @@ -15,12 +15,16 @@ module CNPhenologyMod use shr_sys_mod , only : shr_sys_flush use decompMod , only : bounds_type use clm_varpar , only : numpft, nlevdecomp_full - use clm_varctl , only : iulog, use_cndv + use clm_varctl , only : debug_covercrop ! tboas-fix + use clm_varctl , only : manure_nh4_frac ! tboas-fix + use clm_varctl , only : iulog, use_cndv, use_cfert, manure_CN_ratio, & + manure_freq_years, manure_apply_month, manure_apply_day ! tboas use clm_varcon , only : tfrz use abortutils , only : endrun use CanopyStateType , only : canopystate_type use CNDVType , only : dgvs_type use CNVegstateType , only : cnveg_state_type + use SoilBiogeochemStateType , only : soilbiogeochem_state_type use CNVegCarbonStateType , only : cnveg_carbonstate_type use CNVegCarbonFluxType , only : cnveg_carbonflux_type use CNVegnitrogenstateType , only : cnveg_nitrogenstate_type @@ -33,7 +37,6 @@ module CNPhenologyMod use ColumnType , only : col use GridcellType , only : grc use PatchType , only : patch - use atm2lndType , only : atm2lnd_type use atm2lndType , only : atm2lnd_type ! implicit none @@ -89,13 +92,14 @@ module CNPhenologyMod integer, allocatable :: minplantjday(:,:) ! minimum planting julian day integer, allocatable :: maxplantjday(:,:) ! maximum planting julian day + integer, allocatable :: maxharvjday(:,:) ! maximum harvest julian day (added by O.Dombrowski) integer :: jdayyrstart(inSH) ! julian day of start of year real(r8), private :: initial_seed_at_planting = 3._r8 ! Initial seed at planting + ! tboas: manure carbon parameters character(len=*), parameter, private :: sourcefile = & __FILE__ - !----------------------------------------------------------------------- contains @@ -242,12 +246,13 @@ subroutine CNPhenology (bounds, num_soilc, filter_soilc, num_soilp, & filter_soilp, num_pcropp, filter_pcropp, & doalb, waterstate_inst, temperature_inst, atm2lnd_inst, crop_inst, & canopystate_inst, soilstate_inst, dgvs_inst, & - cnveg_state_inst, cnveg_carbonstate_inst, cnveg_carbonflux_inst, & + cnveg_state_inst, soilbiogeochem_state_inst, cnveg_carbonstate_inst, cnveg_carbonflux_inst, & cnveg_nitrogenstate_inst, cnveg_nitrogenflux_inst, & c13_cnveg_carbonstate_inst, c14_cnveg_carbonstate_inst, & - leaf_prof_patch, froot_prof_patch, phase) + leaf_prof_patch, froot_prof_patch,stem_prof_patch, phase) ! !USES: use CNSharedParamsMod, only: use_fun + use clm_varctl , only: use_fruittree ! tboas ! ! !DESCRIPTION: ! Dynamic phenology routine for coupled carbon-nitrogen code (CN) @@ -270,6 +275,7 @@ subroutine CNPhenology (bounds, num_soilc, filter_soilc, num_soilp, & type(soilstate_type) , intent(in) :: soilstate_inst type(dgvs_type) , intent(inout) :: dgvs_inst type(cnveg_state_type) , intent(inout) :: cnveg_state_inst + type(soilbiogeochem_state_type) , intent(in) :: soilbiogeochem_state_inst type(cnveg_carbonstate_type) , intent(inout) :: cnveg_carbonstate_inst type(cnveg_carbonflux_type) , intent(inout) :: cnveg_carbonflux_inst type(cnveg_nitrogenstate_type) , intent(inout) :: cnveg_nitrogenstate_inst @@ -278,12 +284,14 @@ subroutine CNPhenology (bounds, num_soilc, filter_soilc, num_soilp, & type(cnveg_carbonstate_type) , intent(inout) :: c14_cnveg_carbonstate_inst real(r8) , intent(in) :: leaf_prof_patch(bounds%begp:,1:) real(r8) , intent(in) :: froot_prof_patch(bounds%begp:,1:) + real(r8) , intent(in) :: stem_prof_patch(bounds%begp:,1:) integer , intent(in) :: phase !----------------------------------------------------------------------- SHR_ASSERT_ALL((ubound(leaf_prof_patch) == (/bounds%endp,nlevdecomp_full/)), errMsg(sourcefile, __LINE__)) SHR_ASSERT_ALL((ubound(froot_prof_patch) == (/bounds%endp,nlevdecomp_full/)), errMsg(sourcefile, __LINE__)) + SHR_ASSERT_ALL((ubound(stem_prof_patch) == (/bounds%endp,nlevdecomp_full/)), errMsg(sourcefile, __LINE__)) ! each of the following phenology type routines includes a filter ! to operate only on the relevant patches @@ -308,6 +316,11 @@ subroutine CNPhenology (bounds, num_soilc, filter_soilc, num_soilp, & waterstate_inst, temperature_inst, crop_inst, canopystate_inst, cnveg_state_inst, & cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst, & c13_cnveg_carbonstate_inst, c14_cnveg_carbonstate_inst) + ! FruitTreePhenology routine has a special filter for deciduous tree crop pfts (added by O.Dombrowski) + if (use_fruittree) call FruitTreePhenology(num_pcropp, filter_pcropp, & + waterstate_inst, temperature_inst, crop_inst, canopystate_inst, cnveg_state_inst, dgvs_inst, & + cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst, & + c13_cnveg_carbonstate_inst, c14_cnveg_carbonstate_inst) end if else if ( phase == 2 ) then ! the same onset and offset routines are called regardless of @@ -318,7 +331,7 @@ subroutine CNPhenology (bounds, num_soilc, filter_soilc, num_soilp, & cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst) call CNOffsetLitterfall(num_soilp, filter_soilp, & - cnveg_state_inst, cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst) + crop_inst,cnveg_state_inst, cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst) call CNBackgroundLitterfall(num_soilp, filter_soilp, & cnveg_state_inst, cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst) @@ -334,7 +347,11 @@ subroutine CNPhenology (bounds, num_soilc, filter_soilc, num_soilp, & call CNLitterToColumn(bounds, num_soilc, filter_soilc, & cnveg_state_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst, & leaf_prof_patch(bounds%begp:bounds%endp,1:nlevdecomp_full), & - froot_prof_patch(bounds%begp:bounds%endp,1:nlevdecomp_full)) + froot_prof_patch(bounds%begp:bounds%endp,1:nlevdecomp_full), stem_prof_patch(bounds%begp:bounds%endp,1:nlevdecomp_full)) + + call CNRotationToColumn (num_soilc, filter_soilc, & + cnveg_state_inst, soilbiogeochem_state_inst, crop_inst, cnveg_carbonflux_inst, & + cnveg_nitrogenflux_inst) else call endrun( 'bad phase' ) end if @@ -707,6 +724,7 @@ subroutine CNSeasonDecidPhenology (num_soilp, filter_soilp , & woody => pftcon%woody , & ! Input: binary flag for woody lifeform (1=woody, 0=not woody) season_decid => pftcon%season_decid , & ! Input: binary flag for seasonal-deciduous leaf habit (0 or 1) + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types (0 or 1) t_soisno => temperature_inst%t_soisno_col , & ! Input: [real(r8) (:,:) ] soil temperature (Kelvin) (-nlevsno+1:nlevgrnd) pftmayexist => dgvs_inst%pftmayexist_patch , & ! Output: [logical (:) ] exclude seasonal decid patches from tropics @@ -787,7 +805,7 @@ subroutine CNSeasonDecidPhenology (num_soilp, filter_soilp , & c = patch%column(p) g = patch%gridcell(p) - if (season_decid(ivt(p)) == 1._r8) then + if (season_decid(ivt(p)) == 1._r8 .and. perennial(ivt(p)) == 0._r8) then ! set background litterfall rate, background transfer rate, and ! long growing season factor to 0 for seasonal deciduous types @@ -1416,6 +1434,700 @@ subroutine CNStressDecidPhenology (num_soilp, filter_soilp , & end subroutine CNStressDecidPhenology + !----------------------------------------------------------------------- + subroutine FruitTreePhenology(num_pcropp, filter_pcropp , & + waterstate_inst, temperature_inst, crop_inst, canopystate_inst, cnveg_state_inst, dgvs_inst, & + cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst,& + c13_cnveg_carbonstate_inst, c14_cnveg_carbonstate_inst) + + ! !DESCRIPTION: + ! Code from AgroIBIS adapted for deciduous fruit trees by O. Dombrowski (2022) to determine crop phenology and code from CN to + ! handle CN fluxes during the phenological onset & offset periods. + ! New phenological stages and triggers, as well as management practices typical for fruit orchards are described + + ! !USES: + use shr_const_mod , only : SHR_CONST_TKFRZ + use clm_time_manager , only : get_curr_date, get_curr_calday, get_days_per_year, get_rad_step_size + use pftconMod , only : napple ! the citrus PFT is used for now, separate PFTs for deciduous fruit tree species may be added in the future + use pftconMod , only : nirrig_apple + use clm_varcon , only : spval, secspday + use clm_varctl , only : use_fertilizer + use clm_varctl , only : use_c13, use_c14 + use clm_varcon , only : c13ratio, c14ratio + ! + ! !ARGUMENTS: + integer , intent(in) :: num_pcropp ! number of prog crop patches in filter + integer , intent(in) :: filter_pcropp(:) ! filter for prognostic crop patches + type(waterstate_type) , intent(in) :: waterstate_inst + type(temperature_type) , intent(in) :: temperature_inst + type(crop_type) , intent(inout) :: crop_inst + type(canopystate_type) , intent(in) :: canopystate_inst + type(cnveg_state_type) , intent(inout) :: cnveg_state_inst + type(dgvs_type) , intent(inout) :: dgvs_inst + type(cnveg_carbonstate_type) , intent(inout) :: cnveg_carbonstate_inst + type(cnveg_nitrogenstate_type) , intent(inout) :: cnveg_nitrogenstate_inst + type(cnveg_carbonflux_type) , intent(inout) :: cnveg_carbonflux_inst + type(cnveg_nitrogenflux_type) , intent(inout) :: cnveg_nitrogenflux_inst + type(cnveg_carbonstate_type) , intent(inout) :: c13_cnveg_carbonstate_inst + type(cnveg_carbonstate_type) , intent(inout) :: c14_cnveg_carbonstate_inst + ! + ! LOCAL VARAIBLES: + integer kyr ! current year + integer kmo ! month of year (1, ..., 12) + integer kda ! day of month (1, ..., 31) + integer mcsec ! seconds of day (0, ..., seconds/day) + integer jday ! julian day of the year + integer fp,p ! patch indices + integer c ! column indices + integer g ! gridcell indices + integer h ! hemisphere indices + integer idpp ! number of days past planting + real(r8) :: dtrad ! radiation time step delta t (seconds) + real(r8) dayspyr ! days per year + real(r8) crmcorn ! comparitive relative maturity for corn + real(r8) nfertdays_on ! number of days to fertilize + real(r8):: ws_flag !winter-summer solstice flag (0 or 1) + real(r8):: crit_onset_gdd !critical onset growing degree-day sum + real(r8):: soilt + real(r8) :: Cd !chill day value + real(r8) :: Ca !anti-chill day value + + !------------------------------------------------------------------------ + + associate( & + ivt => patch%itype , & ! Input: [integer (:) ] patch vegetation type + dayl => grc%dayl , & ! Input: [real(r8) (:) ] daylength (s) + prev_dayl => grc%prev_dayl , & ! Input: [real(r8) (:) ] daylength from previous time step (s) + leaf_long => pftcon%leaf_long , & ! Input: leaf longevity (yrs) + leafcn => pftcon%leafcn , & ! Input: leaf C:N (gC/gN) + frootcn => pftcon%frootcn , & ! Input: fine root C:N (gC/gN) + livewdcn => pftcon%livewdcn , & ! Input: live wood C:N (gC/gN) + deadwdcn => pftcon%deadwdcn , & ! Input: dead wood C:N (gC/gN) + manunitro => pftcon%manunitro , & ! Input: max manure to be applied in total (kgN/m2) + mxmat => pftcon%mxmat , & ! Input: + minplanttemp => pftcon%minplanttemp , & ! Input: + planttemp => pftcon%planttemp , & ! Input: + gddmin => pftcon%gddmin , & ! Input: + hybgdd => pftcon%hybgdd , & ! Input: + grnfill => pftcon%grnfill , & ! Input: + lfmat => pftcon%lfmat , & ! Input: + grnrp => pftcon%grnrp , & ! Input: + transplant => pftcon%transplant , & ! Input: (O.Dombrowski) + woody => pftcon%woody , & ! Input: (O.Dombrowski) + season_decid => pftcon%season_decid , & ! Input: binary flag for seasonal-deciduous leaf habit (0 or 1) + baset => pftcon%baset , & ! Input: crop base temperature + ndays_stor => pftcon%ndays_stor , & ! Input: length of period for storage growth of fruit tree crops + crit_temp => pftcon%crit_temp , & ! Input: critical temperature to initiate leaf offset for fruit tree crops + crequ => pftcon%crequ , & ! Input: chilling requirements for fruit tree crops + + pftmayexist => dgvs_inst%pftmayexist_patch , & ! Output: [logical (:) ] exlude seasonal decid patches from tropics + + t_soisno => temperature_inst%t_soisno_col , & ! Input: [real(r8) (:,:) ] soil temperature (Kelvin) (-nlevsno+1:nlevgrnd) + + t_ref2m_min => temperature_inst%t_ref2m_min_patch , & ! Input: [real(r8) (:) ] daily minimum of average 2 m height surface air temperature (K) + t_ref2m_max => temperature_inst%t_ref2m_max_patch , & ! Input: [real(r8) (:) ] daily maximum of average 2 m height surface air temperature (K) + t_ref24 => temperature_inst%t_ref24_patch , & ! Input: [real(r8) (:) ] 24-hour averae 2 m air temperature (K) + t10 => temperature_inst%t_a10_patch , & ! Input: [real(r8) (:) ] 10-day running mean of the 2 m temperature (K) + a5tmin => temperature_inst%t_a5min_patch , & ! Input: [real(r8) (:) ] 5-day running mean of min 2-m temperature + a10tmin => temperature_inst%t_a10min_patch , & ! Input: [real(r8) (:) ] 10-day running mean of min 2-m temperature + gdd020 => temperature_inst%gdd020_patch , & ! Input: [real(r8) (:) ] 20 yr mean of gdd0 + gdd820 => temperature_inst%gdd820_patch , & ! Input: [real(r8) (:) ] 20 yr mean of gdd8 + gdd1020 => temperature_inst%gdd1020_patch , & ! Input: [real(r8) (:) ] 20 yr mean of gdd10 + + fertnitro => crop_inst%fertnitro_patch , & ! Input: [real(r8) (:) ] fertilizer nitrogen + hui => crop_inst%gddplant_patch , & ! Input: [real(r8) (:) ] gdd since planting (gddplant) + leafout => crop_inst%gddtsoi_patch , & ! Input: [real(r8) (:) ] gdd from top soil layer temperature + harvdate => crop_inst%harvdate_patch , & ! Output: [integer (:) ] harvest date + croplive => crop_inst%croplive_patch , & ! Output: [logical (:) ] Flag, true if planted, not harvested + cropplant => crop_inst%cropplant_patch , & ! Output: [logical (:) ] Flag, true if crop may be planted + vf => crop_inst%vf_patch , & ! Output: [real(r8) (:) ] vernalization factor + yrop => crop_inst%yrop_patch , & ! Output: [integer (:) ] year of planting (introduced in CLM-Palm (Fan et al. 2015), and adopted here by O.Dombrowski) + peaklai => cnveg_state_inst%peaklai_patch , & ! Output: [integer (:) ] 1: max allowed lai; 0: not at max + tlai => canopystate_inst%tlai_patch , & ! Input: [real(r8) (:) ] one-sided leaf area index, no burying by snow + + idop => cnveg_state_inst%idop_patch , & ! Output: [integer (:) ] date of planting + gddmaturity => cnveg_state_inst%gddmaturity_patch , & ! Output: [real(r8) (:) ] gdd needed to harvest + huileaf => cnveg_state_inst%huileaf_patch , & ! Output: [real(r8) (:) ] heat unit index at leaf emergence + huigrain => cnveg_state_inst%huigrain_patch , & ! Output: [real(r8) (:) ] heat unit index needed to reach start of fruit fill + huilfmat => cnveg_state_inst%huilfmat_patch , & ! Output: [real(r8) (:) ] heat unit index needed to reach canopy maturity (added by O.Dombrowski) + huiripe => cnveg_state_inst%huiripe_patch , & ! Output: [real(r8) (:) ] heat unit index needed to reach start of fruit cell expansion (added by O.Dombrowski) + bglfr => cnveg_state_inst%bglfr_patch , & ! Output: [real(r8) (:) ] background litterfall rate (1/s) + bgtr => cnveg_state_inst%bgtr_patch , & ! Output: [real(r8) (:) ] background transfer growth rate (1/s) + lgsf => cnveg_state_inst%lgsf_patch , & ! Output: [real(r8) (:) ] long growing season factor [0-1] + annavg_t2m => cnveg_state_inst%annavg_t2m_patch , & ! Input: [real(r8) (:) ] annual average 2m air temperature (K) + dormant_flag => cnveg_state_inst%dormant_flag_patch , & ! Output: [real(r8) (:) ] dormancy flag + days_active => cnveg_state_inst%days_active_patch , & ! Output: [real(r8) (:) ] number of days since last dormancy + onset_flag => cnveg_state_inst%onset_flag_patch , & ! Output: [real(r8) (:) ] onset flag + offset_flag => cnveg_state_inst%offset_flag_patch , & ! Output: [real(r8) (:) ] offset flag + offset2_flag => cnveg_state_inst%offset2_flag_patch , & ! Output: [real(r8) (:) ] orchard rotation flag + onset_counter => cnveg_state_inst%onset_counter_patch , & ! Output: [real(r8) (:) ] onset counter + offset_counter => cnveg_state_inst%offset_counter_patch , & ! Output: [real(r8) (:) ] offset counter + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop phenology (1=perennial, 0=not perennial) (introduced in CLM-Palm (Fan et al. 2015), and adopted here by O.Dombrowski) + harvest_flag => cnveg_state_inst%harvest_flag_patch , & ! Output: [real(r8) (:) ] harvest flag (introduced in CLM-Palm (Fan et al. 2015), and adopted here by O.Dombrowski) + prune_flag => cnveg_state_inst%prune_flag_patch , & ! Output: [real(r8) (:) ] pruning flag for perennials (introduced in CLM-Palm (Fan et al. 2015), and adopted here by O.Dombrowski) + storage_flag => cnveg_state_inst%storage_flag_patch , & ! Output: [real(r8) (:) ] flag to switch to storage growth for perennials (added by O.Dombrowski) + onset_gddflag => cnveg_state_inst%onset_gddflag_patch , & ! Output: [real(r8) (:) ] onset freeze flag + onset_gdd => cnveg_state_inst%onset_gdd_patch , & ! Output: [real(r8) (:) ] onset growing degree days + chill_day => cnveg_state_inst%chill_day_patch , & ! Output: [real(r8) (:) ] chilling days required for bud burst of fruit tree crops + anti_chill_day => cnveg_state_inst%anti_chill_day_patch , & ! Output: [real(r8) (:) ] anti-chill days required for bud burst of fruit tree crops + chill_flag => cnveg_state_inst%chill_flag_patch , & ! Output: [real(r8) (:) ] chill flag + + deadstemc => cnveg_carbonstate_inst%deadstemc_patch , & ! Input: [real(r8) (:) ] (gC/m2) deadstem C + leafc_storage => cnveg_carbonstate_inst%leafc_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) leaf C storage + frootc_storage => cnveg_carbonstate_inst%frootc_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) fine root C storage + livestemc_storage => cnveg_carbonstate_inst%livestemc_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) live stem C storage + deadstemc_storage => cnveg_carbonstate_inst%deadstemc_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) dead stem C storage + livecrootc_storage => cnveg_carbonstate_inst%livecrootc_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) live coarse root C storage + deadcrootc_storage => cnveg_carbonstate_inst%deadcrootc_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) dead coarse root C storage + gresp_storage => cnveg_carbonstate_inst%gresp_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) growth respiration storage + leafc_xfer => cnveg_carbonstate_inst%leafc_xfer_patch , & ! Output: [real(r8) (:) ] (gC/m2) leaf C transfer + frootc_xfer => cnveg_carbonstate_inst%frootc_xfer_patch , & ! Output: [real(r8) (:) ] (gC/m2) fine root C transfer + livestemc_xfer => cnveg_carbonstate_inst%livestemc_xfer_patch , & ! Output: [real(r8) (:) ] (gC/m2) live stem C transfer + deadstemc_xfer => cnveg_carbonstate_inst%deadstemc_xfer_patch , & ! Output: [real(r8) (:) ] (gC/m2) dead stem C transfer + livecrootc_xfer => cnveg_carbonstate_inst%livecrootc_xfer_patch , & ! Output: [real(r8) (:) ] (gC/m2) live coarse root C transfer + deadcrootc_xfer => cnveg_carbonstate_inst%deadcrootc_xfer_patch , & ! Output: [real(r8) (:) ] (gC/m2) dead coarse root C transfer + deadstemc_soy => cnveg_carbonstate_inst%deadstemc_soy_patch , & ! Output: [real(r8) (:) ] (gC/m2) dead stem C at start of year + deadstemc_storage_soy => cnveg_carbonstate_inst%deadstemc_storage_soy_patch , & ! Output: [real(r8) (:) ] (gC/m2) dead stem C storage at start of year + + + deadstemn => cnveg_nitrogenstate_inst%deadstemn_patch , & ! Input: [real(r8) (:) ] (gN/m2) deadstem N + leafn_storage => cnveg_nitrogenstate_inst%leafn_storage_patch , & ! Input: [real(r8) (:) ] (gN/m2) leaf N storage + frootn_storage => cnveg_nitrogenstate_inst%frootn_storage_patch , & ! Input: [real(r8) (:) ] (gN/m2) fine root N storage + livestemn_storage => cnveg_nitrogenstate_inst%livestemn_storage_patch , & ! Input: [real(r8) (:) ] (gN/m2) live stem N storage + deadstemn_storage => cnveg_nitrogenstate_inst%deadstemn_storage_patch , & ! Input: [real(r8) (:) ] (gN/m2) dead stem N storage + livecrootn_storage => cnveg_nitrogenstate_inst%livecrootn_storage_patch , & ! Input: [real(r8) (:) ] (gN/m2) live coarse root N storage + deadcrootn_storage => cnveg_nitrogenstate_inst%deadcrootn_storage_patch , & ! Input: [real(r8) (:) ] (gN/m2) dead coarse root N storage + leafn_xfer => cnveg_nitrogenstate_inst%leafn_xfer_patch , & ! Output: [real(r8) (:) ] (gN/m2) leaf N transfer + frootn_xfer => cnveg_nitrogenstate_inst%frootn_xfer_patch , & ! Output: [real(r8) (:) ] (gN/m2) fine root N transfer + livestemn_xfer => cnveg_nitrogenstate_inst%livestemn_xfer_patch , & ! Output: [real(r8) (:) ] (gN/m2) live stem N transfer + deadstemn_xfer => cnveg_nitrogenstate_inst%deadstemn_xfer_patch , & ! Output: [real(r8) (:) ] (gN/m2) dead stem N transfer + livecrootn_xfer => cnveg_nitrogenstate_inst%livecrootn_xfer_patch , & ! Output: [real(r8) (:) ] (gN/m2) live coarse root N transfer + deadcrootn_xfer => cnveg_nitrogenstate_inst%deadcrootn_xfer_patch , & ! Output: [real(r8) (:) ] (gN/m2) dead coarse root N transfer + deadstemn_soy => cnveg_nitrogenstate_inst%deadstemn_soy_patch , & ! Output: [real(r8) (:) ] (gN/m2) dead stem N at start of year + deadstemn_storage_soy => cnveg_nitrogenstate_inst%deadstemn_storage_soy_patch , & ! Output: [real(r8) (:) ] (gN/m2) dead stem N storage at start of year + + + prev_leafc_to_litter => cnveg_carbonflux_inst%prev_leafc_to_litter_patch , & ! Output: [real(r8) (:) ] previous timestep leaf C litterfall flux (gC/m2/s) + prev_frootc_to_litter => cnveg_carbonflux_inst%prev_frootc_to_litter_patch , & ! Output: [real(r8) (:) ] previous timestep froot C litterfall flux (gC/m2/s) + + leafc_xfer_to_leafc => cnveg_carbonflux_inst%leafc_xfer_to_leafc_patch , & ! Output: [real(r8) (:) ] + frootc_xfer_to_frootc => cnveg_carbonflux_inst%frootc_xfer_to_frootc_patch , & ! Output: [real(r8) (:) ] + livestemc_xfer_to_livestemc => cnveg_carbonflux_inst%livestemc_xfer_to_livestemc_patch , & ! Output: [real(r8) (:) ] + deadstemc_xfer_to_deadstemc => cnveg_carbonflux_inst%deadstemc_xfer_to_deadstemc_patch , & ! Output: [real(r8) (:) ] + livecrootc_xfer_to_livecrootc => cnveg_carbonflux_inst%livecrootc_xfer_to_livecrootc_patch , & ! Output: [real(r8) (:) ] + deadcrootc_xfer_to_deadcrootc => cnveg_carbonflux_inst%deadcrootc_xfer_to_deadcrootc_patch , & ! Output: [real(r8) (:) ] + leafc_storage_to_xfer => cnveg_carbonflux_inst%leafc_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + frootc_storage_to_xfer => cnveg_carbonflux_inst%frootc_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + livestemc_storage_to_xfer => cnveg_carbonflux_inst%livestemc_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + deadstemc_storage_to_xfer => cnveg_carbonflux_inst%deadstemc_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + livecrootc_storage_to_xfer => cnveg_carbonflux_inst%livecrootc_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + deadcrootc_storage_to_xfer => cnveg_carbonflux_inst%deadcrootc_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + gresp_storage_to_xfer => cnveg_carbonflux_inst%gresp_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + + leafn_xfer_to_leafn => cnveg_nitrogenflux_inst%leafn_xfer_to_leafn_patch , & ! Output: [real(r8) (:) ] + frootn_xfer_to_frootn => cnveg_nitrogenflux_inst%frootn_xfer_to_frootn_patch , & ! Output: [real(r8) (:) ] + livestemn_xfer_to_livestemn => cnveg_nitrogenflux_inst%livestemn_xfer_to_livestemn_patch , & ! Output: [real(r8) (:) ] + deadstemn_xfer_to_deadstemn => cnveg_nitrogenflux_inst%deadstemn_xfer_to_deadstemn_patch , & ! Output: [real(r8) (:) ] + livecrootn_xfer_to_livecrootn => cnveg_nitrogenflux_inst%livecrootn_xfer_to_livecrootn_patch , & ! Output: [real(r8) (:) ] + deadcrootn_xfer_to_deadcrootn => cnveg_nitrogenflux_inst%deadcrootn_xfer_to_deadcrootn_patch , & ! Output: [real(r8) (:) ] + leafn_storage_to_xfer => cnveg_nitrogenflux_inst%leafn_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + frootn_storage_to_xfer => cnveg_nitrogenflux_inst%frootn_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + livestemn_storage_to_xfer => cnveg_nitrogenflux_inst%livestemn_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + deadstemn_storage_to_xfer => cnveg_nitrogenflux_inst%deadstemn_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + livecrootn_storage_to_xfer => cnveg_nitrogenflux_inst%livecrootn_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + deadcrootn_storage_to_xfer => cnveg_nitrogenflux_inst%deadcrootn_storage_to_xfer_patch , & ! Output: [real(r8) (:) ] + + grainc => cnveg_carbonstate_inst%grainc_patch , & ! Input: [real(r8) (:) ] (gC/m2) grain C + + crop_seedc_to_leaf => cnveg_carbonflux_inst%crop_seedc_to_leaf_patch, & ! Output: [real(r8) (:) ] (gC/m2/s) seed source to leaf + crop_seedc_to_froot => cnveg_carbonflux_inst%crop_seedc_to_froot_patch, & ! Output: [real(r8) (:) ] (gC/m2/s) seed source to fine root + crop_seedc_to_deadstem => cnveg_carbonflux_inst%crop_seedc_to_deadstem_patch, & ! Output: [real(r8) (:) ] (gC/m2/s) seed source to deadstem + cropseedc_deficit => cnveg_carbonstate_inst%cropseedc_deficit_patch , & ! Output: [real(r8) (:) ] (gC/m2) crop seed C deficit + crop_seedn_to_leaf => cnveg_nitrogenflux_inst%crop_seedn_to_leaf_patch, & ! Output: [real(r8) (:) ] (gN/m2/s) seed source to leaf + crop_seedn_to_froot => cnveg_nitrogenflux_inst%crop_seedn_to_froot_patch, & ! Output: [real(r8) (:) ] (gN/m2/s) seed source to fine root + crop_seedn_to_deadstem => cnveg_nitrogenflux_inst%crop_seedn_to_deadstem_patch, & ! Output: [real(r8) (:) ] (gN/m2/s) seed source to deadstem + cropseedn_deficit => cnveg_nitrogenstate_inst%cropseedn_deficit_patch , & ! Output: [real(r8) (:) ] (gN/m2) crop seed N deficit + cphase => crop_inst%cphase_patch , & ! Output: [real(r8) (:)] phenology phase + fert_counter => cnveg_nitrogenflux_inst%fert_counter_patch , & ! Output: [real(r8) (:) ] >0 fertilize; <=0 not (seconds) + fert => cnveg_nitrogenflux_inst%fert_patch & ! Output: [real(r8) (:) ] (gN/m2/s) fertilizer applied each timestep + ) + + ! get time info + dayspyr = get_days_per_year() + jday = get_curr_calday() + call get_curr_date(kyr, kmo, kda, mcsec) + dtrad = real( get_rad_step_size(), r8 ) + + if (use_fertilizer) then + nfertdays_on = 20._r8 ! number of days to fertilize + else + nfertdays_on = 0._r8 ! number of days to fertilize + end if + + do fp = 1, num_pcropp + p = filter_pcropp(fp) + c = patch%column(p) + g = patch%gridcell(p) + h = inhemi(p) + + if (perennial(ivt(p)) == 1._r8) then ! flags for perennial crop phenology (added by O.Dombrowski) + + ! prepare planting if .not. croplive + if (.not. croplive(p)) then + cropplant(p) = .false. + idop(p) = NOT_PLANTED + end if + + ! background litterfall and transfer rates; long growing season factor + bglfr(p) = 0._r8 + bgtr(p) = 0._r8 + lgsf(p) = 0._r8 + + if (kmo == 1 .and. kda == 1 .and. mcsec == 0) then + ! get deadstem C and N at the start of the year + deadstemc_soy(p) = deadstemc(p) + deadstemc_storage_soy(p) = deadstemc_storage(p) + deadstemn_soy(p) = deadstemn(p) + deadstemn_storage_soy(p) = deadstemn_storage(p) + + end if + + if (season_decid(ivt(p)) == 1._r8) then + + ! set flag for solstice period (winter->summer = 1, summer->winter =0) + if (dayl(g) >= prev_dayl(g)) then + ws_flag = 1._r8 + else + ws_flag = 0._r8 + end if + + ! base temperature, or critical temperature for chill accumulation + tbase = baset(ivt(p)) + + ! set flag for start of chill period (chill_flag=1), + ! set latest date at which to initiate growing growing season even if chill/heat requirements are not met + if (h == 1) then ! for NH + if (kmo == 11 .and. kda == 1) then + chill_flag(p) = 1._r8 + end if + if (kmo == 7 .and. kda == 1 .and. chill_flag(p) == 1._r8) then + chill_day(p) = crequ(ivt(p)) + anti_chill_day(p) = -chill_day(p) + end if + else if (h == 2) then ! for SH + if (kmo == 5 .and. kda == 1) then + chill_flag(p) = 1._r8 + end if + if (kmo == 1 .and. kda == 1 .and. chill_flag(p) == 1._r8) then + chill_day(p) = crequ(ivt(p)) + anti_chill_day(p) = -chill_day(p) + end if + end if + end if + + ! Phase 1: Planting to leaf emergence + + if ( (.not. croplive(p)) .and. (.not. cropplant(p)) ) then + + if ((t10(p) /= spval.and. a10tmin(p) /= spval .and. & + t10(p) > planttemp(ivt(p)) .and. & + a10tmin(p) > minplanttemp(ivt(p)) .and. & + jday >= minplantjday(ivt(p),h) .and. & + jday <= maxplantjday(ivt(p),h) .and. & + t10(p) /= spval .and. a10tmin(p) /= spval .and. & + gdd820(p) /= spval .and. & + gdd820(p) >= gddmin(ivt(p))) .or. & + (jday == maxplantjday(ivt(p),h) .and. & + gdd820(p) > 0._r8 .and. & + gdd820(p) /= spval )) then + + + ! impose limit on growing season length needed + ! for crop maturity - for cold weather constraints + croplive(p) = .true. + cropplant(p) = .true. + idop(p) = jday + yrop(p) = kyr + harvdate(p) = NOT_Harvested + + ! Fruit trees are usually transplanted from nursery as small trees, code is adapted from the initiation for + ! deciduous trees and the transplanting of seedlings introduced in CLM-Palm (Fan et al. 2015), + ! initial gC m-2 is assigned to leaf, fine root and deadstem + ! (added by O.Dombrowski) + if (transplant(ivt(p)) > 0._r8) then + leafc_xfer(p) = transplant(ivt(p)) + else + leafc_xfer(p) = 1._r8 + end if + + frootc_xfer(p) = leafc_xfer(p) ! assign same amount of leafc to fine roots + leafn_xfer(p) = leafc_xfer(p) / leafcn(ivt(p)) ! with onset + frootn_xfer(p) = frootc_xfer(p) / frootcn(ivt(p)) + cropseedc_deficit(p) = cropseedc_deficit(p) - leafc_xfer(p) - frootc_xfer(p) + cropseedn_deficit(p) = cropseedn_deficit(p) - leafn_xfer(p) - frootn_xfer(p) + !for woody crops like fruit trees, assign 10% of initial C to deadstem + if (woody(ivt(p)) == 1._r8) then + deadstemc_xfer(p) = 0.1_r8*leafc_xfer(p) + deadstemn_xfer(p) = deadstemc_xfer(p)/deadwdcn(ivt(p)) + cropseedc_deficit(p) = cropseedc_deficit(p) - deadstemc_xfer(p) + cropseedn_deficit(p) = cropseedn_deficit(p) - deadstemn_xfer(p) + end if + end if + + + onset_counter(p) = 0.0_r8 ! CN terminology to trigger certain + offset_counter(p) = 0.0_r8 ! carbon and nitrogen transfers + onset_flag(p) = 0._r8 + offset_flag(p) = 0._r8 + offset2_flag(p) = 0._r8 + dormant_flag(p) = 1._r8 + + ! at planting of orchard, assume that chilling + ! requirements were already met in previous year and only + ! anti chill days need to be reached. + chill_day(p) = crequ(ivt(p)) + anti_chill_day(p) = 0._r8 + chill_flag(p) = 1._r8 + onset_gddflag(p) = 1._r8 + + harvest_flag(p) = 0._r8 ! annual harvest flag for perennial crops + end if ! crop not live nor planted + + ! ---------------------------------- + ! from AgroIBIS subroutine phenocrop + ! ---------------------------------- + + + if (croplive(p)) then + cphase(p) = 1._r8 + ! days past planting determine orchard rotation once maximum lifetime is reached + ! (introduced in CLM-Palm (Fan et al. 2015), and adopted here by O.Dombrowski) + idpp = int(dayspyr)*(kyr-yrop(p)) + jday - idop(p) + if (season_decid(ivt(p)) == 1._r8) then + + ! Test to turn on chill day accumulation. + ! If off, switch on chill day accumulation on + ! October 1st + if (onset_gddflag(p) == 0._r8 .and. chill_flag(p) == 1._r8) then + onset_gddflag(p) = 1._r8 + chill_day(p) = 0._r8 + anti_chill_day(p) = 0._r8 + end if + + ! Test to turn off chill day accumulation, if on. + ! This test resets the chill day accumulation if it gets past + ! May 1st without reaching the chill requirements. + ! In that case, it will take until the next autumn (October 1st) + ! before the chill day accumulation starts again. + + if (onset_gddflag(p) == 1._r8 .and. chill_flag(p) ==0._r8) then + onset_gddflag(p) = 0._r8 + chill_day(p) = 0._r8 + anti_chill_day(p) = 0._r8 + end if + + + ! if the gdd flag is set, and if the chill day + ! accumulation has not reached + ! chill requirements (crequ), accumulate chill days + ! for all equations temperatures must be in + ! degrees (C) + if (onset_gddflag(p) == 1._r8 .and. chill_day(p) > crequ(ivt(p))) then + if (t_ref2m_min(p) < 1.e30_r8) then + if (0._r8 <= tbase .and. tbase <= (t_ref2m_min(p)-tfrz) .and. t_ref2m_min(p)<= t_ref2m_max(p)) then + Cd = 0._r8 + else if (0._r8 <= (t_ref2m_min(p)-tfrz) .and. (t_ref2m_min(p)-tfrz)<= tbase .and. tbase < (t_ref2m_max(p)-tfrz)) then + Cd = -((t_ref24(p)-t_ref2m_min(p))-((t_ref2m_max(p)-tfrz)-tbase)**2/(2*(t_ref2m_max(p)-t_ref2m_min(p)))) + else if (0._r8 <= (t_ref2m_min(p)-tfrz) .and. t_ref2m_min(p) <= t_ref2m_max(p) .and. (t_ref2m_max(p)-tfrz) <= tbase) then + Cd = -(t_ref24(p)-t_ref2m_min(p)) + else if ((t_ref2m_min(p)-tfrz) < 0._r8 .and. 0._r8 <= (t_ref2m_max(p)-tfrz) .and. (t_ref2m_max(p)-tfrz) <= tbase) then + Cd = -((t_ref2m_max(p)-tfrz)**2/(2*(t_ref2m_max(p)-t_ref2m_min(p)))) + else if ((t_ref2m_min(p)-tfrz) < 0._r8 .and. 0._r8 < tbase .and. tbase < (t_ref2m_max(p)-tfrz)) then + Cd = -(t_ref2m_max(p)-tfrz)**2/(2*(t_ref2m_max(p)-t_ref2m_min(p))) - ((t_ref2m_max(p)-tfrz)-tbase)**2/(2*(t_ref2m_max(p)-t_ref2m_min(p))) + else + Cd = 0._r8 + end if + chill_day(p) = chill_day(p)+Cd + end if + end if + + ! if chill day accumulation has reached chill + ! requirements (crequ), accumulate anti chill days + if (onset_gddflag(p) == 1._r8 .and. chill_day(p) <= crequ(ivt(p))) then + if (t_ref2m_min(p) < 1.e30_r8) then + if (0._r8 <= tbase .and. tbase <= (t_ref2m_min(p)-tfrz) .and. t_ref2m_min(p) <= t_ref2m_max(p)) then + Ca = (t_ref24(p)-tfrz) - tbase + else if (0._r8 <= (t_ref2m_min(p)-tfrz) .and. (t_ref2m_min(p)-tfrz) <= tbase .and. tbase < (t_ref2m_max(p)-tfrz)) then + Ca = ((t_ref2m_max(p)-tfrz)-tbase)**2/(2*(t_ref2m_max(p)-t_ref2m_min(p))) + else if (0._r8 <= (t_ref2m_min(p)-tfrz) .and. t_ref2m_min(p) <= t_ref2m_max(p) .and. (t_ref2m_max(p)-tfrz) <= tbase) then + Ca = 0._r8 + else if ((t_ref2m_min(p)-tfrz) < 0._r8 .and. 0._r8 <= (t_ref2m_max(p)-tfrz) .and. (t_ref2m_max(p)-tfrz) <= tbase) then + Ca = 0._r8 + else if ((t_ref2m_min(p)-tfrz) < 0._r8 .and. 0._r8 < tbase .and. tbase < (t_ref2m_max(p)-tfrz)) then + Ca = ((t_ref2m_max(p)-tfrz)-tbase)**2/(2*(t_ref2m_max(p)-t_ref2m_min(p))) + else + Ca = 0._r8 + end if + anti_chill_day(p) = anti_chill_day(p)+Ca + end if + end if + + ! update offset_counter and test for the end of the offset period + if (offset_flag(p) == 1.0_r8) then + ! decrement counter for offset period + offset_counter(p) = offset_counter(p) - dt + prune_flag(p) = 1._r8 + + ! if this is the end of the offset_period, reset phenology + ! flags and indices + if (offset_counter(p) == 0.0_r8) then + offset_flag(p) = 0._r8 + offset_counter(p) = 0._r8 + dormant_flag(p) = 1._r8 + days_active(p) = 0._r8 + harvest_flag(p) = 0._r8 + storage_flag(p) = 0._r8 + if (use_cndv) then + pftmayexist(p) = .true. + end if + + ! reset the previous timestep litterfall flux memory + prev_leafc_to_litter(p) = 0._r8 + prev_frootc_to_litter(p) = 0._r8 + end if + end if + + ! update onset_counter and test for the end of the onset period + if (onset_flag(p) == 1.0_r8) then + ! decrement counter for onset period + onset_counter(p) = onset_counter(p) - dt + + ! if this is the end of the onset period, reset phenology + ! flags and indices + if (onset_counter(p) == 0.0_r8) then + onset_flag(p) = 0.0_r8 + onset_counter(p) = 0.0_r8 + ! set all transfer growth rates to 0.0 + leafc_xfer_to_leafc(p) = 0.0_r8 + frootc_xfer_to_frootc(p) = 0.0_r8 + leafn_xfer_to_leafn(p) = 0.0_r8 + frootn_xfer_to_frootn(p) = 0.0_r8 + if (woody(ivt(p)) == 1.0_r8) then + livestemc_xfer_to_livestemc(p) = 0.0_r8 + deadstemc_xfer_to_deadstemc(p) = 0.0_r8 + livecrootc_xfer_to_livecrootc(p) = 0.0_r8 + deadcrootc_xfer_to_deadcrootc(p) = 0.0_r8 + livestemn_xfer_to_livestemn(p) = 0.0_r8 + deadstemn_xfer_to_deadstemn(p) = 0.0_r8 + livecrootn_xfer_to_livecrootn(p) = 0.0_r8 + deadcrootn_xfer_to_deadcrootn(p) = 0.0_r8 + end if + ! set transfer pools to 0.0 + leafc_xfer(p) = 0.0_r8 + leafn_xfer(p) = 0.0_r8 + frootc_xfer(p) = 0.0_r8 + frootn_xfer(p) = 0.0_r8 + if (woody(ivt(p)) == 1.0_r8) then + livestemc_xfer(p) = 0.0_r8 + livestemn_xfer(p) = 0.0_r8 + deadstemc_xfer(p) = 0.0_r8 + deadstemn_xfer(p) = 0.0_r8 + livecrootc_xfer(p) = 0.0_r8 + livecrootn_xfer(p) = 0.0_r8 + deadcrootc_xfer(p) = 0.0_r8 + deadcrootn_xfer(p) = 0.0_r8 + end if + end if + end if + + ! test for switching from dormant period to growth period + if (dormant_flag(p) == 1._r8) then + ! Test if maximum orchard lifespan is reached and + ! orchard rotation should be initialized (adapted + ! based on CLM-Palm (Fan et al. 2015): + if (idpp >= mxmat(ivt(p))) then + croplive(p) = .false. + cphase(p) = 4._r8 + offset2_flag(p) = 1._r8 + end if + + prune_flag(p) = 0._r8 + + ! set onset_flag if critical growing degree-day sum is exceeded + if (anti_chill_day(p) > 0._r8 .and. anti_chill_day(p) >= (- chill_day(p))) then + cphase(p) = 2.0_r8 + + ! calculate gdd thresholds from bud burst (huileaf) + huileaf(p) = hui(p) + huigrain(p) = huileaf(p) + grnfill(ivt(p)) + huiripe(p) = huileaf(p) + grnrp(ivt(p)) + huilfmat(p) = huileaf(p) + lfmat(ivt(p)) + gddmaturity(p)= huileaf(p) + hybgdd(ivt(p)) + + ! reset parameters for bud burst calculation + chill_day(p) = 0._r8 + anti_chill_day(p) = 0._r8 + chill_flag(p) = 0._r8 + + onset_flag(p) = 1.0_r8 + dormant_flag(p) = 0.0_r8 + onset_gddflag(p) = 0.0_r8 + onset_gdd(p) = 0.0_r8 + onset_counter(p) = ndays_stor(ivt(p)) * secspday + + fert_counter(p) = nfertdays_on * secspday + if (nfertdays_on .gt. 0) then + fert(p) = (manunitro(ivt(p)) * 1000._r8 + fertnitro(p))/ fert_counter(p) + else + fert(p) = 0._r8 + end if + + ! move all the storage pools into transfer pools, + ! where they will be transfered to displayed growth over the onset period. + ! set carbon fluxes for shifting storage pools to transfer pools + leafc_storage_to_xfer(p) = fstor2tran * leafc_storage(p)/dt + frootc_storage_to_xfer(p) = fstor2tran * frootc_storage(p)/dt + if (woody(ivt(p)) == 1.0_r8) then + livestemc_storage_to_xfer(p) = fstor2tran * livestemc_storage(p)/dt + deadstemc_storage_to_xfer(p) = fstor2tran * deadstemc_storage(p)/dt + livecrootc_storage_to_xfer(p) = fstor2tran * livecrootc_storage(p)/dt + deadcrootc_storage_to_xfer(p) = fstor2tran * deadcrootc_storage(p)/dt + gresp_storage_to_xfer(p) = fstor2tran * gresp_storage(p)/dt + end if + + ! set nitrogen fluxes for shifting storage pools to transfer pools + leafn_storage_to_xfer(p) = fstor2tran * leafn_storage(p)/dt + frootn_storage_to_xfer(p) = fstor2tran * frootn_storage(p)/dt + if (woody(ivt(p)) == 1.0_r8) then + livestemn_storage_to_xfer(p) = fstor2tran * livestemn_storage(p)/dt + deadstemn_storage_to_xfer(p) = fstor2tran * deadstemn_storage(p)/dt + livecrootn_storage_to_xfer(p) = fstor2tran * livecrootn_storage(p)/dt + deadcrootn_storage_to_xfer(p) = fstor2tran * deadcrootn_storage(p)/dt + end if + end if + + ! test for switching from growth period to offset period + else if (dormant_flag(p) == 0.0_r8 .and. offset_flag(p) == 0.0_r8) then + if (use_cndv) then + ! If days_active > 355, then remove patch in + ! CNDVEstablishment at the end of the year. + ! days_active > 355 is a symptom of seasonal decid. patches + ! occurring in + ! gridcells where dayl never drops below crit_dayl. + ! This results in TLAI>1e4 in a few gridcells. + days_active(p) = days_active(p) + fracday + if (days_active(p) > 355._r8) pftmayexist(p) = .false. + end if + + ! other crop stages occur outside the dormancy period + if ((hui(p) >= gddmaturity(p) .and. idpp < mxmat(ivt(p))) .or. & + (jday >= maxharvjday(ivt(p),h) .and. idpp < mxmat(ivt(p)))) then + + if (tlai(p) <= 0._r8 .and. harvest_flag(p) == 0._r8) then ! plant never emerged or died + croplive(p) = .false. + if (harvdate(p) >= NOT_Harvested) harvdate(p) = jday + crop_seedc_to_leaf(p) = crop_seedc_to_leaf(p) - leafc_xfer(p)/dt + crop_seedc_to_froot(p) = crop_seedc_to_froot(p) - frootc_xfer(p)/dt + crop_seedn_to_leaf(p) = crop_seedn_to_leaf(p) - leafn_xfer(p)/dt + crop_seedn_to_froot(p) = crop_seedn_to_froot(p) - frootn_xfer(p)/dt + leafc_xfer(p) = 0._r8 ! revert planting transfers + frootc_xfer(p) = 0._r8 + leafn_xfer(p) = leafc_xfer(p) / leafcn(ivt(p)) + frootn_xfer(p) = frootc_xfer(p) / frootcn(ivt(p)) + if (woody(ivt(p)) == 1._r8) then + crop_seedc_to_deadstem(p) = crop_seedc_to_deadstem(p) - deadstemc_xfer(p)/dt + crop_seedn_to_deadstem(p) = crop_seedn_to_deadstem(p) - deadstemn_xfer(p)/dt + deadstemc_xfer(p) = 0._r8 + deadstemn_xfer(p) = deadstemc_xfer(p) / deadwdcn(ivt(p)) + end if + else if (grainc(p) > 0._r8) then !only harvest when there is positive grainc accumulated during grainfill, adapted based on CLM-Palm (Fan et al. 2015) + harvest_flag(p) = 1._r8 + storage_flag(p) = 1._r8 + end if + else + harvest_flag(p) = 0._r8 + end if + + if (idpp >= mxmat(ivt(p))) then + if (harvdate(p) >= NOT_Harvested) harvdate(p) = jday + croplive(p) = .false. + cphase(p) = 4._r8 + if (tlai(p) > 0._r8) then ! plant had emerged before rotation + offset2_flag(p) = 1._r8 + else ! plant never emerged from ground + crop_seedc_to_leaf(p) = crop_seedc_to_leaf(p) - leafc_xfer(p)/dt + crop_seedc_to_froot(p) = crop_seedc_to_froot(p) - frootc_xfer(p)/dt + crop_seedn_to_leaf(p) = crop_seedn_to_leaf(p) - leafn_xfer(p)/dt + crop_seedn_to_froot(p) = crop_seedn_to_froot(p) - frootn_xfer(p)/dt + leafc_xfer(p) = 0._r8 + frootc_xfer(p) = 0._r8 + leafn_xfer(p) = leafc_xfer(p) / leafcn(ivt(p)) + frootn_xfer(p) = frootc_xfer(p) / frootcn(ivt(p)) + if (woody(ivt(p)) == 1._r8) then + crop_seedc_to_deadstem(p) = crop_seedc_to_deadstem(p) - deadstemc_xfer(p)/dt + crop_seedn_to_deadstem(p) = crop_seedn_to_deadstem(p) - deadstemn_xfer(p)/dt + deadstemc_xfer(p) = 0._r8 + deadstemn_xfer(p) = deadstemc_xfer(p) / deadwdcn(ivt(p)) + end if + end if + end if ! idpp >=mxmat + + if (fert_counter(p) <= 0._r8) then + fert(p) = 0._r8 + else ! continue same fert application every timestep + fert_counter(p) = fert_counter(p) - dtrad + end if + + ! only begin to test for offset critical temperature once past the summer sol + if (ws_flag == 0._r8 .and. t_ref24(p) < crit_temp(ivt(p))) then + offset_flag(p) = 1._r8 + !storage_flag(p) = 0._r8 + offset_counter(p) = ndays_off * secspday + prev_leafc_to_litter(p) = 0._r8 + prev_frootc_to_litter(p) = 0._r8 + ! harvest grainc if crop not harvested yet + if (grainc(p) > 0._r8) harvest_flag(p) = 1._r8 + end if + end if ! dormant_flag == 1 + end if ! season_decid + + else ! crop not live + dormant_flag(p) = 1._r8 + onset_counter(p) = 0._r8 + ! the next lines conserve mass if leaf*/froot*/deadstem*_xfer > 0 due to interpinic. + ! We subtract from any existing value in crop_seedc_to_* / + ! crop_seedn_to_* in the unlikely event that we enter this block of + ! code in the same time step where the planting transfer originally + ! occurred. + crop_seedc_to_leaf(p) = crop_seedc_to_leaf(p) - leafc_xfer(p)/dt + crop_seedc_to_froot(p) = crop_seedc_to_froot(p) - frootc_xfer(p)/dt + crop_seedn_to_leaf(p) = crop_seedn_to_leaf(p) - leafn_xfer(p)/dt + crop_seedn_to_froot(p) = crop_seedn_to_froot(p) - frootn_xfer(p)/dt + leafc_xfer(p) = 0._r8 + frootc_xfer(p) = 0._r8 + leafn_xfer(p) = leafc_xfer(p) / leafcn(ivt(p)) + frootn_xfer(p) = frootc_xfer(p) / frootcn(ivt(p)) + if (woody(ivt(p)) == 1._r8) then + crop_seedc_to_deadstem(p) = crop_seedc_to_deadstem(p) - deadstemc_xfer(p)/dt + crop_seedn_to_deadstem(p) = crop_seedn_to_deadstem(p) - deadstemn_xfer(p)/dt + deadstemc_xfer(p) = 0._r8 + deadstemn_xfer(p) = deadstemc_xfer(p) / deadwdcn(ivt(p)) + end if + if (use_c13) then + c13_cnveg_carbonstate_inst%leafc_xfer_patch(p) = 0._r8 + endif + if (use_c14) then + c14_cnveg_carbonstate_inst%leafc_xfer_patch(p) = 0._r8 + endif + + end if ! croplive + end if ! end if perennial(ivt(p)) == 1._r8 + end do ! prognostic crops loop + + end associate + + end subroutine FruitTreePhenology + !----------------------------------------------------------------------- subroutine CropPhenology(num_pcropp, filter_pcropp , & waterstate_inst, temperature_inst, crop_inst, canopystate_inst, cnveg_state_inst , & @@ -1428,10 +2140,10 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & ! !USES: use clm_time_manager , only : get_curr_date, get_curr_calday, get_days_per_year, get_rad_step_size - use pftconMod , only : ntmp_corn, nswheat, nwwheat, ntmp_soybean - use pftconMod , only : nirrig_tmp_corn, nirrig_swheat, nirrig_wwheat, nirrig_tmp_soybean - use pftconMod , only : ntrp_corn, nsugarcane, ntrp_soybean, ncotton, nrice - use pftconMod , only : nirrig_trp_corn, nirrig_sugarcane, nirrig_trp_soybean + use pftconMod , only : ntmp_corn, nswheat, nwwheat, ntmp_soybean, nbarley, nwbarley, nrye, nwrye, ncassava, napple, ncocoa, ncoffee, ncotton, ndatepalm, nfoddergrass, ngrapes, ngroundnuts, nmillet, noilpalm, npotatoes, npulses, nrapeseed, nrice, nsorghum, nsugarbeet, nsunflower, nmiscanthus, nswitchgrass, nc3crop, ncovercrop_1, ncovercrop_2 + use pftconMod , only : nirrig_tmp_corn, nirrig_swheat, nirrig_wwheat, nirrig_tmp_soybean, nirrig_barley, nirrig_wbarley, nirrig_rye, nirrig_wrye, nirrig_cassava, nirrig_apple, nirrig_cocoa, nirrig_coffee, nirrig_cotton, nirrig_datepalm, nirrig_foddergrass, nirrig_grapes, nirrig_groundnuts, nirrig_millet, nirrig_oilpalm, nirrig_potatoes, nirrig_pulses, nirrig_rapeseed, nirrig_rice, nirrig_sorghum, nirrig_sugarbeet, nirrig_sunflower, nirrig_miscanthus, nirrig_switchgrass, nc3irrig + use pftconMod , only : ntrp_corn, nsugarcane, ncotton, nrice + use pftconMod , only : nirrig_trp_corn, nirrig_sugarcane use pftconMod , only : nirrig_cotton, nirrig_rice use clm_varcon , only : spval, secspday use clm_varctl , only : use_fertilizer @@ -1468,6 +2180,9 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & real(r8) dayspyr ! days per year real(r8) crmcorn ! comparitive relative maturity for corn real(r8) ndays_on ! number of days to fertilize + real(r8) :: manureC ! tboas: organic carbon from manure based on fixed C:N ratio (gC/m2) + real(r8) :: manureN_tot ! tboas-fix: total manure N offered to this patch this year (gN/m2) + logical :: apply_manure ! tboas-fix: manure is applied in this year / on this date !------------------------------------------------------------------------ associate( & @@ -1484,6 +2199,8 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & lfemerg => pftcon%lfemerg , & ! Input: grnfill => pftcon%grnfill , & ! Input: + perennial => pftcon%perennial , & ! Input: [integer (:) ] binary flag for perennial crop phenology (1=perennial, 0= not perennial) (added by O.Dombrowski) + covercrop => pftcon%covercrop , & ! Input: covercrop flag t_ref2m_min => temperature_inst%t_ref2m_min_patch , & ! Input: [real(r8) (:) ] daily minimum of average 2 m height surface air temperature (K) t10 => temperature_inst%t_a10_patch , & ! Input: [real(r8) (:) ] 10-day running mean of the 2 m temperature (K) a5tmin => temperature_inst%t_a5min_patch , & ! Input: [real(r8) (:) ] 5-day running mean of min 2-m temperature @@ -1519,13 +2236,28 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & leafc_xfer => cnveg_carbonstate_inst%leafc_xfer_patch , & ! Output: [real(r8) (:) ] (gC/m2) leaf C transfer crop_seedc_to_leaf => cnveg_carbonflux_inst%crop_seedc_to_leaf_patch, & ! Output: [real(r8) (:) ] (gC/m2/s) seed source to leaf + frootc_xfer => cnveg_carbonstate_inst%frootc_xfer_patch , & ! Input: [real(r8) (:) ] (gC/m2) fine root C transfer + frootn_xfer => cnveg_nitrogenstate_inst%frootn_xfer_patch , & ! Input: [real(r8) (:) ] (gN/m2) fine root N transfer + frootcn => pftcon%frootcn , & ! Input: fine root C:N (gC/gN) fert_counter => cnveg_nitrogenflux_inst%fert_counter_patch , & ! Output: [real(r8) (:) ] >0 fertilize; <=0 not (seconds) leafn_xfer => cnveg_nitrogenstate_inst%leafn_xfer_patch , & ! Output: [real(r8) (:) ] (gN/m2) leaf N transfer crop_seedn_to_leaf => cnveg_nitrogenflux_inst%crop_seedn_to_leaf_patch, & ! Output: [real(r8) (:) ] (gN/m2/s) seed source to leaf cphase => crop_inst%cphase_patch , & ! Output: [real(r8) (:)] phenology phase - fert => cnveg_nitrogenflux_inst%fert_patch & ! Output: [real(r8) (:) ] (gN/m2/s) fertilizer applied each timestep + fert => cnveg_nitrogenflux_inst%fert_patch , & ! Output: [real(r8) (:) ] (gN/m2/s) fertilizer applied each timestep + lt50 => crop_inst%lt50_patch , & ! Output: [real(r8) (:)] the lethal temperature at which 50% of the individuals are damaged + wdd => crop_inst%wdd_patch , & ! Output: [real(r8) (:)] winter wheat weighted cumulated degree days + rateh => crop_inst%rateh_patch , & ! Output: [real(r8) (:)] increaseof tolerance cuased byhardening + rated => crop_inst%rated_patch , & ! Output: [real(r8) (:)] loss of tolerance cause by dehardening + rates => crop_inst%rates_patch , & ! Output: [real(r8) (:)] loss of tolerance caused by low tempeature + rater => crop_inst%rater_patch , & ! Output: [real(r8) (:)] loss of tolerance caused by respiration under snow + fsurv => crop_inst%fsurv_patch , & ! Output: [real(r8) (:)] winter wheat survival rate + accfsurv => crop_inst%accfsurv_patch , & ! Output: [real(r8) (:)] accumulated winter wheat survival rate + countfsurv => crop_inst%countfsurv_patch , & ! Output: [real(r8) (:)] numbers of accumulated winter wheat survival rate + fertC => cnveg_carbonflux_inst%fertC_patch , & ! Output: [real(r8) (:)] (gC/m2/s) organic C fertilizer from manure (tboas) + fertN => cnveg_nitrogenflux_inst%fertN_patch & ! Output: [real(r8) (:)] (gN/m2/s) organic N applied with manure (tboas-fix) ) + !variables for coldtolerance subroutine modified after Lu (2017) (tboas) ! get time info dayspyr = get_days_per_year() @@ -1545,6 +2277,37 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & g = patch%gridcell(p) h = inhemi(p) + !-------------------------------------------------------------------- + ! tboas-fix: calendar-date manure application. + ! + ! manure_apply_month = 0 keeps the original behaviour -- the organic C + ! and N are released at leaf-emergence onset, in the phase-2 block + ! further down. For manure_apply_month > 0 the release must NOT be tied + ! to that block: it fires on a single timestep once per season, so a + ! fixed calendar date would essentially never coincide with it and the + ! manure was silently never applied. That case is handled here instead, + ! which is reached on every timestep of every crop patch in the filter, + ! perennials included (FruitTreePhenology writes no fertC/fertN of its + ! own, so this is also the only manure path a fruit tree ever sees). + ! + ! Only the organic C and N are date-driven. The ammoniacal fraction + ! stays on the standard fertiliser schedule, metered from onset over + ! ndays_on, because that is plant-available N and CLM5 meters all + ! mineral fertiliser that way. + !-------------------------------------------------------------------- + if (use_cfert .and. manure_apply_month > 0) then + if (kmo == manure_apply_month .and. kda == manure_apply_day .and. & + mcsec == 0) then + if (manure_freq_years <= 1 .or. & + mod(kyr, manure_freq_years) == 1) then + manureN_tot = manunitro(ivt(p)) * 1000._r8 + fertN(p) = manureN_tot * (1._r8 - manure_nh4_frac) / dtrad + fertC(p) = fertN(p) * manure_CN_ratio + end if + end if + end if + + if (perennial(ivt(p)) == 0._r8) then ! background litterfall and transfer rates; long growing season factor bglfr(p) = 0._r8 ! this value changes later in a crop's life cycle @@ -1576,14 +2339,27 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & ! if we removed elseif, ! winter cereal grown continuously would amount to a cereal/fallow ! rotation because cereal would only be planted every other year - - else if (croplive(p) .and. (ivt(p) == nwwheat .or. ivt(p) == nirrig_wwheat)) then - cropplant(p) = .false. + ! (tboas) here, this only prevents the crop to be killed on the + ! first day of a new year and still results in a cereal-fallow + ! rotation + + else if (croplive(p) .and. (ivt(p) == nwwheat .or. ivt(p) == nirrig_wwheat .or. & + ivt(p) == ncovercrop_1 .or. ivt(p) == ncovercrop_2 .or. & + ivt(p) == nwbarley .or. ivt(p) == nirrig_wbarley .or. & + ivt(p) == nrapeseed .or. ivt(p) == nirrig_rapeseed)) then + cropplant(p) = .true. ! else ! not possible to have croplive and ivt==cornORsoy? (slevis) end if end if + !(tboas) try to avaoid cereral/fallow rotation + if (.not. croplive(p) .and. jday >= 170._r8 .and. & + (ivt(p) == nwwheat .or. ivt(p) == nirrig_wwheat)) then + cropplant(p) = .false. + idop(p) = NOT_Planted + end if + if ( (.not. croplive(p)) .and. (.not. cropplant(p)) ) then ! gdd needed for * chosen crop and a likely hybrid (for that region) * @@ -1603,7 +2379,10 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & ! winter temperate cereal : use gdd0 as a limit to plant winter cereal - if (ivt(p) == nwwheat .or. ivt(p) == nirrig_wwheat) then + if (ivt(p) == nwwheat .or. ivt(p) == nirrig_wwheat .or. & + ivt(p) == ncovercrop_1 .or. ivt(p) == ncovercrop_2 .or. & + ivt(p) == nwbarley .or. ivt(p) == nirrig_wbarley .or. & + ivt(p) == nrapeseed .or. ivt(p) == nirrig_rapeseed) then ! add check to only plant winter cereal after other crops (soybean, maize) ! have been harvested @@ -1626,9 +2405,22 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & (gdd020(p) /= spval .and. & gdd020(p) >= gddmin(ivt(p)))) then + if (debug_covercrop) then ! tboas-fix + write (iulog,*) 'planting winter crop' + end if cumvd(p) = 0._r8 hdidx(p) = 0._r8 vf(p) = 0._r8 + !coldtolerance parameters modified after Lu (2017) (tboas) + lt50(p) = -5._r8 + wdd(p) = 0._r8 + rateh(p) = 0._r8 + rated(p) = 0._r8 + rater(p) = 0._r8 + rates(p) = 0._r8 + fsurv(p) = 1._r8 + accfsurv(p) = 1._r8 + countfsurv(p) = 1._r8 croplive(p) = .true. cropplant(p) = .true. idop(p) = jday @@ -1636,8 +2428,10 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & gddmaturity(p) = hybgdd(ivt(p)) leafc_xfer(p) = initial_seed_at_planting leafn_xfer(p) = leafc_xfer(p) / leafcn(ivt(p)) ! with onset - crop_seedc_to_leaf(p) = leafc_xfer(p)/dt - crop_seedn_to_leaf(p) = leafn_xfer(p)/dt + frootc_xfer(p) = 0.1_r8 + frootn_xfer(p) = frootc_xfer(p) / frootcn(ivt(p)) ! with onset + crop_seedc_to_leaf(p) = leafc_xfer(p)/dt + frootc_xfer(p)/dt + crop_seedn_to_leaf(p) = leafn_xfer(p)/dt + frootn_xfer(p)/dt ! because leafc_xfer is set above rather than incremneted through the normal process, must also set its isotope ! pools here. use totvegc_patch as the closest analogue if nonzero, and use initial value otherwise @@ -1665,9 +2459,22 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & gdd020(p) /= spval .and. & gdd020(p) >= gddmin(ivt(p))) then + if (debug_covercrop) then ! tboas-fix + write (iulog,*) 'planting winter crop' + end if cumvd(p) = 0._r8 hdidx(p) = 0._r8 vf(p) = 0._r8 + ! coldtolerance mod. after Lu (2017) (tboas) + rateh(p) = 0._r8 + rated(p) = 0._r8 + rater(p) = 0._r8 + rates(p) = 0._r8 + fsurv(p) = 1._r8 + accfsurv(p) = 1._r8 + countfsurv(p) = 1._r8 + lt50(p) = -5._r8 + wdd(p) = 0._r8 croplive(p) = .true. cropplant(p) = .true. idop(p) = jday @@ -1675,8 +2482,10 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & gddmaturity(p) = hybgdd(ivt(p)) leafc_xfer(p) = initial_seed_at_planting leafn_xfer(p) = leafc_xfer(p) / leafcn(ivt(p)) ! with onset - crop_seedc_to_leaf(p) = leafc_xfer(p)/dt - crop_seedn_to_leaf(p) = leafn_xfer(p)/dt + frootc_xfer(p) = 0.1_r8 + frootn_xfer(p) = frootc_xfer(p) / frootcn(ivt(p)) ! with onset + crop_seedc_to_leaf(p) = leafc_xfer(p)/dt + frootc_xfer(p)/dt + crop_seedn_to_leaf(p) = leafn_xfer(p)/dt + frootn_xfer(p)/dt ! because leafc_xfer is set above rather than incremneted through the normal process, must also set its isotope ! pools here. use totvegc_patch as the closest analogue if nonzero, and use initial value otherwise @@ -1721,15 +2530,23 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & ! go a specified amount of time before/after ! climatological date - if (ivt(p) == ntmp_soybean .or. ivt(p) == nirrig_tmp_soybean .or. & - ivt(p) == ntrp_soybean .or. ivt(p) == nirrig_trp_soybean) then - gddmaturity(p) = min(gdd1020(p), hybgdd(ivt(p))) - end if + !if (ivt(p) == ntmp_soybean .or. ivt(p) == nirrig_tmp_soybean .or. & + ! ivt(p) == ntrp_soybean .or. ivt(p) == nirrig_trp_soybean) then + ! gddmaturity(p) = min(gdd1020(p), hybgdd(ivt(p))) + !end if if (ivt(p) == ntmp_corn .or. ivt(p) == nirrig_tmp_corn .or. & ivt(p) == ntrp_corn .or. ivt(p) == nirrig_trp_corn .or. & ivt(p) == nsugarcane .or. ivt(p) == nirrig_sugarcane) then - gddmaturity(p) = max(950._r8, min(gdd820(p)*0.85_r8, hybgdd(ivt(p)))) - gddmaturity(p) = max(950._r8, min(gddmaturity(p)+150._r8, 1850._r8)) + gddmaturity(p) = hybgdd(ivt(p)) ! tboas: use hybgdd directly + gddmaturity(p) = gddmaturity(p) ! tboas: no adjustment + end if + ! tboas: sugar beet and potato use hybgdd directly. The + ! min(gdd020,...) form caps maturity at the climatological + ! annual GDD (~1400 at Selhausen), forcing a ~90-day season + ! and a July lift instead of the observed Apr-Oct season. + if (ivt(p) == nsugarbeet .or. ivt(p) == nirrig_sugarbeet .or. & + ivt(p) == npotatoes .or. ivt(p) == nirrig_potatoes) then + gddmaturity(p) = hybgdd(ivt(p)) end if if (ivt(p) == nswheat .or. ivt(p) == nirrig_swheat .or. & ivt(p) == ncotton .or. ivt(p) == nirrig_cotton .or. & @@ -1770,8 +2587,8 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & idop(p) = jday harvdate(p) = NOT_Harvested - if (ivt(p) == ntmp_soybean .or. ivt(p) == nirrig_tmp_soybean .or. & - ivt(p) == ntrp_soybean .or. ivt(p) == nirrig_trp_soybean) then + if (ivt(p) == ntmp_soybean .or. ivt(p) == nirrig_tmp_soybean) then !.or. & + !ivt(p) == ntrp_soybean .or. ivt(p) == nirrig_trp_soybean) then gddmaturity(p) = min(gdd1020(p), hybgdd(ivt(p))) end if if (ivt(p) == ntmp_corn .or. ivt(p) == nirrig_tmp_corn .or. & @@ -1779,6 +2596,14 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & ivt(p) == nsugarcane .or. ivt(p) == nirrig_sugarcane) then gddmaturity(p) = max(950._r8, min(gdd820(p)*0.85_r8, hybgdd(ivt(p)))) end if + ! tboas: sugar beet and potato use hybgdd directly. The + ! min(gdd020,...) form caps maturity at the climatological + ! annual GDD (~1400 at Selhausen), forcing a ~90-day season + ! and a July lift instead of the observed Apr-Oct season. + if (ivt(p) == nsugarbeet .or. ivt(p) == nirrig_sugarbeet .or. & + ivt(p) == npotatoes .or. ivt(p) == nirrig_potatoes) then + gddmaturity(p) = hybgdd(ivt(p)) + end if if (ivt(p) == nswheat .or. ivt(p) == nirrig_swheat .or. & ivt(p) == ncotton .or. ivt(p) == nirrig_cotton .or. & ivt(p) == nrice .or. ivt(p) == nirrig_rice) then @@ -1902,18 +2727,42 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & if (croplive(p)) then cphase(p) = 1._r8 + ! old vernalization routine inactive ! call vernalization if winter temperate cereal planted, living, and the ! vernalization factor is not 1; ! vf affects the calculation of gddtsoi & gddplant - if (t_ref2m_min(p) < 1.e30_r8 .and. vf(p) /= 1._r8 .and. & - (ivt(p) == nwwheat .or. ivt(p) == nirrig_wwheat)) then - call vernalization(p, & - canopystate_inst, temperature_inst, waterstate_inst, cnveg_state_inst, & - crop_inst) + !if (t_ref2m_min(p) < 1.e30_r8 .and. vf(p) /= 1._r8 .and. & + ! (ivt(p) == nwwheat .or. ivt(p) == nirrig_wwheat .or. & + ! ivt(p) == ncovercrop_1 .or. ivt(p) == ncovercrop_2 .or. & + ! ivt(p) == nwbarley .or. ivt(p) == nirrig_wbarley .or. & + ! ivt(p) == nrapeseed .or. ivt(p) == nirrig_rapeseed)) then + ! write (iulog,*) 'call vernalization old' + ! call vernalization(p, & + ! canopystate_inst, temperature_inst, waterstate_inst, cnveg_state_inst, & + ! crop_inst) + + !new vernalization routine + if (vf(p) /= 1._r8 .and. & + (ivt(p) == nwwheat .or. ivt(p) == nirrig_wwheat .or. & + ivt(p) == ncovercrop_1 .or. ivt(p) == ncovercrop_2 .or. & + ivt(p) == nwbarley .or. ivt(p) == nirrig_wbarley .or. & + ivt(p) == nrapeseed .or. ivt(p) == nirrig_rapeseed)) then + call vernalization_2(p, & + temperature_inst, waterstate_inst, cnveg_state_inst, & + crop_inst, cnveg_carbonflux_inst) end if - ! days past planting may determine harvest + ! call cold tolerance in cphase 2 + ! if (ivt(p)== nwwheat .or. ivt(p) == nirrig_wwheat .or. & + ! ivt(p) == ncovercrop_1 .or. ivt(p) == ncovercrop_2 .or. & + ! ivt(p) == nwbarley .or. ivt(p) == nirrig_wbarley .or. & + ! ivt(p) == nrapeseed .or. ivt(p) == nirrig_rapeseed) then + ! call coldtolerance(p,canopystate_inst,temperature_inst, & + ! waterstate_inst,cnveg_state_inst, crop_inst, & + ! cnveg_nitrogenflux_inst, cnveg_carbonflux_inst, & + ! cnveg_carbonstate_inst, cnveg_nitrogenstate_inst) + ! end if if (jday >= idop(p)) then idpp = jday - idop(p) @@ -1935,14 +2784,77 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & if (leafout(p) >= huileaf(p) .and. hui(p) < huigrain(p) .and. idpp < mxmat(ivt(p))) then cphase(p) = 2._r8 + if (ivt(p)==nwwheat .or. ivt(p) == nirrig_wwheat .or. & + ivt(p) == ncovercrop_1 .or. ivt(p) == ncovercrop_2 .or. & + ivt(p) == nwbarley .or. ivt(p) == nirrig_wbarley .or. & + ivt(p) == nrapeseed .or. ivt(p) == nirrig_rapeseed) then + call coldtolerance(p,canopystate_inst,temperature_inst, & + waterstate_inst,cnveg_state_inst, crop_inst, & + cnveg_nitrogenflux_inst, cnveg_carbonflux_inst, & + cnveg_carbonstate_inst, cnveg_nitrogenstate_inst) + end if if (abs(onset_counter(p)) > 1.e-6_r8) then onset_flag(p) = 1._r8 onset_counter(p) = dt fert_counter(p) = ndays_on * secspday + ! tboas-fix: decide ONCE whether manure is applied in this year + ! and on this date, then use that single decision for both the + ! mineral and the organic part of the manure. Previously the + ! frequency/date gate applied only to the carbon, so the manure + ! nitrogen was applied every year even when the carbon was not. + ! Check application frequency: apply only every manure_freq_years. + ! Use kyr modulo so year 2009->1, 2010->2 etc; fires when remainder=1. + ! Check timing: manure_apply_month=0 means apply at planting onset, + ! >0 means only on that calendar date. + ! tboas-fix: only the "apply at planting onset" case is handled + ! here. manure_apply_month > 0 is handled on its own calendar + ! date at the top of the patch loop, so it must not also fire + ! here or the manure would be applied twice. + apply_manure = .false. + if (use_cfert .and. ndays_on > 0 .and. manure_apply_month == 0) then + if (manure_freq_years <= 1 .or. & + mod(kyr, manure_freq_years) == 1) then + apply_manure = .true. + end if + end if + + ! total manure N offered to this patch this year (gN/m2) + manureN_tot = manunitro(ivt(p)) * 1000._r8 if (ndays_on .gt. 0) then - fert(p) = (manunitro(ivt(p)) * 1000._r8 + fertnitro(p))/ fert_counter(p) + if (use_cfert) then + ! tboas-fix: with the organic-C pathway active, only the + ! ammoniacal fraction of the manure N is immediately + ! plant-available. The organic remainder travels with the + ! manure C into the litter pools (CNCSoilFert) and is + ! mineralised by the decomposition cascade, so it must not + ! also be added to the mineral pool here. + ! The ammoniacal N follows the same every-N-years gate as + ! the carbon, whichever release date is in use. + if (manure_freq_years <= 1 .or. & + mod(kyr, manure_freq_years) == 1) then + fert(p) = (manureN_tot * manure_nh4_frac + fertnitro(p)) / fert_counter(p) + else + fert(p) = fertnitro(p) / fert_counter(p) + end if + else + ! use_cfert = .false. : unchanged CLM5 behaviour, manunitro + ! is treated purely as mineral fertiliser N + fert(p) = (manureN_tot + fertnitro(p)) / fert_counter(p) + end if else fert(p) = 0._r8 + end if + + ! tboas: apply manure C in a single timestep at onset + fertC(p) = 0._r8 + fertN(p) = 0._r8 + if (apply_manure) then + ! tboas-fix: the organic N and the carbon that carries it are + ! emitted as a matched pair, so the litter pools receive manure + ! at exactly manure_CN_ratio and no nitrogen is counted twice. + manureC = manureN_tot * (1._r8 - manure_nh4_frac) * manure_CN_ratio + fertC(p) = manureC / dtrad ! full amount in one timestep + fertN(p) = manureN_tot * (1._r8 - manure_nh4_frac) / dtrad end if else ! this ensures no re-entry to onset of phase2 @@ -1960,10 +2872,18 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & ! changes to the offset subroutine below else if (hui(p) >= gddmaturity(p) .or. idpp >= mxmat(ivt(p))) then - if (harvdate(p) >= NOT_Harvested) harvdate(p) = jday - croplive(p) = .false. ! no re-entry in greater if-block + if (harvdate(p) >= NOT_Harvested)then + harvdate(p) = jday + ! Always kill crop after harvest/maturity --- tboas + croplive(p) = .false. cphase(p) = 4._r8 + ! Post-harvest: switch to current year summer crop if needed --- tboas + ! Winter crops are handled by Oct 1 switch + endif if (tlai(p) > 0._r8) then ! plant had emerged before harvest + if (debug_covercrop) then ! tboas-fix + write (iulog,*) 'plant emerged' + end if offset_flag(p) = 1._r8 offset_counter(p) = dt else ! plant never emerged from the ground @@ -1972,10 +2892,13 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & ! crop_seedn_to_leaf in the unlikely event that we enter this block of ! code in the same time step where the planting transfer originally ! occurred. + !write (iulog,*) 'plant not emerged' crop_seedc_to_leaf(p) = crop_seedc_to_leaf(p) - leafc_xfer(p)/dt crop_seedn_to_leaf(p) = crop_seedn_to_leaf(p) - leafn_xfer(p)/dt leafc_xfer(p) = 0._r8 leafn_xfer(p) = leafc_xfer(p) / leafcn(ivt(p)) + frootc_xfer(p) = 0._r8 + frootn_xfer(p) = 0._r8 !frootc_xfer(p) / frootcn((ivt)p) ! with onset if (use_c13) then c13_cnveg_carbonstate_inst%leafc_xfer_patch(p) = 0._r8 endif @@ -2001,8 +2924,10 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & if (fert_counter(p) <= 0._r8) then fert(p) = 0._r8 - else ! continue same fert application every timestep + fertC(p) = 0._r8 ! tboas: zero organic C flux when application window ends + else ! continue fertilizer N application — C already applied at onset fert_counter(p) = fert_counter(p) - dtrad + ! tboas: fertC zeroed by SetValues each timestep — no re-assignment needed end if else ! crop not live @@ -2024,6 +2949,7 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , & endif end if ! croplive + end if ! not perennial end do ! prognostic crops loop end associate @@ -2040,6 +2966,7 @@ subroutine CropPhenologyInit(bounds) ! !USES: use pftconMod , only: npcropmin, npcropmax use clm_time_manager, only: get_calday + use clm_varctl , only: use_fruittree ! tboas ! ! !ARGUMENTS: type(bounds_type), intent(in) :: bounds @@ -2051,7 +2978,8 @@ subroutine CropPhenologyInit(bounds) allocate( inhemi(bounds%begp:bounds%endp) ) allocate( minplantjday(0:numpft,inSH)) ! minimum planting julian day - allocate( maxplantjday(0:numpft,inSH)) ! minimum planting julian day + allocate( maxplantjday(0:numpft,inSH)) ! maximum planting julian day + allocate( maxharvjday(0:numpft,inSH)) ! maximum harvest julian day (added by O.Dombrowski) ! Julian day for the start of the year (mid-winter) jdayyrstart(inNH) = 1 @@ -2060,13 +2988,18 @@ subroutine CropPhenologyInit(bounds) ! Convert planting dates into julian day minplantjday(:,:) = huge(1) maxplantjday(:,:) = huge(1) + maxharvjday(:,:) = huge(1) + + ! tboas: planting/harvest dates needed for ALL crops, not just fruittree do n = npcropmin, npcropmax if (pftcon%is_pft_known_to_model(n)) then - minplantjday(n, inNH) = int( get_calday( pftcon%mnNHplantdate(n), 0 ) ) - maxplantjday(n, inNH) = int( get_calday( pftcon%mxNHplantdate(n), 0 ) ) + if (pftcon%mnNHplantdate(n) > 0) minplantjday(n, inNH) = int( get_calday( pftcon%mnNHplantdate(n), 0 ) ) + if (pftcon%mxNHplantdate(n) > 0) maxplantjday(n, inNH) = int( get_calday( pftcon%mxNHplantdate(n), 0 ) ) + if (pftcon%mxNHharvdate(n) > 0) maxharvjday(n, inNH) = int( get_calday( pftcon%mxNHharvdate(n), 0 ) ) + if (pftcon%mnSHplantdate(n) > 0) minplantjday(n, inSH) = int( get_calday( pftcon%mnSHplantdate(n), 0 ) ) + if (pftcon%mxSHplantdate(n) > 0) maxplantjday(n, inSH) = int( get_calday( pftcon%mxSHplantdate(n), 0 ) ) + if (pftcon%mxSHharvdate(n) > 0) maxharvjday(n, inSH) = int( get_calday( pftcon%mxSHharvdate(n), 0 ) ) - minplantjday(n, inSH) = int( get_calday( pftcon%mnSHplantdate(n), 0 ) ) - maxplantjday(n, inSH) = int( get_calday( pftcon%mxSHplantdate(n), 0 ) ) end if end do @@ -2173,9 +3106,13 @@ subroutine vernalization(p, & cumvd(p) = cumvd(p) - 0.5_r8 * (t_ref2m_max(p) - tfrz - 30._r8) end if cumvd(p) = max(0._r8, cumvd(p)) ! must be > 0 + ! tboas: debug write disabled for regional runs + !write(iulog,*)'vernalization_old cumvd(p)=', cumvd(p) vf(p) = 1._r8 - p1v * (50._r8 - cumvd(p)) vf(p) = max(0._r8, min(vf(p), 1._r8)) ! must be between 0 - 1 + ! tboas: debug write disabled for regional runs + !write(iulog,*)'vernalization_old vf(p)=', vf(p) end if ! calculate cold hardening of plant @@ -2238,6 +3175,258 @@ subroutine vernalization(p, & end associate end subroutine vernalization + !----------------------------------------------------------------------- + subroutine vernalization_2(p, & + temperature_inst, waterstate_inst, cnveg_state_inst, crop_inst, cnveg_carbonflux_inst) + + ! + ! !DESCRIPTION: + ! !Alternative vernalization routine tranfered from CLM 4.5 after Lu et al. (2017) (tboas) + ! * * * only call for winter temperate cereal * * * + ! + ! subroutine calculates vernalization and photoperiod effects on + ! gdd accumulation in winter temperate cereal varieties. Thermal time + ! accumulation is reduced in 1st period until plant is fully vernalized. + ! During this time of emergence to spikelet formation, photoperiod can also have a + ! drastic effect on plant development. + + use clm_time_manager, only: get_step_size,get_curr_date + + ! + ! !ARGUMENTS: + integer , intent(in) :: p ! PATCH index running over + type(temperature_type) , intent(in) :: temperature_inst + type(waterstate_type) , intent(in) :: waterstate_inst + type(cnveg_state_type) , intent(inout) :: cnveg_state_inst + type(crop_type) , intent(inout) :: crop_inst + type(cnveg_carbonflux_type) , intent(inout) :: cnveg_carbonflux_inst + + + ! + ! LOCAL VARAIBLES: + real(r8) vd, vd1, vd2 ! vernalization dependence + real(r8) vtmin,vtopt,vtmax ! vernalization minimum, optimum, maximumtemperature + real(r8) alpha ! parameter in calculating vernalization rate + real(r8) tc ! t_ref2m in degree C + !real(r8) tcrown ! ? + integer c ! column indices + integer g ! gridcell indices + real(r8) dt ! land model time step (sec) + real(r8) dtime ! convert dt from sec to hour + + associate( & + ivt => patch%itype , & ! Input: [integer (:)] pft vegetation type + cumvd => cnveg_state_inst%cumvd_patch , & ! Output: [real(r8) (:)] cumulative vernalization d?ependence? + vf => crop_inst%vf_patch , & ! Output: [real(r8) (:)] vernalization factor for cereal + t_ref2m => temperature_inst%t_ref2m_patch , & ! Input: [real(r8) (:)] 2 m height surface air temperature (K) + tcrown => crop_inst%tcrown_patch , & ! Output: [real(r8) (:)] crown temperature + snow_depth => waterstate_inst%snow_depth_col , & ! Input: [real(r8) (:)] snow height (m) + hui => crop_inst%gddplant_patch , & ! Input: [real(r8) (:) ] gdd since planting (gddplant) + leafout => crop_inst%gddtsoi_patch , & ! Input: [real(r8) (:) ] gdd from top soil layer temperature + cpool_to_grainc => cnveg_carbonflux_inst%cpool_to_grainc_patch & ! Input: [real(r8) (:) ] allocation to grain C (gC/m2/s) + ) + + c = patch%column(p) + dt=real( get_step_size(), r8 ) + + if (t_ref2m(p) < tfrz) then + tcrown(p) = 2._r8 + (t_ref2m(p) - tfrz) * (0.4_r8 + 0.0018_r8 * & + (min(snow_depth(c)*100._r8, 15._r8) - 15._r8)**2) + else + tcrown(p) = t_ref2m(p) - tfrz + end if + + ! write (iulog,*) 'subroutine vernalization_2' + + ! Vernalization factor calculation + ! if vf(p) = 1. then plant is fully vernalized - and thermal time + ! accumulation in phase 1 will be unaffected + ! refers to gddtsoi & gddplant, defined in the accumulation routines (slevis) + ! reset vf, cumvd, and hdidx to 0 at planting of crop (slevis) + !----------------------------------------------------------------------------- + !----------------------------------------------------------------------------- + ! ylu modified the vernalization function 10/16/15 + ! A generalized vernalization response function for winter wheat (Streck et al.,2003) was used here + ! Streck, N.A., Weiss, A., Baenziger, P.S., 2003. A generalized vernalization response & + ! function for winter wheat. Agron. J. 95 + + vtmin=-1.3_r8 + vtopt=4.9_r8 + vtmax=15.7_r8 + dtime=dt/3600.0_r8 !dtime is the time step in hour + + alpha=log(2._r8)/(log((vtmax-vtmin)/(vtopt-vtmin))) + ! tboas: debug write disabled for regional runs + !write(iulog,*) 'alpha=',alpha + ! tboas: debug write disabled for regional runs + !write(iulog,*) 'tcrown=',tcrown(p) + !tc = t_ref2m(p)-tfrz + if(tcrown(p) >=vtmin .and. tcrown(p) <= vtmax) then + cumvd(p)=cumvd(p) + ((2._r8*((tcrown(p)-vtmin)**alpha)*(vtopt-vtmin)**alpha & + - (tcrown(p)-vtmin)**(2._r8*alpha))/((vtopt-vtmin)**(2._r8*alpha)))*(dtime/24._r8) + end if + cumvd(p) = max(0._r8, cumvd(p)) ! must be > 0 + + ! tboas: debug write disabled for regional runs + !write(iulog,*)'vernalization_2 cumvd(p)=', cumvd(p) + vf(p)=(cumvd(p)**5._r8)/(22.5_r8**5._r8+cumvd(p)**5._r8) + vf(p) = max(0._r8, min(vf(p), 1._r8)) ! must be between 0 - 1 + ! tboas: debug write disabled for regional runs + !write(iulog,*)'vernalization_2 vf(p)=', vf(p) + + ! tboas: debug write disabled for regional runs + !write(iulog,*)'vernalization_2 cpool_to_grainc(p),hui(p) ',hui(p),cpool_to_grainc(p) + + end associate + + end subroutine vernalization_2 + + !----------------------------------------------------------------------- + subroutine coldtolerance (p,canopystate_inst,temperature_inst, & + waterstate_inst,cnveg_state_inst, crop_inst, & + cnveg_nitrogenflux_inst, cnveg_carbonflux_inst, & + cnveg_carbonstate_inst, cnveg_nitrogenstate_inst) + + ! !DESCRIPTION: + ! !Subroutine for coldtolerance modified after Lu(2017): 'Representing witer wheat in the Community Land Model (version 4.5) (tboas) + ! * * * only call for winter temperate cereal * * * + ! + !the subroutine calculates the lethal temperature at 50% of crop alive, + !survival rate, winter degree days + + + use clm_time_manager, only: get_step_size,get_curr_date + + ! + ! !ARGUMENTS: + !implicit none + integer, intent(in) :: p ! PFT index running over + type(canopystate_type) , intent(in) :: canopystate_inst + type(temperature_type) , intent(in) :: temperature_inst + type(waterstate_type) , intent(in) :: waterstate_inst + type(cnveg_carbonstate_type) , intent(in) :: cnveg_carbonstate_inst + type(cnveg_nitrogenstate_type), intent(in) :: cnveg_nitrogenstate_inst + type(cnveg_state_type) , intent(inout) :: cnveg_state_inst + type(crop_type) , intent(inout) :: crop_inst + type(cnveg_nitrogenflux_type) , intent(inout) :: cnveg_nitrogenflux_inst + type(cnveg_carbonflux_type) , intent(inout) :: cnveg_carbonflux_inst + ! + + ! LOCAL VARAIBLES: + real(r8) tcrown ! crown temperature + logical :: end_cd ! temporary for is_end_curr_day() value + real(r8) tc ! t_ref2m in degree C + real(r8) prevleafc ! previous step leafc + real(r8) tempfsurv ! averaged survival rate + integer c ! column indices + integer g ! gridcell indices + real(r8) dt ! land model time step (sec) + real(r8) dtime ! convert dt from sec to hour + integer :: kyr ! current year + integer :: kmo ! month of year (1, ..., 12) + integer :: kda ! day of month (1, ..., 31) + integer :: mcsec ! seconds of day (0, ..., seconds/day) + real(r8), parameter :: Hparam=0.0093 + real(r8), parameter :: Dparam=2.7e-5 + real(r8), parameter :: Sparam=1.9 + real(r8), parameter :: Rparam=0.54 + real(r8), parameter :: T_S_max=12.5 + real(r8), parameter :: lt50max=-23 + !the calculation of frost tolerance is based on Bergjord et al.,(2008),Europ.J.Agronomuy + !the calculation of survival rate and WDD is based on Vico et al.,(2014),Agri and Forest Metero. + + !------------------------------------------------------------------------ + + associate( & + ivt => patch%itype , & ! Input: [integer (:)] pft vegetation type + croplive => crop_inst%croplive_patch , & ! Input: [logical (:)] Flag,true if planted, not harvested + hdidx => cnveg_state_inst%hdidx_patch , & ! Output: [real(r8) (:)] cold hardening index? + rateh => crop_inst%rateh_patch , & ! Output: [real(r8)(:)] increase of tolerance cuased byhardening + rated => crop_inst%rated_patch , & ! Output: [real(r8) (:)] loss of tolerance cause by dehardening + rates => crop_inst%rates_patch , & ! Output: [real(r8) (:)] loss of tolerance caused by low tempeature + rater => crop_inst%rater_patch , & ! Output: [real(r8) (:)] loss of tolerance caused by respiration under snow + lt50 => crop_inst%lt50_patch , & ! Output: [real(r8) (:)] the lethal temperature at which 50% of the individuals are damaged + fsurv => crop_inst%fsurv_patch , & ! Output: [real(r8) (:)] winter wheat survival rate + accfsurv => crop_inst%accfsurv_patch , & ! Output: [real(r8) (:)] accumulated winter wheat survival rate [0 crop_inst%countfsurv_patch , & ! Output: [real(r8) (:)] numbers of accumulated winter wheat survival rate + wdd => crop_inst%wdd_patch , & ! Output: [real(r8) (:)] winter wheat weighted cumulated degree days + ck => crop_inst%ck_patch , & ! Output: [real(r8) (:)] fraction of green leaf area killed + cumvd => cnveg_state_inst%cumvd_patch , & ! Output: [real(r8) (:)] cumulative vernalization d?ependence? + vf => crop_inst%vf_patch , & ! Output: [real(r8) (:)] vernalization factor for cereal + gddmaturity => cnveg_state_inst%gddmaturity_patch , & ! Output: [real(r8) (:)] gdd needed to harvest + huigrain => cnveg_state_inst%huigrain_patch , & ! Output: [real(r8) (:)] heat unit index needed to reach vegetative maturity + leafc_to_litter => cnveg_carbonflux_inst%leafc_to_litter_patch , & ! Output: [real(r8) (:)] leaf C litterfall (gC/m2/s) + leafn_to_litter => cnveg_nitrogenflux_inst%leafn_to_litter_patch , & ! Output: [real(r8) (:)] leaf N litterfall (gN/m2/s) + leafc => cnveg_carbonstate_inst%leafc_patch , & ! Input: [real(r8) (:)] (gC/m2) leaf C + leafcn => pftcon%leafcn , & ! Input: [real(r8) (:)] leaf C:N (gC/gN) + leafn => cnveg_nitrogenstate_inst%leafn_patch , & ! Input: [real(r8)(:)] (gN/m2) leaf N + lflitcn => pftcon%lflitcn , & ! Input: [real(r8) (:)] leaf litter C:N (gC/gN) + tlai => canopystate_inst%tlai_patch , & ! Input: [real(r8) (:)] one-sided leaf area index, no burying by snow + t_ref2m => temperature_inst%t_ref2m_patch , & ! Input: [real(r8) (:)] 2 m height surface air temperature (K) + tcrown => crop_inst%tcrown_patch , & ! Output: [real(r8) (:)] crown temperature + snow_depth => waterstate_inst%snow_depth_col & ! Input: [real(r8) (:)] snow height (m) + ) + + c = patch%column(p) + dt=real( get_step_size(), r8 ) + + if (t_ref2m(p) < tfrz) then !slevis: t_ref2m inst of td=daily avg (K) + tcrown(p) = 2._r8 + (t_ref2m(p) - tfrz) * (0.4_r8 + 0.0018_r8 * & + (min(snow_depth(c)*100._r8, 15._r8) - 15._r8)**2) + else !slevis: snow_depth inst of adsnod=daily average (m) + tcrown(p) = t_ref2m(p) - tfrz + end if + + dtime=dt/3600.0_r8 !dtime is the time step dt in hour + +!frost tolerance and survival rate calculation + + if(tcrown(p) < 10._r8) then + rateh(p)=Hparam*(10._r8-tcrown(p))*(lt50(p)-lt50max) + ! tboas: debug write disabled for regional runs + !write(iulog,*) 'rateh=',rateh(p),'lt50=',lt50(p),'tcrown=',tcrown(p) + ! tboas: debug write disabled for regional runs + !write(iulog,*) 'snow_depth=',snow_depth(c) + end if + + if((tcrown(p) >=-4._r8 .and. vf(p) == 1._r8) .or. (tcrown(p)>=10._r8 .and. vf(p) <1._r8)) then + rated(p)=Dparam*(-0.6_r8+0.142_r8*lt50max-lt50(p))*(tcrown(p)+4._r8)**3._r8 + end if + + rater(p)=Rparam*(exp(0.84+0.051*tcrown(p))-2._r8)/1.85_r8*(snow_depth(c)*100._r8)/12.5 + rates(p)=(lt50(p)-tcrown(p))/exp(-Sparam*(lt50(p)-tcrown(p))-3.74_r8) + lt50(p)=lt50(p)+(rated(p)+rates(p)+rater(p)-rateh(p))*(dtime/24._r8) + + fsurv(p)=2._r8**(-(abs(tcrown(p))/abs(lt50(p)))**4._r8) + wdd(p)=wdd(p)+(max(tbase-tcrown(p),0._r8)*(1._r8-fsurv(p)))*(dtime/24._r8) + + if(wdd(p) >0._r8) then + accfsurv(p) = accfsurv(p) + fsurv(p) + countfsurv(p) = countfsurv(p) + 1._r8 + end if + + call get_curr_date(kyr, kmo, kda, mcsec) + end_cd = (mcsec == 0) + if( end_cd .and. wdd(p) > 0._r8 .and. vf(p) <0.9_r8 .and. leafc(p) > 10._r8 ) then + leafc_to_litter(p)=leafc_to_litter(p)+5._r8*(1._r8-fsurv(p))/dt + leafn_to_litter(p)=leafn_to_litter(p)+(5._r8*(1._r8-fsurv(p)))/(dt*lflitcn(ivt(p))) + end if + + if(end_cd .and. wdd(p) > 1.0_r8 .and. vf(p)>0.9_r8 ) then + tempfsurv=accfsurv(p)/countfsurv(p) + prevleafc=leafc(p) + leafc_to_litter(p)=leafc_to_litter(p)+prevleafc*(1._r8-tempfsurv)/dt + leafn_to_litter(p)=leafn_to_litter(p)+(prevleafc*(1._r8-tempfsurv))/(dt*lflitcn(ivt(p))) + accfsurv(p) = 1._r8 + countfsurv(p) = 1._r8 + wdd(p) =0._r8 + if (debug_covercrop) then ! tboas-fix + write (iulog,*) 'subroutine coldtolerance ending' + end if + end if + + end associate + end subroutine coldtolerance !----------------------------------------------------------------------- subroutine CNOnsetGrowth (num_soilp, filter_soilp, & @@ -2362,7 +3551,7 @@ end subroutine CNOnsetGrowth !----------------------------------------------------------------------- subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & - cnveg_state_inst, cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst) + crop_inst,cnveg_state_inst, cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst) ! ! !DESCRIPTION: ! Determines the flux of C and N from displayed pools to litter @@ -2372,10 +3561,12 @@ subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & use pftconMod , only : npcropmin use CNSharedParamsMod, only : use_fun use clm_varctl , only : CNratio_floating + use clm_time_manager , only : get_curr_date, get_curr_calday, get_days_per_year, is_beg_curr_year ! ! !ARGUMENTS: integer , intent(in) :: num_soilp ! number of soil patches in filter integer , intent(in) :: filter_soilp(:) ! filter for soil patches + type(crop_type) , intent(inout) :: crop_inst type(cnveg_state_type) , intent(inout) :: cnveg_state_inst type(cnveg_carbonstate_type) , intent(in) :: cnveg_carbonstate_inst type(cnveg_nitrogenstate_type), intent(in) :: cnveg_nitrogenstate_inst @@ -2385,21 +3576,36 @@ subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & ! !LOCAL VARIABLES: integer :: p, c ! indices integer :: fp ! lake filter patch index + integer :: kyr, kmo, kda, mcsec ! time info + integer :: dayspyr ! days per year + integer :: idpp ! number of days past planting + integer :: jday ! julian day of year real(r8):: t1 ! temporary variable real(r8):: denom ! temporary variable for divisor real(r8) :: ntovr_leaf real(r8) :: fr_leafn_to_litter ! fraction of the nitrogen turnover that goes to litter; remaining fraction is retranslocated + real(r8) :: pr_fr ! fraction of total stem biomass that is pruned !----------------------------------------------------------------------- associate( & ivt => patch%itype , & ! Input: [integer (:) ] patch vegetation type + mxmat => pftcon%mxmat , & ! Input: leafcn => pftcon%leafcn , & ! Input: leaf C:N (gC/gN) lflitcn => pftcon%lflitcn , & ! Input: leaf litter C:N (gC/gN) frootcn => pftcon%frootcn , & ! Input: fine root C:N (gC/gN) graincn => pftcon%graincn , & ! Input: grain C:N (gC/gN) - + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop phenology (added by O.Dombrowski) + mulch_pruning => pftcon%mulch_pruning , & ! Input: binary flag for exporting or mulching of pruning material (added by O.Dombrowski) + prune_fr => pftcon%prune_fr , & ! Input: fraction of deadstem biomass that is pruned (added by O.Dombrowski) + prune_flag => cnveg_state_inst%prune_flag_patch , & ! Input: binary flag for pruning (added by O.Dombrowski) + harvest_flag => cnveg_state_inst%harvest_flag_patch , & ! Input: [real(r8) (:) ] harvest flag (added by O.Dombrowski) + + idop => cnveg_state_inst%idop_patch , & ! Output: [integer (:)] date of planting + yrop => crop_inst%yrop_patch , & ! Output: [integer (:)] year of planting (added by O.Dombrowski) + croplive => crop_inst%croplive_patch , & ! Output: [logical (:) ] Flag, true if planted, not harvested offset_flag => cnveg_state_inst%offset_flag_patch , & ! Input: [real(r8) (:) ] offset flag + offset2_flag => cnveg_state_inst%offset2_flag_patch , & ! Input: [real(r8) (:) ] orchard rotation flag offset_counter => cnveg_state_inst%offset_counter_patch , & ! Input: [real(r8) (:) ] offset days counter leafc => cnveg_carbonstate_inst%leafc_patch , & ! Input: [real(r8) (:) ] (gC/m2) leaf C @@ -2407,8 +3613,49 @@ subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & grainc => cnveg_carbonstate_inst%grainc_patch , & ! Input: [real(r8) (:) ] (gC/m2) grain C cropseedc_deficit => cnveg_carbonstate_inst%cropseedc_deficit_patch , & ! Input: [real(r8) (:) ] (gC/m2) crop seed C deficit livestemc => cnveg_carbonstate_inst%livestemc_patch , & ! Input: [real(r8) (:) ] (gC/m2) livestem C + deadstemc => cnveg_carbonstate_inst%deadstemc_patch , & ! Input: [real(r8) (:) ] (gC/m2) deadstem C + deadstemc_soy => cnveg_carbonstate_inst%deadstemc_soy_patch , & ! Input: [real(r8) (:) ] (gC/m2) dead stem C at the start of season + livecrootc => cnveg_carbonstate_inst%livecrootc_patch , & ! Input: [real(r8) (:) ] (gC/m2) live coarse root C + deadcrootc => cnveg_carbonstate_inst%deadcrootc_patch , & ! Input: [real(r8) (:) ] (gC/m2) dead coarse root C + xsmrpool => cnveg_carbonstate_inst%xsmrpool_patch , & ! Input: [real(r8) (:)] (gC/m2) abstract C pool to meet excess MR demand + leafc_storage => cnveg_carbonstate_inst%leafc_storage_patch , & ! Input: [real(r8) (:)] (gC/m2) leaf C storage + frootc_storage => cnveg_carbonstate_inst%frootc_storage_patch , & ! Input: [real(r8) (:)] (gC/m2) fine root C storage + livestemc_storage => cnveg_carbonstate_inst%livestemc_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) livestem storage C + deadstemc_storage => cnveg_carbonstate_inst%deadstemc_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) deadstem storage C + deadstemc_storage_soy => cnveg_carbonstate_inst%deadstemc_storage_soy_patch , & ! Input: [real(r8) (:) ] (gC/m2) dead stem C storage at the start of season + livecrootc_storage => cnveg_carbonstate_inst%livecrootc_storage_patch , & ! Input: [real(r8) (:) ] (gC/m2) livecrootc storage C + deadcrootc_storage => cnveg_carbonstate_inst%deadcrootc_storage_patch , & ! Input: [real(r8) (:)] (gC/m2) dead coarse root C storage cropseedn_deficit => cnveg_nitrogenstate_inst%cropseedn_deficit_patch , & ! Input: [real(r8) (:) ] (gC/m2) crop seed N deficit + gresp_storage => cnveg_carbonstate_inst%gresp_storage_patch , & ! Input: [real(r8) (:)] (gC/m2) growth respiration storage + leafc_xfer => cnveg_carbonstate_inst%leafc_xfer_patch , & ! Input: [real(r8) (:)] (gC/m2) leaf C transfer + frootc_xfer => cnveg_carbonstate_inst%frootc_xfer_patch , & ! Input: [real(r8) (:)] (gC/m2) fine root C transfer + livestemc_xfer => cnveg_carbonstate_inst%livestemc_xfer_patch , & ! Input: [real(r8) (:)] (gC/m2) live stem C transfer + deadstemc_xfer => cnveg_carbonstate_inst%deadstemc_xfer_patch , & ! Input: [real(r8) (:)] (gC/m2) dead stem C transfer + livecrootc_xfer => cnveg_carbonstate_inst%livecrootc_xfer_patch , & ! Input: [real(r8) (:)] (gC/m2) live coarse root C transfer + deadcrootc_xfer => cnveg_carbonstate_inst%deadcrootc_xfer_patch , & ! Input: [real(r8) (:)] (gC/m2) dead coarse root C transfer + gresp_xfer => cnveg_carbonstate_inst%gresp_xfer_patch , & ! Input: [real(r8) (:)] (gC/m2) growth respiration transfer + + leafn => cnveg_nitrogenstate_inst%leafn_patch , & ! Input: [real(r8) (:)] (gN/m2) leaf N + frootn => cnveg_nitrogenstate_inst%frootn_patch , & ! Input: [real(r8) (:)] (gN/m2) fine root N livestemn => cnveg_nitrogenstate_inst%livestemn_patch , & ! Input: [real(r8) (:) ] (gN/m2) livestem N + deadstemn => cnveg_nitrogenstate_inst%deadstemn_patch , & ! Input: [real(r8) (:)] (gN/m2) dead stem N + deadstemn_soy => cnveg_nitrogenstate_inst%deadstemn_soy_patch , & ! Input: [real(r8) (:)] (gN/m2) dead stem N at the start of season + livecrootn => cnveg_nitrogenstate_inst%livecrootn_patch , & ! Input: [real(r8) (:)] (gN/m2) live coarse root N + deadcrootn => cnveg_nitrogenstate_inst%deadcrootn_patch , & ! Input: [real(r8) (:)] (gN/m2) dead coarse root N + retransn => cnveg_nitrogenstate_inst%retransn_patch , & ! Input: [real(r8) (:)] (gN/m2) plant pool of retranslocated N + leafn_storage => cnveg_nitrogenstate_inst%leafn_storage_patch , & ! Input: [real(r8) (:)] (gN/m2) leaf N storage + frootn_storage => cnveg_nitrogenstate_inst%frootn_storage_patch , & ! Input: [real(r8) (:)] (gN/m2) fine root N storage + livestemn_storage => cnveg_nitrogenstate_inst%livestemn_storage_patch , & ! Input: [real(r8) (:)] (gN/m2) live stem N storage + deadstemn_storage => cnveg_nitrogenstate_inst%deadstemn_storage_patch , & ! Input: [real(r8) (:)] (gN/m2) dead stem N storage + deadstemn_storage_soy => cnveg_nitrogenstate_inst%deadstemn_storage_soy_patch , & ! Input: [real(r8) (:)] (gN/m2) dead stem N storage at the start of season + livecrootn_storage => cnveg_nitrogenstate_inst%livecrootn_storage_patch , & ! Input: [real(r8) (:)] (gN/m2) live coarse root N storage + deadcrootn_storage => cnveg_nitrogenstate_inst%deadcrootn_storage_patch , & ! Input: [real(r8) (:)] (gN/m2) dead coarse root N storage + leafn_xfer => cnveg_nitrogenstate_inst%leafn_xfer_patch , & ! Input: [real(r8) (:)] (gN/m2) leaf N transfer + frootn_xfer => cnveg_nitrogenstate_inst%frootn_xfer_patch , & ! Input: [real(r8) (:)] (gN/m2) fine root N transfer + livestemn_xfer => cnveg_nitrogenstate_inst%livestemn_xfer_patch , & ! Input: [real(r8) (:)] (gN/m2) live stem N transfer + deadstemn_xfer => cnveg_nitrogenstate_inst%deadstemn_xfer_patch , & ! Input: [real(r8) (:)] (gN/m2) dead stem N transfer + livecrootn_xfer => cnveg_nitrogenstate_inst%livecrootn_xfer_patch , & ! Input: [real(r8) (:)] (gN/m2) live coarse root N transfer + deadcrootn_xfer => cnveg_nitrogenstate_inst%deadcrootn_xfer_patch , & ! Input: [real(r8) (:)] (gN/m2) dead coarse root N transfer cpool_to_grainc => cnveg_carbonflux_inst%cpool_to_grainc_patch , & ! Input: [real(r8) (:) ] allocation to grain C (gC/m2/s) npool_to_grainn => cnveg_nitrogenflux_inst%npool_to_grainn_patch , & ! Input: [real(r8) (:) ] allocation to grain N (gN/m2/s) @@ -2416,17 +3663,65 @@ subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & cpool_to_livestemc => cnveg_carbonflux_inst%cpool_to_livestemc_patch , & ! Input: [real(r8) (:) ] allocation to live stem C (gC/m2/s) cpool_to_leafc => cnveg_carbonflux_inst%cpool_to_leafc_patch , & ! Input: [real(r8) (:) ] allocation to leaf C (gC/m2/s) cpool_to_frootc => cnveg_carbonflux_inst%cpool_to_frootc_patch , & ! Input: [real(r8) (:) ] allocation to fine root C (gC/m2/s) + cpool_to_livestemc_storage => cnveg_carbonflux_inst%cpool_to_livestemc_storage_patch , & ! Input: [real(r8) (:) ] allocation to live stem storage C (gC/m2/s) + cpool_to_deadstemc_storage => cnveg_carbonflux_inst%cpool_to_deadstemc_storage_patch , & ! Input: [real(r8) (:) ] allocation to dead stem storage C (gC/m2/s) prev_leafc_to_litter => cnveg_carbonflux_inst%prev_leafc_to_litter_patch , & ! Output: [real(r8) (:) ] previous timestep leaf C litterfall flux (gC/m2/s) prev_frootc_to_litter => cnveg_carbonflux_inst%prev_frootc_to_litter_patch , & ! Output: [real(r8) (:) ] previous timestep froot C litterfall flux (gC/m2/s) leafc_to_litter => cnveg_carbonflux_inst%leafc_to_litter_patch , & ! Output: [real(r8) (:) ] leaf C litterfall (gC/m2/s) frootc_to_litter => cnveg_carbonflux_inst%frootc_to_litter_patch , & ! Output: [real(r8) (:) ] fine root C litterfall (gC/m2/s) livestemc_to_litter => cnveg_carbonflux_inst%livestemc_to_litter_patch , & ! Output: [real(r8) (:) ] live stem C litterfall (gC/m2/s) + prunec_to_litter => cnveg_carbonflux_inst%prunec_to_litter_patch , & ! Output: [real(r8) (:) ] pruning C litterfall (gC/m2/s) + prunec_storage_to_litter => cnveg_carbonflux_inst%prunec_storage_to_litter_patch , & ! Output: [real(r8) (:) ] pruning storage C litterfall (gC/m2/s) + + hrv_leafc_to_litter => cnveg_carbonflux_inst%hrv_leafc_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_frootc_to_litter => cnveg_carbonflux_inst%hrv_frootc_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_livestemc_to_litter => cnveg_carbonflux_inst%hrv_livestemc_to_litter_patch , & ! Output: [real(r8) (:)] + wood_harvestc => cnveg_carbonflux_inst%wood_harvestc_patch , & ! Output: [real(r8) (:)] + hrv_livecrootc_to_litter => cnveg_carbonflux_inst%hrv_livecrootc_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadcrootc_to_litter => cnveg_carbonflux_inst%hrv_deadcrootc_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_xsmrpool_to_atm => cnveg_carbonflux_inst%hrv_xsmrpool_to_atm_patch , & ! Output: [real(r8) (:)] + hrv_leafc_storage_to_litter => cnveg_carbonflux_inst%hrv_leafc_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_frootc_storage_to_litter => cnveg_carbonflux_inst%hrv_frootc_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_livestemc_storage_to_litter => cnveg_carbonflux_inst%hrv_livestemc_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadstemc_storage_to_litter => cnveg_carbonflux_inst%hrv_deadstemc_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_livecrootc_storage_to_litter => cnveg_carbonflux_inst%hrv_livecrootc_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadcrootc_storage_to_litter => cnveg_carbonflux_inst%hrv_deadcrootc_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_gresp_storage_to_litter => cnveg_carbonflux_inst%hrv_gresp_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_leafc_xfer_to_litter => cnveg_carbonflux_inst%hrv_leafc_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_frootc_xfer_to_litter => cnveg_carbonflux_inst%hrv_frootc_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_livestemc_xfer_to_litter => cnveg_carbonflux_inst%hrv_livestemc_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadstemc_xfer_to_litter => cnveg_carbonflux_inst%hrv_deadstemc_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_livecrootc_xfer_to_litter => cnveg_carbonflux_inst%hrv_livecrootc_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadcrootc_xfer_to_litter => cnveg_carbonflux_inst%hrv_deadcrootc_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_gresp_xfer_to_litter => cnveg_carbonflux_inst%hrv_gresp_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + + hrv_leafn_to_litter => cnveg_nitrogenflux_inst%hrv_leafn_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_frootn_to_litter => cnveg_nitrogenflux_inst%hrv_frootn_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_livestemn_to_litter => cnveg_nitrogenflux_inst%hrv_livestemn_to_litter_patch , & ! Output: [real(r8) (:)] + wood_harvestn => cnveg_nitrogenflux_inst%wood_harvestn_patch , & ! Output: [real(r8) (:)] + hrv_livecrootn_to_litter => cnveg_nitrogenflux_inst%hrv_livecrootn_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadcrootn_to_litter => cnveg_nitrogenflux_inst%hrv_deadcrootn_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_retransn_to_litter => cnveg_nitrogenflux_inst%hrv_retransn_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_leafn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_leafn_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_frootn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_frootn_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_livestemn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_livestemn_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadstemn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_deadstemn_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_livecrootn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_livecrootn_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadcrootn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_deadcrootn_storage_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_leafn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_leafn_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_frootn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_frootn_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_livestemn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_livestemn_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadstemn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_deadstemn_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + + + hrv_livecrootn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_livecrootn_xfer_to_litter_patch , & ! Output: [real(r8) (:)] + hrv_deadcrootn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_deadcrootn_xfer_to_litter_patch , & ! Output: [real(r8) (:)] grainc_to_food => cnveg_carbonflux_inst%grainc_to_food_patch , & ! Output: [real(r8) (:) ] grain C to food (gC/m2/s) grainc_to_seed => cnveg_carbonflux_inst%grainc_to_seed_patch , & ! Output: [real(r8) (:) ] grain C to seed (gC/m2/s) - leafn => cnveg_nitrogenstate_inst%leafn_patch , & ! Input: [real(r8) (:) ] (gN/m2) leaf N - frootn => cnveg_nitrogenstate_inst%frootn_patch , & ! Input: [real(r8) (:) ] (gN/m2) fine root N livestemn_to_litter => cnveg_nitrogenflux_inst%livestemn_to_litter_patch , & ! Output: [real(r8) (:) ] livestem N to litter (gN/m2/s) + prunen_to_litter => cnveg_nitrogenflux_inst%prunen_to_litter_patch , & ! Output: [real(r8) (:) ] pruning N litterfall (gN/m2/s) + prunen_storage_to_litter => cnveg_nitrogenflux_inst%prunen_storage_to_litter_patch , & ! Output: [real(r8) (:) ] pruning storage N litterfall (gN/m2/s) grainn_to_food => cnveg_nitrogenflux_inst%grainn_to_food_patch , & ! Output: [real(r8) (:) ] grain N to food (gN/m2/s) grainn_to_seed => cnveg_nitrogenflux_inst%grainn_to_seed_patch , & ! Output: [real(r8) (:) ] grain N to seed (gN/m2/s) leafn_to_litter => cnveg_nitrogenflux_inst%leafn_to_litter_patch , & ! Output: [real(r8) (:) ] leaf N litterfall (gN/m2/s) @@ -2438,13 +3733,35 @@ subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & leafcn_offset => cnveg_state_inst%leafcn_offset_patch & ! Output: [real(r8) (:) ] Leaf C:N used by FUN ) + ! get time info + dayspyr = get_days_per_year() + jday = get_curr_calday() + call get_curr_date(kyr, kmo, kda, mcsec) ! The litterfall transfer rate starts at 0.0 and increases linearly ! over time, with displayed growth going to 0.0 on the last day of litterfall do fp = 1,num_soilp p = filter_soilp(fp) - ! only calculate fluxes during offset period + ! determine days past planting for pruning management + idpp = int(dayspyr)*(kyr-yrop(p)) + jday - idop(p) + !incorporate a one-time harvest: annually for perennial crops (added by O.Dombrowski adopted based on CLM-Palm (Fan et al. 2015)) + !grain flux goes to food + if (harvest_flag(p) == 1._r8)then + if (perennial(ivt(p)) == 1._r8) then + if (grainc(p) > 0._r8) then + t1 = 1.0_r8 / dt + ! replenish seed deficit (needed to balance seedc used for orchard establishment) + grainc_to_seed(p) = t1 * min(-cropseedc_deficit(p), grainc(p)) + grainn_to_seed(p) = t1 * min(-cropseedn_deficit(p), grainn(p)) + ! send remaining grainc to food product pool + grainc_to_food(p) = t1 * grainc(p) + cpool_to_grainc(p) - grainc_to_seed(p) + grainn_to_food(p) = t1 * grainn(p) + npool_to_grainn(p) - grainn_to_seed(p) + + end if + end if + end if + ! only calculate fluxes during offset period (a one time step for crops; multiple days for trees) if (offset_flag(p) == 1._r8) then if (offset_counter(p) == dt) then @@ -2453,7 +3770,9 @@ subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & frootc_to_litter(p) = t1 * frootc(p) + cpool_to_frootc(p) ! this assumes that offset_counter == dt for crops ! if this were ever changed, we'd need to add code to the "else" - if (ivt(p) >= npcropmin) then + ! for perennial crops final harvest happens only at rotation + + if (ivt(p) >= npcropmin .and. perennial(ivt(p)) == 0._r8) then ! Replenish the seed deficits from grain, if there is enough ! available grain. (If there is not enough available grain, the seed ! deficits will accumulate until there is eventually enough grain to @@ -2466,6 +3785,31 @@ subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & livestemc_to_litter(p) = t1 * livestemc(p) + cpool_to_livestemc(p) end if + if (prune_flag(p) == 1._r8) then ! perennial fruit tree crops are pruned at the start of the dormancy period + ! young fruit trees are not pruned in the first 3 years after + ! transplanting + if (idpp < 1095._r8) then + pr_fr = 0._r8 + else + pr_fr = prune_fr(ivt(p)) + end if + if (mulch_pruning(ivt(p)) == 0._r8) then ! pruning material is exported + ! carbon fluxes to wood product pool + wood_harvestc(p) = t1 * ((deadstemc(p)-deadstemc_soy(p))*pr_fr) + hrv_deadstemc_storage_to_litter(p) = t1 * ((deadstemc_storage(p)-deadstemc_storage_soy(p))*pr_fr) + ! corresponding nitrogen fluxes + wood_harvestn(p) = t1 * ((deadstemn(p)-deadstemn_soy(p))*pr_fr) + hrv_deadstemn_storage_to_litter(p) = t1 * ((deadstemn_storage(p)-deadstemn_storage_soy(p))*pr_fr) + + else if (mulch_pruning(ivt(p)) == 1._r8) then ! pruning material is mulched into the soil + ! carbon fluxes to wood product pool + prunec_to_litter(p) = t1 * ((deadstemc(p)-deadstemc_soy(p))*pr_fr) + prunec_storage_to_litter(p) = t1 * ((deadstemc_storage(p)-deadstemc_storage_soy(p))*pr_fr) + ! corresponding nitrogen fluxes + prunen_to_litter(p) = t1 * ((deadstemn(p)-deadstemn_soy(p))*pr_fr) + prunen_storage_to_litter(p) = t1 *((deadstemn_storage(p)-deadstemn_storage_soy(p))*pr_fr) + end if + end if else t1 = dt * 2.0_r8 / (offset_counter(p) * offset_counter(p)) leafc_to_litter(p) = prev_leafc_to_litter(p) + t1*(leafc(p) - prev_leafc_to_litter(p)*offset_counter(p)) @@ -2542,7 +3886,7 @@ subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & endif end if - if (ivt(p) >= npcropmin) then + if (ivt(p) >= npcropmin .and. perennial(ivt(p)) == 0._r8) then ! NOTE(slevis, 2014-12) results in -ve livestemn and -ve totpftn !X! livestemn_to_litter(p) = livestemc_to_litter(p) / livewdcn(ivt(p)) ! NOTE(slevis, 2014-12) Beth Drewniak suggested this instead @@ -2554,7 +3898,71 @@ subroutine CNOffsetLitterfall (num_soilp, filter_soilp, & prev_frootc_to_litter(p) = frootc_to_litter(p) end if ! end if offset period + ! offset2 is newly implemented for fruit trees, it initializes orchard + ! rotation (complete harvest of all plant organs) after maximum + ! lifespan is reached + ! (introduced in CLM-Palm (Fan et al. 2015), and adopted here by O.Dombrowski) + if (offset2_flag(p) == 1._r8 .and. perennial(ivt(p)) == 1._r8) then + ! Apply all harvest at the start of the year, otherwise will get + ! error because of non zero delta mid-year for dribbler + ! hrv_xsmrpool_to_atm_c + if (is_beg_curr_year()) then + croplive(p) = .false. + t1 = 1.0_r8 / dt + ! clear-cut carbon fluxes, remove all displayed/storage/transfer pools + ! displayed pools + hrv_leafc_to_litter(p) = leafc(p) * t1 + hrv_leafn_to_litter(p) = leafn(p) * t1 + hrv_frootc_to_litter(p) = frootc(p) * t1 + hrv_frootn_to_litter(p) = frootn(p) * t1 + hrv_livestemc_to_litter(p) = livestemc(p) * t1 + hrv_livestemn_to_litter(p) = livestemn(p) * t1 + wood_harvestc(p) = deadstemc(p) * t1 + wood_harvestn(p) = deadstemn(p) * t1 + hrv_livecrootc_to_litter(p) = livecrootc(p) * t1 + hrv_livecrootn_to_litter(p) = livecrootn(p) * t1 + hrv_deadcrootc_to_litter(p) = deadcrootc(p) * t1 + hrv_deadcrootn_to_litter(p) = deadcrootn(p) * t1 + hrv_xsmrpool_to_atm(p) = xsmrpool(p) * t1 + + ! storage pools + hrv_leafc_storage_to_litter(p) = leafc_storage(p) * t1 + hrv_leafn_storage_to_litter(p) = leafn_storage(p) * t1 + hrv_frootc_storage_to_litter(p) = frootc_storage(p) * t1 + hrv_frootn_storage_to_litter(p) = frootn_storage(p) * t1 + hrv_livestemc_storage_to_litter(p) = livestemc_storage(p) * t1 + hrv_livestemn_storage_to_litter(p) = livestemn_storage(p) * t1 + hrv_deadstemc_storage_to_litter(p) = deadstemc_storage(p) * t1 + hrv_deadstemn_storage_to_litter(p) = deadstemn_storage(p) * t1 + hrv_livecrootc_storage_to_litter(p) = livecrootc_storage(p) * t1 + hrv_livecrootn_storage_to_litter(p) = livecrootn_storage(p) * t1 + hrv_deadcrootc_storage_to_litter(p) = deadcrootc_storage(p) * t1 + hrv_deadcrootn_storage_to_litter(p) = deadcrootn_storage(p) * t1 + hrv_gresp_storage_to_litter(p) = gresp_storage(p) * t1 + + ! transfer pools + hrv_leafc_xfer_to_litter(p) = leafc_xfer(p) * t1 + hrv_leafn_xfer_to_litter(p) = leafn_xfer(p) * t1 + hrv_frootc_xfer_to_litter(p) = frootc_xfer(p) * t1 + hrv_frootn_xfer_to_litter(p) = frootn_xfer(p) * t1 + hrv_livestemc_xfer_to_litter(p) = livestemc_xfer(p) * t1 + hrv_livestemn_xfer_to_litter(p) = livestemn_xfer(p) * t1 + hrv_deadstemc_xfer_to_litter(p) = deadstemc_xfer(p) * t1 + hrv_deadstemn_xfer_to_litter(p) = deadstemn_xfer(p) * t1 + hrv_livecrootc_xfer_to_litter(p) = livecrootc_xfer(p) * t1 + hrv_livecrootn_xfer_to_litter(p) = livecrootn_xfer(p) * t1 + hrv_deadcrootc_xfer_to_litter(p) = deadcrootc_xfer(p) * t1 + hrv_deadcrootn_xfer_to_litter(p) = deadcrootn_xfer(p) * t1 + hrv_gresp_xfer_to_litter(p) = gresp_xfer(p) * t1 + + ! retransn pools + hrv_retransn_to_litter(p) = retransn(p) * t1 + else + croplive(p) = .true. + end if + + end if ! end orchard rotation end do ! end patch loop end associate @@ -2811,6 +4219,7 @@ subroutine CNGrainToProductPools(bounds, num_soilp, filter_soilp, num_soilc, fil ! !USES: use clm_varctl , only : use_crop use clm_varctl , only : use_grainproduct + use pftconMod , only : is_covercrop ! tboas use subgridAveMod , only : p2c ! ! !ARGUMENTS: @@ -2834,6 +4243,9 @@ subroutine CNGrainToProductPools(bounds, num_soilp, filter_soilp, num_soilc, fil if (use_crop .and. use_grainproduct) then do fp = 1, num_soilp p = filter_soilp(fp) + ! tboas: cover crops contribute no crop product; their grain carbon + ! is routed to litter instead (see the phenology litter block) + if (is_covercrop(patch%itype(p))) cycle cnveg_carbonflux_inst%grainc_to_cropprodc_patch(p) = & cnveg_carbonflux_inst%grainc_to_food_patch(p) cnveg_nitrogenflux_inst%grainn_to_cropprodn_patch(p) = & @@ -2857,16 +4269,17 @@ end subroutine CNGrainToProductPools !----------------------------------------------------------------------- subroutine CNLitterToColumn (bounds, num_soilc, filter_soilc, & cnveg_state_inst,cnveg_carbonflux_inst, cnveg_nitrogenflux_inst, & - leaf_prof_patch, froot_prof_patch) + leaf_prof_patch, froot_prof_patch, stem_prof_patch) ! ! !DESCRIPTION: ! called at the end of cn_phenology to gather all patch-level litterfall fluxes ! to the column level and assign them to the three litter pools ! ! !USES: - use clm_varpar , only : max_patch_per_col, nlevdecomp + use clm_varpar , only : max_patch_per_col,maxpatch_pft, nlevdecomp use pftconMod , only : npcropmin use clm_varctl , only : use_grainproduct + use pftconMod , only : is_covercrop ! tboas ! ! !ARGUMENTS: type(bounds_type) , intent(in) :: bounds @@ -2877,6 +4290,7 @@ subroutine CNLitterToColumn (bounds, num_soilc, filter_soilc, & type(cnveg_nitrogenflux_type) , intent(inout) :: cnveg_nitrogenflux_inst real(r8) , intent(in) :: leaf_prof_patch(bounds%begp:,1:) real(r8) , intent(in) :: froot_prof_patch(bounds%begp:,1:) + real(r8) , intent(in) :: stem_prof_patch(bounds%begp:,1:) ! ! !LOCAL VARIABLES: integer :: fc,c,pi,p,j ! indices @@ -2884,11 +4298,13 @@ subroutine CNLitterToColumn (bounds, num_soilc, filter_soilc, & SHR_ASSERT_ALL((ubound(leaf_prof_patch) == (/bounds%endp,nlevdecomp_full/)), errMsg(sourcefile, __LINE__)) SHR_ASSERT_ALL((ubound(froot_prof_patch) == (/bounds%endp,nlevdecomp_full/)), errMsg(sourcefile, __LINE__)) + SHR_ASSERT_ALL((ubound(stem_prof_patch) == (/bounds%endp,nlevdecomp_full/)), errMsg(sourcefile, __LINE__)) associate( & leaf_prof => leaf_prof_patch , & ! Input: [real(r8) (:,:) ] (1/m) profile of leaves froot_prof => froot_prof_patch , & ! Input: [real(r8) (:,:) ] (1/m) profile of fine roots + stem_prof => stem_prof_patch , & ! Input: [real(r8) (:,:) ] (1/m) profile of stems ivt => patch%itype , & ! Input: [integer (:) ] patch vegetation type wtcol => patch%wtcol , & ! Input: [real(r8) (:) ] weight (relative to column) for this patch (0-1) @@ -2899,21 +4315,52 @@ subroutine CNLitterToColumn (bounds, num_soilc, filter_soilc, & fr_fcel => pftcon%fr_fcel , & ! Input: fine root litter cellulose fraction fr_flig => pftcon%fr_flig , & ! Input: fine root litter lignin fraction + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types + mulch_pruning => pftcon%mulch_pruning , & ! Input: binary flag for mulching or exporting of pruning material + prune_flag => cnveg_state_inst%prune_flag_patch , & ! Input: binary flag for pruning of perennial crop types + offset2_flag => cnveg_state_inst%offset2_flag_patch , & ! Input: binary flag for rotation of perennial crop types leafc_to_litter => cnveg_carbonflux_inst%leafc_to_litter_patch , & ! Input: [real(r8) (:) ] leaf C litterfall (gC/m2/s) frootc_to_litter => cnveg_carbonflux_inst%frootc_to_litter_patch , & ! Input: [real(r8) (:) ] fine root N litterfall (gN/m2/s) livestemc_to_litter => cnveg_carbonflux_inst%livestemc_to_litter_patch , & ! Input: [real(r8) (:) ] live stem C litterfall (gC/m2/s) + prunec_to_litter => cnveg_carbonflux_inst%prunec_to_litter_patch , & ! Input: [real(r8) (:) ] pruning C litterfall (gC/m2/s) + prunec_storage_to_litter => cnveg_carbonflux_inst%prunec_storage_to_litter_patch , & ! Input: [real(r8) (:) ] pruning storage C litterfall (gC/m2/s) grainc_to_food => cnveg_carbonflux_inst%grainc_to_food_patch , & ! Input: [real(r8) (:) ] grain C to food (gC/m2/s) phenology_c_to_litr_met_c => cnveg_carbonflux_inst%phenology_c_to_litr_met_c_col , & ! Output: [real(r8) (:,:) ] C fluxes associated with phenology (litterfall and crop) to litter metabolic pool (gC/m3/s) phenology_c_to_litr_cel_c => cnveg_carbonflux_inst%phenology_c_to_litr_cel_c_col , & ! Output: [real(r8) (:,:) ] C fluxes associated with phenology (litterfall and crop) to litter cellulose pool (gC/m3/s) phenology_c_to_litr_lig_c => cnveg_carbonflux_inst%phenology_c_to_litr_lig_c_col , & ! Output: [real(r8) (:,:) ] C fluxes associated with phenology (litterfall and crop) to litter lignin pool (gC/m3/s) livestemn_to_litter => cnveg_nitrogenflux_inst%livestemn_to_litter_patch , & ! Input: [real(r8) (:) ] livestem N to litter (gN/m2/s) + prunen_to_litter => cnveg_nitrogenflux_inst%prunen_to_litter_patch , & ! Input: [real(r8) (:) ] pruning N litterfall (gN/m2/s) + prunen_storage_to_litter => cnveg_nitrogenflux_inst%prunen_storage_to_litter_patch , & ! Input: [real(r8) (:) ] pruning storage N litterfall (gN/m2/s) grainn_to_food => cnveg_nitrogenflux_inst%grainn_to_food_patch , & ! Input: [real(r8) (:) ] grain N to food (gN/m2/s) leafn_to_litter => cnveg_nitrogenflux_inst%leafn_to_litter_patch , & ! Input: [real(r8) (:) ] leaf N litterfall (gN/m2/s) frootn_to_litter => cnveg_nitrogenflux_inst%frootn_to_litter_patch , & ! Input: [real(r8) (:) ] fine root N litterfall (gN/m2/s) phenology_n_to_litr_met_n => cnveg_nitrogenflux_inst%phenology_n_to_litr_met_n_col , & ! Output: [real(r8) (:,:) ] N fluxes associated with phenology (litterfall and crop) to litter metabolic pool (gN/m3/s) phenology_n_to_litr_cel_n => cnveg_nitrogenflux_inst%phenology_n_to_litr_cel_n_col , & ! Output: [real(r8) (:,:) ] N fluxes associated with phenology (litterfall and crop) to litter cellulose pool (gN/m3/s) - phenology_n_to_litr_lig_n => cnveg_nitrogenflux_inst%phenology_n_to_litr_lig_n_col & ! Output: [real(r8) (:,:) ] N fluxes associated with phenology (litterfall and crop) to litter lignin pool (gN/m3/s) + phenology_n_to_litr_lig_n => cnveg_nitrogenflux_inst%phenology_n_to_litr_lig_n_col , & ! Output: [real(r8) (:,:) ] N fluxes associated with phenology (litterfall and crop) to litter lignin pool (gN/m3/s) + hrv_livestemc_to_litter => cnveg_carbonflux_inst%hrv_livestemc_to_litter_patch , & ! Input: [real(r8) (:) ] + pwood_harvestc => cnveg_carbonflux_inst%wood_harvestc_patch , & ! Input: [real(r8) (:) ] + hrv_livestemc_storage_to_litter => cnveg_carbonflux_inst%hrv_livestemc_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadstemc_storage_to_litter => cnveg_carbonflux_inst%hrv_deadstemc_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + cwood_harvestc => cnveg_carbonflux_inst%wood_harvestc_col , & ! InOut: [real(r8) (:) ] + m_deadstemc_to_litter => cnveg_carbonflux_inst%m_deadstemc_to_litter_patch , & ! Input: [real(r8) (:) ] + m_deadstemc_storage_to_litter => cnveg_carbonflux_inst%m_deadstemc_storage_to_litter_patch , & ! Input:[real(r8) (:) ] + harvest_c_to_litr_met_c => cnveg_carbonflux_inst%harvest_c_to_litr_met_c_col , & ! InOut: [real(r8) (:,:) ] C fluxes associated with harvest to litter metabolic pool (gC/m3/s) + harvest_c_to_cwdc => cnveg_carbonflux_inst%harvest_c_to_cwdc_col , & ! InOut: [real(r8) (:,:) ] C fluxes associated with harvest to CWD pool (gC/m3/s) + gap_mortality_c_to_litr_met_c => cnveg_carbonflux_inst%gap_mortality_c_to_litr_met_c_col , & ! Output: [real(r8) (:,:) ] C fluxes associated with gap mortality to litter metabolic pool (gC/m3/s) + gap_mortality_c_to_cwdc => cnveg_carbonflux_inst%gap_mortality_c_to_cwdc_col , & ! Output: [real(r8) (:,:) ] C fluxes associated with gap mortality to CWD pool (gC/m3/s) + hrv_livestemn_to_litter => cnveg_nitrogenflux_inst%hrv_livestemn_to_litter_patch , & ! Input: [real(r8) (:) ] + pwood_harvestn => cnveg_nitrogenflux_inst%wood_harvestn_patch , & ! Input: [real(r8) (:) ] + hrv_livestemn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_livestemn_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadstemn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_deadstemn_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + cwood_harvestn => cnveg_nitrogenflux_inst%wood_harvestn_col , & ! InOut: [real(r8) (:) ] + harvest_n_to_litr_met_n => cnveg_nitrogenflux_inst%harvest_n_to_litr_met_n_col , & ! InOut: [real(r8) (:,:) ] N fluxes associated with harvest to litter metabolic pool (gN/m3/s) + harvest_n_to_cwdn => cnveg_nitrogenflux_inst%harvest_n_to_cwdn_col , & ! InOut: [real(r8) (:,:) ] C fluxes associated with harvest to CWD pool (gC/m3/s) + m_deadstemn_to_litter => cnveg_nitrogenflux_inst%m_deadstemn_to_litter_patch , & ! Input: [real(r8) (:) ] + m_deadstemn_storage_to_litter => cnveg_nitrogenflux_inst%m_deadstemn_storage_to_litter_patch , & ! Input:[real(r8) (:) ] + + gap_mortality_n_to_litr_met_n => cnveg_nitrogenflux_inst%gap_mortality_n_to_litr_met_n_col , & ! Output: [real(r8) (:,:) ] N fluxes associated with gap mortality to litter metabolic pool (gN/m3/s) + gap_mortality_n_to_cwdn => cnveg_nitrogenflux_inst%gap_mortality_n_to_cwdn_col & ! Output: [real(r8) (:,:) ] N fluxes associated with gap mortality to CWD pool (gN/m3/s) ) do j = 1, nlevdecomp @@ -2962,7 +4409,9 @@ subroutine CNLitterToColumn (bounds, num_soilc, filter_soilc, & ! new ones for now (slevis) ! also for simplicity I've put "food" into the litter pools - if (ivt(p) >= npcropmin) then ! add livestemc to litter + if (ivt(p) >= npcropmin) then + if ( perennial(ivt(p)) == 0._r8) then + ! add livestemc to litter ! stem litter carbon fluxes phenology_c_to_litr_met_c(c,j) = phenology_c_to_litr_met_c(c,j) & + livestemc_to_litter(p) * lf_flab(ivt(p)) * wtcol(p) * leaf_prof(p,j) @@ -2979,8 +4428,11 @@ subroutine CNLitterToColumn (bounds, num_soilc, filter_soilc, & phenology_n_to_litr_lig_n(c,j) = phenology_n_to_litr_lig_n(c,j) & + livestemn_to_litter(p) * lf_flig(ivt(p)) * wtcol(p) * leaf_prof(p,j) - if (.not. use_grainproduct) then - ! grain litter carbon fluxes + end if + + if (.not. use_grainproduct .or. is_covercrop(ivt(p))) then + ! grain litter carbon fluxes --- tboas: cover crop + ! grain is ploughed in, never a crop product phenology_c_to_litr_met_c(c,j) = phenology_c_to_litr_met_c(c,j) & + grainc_to_food(p) * lf_flab(ivt(p)) * wtcol(p) * leaf_prof(p,j) phenology_c_to_litr_cel_c(c,j) = phenology_c_to_litr_cel_c(c,j) & @@ -2997,18 +4449,337 @@ subroutine CNLitterToColumn (bounds, num_soilc, filter_soilc, & + grainn_to_food(p) * lf_flig(ivt(p)) * wtcol(p) * leaf_prof(p,j) end if + ! calculate pruning litter fluxes added by O.Dombrowski + ! and adapted based on CLM-Palm (Fan et al. 2015) + if ( perennial(ivt(p)) == 1._r8 .and. prune_flag(p) == 1._r8) then + if (mulch_pruning(ivt(p)) == 0._r8) then + ! export pruning material as harvest + ! storage harvest mortality carbon fluxes + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_deadstemc_storage_to_litter(p) * wtcol(p) * stem_prof(p,j) + ! storage harvest mortality nitrogen fluxes + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_deadstemn_storage_to_litter(p) * wtcol(p) * stem_prof(p,j) + + ! wood harvest mortality carbon fluxes to product pools + !cwood_harvestc(c) = cwood_harvestc(c) + & + !pwood_harvestc(p) * wtcol(p) + ! wood harvest mortality nitrogen fluxes to product pools + !cwood_harvestn(c) = cwood_harvestn(c) + & + !pwood_harvestn(p) * wtcol(p) + + else if (mulch_pruning(ivt(p)) == 1._r8) then + ! add pruning material to litter + ! pruning carbon fluxes + phenology_c_to_litr_met_c(c,j) = phenology_c_to_litr_met_c(c,j) & + + prunec_to_litter(p) * lf_flab(ivt(p)) * wtcol(p) * leaf_prof(p,j) & + + prunec_storage_to_litter(p) * lf_flab(ivt(p)) * wtcol(p) * leaf_prof(p,j) + phenology_c_to_litr_cel_c(c,j) = phenology_c_to_litr_cel_c(c,j) & + + prunec_to_litter(p) * lf_fcel(ivt(p)) * wtcol(p) * leaf_prof(p,j) & + + prunec_storage_to_litter(p) * lf_fcel(ivt(p)) * wtcol(p) * leaf_prof(p,j) + phenology_c_to_litr_lig_c(c,j) = phenology_c_to_litr_lig_c(c,j) & + + prunec_to_litter(p) * lf_flig(ivt(p)) * wtcol(p) * leaf_prof(p,j) & + + prunec_storage_to_litter(p) * lf_flig(ivt(p)) * wtcol(p) * leaf_prof(p,j) + + ! pruning nitrogen fluxes + phenology_n_to_litr_met_n(c,j) = phenology_n_to_litr_met_n(c,j) & + + prunen_to_litter(p) * lf_flab(ivt(p)) * wtcol(p) * leaf_prof(p,j) & + + prunen_storage_to_litter(p) * lf_flab(ivt(p)) * wtcol(p) * leaf_prof(p,j) + phenology_n_to_litr_cel_n(c,j) = phenology_n_to_litr_cel_n(c,j) & + + prunen_to_litter(p) * lf_fcel(ivt(p)) * wtcol(p) * leaf_prof(p,j) & + + prunen_storage_to_litter(p) * lf_fcel(ivt(p)) * wtcol(p) * leaf_prof(p,j) + phenology_n_to_litr_lig_n(c,j) = phenology_n_to_litr_lig_n(c,j) & + + prunen_to_litter(p) * lf_flig(ivt(p)) * wtcol(p) * leaf_prof(p,j) & + + prunen_storage_to_litter(p) * lf_flig(ivt(p)) * wtcol(p) * leaf_prof(p,j) + end if + end if end if end if end if end do + end do + end do + + + do pi = 1,maxpatch_pft + do fc = 1,num_soilc + c = filter_soilc(fc) + + if (pi <= col%npatches(c)) then + p = col%patchi(c) + pi - 1 + if (perennial(ivt(p)) == 1._r8 .and. prune_flag(p) == 1._r8 .and. mulch_pruning(ivt(p)) == 0._r8) then + if (patch%active(p)) then + ! wood harvest mortality carbon fluxes to product pools + cwood_harvestc(c) = cwood_harvestc(c) + & + pwood_harvestc(p) * wtcol(p) + + ! wood harvest mortality nitrogen fluxes to product pools + cwood_harvestn(c) = cwood_harvestn(c) + & + pwood_harvestn(p) * wtcol(p) + end if + end if + end if + + end do + + end do + + end associate + + end subroutine CNLitterToColumn + + !----------------------------------------------------------------------- + subroutine CNRotationToColumn (num_soilc, filter_soilc, & + cnveg_state_inst, soilbiogeochem_state_inst, & + crop_inst, cnveg_carbonflux_inst, cnveg_nitrogenflux_inst) + ! + ! !DESCRIPTION: + ! called at the end of CNPhenology to gather all patch-level orchard rotation litterfall + ! fluxes + ! to the column level and assign them to the three litter pools + ! + ! !USES: + use clm_varpar , only : maxpatch_pft, nlevdecomp + use pftconMod , only : npcropmin + ! + ! !ARGUMENTS: + integer , intent(in) :: num_soilc ! number of soil columns in filter + integer , intent(in) :: filter_soilc(:) ! soil column filter + type(crop_type) , intent(inout) :: crop_inst + type(cnveg_state_type) , intent(in) :: cnveg_state_inst + type(soilbiogeochem_state_type) , intent(in) :: soilbiogeochem_state_inst + type(cnveg_carbonflux_type) , intent(inout) :: cnveg_carbonflux_inst + type(cnveg_nitrogenflux_type) , intent(inout) :: cnveg_nitrogenflux_inst + ! + ! !LOCAL VARIABLES: + integer :: fc,c,pi,p,j ! indices + !----------------------------------------------------------------------- + + associate( & + ivt => patch%itype , & ! Input: [integer (:) ] pft vegetation type + wtcol => patch%wtcol , & ! Input: [real(r8) (:) ] pft weight relative to column (0-1) + + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types + lf_flab => pftcon%lf_flab , & ! Input: leaf litter labile fraction + lf_fcel => pftcon%lf_fcel , & ! Input: leaf litter cellulose fraction + lf_flig => pftcon%lf_flig , & ! Input: leaf litter lignin fraction + fr_flab => pftcon%fr_flab , & ! Input: fine root litter labile fraction + fr_fcel => pftcon%fr_fcel , & ! Input: fine root litter cellulose fraction + fr_flig => pftcon%fr_flig , & ! Input: fine root litter lignin fraction + + offset2_flag => cnveg_state_inst%offset2_flag_patch , & ! Input: binary flag for rotation of perennial crop types + croplive => crop_inst%croplive_patch , & ! Output: [logical (:) ] Flag, true if planted, not harvested + + leaf_prof => soilbiogeochem_state_inst%leaf_prof_patch , & ! Input: [real(r8) (:,:) ] (1/m) profile of leaves + froot_prof => soilbiogeochem_state_inst%froot_prof_patch , & ! Input: [real(r8) (:,:) ] (1/m) profile of fine roots + croot_prof => soilbiogeochem_state_inst%croot_prof_patch , & ! Input: [real(r8) (:,:) ] (1/m) profile of coarse roots + stem_prof => soilbiogeochem_state_inst%stem_prof_patch , & ! Input: [real(r8) (:,:) ] (1/m) profile of stems + + hrv_leafc_to_litter => cnveg_carbonflux_inst%hrv_leafc_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_frootc_to_litter => cnveg_carbonflux_inst%hrv_frootc_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livestemc_to_litter => cnveg_carbonflux_inst%hrv_livestemc_to_litter_patch , & ! Input: [real(r8) (:) ] + pwood_harvestc => cnveg_carbonflux_inst%wood_harvestc_patch , & ! Input: [real(r8) (:) ] + hrv_livecrootc_to_litter => cnveg_carbonflux_inst%hrv_livecrootc_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadcrootc_to_litter => cnveg_carbonflux_inst%hrv_deadcrootc_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_leafc_storage_to_litter => cnveg_carbonflux_inst%hrv_leafc_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_frootc_storage_to_litter => cnveg_carbonflux_inst%hrv_frootc_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livestemc_storage_to_litter => cnveg_carbonflux_inst%hrv_livestemc_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadstemc_storage_to_litter => cnveg_carbonflux_inst%hrv_deadstemc_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livecrootc_storage_to_litter => cnveg_carbonflux_inst%hrv_livecrootc_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadcrootc_storage_to_litter => cnveg_carbonflux_inst%hrv_deadcrootc_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_gresp_storage_to_litter => cnveg_carbonflux_inst%hrv_gresp_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_leafc_xfer_to_litter => cnveg_carbonflux_inst%hrv_leafc_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_frootc_xfer_to_litter => cnveg_carbonflux_inst%hrv_frootc_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livestemc_xfer_to_litter => cnveg_carbonflux_inst%hrv_livestemc_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadstemc_xfer_to_litter => cnveg_carbonflux_inst%hrv_deadstemc_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livecrootc_xfer_to_litter => cnveg_carbonflux_inst%hrv_livecrootc_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadcrootc_xfer_to_litter => cnveg_carbonflux_inst%hrv_deadcrootc_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_gresp_xfer_to_litter => cnveg_carbonflux_inst%hrv_gresp_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + cwood_harvestc => cnveg_carbonflux_inst%wood_harvestc_col , & ! InOut: [real(r8) (:) ] + harvest_c_to_litr_met_c => cnveg_carbonflux_inst%harvest_c_to_litr_met_c_col , & ! InOut: [real(r8) (:,:) ] C fluxes associated with harvest to litter metabolic pool (gC/m3/s) + harvest_c_to_litr_cel_c => cnveg_carbonflux_inst%harvest_c_to_litr_cel_c_col , & ! InOut: [real(r8) (:,:) ] C fluxes associated with harvest to litter cellulose pool (gC/m3/s) + harvest_c_to_litr_lig_c => cnveg_carbonflux_inst%harvest_c_to_litr_lig_c_col , & ! InOut: [real(r8) (:,:) ] C fluxes associated with harvest to litter lignin pool (gC/m3/s) + harvest_c_to_cwdc => cnveg_carbonflux_inst%harvest_c_to_cwdc_col , & ! InOut: [real(r8) (:,:) ] C fluxes associated with harvest to CWD pool (gC/m3/s) + + hrv_leafn_to_litter => cnveg_nitrogenflux_inst%hrv_leafn_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_frootn_to_litter => cnveg_nitrogenflux_inst%hrv_frootn_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livestemn_to_litter => cnveg_nitrogenflux_inst%hrv_livestemn_to_litter_patch , & ! Input: [real(r8) (:) ] + pwood_harvestn => cnveg_nitrogenflux_inst%wood_harvestn_patch , & ! Input: [real(r8) (:) ] + hrv_livecrootn_to_litter => cnveg_nitrogenflux_inst%hrv_livecrootn_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadcrootn_to_litter => cnveg_nitrogenflux_inst%hrv_deadcrootn_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_retransn_to_litter => cnveg_nitrogenflux_inst%hrv_retransn_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_leafn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_leafn_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_frootn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_frootn_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livestemn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_livestemn_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadstemn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_deadstemn_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livecrootn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_livecrootn_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadcrootn_storage_to_litter => cnveg_nitrogenflux_inst%hrv_deadcrootn_storage_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_leafn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_leafn_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_frootn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_frootn_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livestemn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_livestemn_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadstemn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_deadstemn_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_livecrootn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_livecrootn_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + hrv_deadcrootn_xfer_to_litter => cnveg_nitrogenflux_inst%hrv_deadcrootn_xfer_to_litter_patch , & ! Input: [real(r8) (:) ] + cwood_harvestn => cnveg_nitrogenflux_inst%wood_harvestn_col , & ! InOut: [real(r8) (:) ] + harvest_n_to_litr_met_n => cnveg_nitrogenflux_inst%harvest_n_to_litr_met_n_col , & ! InOut: [real(r8) (:,:) ] N fluxes associated with harvest to litter metabolic pool (gN/m3/s) + harvest_n_to_litr_cel_n => cnveg_nitrogenflux_inst%harvest_n_to_litr_cel_n_col , & ! InOut: [real(r8) (:,:) ] N fluxes associated with harvest to litter cellulose pool (gN/m3/s) + harvest_n_to_litr_lig_n => cnveg_nitrogenflux_inst%harvest_n_to_litr_lig_n_col , & ! InOut: [real(r8) (:,:) ] N fluxes associated with harvest to litter lignin pool (gN/m3/s) + harvest_n_to_cwdn => cnveg_nitrogenflux_inst%harvest_n_to_cwdn_col & ! InOut: [real(r8) (:,:) ] N fluxes associated with harvest to CWD pool (gN/m3/s) + ) + + do j = 1, nlevdecomp + do pi = 1,maxpatch_pft + do fc = 1,num_soilc + c = filter_soilc(fc) + + if (pi <= col%npatches(c)) then + p = col%patchi(c) + pi - 1 + + if (patch%active(p) .and. (.not. croplive(p)) .and. ivt(p) >= npcropmin .and. perennial(ivt(p)) == 1._r8 .and. offset2_flag(p) == 1._r8) then + + ! leaf harvest mortality carbon fluxes + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_leafc_to_litter(p) * lf_flab(ivt(p)) * wtcol(p) * leaf_prof(p,j) + harvest_c_to_litr_cel_c(c,j) = harvest_c_to_litr_cel_c(c,j) + & + hrv_leafc_to_litter(p) * lf_fcel(ivt(p)) * wtcol(p) * leaf_prof(p,j) + harvest_c_to_litr_lig_c(c,j) = harvest_c_to_litr_lig_c(c,j) + & + hrv_leafc_to_litter(p) * lf_flig(ivt(p)) * wtcol(p) * leaf_prof(p,j) + + ! fine root harvest mortality carbon fluxes + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_frootc_to_litter(p) * fr_flab(ivt(p)) * wtcol(p) * froot_prof(p,j) + harvest_c_to_litr_cel_c(c,j) = harvest_c_to_litr_cel_c(c,j) + & + hrv_frootc_to_litter(p) * fr_fcel(ivt(p)) * wtcol(p) * froot_prof(p,j) + harvest_c_to_litr_lig_c(c,j) = harvest_c_to_litr_lig_c(c,j) + & + hrv_frootc_to_litter(p) * fr_flig(ivt(p)) * wtcol(p) * froot_prof(p,j) + + ! wood harvest mortality carbon fluxes + harvest_c_to_cwdc(c,j) = harvest_c_to_cwdc(c,j) + & + hrv_livestemc_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_c_to_cwdc(c,j) = harvest_c_to_cwdc(c,j) + & + hrv_livecrootc_to_litter(p) * wtcol(p) * croot_prof(p,j) + harvest_c_to_cwdc(c,j) = harvest_c_to_cwdc(c,j) + & + hrv_deadcrootc_to_litter(p) * wtcol(p) * croot_prof(p,j) + ! storage harvest mortality carbon fluxes + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_leafc_storage_to_litter(p) * wtcol(p) * leaf_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_frootc_storage_to_litter(p) * wtcol(p) * froot_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_livestemc_storage_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_deadstemc_storage_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_livecrootc_storage_to_litter(p) * wtcol(p) * croot_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_deadcrootc_storage_to_litter(p) * wtcol(p) * croot_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_gresp_storage_to_litter(p) * wtcol(p) * leaf_prof(p,j) + + ! transfer harvest mortality carbon fluxes + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_leafc_xfer_to_litter(p) * wtcol(p) * leaf_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_frootc_xfer_to_litter(p) * wtcol(p) * froot_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_livestemc_xfer_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_deadstemc_xfer_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_livecrootc_xfer_to_litter(p) * wtcol(p) * croot_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_deadcrootc_xfer_to_litter(p) * wtcol(p) * croot_prof(p,j) + harvest_c_to_litr_met_c(c,j) = harvest_c_to_litr_met_c(c,j) + & + hrv_gresp_xfer_to_litter(p) * wtcol(p) * leaf_prof(p,j) + + ! leaf harvest mortality nitrogen fluxes + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_leafn_to_litter(p) * lf_flab(ivt(p)) * wtcol(p) * leaf_prof(p,j) + harvest_n_to_litr_cel_n(c,j) = harvest_n_to_litr_cel_n(c,j) + & + hrv_leafn_to_litter(p) * lf_fcel(ivt(p)) * wtcol(p) * leaf_prof(p,j) + harvest_n_to_litr_lig_n(c,j) = harvest_n_to_litr_lig_n(c,j) + & + hrv_leafn_to_litter(p) * lf_flig(ivt(p)) * wtcol(p) * leaf_prof(p,j) + + ! fine root litter nitrogen fluxes + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_frootn_to_litter(p) * fr_flab(ivt(p)) * wtcol(p) * froot_prof(p,j) + harvest_n_to_litr_cel_n(c,j) = harvest_n_to_litr_cel_n(c,j) + & + hrv_frootn_to_litter(p) * fr_fcel(ivt(p)) * wtcol(p) * froot_prof(p,j) + harvest_n_to_litr_lig_n(c,j) = harvest_n_to_litr_lig_n(c,j) + & + hrv_frootn_to_litter(p) * fr_flig(ivt(p)) * wtcol(p) * froot_prof(p,j) + + ! wood harvest mortality nitrogen fluxes + harvest_n_to_cwdn(c,j) = harvest_n_to_cwdn(c,j) + & + hrv_livestemn_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_n_to_cwdn(c,j) = harvest_n_to_cwdn(c,j) + & + hrv_livecrootn_to_litter(p) * wtcol(p) * croot_prof(p,j) + harvest_n_to_cwdn(c,j) = harvest_n_to_cwdn(c,j) + & + hrv_deadcrootn_to_litter(p) * wtcol(p) * croot_prof(p,j) + + ! retranslocated N pool harvest mortality fluxes + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_retransn_to_litter(p) * wtcol(p) * leaf_prof(p,j) + + ! storage harvest mortality nitrogen fluxes + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_leafn_storage_to_litter(p) * wtcol(p) * leaf_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_frootn_storage_to_litter(p) * wtcol(p) * froot_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_livestemn_storage_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_deadstemn_storage_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_livecrootn_storage_to_litter(p) * wtcol(p) * croot_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_deadcrootn_storage_to_litter(p) * wtcol(p) * croot_prof(p,j) + + ! transfer harvest mortality nitrogen fluxes + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_leafn_xfer_to_litter(p) * wtcol(p) * leaf_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_frootn_xfer_to_litter(p) * wtcol(p) * froot_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_livestemn_xfer_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_deadstemn_xfer_to_litter(p) * wtcol(p) * stem_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_livecrootn_xfer_to_litter(p) * wtcol(p) * croot_prof(p,j) + harvest_n_to_litr_met_n(c,j) = harvest_n_to_litr_met_n(c,j) + & + hrv_deadcrootn_xfer_to_litter(p) * wtcol(p) * croot_prof(p,j) + end if + end if + + end do end do end do + do pi = 1,maxpatch_pft + do fc = 1,num_soilc + c = filter_soilc(fc) + + if (pi <= col%npatches(c)) then + p = col%patchi(c) + pi - 1 + + if (patch%active(p)) then + ! wood harvest mortality carbon fluxes to product pools + cwood_harvestc(c) = cwood_harvestc(c) + & + pwood_harvestc(p) * wtcol(p) + + ! wood harvest mortality nitrogen fluxes to product pools + cwood_harvestn(c) = cwood_harvestn(c) + & + pwood_harvestn(p) * wtcol(p) + end if + end if + + end do + + end do end associate - end subroutine CNLitterToColumn + end subroutine CNRotationToColumn end module CNPhenologyMod diff --git a/src/clm5/biogeochem/CNVegCarbonFluxType.F90 b/src/clm5/biogeochem/CNVegCarbonFluxType.F90 index f88c7f5e66..7a44ea42a1 100644 --- a/src/clm5/biogeochem/CNVegCarbonFluxType.F90 +++ b/src/clm5/biogeochem/CNVegCarbonFluxType.F90 @@ -15,9 +15,11 @@ module CNVegCarbonFluxType use clm_varcon , only : spval, dzsoi_decomp use clm_varctl , only : use_cndv, use_c13, use_nitrif_denitrif, use_crop use clm_varctl , only : use_grainproduct + use pftconMod , only : is_covercrop ! tboas use clm_varctl , only : iulog + use clm_varctl , only : use_cfert ! tboas: namelist flag for organic C fertilizer use landunit_varcon , only : istsoil, istcrop, istdlak - use pftconMod , only : npcropmin + use pftconMod , only : npcropmin, pftcon use LandunitType , only : lun use ColumnType , only : col use PatchType , only : patch @@ -135,6 +137,9 @@ module CNVegCarbonFluxType real(r8), pointer :: livestemc_to_litter_patch (:) ! live stem C litterfall (gC/m2/s) real(r8), pointer :: grainc_to_food_patch (:) ! grain C to food for prognostic crop(gC/m2/s) real(r8), pointer :: grainc_to_seed_patch (:) ! grain C to seed for prognostic crop(gC/m2/s) + ! pruning litterfall flux + real(r8), pointer :: prunec_to_litter_patch (:) ! pruning C litterfall (gC/m2/s) + real(r8), pointer :: prunec_storage_to_litter_patch (:) ! pruning storage C litterfall (gC/m2/s) ! maintenance respiration fluxes real(r8), pointer :: cpool_to_resp_patch (:) ! CNflex excess C maintenance respiration (gC/m2/s) @@ -274,6 +279,10 @@ module CNVegCarbonFluxType ! crop fluxes real(r8), pointer :: crop_seedc_to_leaf_patch (:) ! (gC/m2/s) seed source to leaf, for crops + real(r8), pointer :: crop_seedc_to_froot_patch (:) ! (gC/m2/s) seed source to fine roots, for perennial crops (added by O.Dombrowski) + real(r8), pointer :: crop_seedc_to_deadstem_patch (:) ! (gC/m2/s) seed source to deadstem, for perennial crops (added by O.Dombrowski) + ! tboas: organic carbon fertilizer flux from manure application + real(r8), pointer :: fertC_patch (:) ! (gC/m2/s) organic C fertilizer from manure applied each timestep ! summary (diagnostic) flux variables, not involved in mass balance real(r8), pointer :: gpp_before_downreg_patch (:) ! (gC/m2/s) gross primary production before down regulation @@ -615,6 +624,8 @@ subroutine InitAllocate(this, bounds, carbon_type) allocate(this%leafc_loss_patch (begp:endp)) ; this%leafc_loss_patch (:) = nan allocate(this%woodc_alloc_patch (begp:endp)) ; this%woodc_alloc_patch (:) = nan allocate(this%woodc_loss_patch (begp:endp)) ; this%woodc_loss_patch (:) = nan + allocate(this%prunec_to_litter_patch (begp:endp)) ; this%prunec_to_litter_patch (:) = nan + allocate(this%prunec_storage_to_litter_patch (begp:endp)) ; this%prunec_storage_to_litter_patch (:) = nan allocate(this%phenology_c_to_litr_met_c_col (begc:endc,1:nlevdecomp_full)); this%phenology_c_to_litr_met_c_col (:,:)=nan @@ -655,6 +666,11 @@ subroutine InitAllocate(this, bounds, carbon_type) allocate(this%crop_seedc_to_leaf_patch (begp:endp)) ; this%crop_seedc_to_leaf_patch (:) =nan + allocate(this%crop_seedc_to_froot_patch (begp:endp)) ; this%crop_seedc_to_froot_patch (:) =nan + allocate(this%crop_seedc_to_deadstem_patch (begp:endp)) ; this%crop_seedc_to_deadstem_patch (:) =nan + ! tboas: always allocate fertC_patch so associate pointer in CNPhenologyMod is always valid + ! When use_cfert=False the array is zeroed and never written to litter pools + allocate(this%fertC_patch (begp:endp)) ; this%fertC_patch(:) = 0.0_r8 allocate(this%cwdc_hr_col (begc:endc)) ; this%cwdc_hr_col (:) =nan allocate(this%cwdc_loss_col (begc:endc)) ; this%cwdc_loss_col (:) =nan allocate(this%litterc_loss_col (begc:endc)) ; this%litterc_loss_col (:) =nan @@ -836,6 +852,14 @@ subroutine InitHistory(this, bounds, carbon_type) ptr_patch=this%grainc_to_seed_patch) end if + ! tboas: history field for organic carbon fertilizer from manure + if (use_crop .and. use_cfert) then + this%fertC_patch(begp:endp) = 0.0_r8 + call hist_addfld1d (fname='Corg_FERT', units='gC/m^2/s', & + avgflag='A', long_name='Organic carbon fertilizer applied from manure', & + ptr_patch=this%fertC_patch, default='inactive') + end if + this%litterc_loss_col(begc:endc) = spval call hist_addfld1d (fname='LITTERC_LOSS', units='gC/m^2/s', & avgflag='A', long_name='litter C loss', & @@ -1263,6 +1287,10 @@ subroutine InitHistory(this, bounds, carbon_type) call hist_addfld1d (fname='LIVECROOT_MR', units='gC/m^2/s', & avgflag='A', long_name='live coarse root maintenance respiration', & ptr_patch=this%livecroot_mr_patch, default='inactive') + this%grain_mr_patch(begp:endp) = spval + call hist_addfld1d (fname='GRAIN_MR', units='gC/m^2/s', & + avgflag='A', long_name='grain maintenance respiration', & + ptr_patch=this%grain_mr_patch, default='inactive') this%psnsun_to_cpool_patch(begp:endp) = spval call hist_addfld1d (fname='PSNSUN_TO_CPOOL', units='gC/m^2/s', & @@ -2918,6 +2946,15 @@ subroutine InitHistory(this, bounds, carbon_type) avgflag='A', long_name='crop seed source to leaf', & ptr_patch=this%crop_seedc_to_leaf_patch, default='inactive') + this%crop_seedc_to_froot_patch(begp:endp) = spval + call hist_addfld1d (fname='CROP_SEEDC_TO_FROOT', units='gC/m^2/s', & + avgflag='A', long_name='crop seed source to fine root', & + ptr_patch=this%crop_seedc_to_froot_patch, default='inactive') + + this%crop_seedc_to_deadstem_patch(begp:endp) = spval + call hist_addfld1d (fname='CROP_SEEDC_TO_DEADSTEM', units='gC/m^2/s', & + avgflag='A', long_name='crop seed source to deadstem', & + ptr_patch=this%crop_seedc_to_deadstem_patch, default='inactive') this%sr_col(begc:endc) = spval call hist_addfld1d (fname='SR', units='gC/m^2/s', & avgflag='A', long_name='total soil respiration (HR + root resp)', & @@ -3092,6 +3129,15 @@ subroutine InitHistory(this, bounds, carbon_type) avgflag='A', long_name='C13 crop seed source to leaf', & ptr_patch=this%crop_seedc_to_leaf_patch, default='inactive') + this%crop_seedc_to_froot_patch(begp:endp) = spval + call hist_addfld1d (fname='C13_CROP_SEEDC_TO_FROOT', units='gC13/m^2/s', & + avgflag='A', long_name='C13 crop seed source to fine root', & + ptr_patch=this%crop_seedc_to_froot_patch, default='inactive') + + this%crop_seedc_to_deadstem_patch(begp:endp) = spval + call hist_addfld1d (fname='C13_CROP_SEEDC_TO_DEADSTEM', units='gC13/m^2/s', & + avgflag='A', long_name='C13 crop seed source to deadstem', & + ptr_patch=this%crop_seedc_to_deadstem_patch, default='inactive') this%sr_col(begc:endc) = spval call hist_addfld1d (fname='C13_SR', units='gC13/m^2/s', & avgflag='A', long_name='C13 total soil respiration (HR + root resp)', & @@ -3247,6 +3293,15 @@ subroutine InitHistory(this, bounds, carbon_type) call hist_addfld1d (fname='C14_CROP_SEEDC_TO_LEAF', units='gC14/m^2/s', & avgflag='A', long_name='C14 crop seed source to leaf', & ptr_patch=this%crop_seedc_to_leaf_patch, default='inactive') + this%crop_seedc_to_froot_patch(begp:endp) = spval + call hist_addfld1d (fname='C14_CROP_SEEDC_TO_FROOT', units='gC14/m^2/s', & + avgflag='A', long_name='C14 crop seed source to fine root', & + ptr_patch=this%crop_seedc_to_froot_patch, default='inactive') + + this%crop_seedc_to_deadstem_patch(begp:endp) = spval + call hist_addfld1d (fname='C14_CROP_SEEDC_TO_DEADSTEM', units='gC14/m^2/s', & + avgflag='A', long_name='C14 crop seed source to deadstem', & + ptr_patch=this%crop_seedc_to_deadstem_patch, default='inactive') this%sr_col(begc:endc) = spval call hist_addfld1d (fname='C14_SR', units='gC14/m^2/s', & @@ -3521,6 +3576,24 @@ subroutine RestartBulkOnly ( this, bounds, ncid, flag ) long_name='grain C shift storage to transfer', units='gC/m2/s', & interpinic_flag='interp', readvar=readvar, data=this%grainc_storage_to_xfer_patch) + call restartvar(ncid=ncid, flag=flag, varname='prunec_to_litter', xtype=ncd_double, & + dim1name='pft', & + long_name='pruning C litterfall', units='gC/m2/s', & + interpinic_flag='interp', readvar=readvar, data=this%prunec_to_litter_patch) + + call restartvar(ncid=ncid, flag=flag, varname='prunec_storage_to_litter', xtype=ncd_double, & + dim1name='pft', & + long_name='pruning storage C litterfall', units='gC/m2/s', & + interpinic_flag='interp', readvar=readvar, data=this%prunec_storage_to_litter_patch) + + + ! tboas: restart for organic C fertilizer flux from manure + if (use_cfert) then + call restartvar(ncid=ncid, flag=flag, varname='fertC_patch', xtype=ncd_double, & + dim1name='pft', & + long_name='organic C fertilizer flux from manure', units='gC/m2/s', & + interpinic_flag='interp', readvar=readvar, data=this%fertC_patch) + end if end if call restartvar(ncid=ncid, flag=flag, varname='gpp_pepv', xtype=ncd_double, & @@ -3818,7 +3891,11 @@ subroutine SetValues ( this, & this%woodc_loss_patch(i) = value_patch this%crop_seedc_to_leaf_patch(i) = value_patch + this%crop_seedc_to_froot_patch(i) = value_patch + this%crop_seedc_to_deadstem_patch(i) = value_patch this%grainc_to_cropprodc_patch(i) = value_patch + ! tboas: zero fertC_patch for all patches + if (use_cfert) this%fertC_patch(i) = value_patch end do if ( use_crop )then @@ -3835,6 +3912,10 @@ subroutine SetValues ( this, & this%cpool_grain_storage_gr_patch(i) = value_patch this%transfer_grain_gr_patch(i) = value_patch this%grainc_storage_to_xfer_patch(i) = value_patch + this%prunec_to_litter_patch(i) = value_patch + this%prunec_storage_to_litter_patch(i) = value_patch + ! tboas: zero fertC_patch in use_crop block + if (use_cfert) this%fertC_patch(i) = value_patch end do end if @@ -4273,9 +4354,12 @@ subroutine Summary_carbonflux(this, & if ( use_crop .and. patch%itype(p) >= npcropmin )then this%litfall_patch(p) = & this%litfall_patch(p) + & - this%livestemc_to_litter_patch(p) - - if (.not. use_grainproduct) then + this%livestemc_to_litter_patch(p) + & + this%prunec_to_litter_patch(p) + & + this%prunec_storage_to_litter_patch(p) + ! tboas: per patch, so a cover crop routes its grain C to litter + ! regardless of the domain-wide namelist setting + if (.not. use_grainproduct .or. is_covercrop(patch%itype(p))) then this%litfall_patch(p) = & this%litfall_patch(p) + & this%grainc_to_food_patch(p) diff --git a/src/clm5/biogeochem/CNVegCarbonStateType.F90 b/src/clm5/biogeochem/CNVegCarbonStateType.F90 index 1d568dc60d..e37cd70d74 100644 --- a/src/clm5/biogeochem/CNVegCarbonStateType.F90 +++ b/src/clm5/biogeochem/CNVegCarbonStateType.F90 @@ -48,6 +48,8 @@ module CNVegCarbonStateType real(r8), pointer :: deadstemc_patch (:) ! (gC/m2) dead stem C real(r8), pointer :: deadstemc_storage_patch (:) ! (gC/m2) dead stem C storage real(r8), pointer :: deadstemc_xfer_patch (:) ! (gC/m2) dead stem C transfer + real(r8), pointer :: deadstemc_soy_patch (:) ! (gC/m2) dead stem C at the start of year + real(r8), pointer :: deadstemc_storage_soy_patch (:) ! (gC/m2) dead stem C storage at the start of year real(r8), pointer :: livecrootc_patch (:) ! (gC/m2) live coarse root C real(r8), pointer :: livecrootc_storage_patch (:) ! (gC/m2) live coarse root C storage real(r8), pointer :: livecrootc_xfer_patch (:) ! (gC/m2) live coarse root C transfer @@ -234,6 +236,8 @@ subroutine InitAllocate(this, bounds) allocate(this%deadstemc_patch (begp:endp)) ; this%deadstemc_patch (:) = nan allocate(this%deadstemc_storage_patch (begp:endp)) ; this%deadstemc_storage_patch (:) = nan allocate(this%deadstemc_xfer_patch (begp:endp)) ; this%deadstemc_xfer_patch (:) = nan + allocate(this%deadstemc_soy_patch (begp:endp)) ; this%deadstemc_soy_patch (:) = nan + allocate(this%deadstemc_storage_soy_patch (begp:endp)) ; this%deadstemc_storage_soy_patch (:) = nan allocate(this%livecrootc_patch (begp:endp)) ; this%livecrootc_patch (:) = nan allocate(this%livecrootc_storage_patch (begp:endp)) ; this%livecrootc_storage_patch (:) = nan allocate(this%livecrootc_xfer_patch (begp:endp)) ; this%livecrootc_xfer_patch (:) = nan @@ -399,6 +403,15 @@ subroutine InitHistory(this, bounds, carbon_type) call hist_addfld1d (fname='DEADSTEMC_XFER', units='gC/m^2', & avgflag='A', long_name='dead stem C transfer', & ptr_patch=this%deadstemc_xfer_patch, default='inactive') + this%deadstemc_soy_patch(begp:endp) = spval + call hist_addfld1d (fname='DEADSTEMC_SOY', units='gC/m^2', & + avgflag='A', long_name='dead stem C at start of year', & + ptr_patch=this%deadstemc_soy_patch, default='inactive') + + this%deadstemc_storage_soy_patch(begp:endp) = spval + call hist_addfld1d (fname='DEADSTEMC_STORAGE_SOY', units='gC/m^2', & + avgflag='A', long_name='dead stem C storage at start of year', & + ptr_patch=this%deadstemc_storage_soy_patch, default='inactive') this%livecrootc_patch(begp:endp) = spval call hist_addfld1d (fname='LIVECROOTC', units='gC/m^2', & @@ -942,6 +955,14 @@ subroutine InitCold(this, bounds, ratio, carbon_type, c12_cnveg_carbonstate_inst this%leafc_storage_patch(p) = 0._r8 this%frootc_patch(p) = 0._r8 this%frootc_storage_patch(p) = 0._r8 +! if (pftcon%perennial(patch%itype(p)) == 1._r8 .and. pftcon%woody(patch%itype(p)) == 1._r8) then +! this%leafc_patch(p) = 0._r8 +! this%leafc_storage_patch(p) = cnvegcstate_const%initial_vegC * ratio +! this%frootc_patch(p) = 0._r8 +! this%frootc_storage_patch(p) = cnvegcstate_const%initial_vegC * ratio +! this%deadstemc_soy_patch(p) = 0._r8 +! this%deadstemc_storage_soy_patch(p) = 0._r8 +! end if else this%leafc_patch(p) = 0._r8 this%leafc_storage_patch(p) = cnvegcstate_const%initial_vegC * ratio @@ -964,7 +985,11 @@ subroutine InitCold(this, bounds, ratio, carbon_type, c12_cnveg_carbonstate_inst this%livestemc_xfer_patch(p) = 0._r8 if (pftcon%woody(patch%itype(p)) == 1._r8) then + if (patch%itype(p) < npcropmin)then ! (added by O.Dombrowski) this%deadstemc_patch(p) = 0.1_r8 * ratio + else + this%deadstemc_patch(p) = 0._r8 ! (added by O.Dombrowski) + end if else this%deadstemc_patch(p) = 0._r8 end if @@ -1188,6 +1213,13 @@ subroutine Restart ( this, bounds, ncid, flag, carbon_type, reseed_dead_plants, dim1name='pft', long_name='', units='', & interpinic_flag='interp', readvar=readvar, data=this%deadstemc_xfer_patch) + call restartvar(ncid=ncid, flag=flag, varname='deadstemc_soy', xtype=ncd_double, & + dim1name='pft', long_name='', units='', & + interpinic_flag='interp', readvar=readvar, data=this%deadstemc_soy_patch) + + call restartvar(ncid=ncid, flag=flag, varname='deadstemc_storage_soy', xtype=ncd_double, & + dim1name='pft', long_name='', units='', & + interpinic_flag='interp', readvar=readvar, data=this%deadstemc_storage_soy_patch) call restartvar(ncid=ncid, flag=flag, varname='livecrootc', xtype=ncd_double, & dim1name='pft', long_name='', units='', & interpinic_flag='interp', readvar=readvar, data=this%livecrootc_patch) @@ -1271,6 +1303,11 @@ subroutine Restart ( this, bounds, ncid, flag, carbon_type, reseed_dead_plants, do i = bounds%begp,bounds%endp this%deadstemc_patch(i) = this%deadstemc_patch(i) * 10._r8 this%deadcrootc_patch(i) = this%deadcrootc_patch(i) * 10._r8 + ! tboas-fix: the perennial reference pools are expressed on the + ! same scale as deadstemc and are compared against it in the + ! pruning/harvest calculation, so they must be rescaled too. + this%deadstemc_soy_patch(i) = this%deadstemc_soy_patch(i) * 10._r8 + this%deadstemc_storage_soy_patch(i) = this%deadstemc_storage_soy_patch(i) * 10._r8 end do else if (spinup_state == 2 .and. restart_file_spinup_state <= 1 )then if (spinup_state == 2 .and. restart_file_spinup_state <= 1 )then @@ -1280,6 +1317,9 @@ subroutine Restart ( this, bounds, ncid, flag, carbon_type, reseed_dead_plants, do i = bounds%begp,bounds%endp this%deadstemc_patch(i) = this%deadstemc_patch(i) / 10._r8 this%deadcrootc_patch(i) = this%deadcrootc_patch(i) / 10._r8 + ! tboas-fix: keep the perennial reference pools on the same scale + this%deadstemc_soy_patch(i) = this%deadstemc_soy_patch(i) / 10._r8 + this%deadstemc_storage_soy_patch(i) = this%deadstemc_storage_soy_patch(i) / 10._r8 end do end if end if @@ -1380,8 +1420,18 @@ subroutine Restart ( this, bounds, ncid, flag, carbon_type, reseed_dead_plants, this%leafcmax_patch(i) = 0._r8 + ! tboas-fix: l must be set from the CURRENT patch before it is + ! used. Previously the perennial test below read the landunit + ! index left over from the previous loop iteration (undefined + ! on the first), so the soy/fruit-tree reference pools were + ! reset on the wrong patches. l = patch%landunit(i) - if (lun%itype(l) == istsoil .or. patch%itype(i) == nc3crop .or. patch%itype(i) == nc3irrig)then + if (lun%itype(l) == istcrop .and. pftcon%perennial(patch%itype(i)) == 1._r8) then + this%deadstemc_soy_patch(i) = 0._r8 + this%deadstemc_storage_soy_patch(i) = 0._r8 + end if + if (lun%itype(l) == istsoil .or. patch%itype(i) == nc3crop .or. patch%itype(i) == nc3irrig) then!.or. & +! (lun%itype(l) == istcrop .and. pftcon%perennial(patch%itype(i)) == 1._r8)) then ! (added by O.Dombrowski) if ( present(num_reseed_patch) ) then num_reseed_patch = num_reseed_patch + 1 filter_reseed_patch(num_reseed_patch) = i @@ -1420,9 +1470,11 @@ subroutine Restart ( this, bounds, ncid, flag, carbon_type, reseed_dead_plants, this%livestemc_xfer_patch(i) = 0._r8 if (pftcon%woody(patch%itype(i)) == 1._r8) then + if (patch%itype(p) < npcropmin) then this%deadstemc_patch(i) = 0.1_r8 * ratio else this%deadstemc_patch(i) = 0._r8 + end if end if this%deadstemc_storage_patch(i) = 0._r8 this%deadstemc_xfer_patch(i) = 0._r8 @@ -2367,6 +2419,8 @@ subroutine SetValues ( this, & this%deadstemc_patch(i) = value_patch this%deadstemc_storage_patch(i) = value_patch this%deadstemc_xfer_patch(i) = value_patch + this%deadstemc_soy_patch(i) = value_patch + this%deadstemc_storage_soy_patch(i) = value_patch this%livecrootc_patch(i) = value_patch this%livecrootc_storage_patch(i) = value_patch this%livecrootc_xfer_patch(i) = value_patch diff --git a/src/clm5/biogeochem/CNVegComputeSeedMod.F90 b/src/clm5/biogeochem/CNVegComputeSeedMod.F90 index 01cf471e20..8ac2b175b2 100644 --- a/src/clm5/biogeochem/CNVegComputeSeedMod.F90 +++ b/src/clm5/biogeochem/CNVegComputeSeedMod.F90 @@ -9,7 +9,7 @@ module CNVegComputeSeedMod use shr_kind_mod , only : r8 => shr_kind_r8 use shr_log_mod , only : errMsg => shr_log_errMsg use decompMod , only : bounds_type - use pftconMod , only : pftcon, noveg + use pftconMod , only : pftcon, noveg, npcropmin use clm_varcon , only : c3_r2, c4_r2, c14ratio use clm_varctl , only : iulog use PatchType , only : patch @@ -133,7 +133,7 @@ subroutine ComputeSeedAmounts(bounds, & if (pft_type /= noveg) then my_leaf_seed = leafc_seed * & SpeciesTypeMultiplier(species, pft_type, COMPONENT_LEAF) - if (pftcon%woody(pft_type) == 1._r8) then + if (pftcon%woody(pft_type) == 1._r8 .and. patch%itype(p) < npcropmin) then my_deadstem_seed = deadstemc_seed * & SpeciesTypeMultiplier(species, pft_type, COMPONENT_DEADWOOD) end if diff --git a/src/clm5/biogeochem/CNVegNitrogenFluxType.F90 b/src/clm5/biogeochem/CNVegNitrogenFluxType.F90 index 47b620bf91..b7a424bf90 100644 --- a/src/clm5/biogeochem/CNVegNitrogenFluxType.F90 +++ b/src/clm5/biogeochem/CNVegNitrogenFluxType.F90 @@ -7,6 +7,7 @@ module CNVegNitrogenFluxType use clm_varpar , only : nlevdecomp_full, nlevdecomp use clm_varcon , only : spval, ispval, dzsoi_decomp use clm_varctl , only : use_nitrif_denitrif, use_vertsoilc, use_crop + use clm_varctl , only : use_cfert ! tboas-fix: organic manure N flux use CNSharedParamsMod , only : use_fun use decompMod , only : bounds_type use abortutils , only : endrun @@ -137,6 +138,9 @@ module CNVegNitrogenFluxType real(r8), pointer :: frootn_to_retransn_patch (:) ! patch fine root N to retranslocated N pool (gN/m2/s) real(r8), pointer :: frootn_to_litter_patch (:) ! patch fine root N litterfall (gN/m2/s) + ! pruning fluxes + real(r8), pointer :: prunen_to_litter_patch (:) ! patch pruning N to litter (gN/m2/s) + real(r8), pointer :: prunen_storage_to_litter_patch (:) ! patch pruning N to litter (gN/m2/s) ! allocation fluxes real(r8), pointer :: retransn_to_npool_patch (:) ! patch deployment of retranslocated N (gN/m2/s) real(r8), pointer :: free_retransn_to_npool_patch (:) ! patch deployment of free retranslocated N (gN/m2/s) @@ -165,6 +169,11 @@ module CNVegNitrogenFluxType real(r8), pointer :: livecrootn_storage_to_xfer_patch (:) ! patch live coarse root N shift storage to transfer (gN/m2/s) real(r8), pointer :: deadcrootn_storage_to_xfer_patch (:) ! patch dead coarse root N shift storage to transfer (gN/m2/s) real(r8), pointer :: fert_patch (:) ! patch applied fertilizer (gN/m2/s) + ! tboas-fix: organic N applied with farmyard manure. This is the counterpart of + ! cnveg_carbonflux_type%fertC_patch: it enters the litter pools together with the + ! manure C at manure_CN_ratio and is mineralised by the decomposition cascade, + ! rather than being injected into the mineral pool like fert_patch. + real(r8), pointer :: fertN_patch (:) ! (gN/m2/s) organic N applied with manure real(r8), pointer :: fert_counter_patch (:) ! patch >0 fertilize; <=0 not real(r8), pointer :: soyfixn_patch (:) ! patch soybean fixed N (gN/m2/s) @@ -206,6 +215,8 @@ module CNVegNitrogenFluxType ! crop fluxes real(r8), pointer :: crop_seedn_to_leaf_patch (:) ! patch (gN/m2/s) seed source to leaf, for crops + real(r8), pointer :: crop_seedn_to_froot_patch (:) ! patch (gN/m2/s) seed source to fine root, for perennial crops (added by O.Dombrowski) + real(r8), pointer :: crop_seedn_to_deadstem_patch (:) ! patch (gN/m2/s) seed source to deadstem, for perennial crops (added by O.Dombrowski) ! Misc real(r8), pointer :: plant_ndemand_patch (:) ! N flux required to support initial GPP (gN/m2/s) @@ -417,8 +428,13 @@ subroutine InitAllocate(this, bounds) allocate(this%grainn_xfer_to_grainn_patch (begp:endp)) ; this%grainn_xfer_to_grainn_patch (:) = nan allocate(this%grainn_storage_to_xfer_patch (begp:endp)) ; this%grainn_storage_to_xfer_patch (:) = nan allocate(this%fert_patch (begp:endp)) ; this%fert_patch (:) = nan + ! tboas-fix: always allocated (and zeroed) so the associate pointer in + ! CNPhenologyMod is valid even when use_cfert = .false. + allocate(this%fertN_patch (begp:endp)) ; this%fertN_patch (:) = 0.0_r8 allocate(this%fert_counter_patch (begp:endp)) ; this%fert_counter_patch (:) = nan allocate(this%soyfixn_patch (begp:endp)) ; this%soyfixn_patch (:) = nan + allocate(this%prunen_to_litter_patch (begp:endp)) ; this%prunen_to_litter_patch (:) = nan + allocate(this%prunen_storage_to_litter_patch (begp:endp)) ; this%prunen_storage_to_litter_patch (:) = nan allocate(this%grainn_to_cropprodn_patch (begp:endp)) ; this%grainn_to_cropprodn_patch (:) = nan allocate(this%grainn_to_cropprodn_col (begc:endc)) ; this%grainn_to_cropprodn_col (:) = nan @@ -447,6 +463,8 @@ subroutine InitAllocate(this, bounds) allocate(this%dwt_deadcrootn_to_cwdn_col (begc:endc,1:nlevdecomp_full)) ; this%dwt_deadcrootn_to_cwdn_col (:,:) = nan allocate(this%crop_seedn_to_leaf_patch (begp:endp)) ; this%crop_seedn_to_leaf_patch (:) = nan + allocate(this%crop_seedn_to_froot_patch (begp:endp)) ; this%crop_seedn_to_froot_patch (:) = nan + allocate(this%crop_seedn_to_deadstem_patch (begp:endp)) ; this%crop_seedn_to_deadstem_patch (:) = nan allocate(this%m_decomp_npools_to_fire_vr_col (begc:endc,1:nlevdecomp_full,1:ndecomp_pools)) allocate(this%m_decomp_npools_to_fire_col (begc:endc,1:ndecomp_pools )) @@ -950,6 +968,13 @@ subroutine InitHistory(this, bounds) ptr_patch=this%fert_patch) end if + ! tboas-fix: diagnostic for the organic N applied with manure + if (use_crop .and. use_cfert) then + this%fertN_patch(begp:endp) = 0.0_r8 + call hist_addfld1d (fname='Norg_FERT', units='gN/m^2/s', & + avgflag='A', long_name='Organic nitrogen applied with farmyard manure', & + ptr_patch=this%fertN_patch, default='inactive') + end if if (use_crop .and. .not. use_fun) then this%soyfixn_patch(begp:endp) = spval call hist_addfld1d (fname='SOYFIXN', units='gN/m^2/s', & @@ -1062,6 +1087,15 @@ subroutine InitHistory(this, bounds) call hist_addfld1d (fname='CROP_SEEDN_TO_LEAF', units='gN/m^2/s', & avgflag='A', long_name='crop seed source to leaf', & ptr_patch=this%crop_seedn_to_leaf_patch, default='inactive') + this%crop_seedn_to_froot_patch(begp:endp) = spval + call hist_addfld1d (fname='CROP_SEEDN_TO_FROOT', units='gN/m^2/s', & + avgflag='A', long_name='crop seed source to fine root', & + ptr_patch=this%crop_seedn_to_froot_patch, default='inactive') + + this%crop_seedn_to_deadstem_patch(begp:endp) = spval + call hist_addfld1d (fname='CROP_SEEDN_TO_DEADSTEM', units='gN/m^2/s', & + avgflag='A', long_name='crop seed source to deadstem', & + ptr_patch=this%crop_seedn_to_deadstem_patch, default='inactive') this%plant_ndemand_patch(begp:endp) = spval call hist_addfld1d (fname='PLANT_NDEMAND', units='gN/m^2/s', & @@ -1260,6 +1294,7 @@ subroutine InitCold(this, bounds) if ( use_crop )then this%fert_counter_patch(p) = spval this%fert_patch(p) = 0._r8 + this%fertN_patch(p) = 0._r8 ! tboas-fix this%soyfixn_patch(p) = 0._r8 end if @@ -1350,6 +1385,13 @@ subroutine Restart (this, bounds, ncid, flag ) interpinic_flag='interp', readvar=readvar, data=this%fert_patch) end if + ! tboas-fix: restart the organic manure N flux alongside fertC_patch + if (use_cfert) then + call restartvar(ncid=ncid, flag=flag, varname='fertN_patch', xtype=ncd_double, & + dim1name='pft', & + long_name='organic N flux applied with farmyard manure', units='gN/m2/s', & + interpinic_flag='interp', readvar=readvar, data=this%fertN_patch) + end if if (use_crop) then call restartvar(ncid=ncid, flag=flag, varname='grainn_xfer_to_grainn', xtype=ncd_double, & dim1name='pft', & @@ -1392,6 +1434,18 @@ subroutine Restart (this, bounds, ncid, flag ) interpinic_flag='interp', readvar=readvar, data=this%grainn_storage_to_xfer_patch) end if + if (use_crop) then + call restartvar(ncid=ncid, flag=flag, varname='prunen_to_litter', xtype=ncd_double, & + dim1name='pft', & + long_name='pruning N to litterfall', units='gN/m2/s', & + interpinic_flag='interp', readvar=readvar, data=this%prunen_to_litter_patch) + + call restartvar(ncid=ncid, flag=flag, varname='prunen_storage_to_litter', xtype=ncd_double, & + dim1name='pft', & + long_name='pruning storage N to litterfall', units='gN/m2/s', & + interpinic_flag='interp', readvar=readvar, data=this%prunen_storage_to_litter_patch) + end if + call restartvar(ncid=ncid, flag=flag, varname='plant_ndemand', xtype=ncd_double, & dim1name='pft', & long_name='', units='', & @@ -1682,6 +1736,9 @@ subroutine SetValues ( this, & this%fire_nloss_patch(i) = value_patch this%crop_seedn_to_leaf_patch(i) = value_patch + if (use_cfert) this%fertN_patch(i) = value_patch ! tboas-fix + this%crop_seedn_to_froot_patch(i) = value_patch + this%crop_seedn_to_deadstem_patch(i) = value_patch this%grainn_to_cropprodn_patch(i) = value_patch end do @@ -1697,6 +1754,8 @@ subroutine SetValues ( this, & this%grainn_storage_to_xfer_patch(i) = value_patch this%soyfixn_patch(i) = value_patch this%frootn_to_retransn_patch(i) = value_patch + this%prunen_to_litter_patch(i) = value_patch + this%prunen_storage_to_litter_patch(i) = value_patch end do end if diff --git a/src/clm5/biogeochem/CNVegNitrogenStateType.F90 b/src/clm5/biogeochem/CNVegNitrogenStateType.F90 index 97a5ffaae4..ce95df7cfc 100644 --- a/src/clm5/biogeochem/CNVegNitrogenStateType.F90 +++ b/src/clm5/biogeochem/CNVegNitrogenStateType.F90 @@ -51,6 +51,8 @@ module CNVegNitrogenStateType real(r8), pointer :: deadstemn_patch (:) ! (gN/m2) dead stem N real(r8), pointer :: deadstemn_storage_patch (:) ! (gN/m2) dead stem N storage real(r8), pointer :: deadstemn_xfer_patch (:) ! (gN/m2) dead stem N transfer + real(r8), pointer :: deadstemn_soy_patch (:) ! (gN/m2) dead stem N at the start of season + real(r8), pointer :: deadstemn_storage_soy_patch (:) ! (gN/m2) dead stem N at the start of season real(r8), pointer :: livecrootn_patch (:) ! (gN/m2) live coarse root N real(r8), pointer :: livecrootn_storage_patch (:) ! (gN/m2) live coarse root N storage real(r8), pointer :: livecrootn_xfer_patch (:) ! (gN/m2) live coarse root N transfer @@ -147,6 +149,8 @@ subroutine InitAllocate(this, bounds) allocate(this%deadstemn_patch (begp:endp)) ; this%deadstemn_patch (:) = nan allocate(this%deadstemn_storage_patch (begp:endp)) ; this%deadstemn_storage_patch (:) = nan allocate(this%deadstemn_xfer_patch (begp:endp)) ; this%deadstemn_xfer_patch (:) = nan + allocate(this%deadstemn_soy_patch (begp:endp)) ; this%deadstemn_soy_patch (:) = nan + allocate(this%deadstemn_storage_soy_patch (begp:endp)) ; this%deadstemn_storage_soy_patch (:) = nan allocate(this%livecrootn_patch (begp:endp)) ; this%livecrootn_patch (:) = nan allocate(this%livecrootn_storage_patch (begp:endp)) ; this%livecrootn_storage_patch (:) = nan allocate(this%livecrootn_xfer_patch (begp:endp)) ; this%livecrootn_xfer_patch (:) = nan @@ -282,6 +286,15 @@ subroutine InitHistory(this, bounds) call hist_addfld1d (fname='DEADSTEMN_XFER', units='gN/m^2', & avgflag='A', long_name='dead stem N transfer', & ptr_patch=this%deadstemn_xfer_patch, default='inactive') + this%deadstemn_soy_patch(begp:endp) = spval + call hist_addfld1d (fname='DEADSTEMN_SOY', units='gN/m^2', & + avgflag='A', long_name='dead stem N at start of year', & + ptr_patch=this%deadstemn_soy_patch, default='inactive') + + this%deadstemn_storage_soy_patch(begp:endp) = spval + call hist_addfld1d (fname='DEADSTEMN_STORAGE_SOY', units='gN/m^2', & + avgflag='A', long_name='dead stem N storage at start of year', & + ptr_patch=this%deadstemn_storage_soy_patch, default='inactive') this%livecrootn_patch(begp:endp) = spval call hist_addfld1d (fname='LIVECROOTN', units='gN/m^2', & @@ -471,13 +484,19 @@ subroutine InitCold(this, bounds, & ! roughness length is not zero in canopy flux calculation if (pftcon%woody(patch%itype(p)) == 1._r8) then + if (patch%itype(p) < npcropmin) then this%deadstemn_patch(p) = deadstemc_patch(p) / pftcon%deadwdcn(patch%itype(p)) + else + this%deadstemn_patch(p) = 0._r8 + end if else this%deadstemn_patch(p) = 0._r8 end if this%deadstemn_storage_patch(p) = 0._r8 this%deadstemn_xfer_patch(p) = 0._r8 + this%deadstemn_soy_patch(p) = 0._r8 + this%deadstemn_storage_soy_patch(p) = 0._r8 this%livecrootn_patch(p) = 0._r8 this%livecrootn_storage_patch(p) = 0._r8 this%livecrootn_xfer_patch(p) = 0._r8 @@ -630,6 +649,13 @@ subroutine Restart ( this, bounds, ncid, flag, leafc_patch, & dim1name='pft', long_name='', units='', & interpinic_flag='interp', readvar=readvar, data=this%deadstemn_xfer_patch) + call restartvar(ncid=ncid, flag=flag, varname='deadstemn_soy', xtype=ncd_double, & + dim1name='pft', long_name='', units='', & + interpinic_flag='interp', readvar=readvar, data=this%deadstemn_soy_patch) + + call restartvar(ncid=ncid, flag=flag, varname='deadstemn_storage_soy', xtype=ncd_double, & + dim1name='pft', long_name='', units='', & + interpinic_flag='interp', readvar=readvar, data=this%deadstemn_storage_soy_patch) call restartvar(ncid=ncid, flag=flag, varname='livecrootn', xtype=ncd_double, & dim1name='pft', long_name='', units='', & interpinic_flag='interp', readvar=readvar, data=this%livecrootn_patch) @@ -721,6 +747,9 @@ subroutine Restart ( this, bounds, ncid, flag, leafc_patch, & do i = bounds%begp,bounds%endp this%deadstemn_patch(i) = this%deadstemn_patch(i) * 10._r8 this%deadcrootn_patch(i) = this%deadcrootn_patch(i) * 10._r8 + ! tboas-fix: keep the perennial reference pool on the same scale as + ! deadstemn, as is done for deadstemc_soy in CNVegCarbonStateType + this%deadstemn_soy_patch(i) = this%deadstemn_soy_patch(i) * 10._r8 end do else if (spinup_state == 2 .and. restart_file_spinup_state <= 1 ) then if ( masterproc ) write(iulog,*) ' CNRest: taking Dead wood N pools into AD spinup mode' @@ -729,6 +758,8 @@ subroutine Restart ( this, bounds, ncid, flag, leafc_patch, & do i = bounds%begp,bounds%endp this%deadstemn_patch(i) = this%deadstemn_patch(i) / 10._r8 this%deadcrootn_patch(i) = this%deadcrootn_patch(i) / 10._r8 + ! tboas-fix: keep the perennial reference pool on the same scale + this%deadstemn_soy_patch(i) = this%deadstemn_soy_patch(i) / 10._r8 end do endif @@ -781,13 +812,19 @@ subroutine Restart ( this, bounds, ncid, flag, leafc_patch, & ! roughness length is not zero in canopy flux calculation if (pftcon%woody(patch%itype(p)) == 1._r8) then + if (patch%itype(p) < npcropmin) then this%deadstemn_patch(p) = deadstemc_patch(p) / pftcon%deadwdcn(patch%itype(p)) + else + this%deadstemn_patch(p) = 0._r8 + end if else this%deadstemn_patch(p) = 0._r8 end if this%deadstemn_storage_patch(p) = 0._r8 this%deadstemn_xfer_patch(p) = 0._r8 + this%deadstemn_soy_patch(p) = 0._r8 + this%deadstemn_storage_soy_patch(p) = 0._r8 this%livecrootn_patch(p) = 0._r8 this%livecrootn_storage_patch(p) = 0._r8 this%livecrootn_xfer_patch(p) = 0._r8 @@ -876,6 +913,8 @@ subroutine SetValues ( this, & this%deadstemn_patch(i) = value_patch this%deadstemn_storage_patch(i) = value_patch this%deadstemn_xfer_patch(i) = value_patch + this%deadstemn_soy_patch(i) = value_patch + this%deadstemn_storage_soy_patch(i) = value_patch this%livecrootn_patch(i) = value_patch this%livecrootn_storage_patch(i) = value_patch this%livecrootn_xfer_patch(i) = value_patch diff --git a/src/clm5/biogeochem/CNVegStateType.F90 b/src/clm5/biogeochem/CNVegStateType.F90 index afdfa190aa..6cb17694b4 100644 --- a/src/clm5/biogeochem/CNVegStateType.F90 +++ b/src/clm5/biogeochem/CNVegStateType.F90 @@ -35,9 +35,14 @@ module CNVegStateType real(r8) , pointer :: cumvd_patch (:) ! patch cumulative vernalization d?ependence? real(r8) , pointer :: gddmaturity_patch (:) ! patch growing degree days (gdd) needed to harvest (ddays) real(r8) , pointer :: huileaf_patch (:) ! patch heat unit index needed from planting to leaf emergence - real(r8) , pointer :: huigrain_patch (:) ! patch heat unit index needed to reach vegetative maturity + real(r8) , pointer :: huigrain_patch (:) ! patch heat unit index needed to reach vegetative maturity/to start fruit fill for perennial crops + real(r8) , pointer :: huilfmat_patch (:) ! patch heat unit index needed to reach canopy maturity (added by O.Dombrowski) + real(r8) , pointer :: huiripe_patch (:) ! patch heat unit index needed to reach fruit cell expansion (ripening) (added by O.Dombrowski) real(r8) , pointer :: aleafi_patch (:) ! patch saved leaf allocation coefficient from phase 2 real(r8) , pointer :: astemi_patch (:) ! patch saved stem allocation coefficient from phase 2 + real(r8) , pointer :: arooti2_patch (:) ! patch saved root allocation coefficient from phase 2 + real(r8) , pointer :: arooti3_patch (:) ! patch saved root allocation coefficient from phase 3 + real(r8) , pointer :: aleafi3_patch (:) ! patch saved leaf allocation coefficient from phase 3 real(r8) , pointer :: aleaf_patch (:) ! patch leaf allocation coefficient real(r8) , pointer :: astem_patch (:) ! patch stem allocation coefficient real(r8) , pointer :: htmx_patch (:) ! patch max hgt attained by a crop during yr (m) @@ -85,6 +90,7 @@ module CNVegStateType real(r8), pointer :: onset_gdd_patch (:) ! patch onset growing degree days real(r8), pointer :: onset_swi_patch (:) ! patch onset soil water index real(r8), pointer :: offset_flag_patch (:) ! patch offset flag + real(r8), pointer :: offset2_flag_patch (:) ! patch orchard rotation flag real(r8), pointer :: offset_counter_patch (:) ! patch offset days counter real(r8), pointer :: offset_fdd_patch (:) ! patch offset freezing degree days counter real(r8), pointer :: offset_swi_patch (:) ! patch offset soil water index @@ -95,6 +101,13 @@ module CNVegStateType real(r8), pointer :: c_allometry_patch (:) ! patch C allocation index (DIM) real(r8), pointer :: n_allometry_patch (:) ! patch N allocation index (DIM) + real(r8), pointer :: chill_day_patch (:) ! patch chill days requirements for fruit tree crops + real(r8), pointer :: anti_chill_day_patch (:) ! patch anti-chill days requirements for fruit tree crops + real(r8), pointer :: chill_flag_patch (:) ! patch chill requirements flag for fruit tree crops + + real(r8), pointer :: harvest_flag_patch (:) ! patch harvest flag (added by O.Dombrowski) + real(r8), pointer :: prune_flag_patch (:) ! patch pruning flag (added by O.Dombrowski) + real(r8), pointer :: storage_flag_patch (:) ! patch storage growth flag (added by O.Dombrowski) real(r8), pointer :: tempsum_potential_gpp_patch (:) ! patch temporary annual sum of potential GPP real(r8), pointer :: annsum_potential_gpp_patch (:) ! patch annual sum of potential GPP real(r8), pointer :: tempmax_retransn_patch (:) ! patch temporary annual max of retranslocated N pool (gN/m2) @@ -201,7 +214,12 @@ subroutine InitAllocate(this, bounds) allocate(this%gddmaturity_patch (begp:endp)) ; this%gddmaturity_patch (:) = spval allocate(this%huileaf_patch (begp:endp)) ; this%huileaf_patch (:) = nan allocate(this%huigrain_patch (begp:endp)) ; this%huigrain_patch (:) = 0.0_r8 + allocate(this%huilfmat_patch (begp:endp)) ; this%huilfmat_patch (:) = 0.0_r8 + allocate(this%huiripe_patch (begp:endp)) ; this%huiripe_patch (:) = 0.0_r8 allocate(this%aleafi_patch (begp:endp)) ; this%aleafi_patch (:) = nan + allocate(this%arooti2_patch (begp:endp)) ; this%arooti2_patch (:) = nan + allocate(this%arooti3_patch (begp:endp)) ; this%arooti3_patch (:) = nan + allocate(this%aleafi3_patch (begp:endp)) ; this%aleafi3_patch (:) = nan allocate(this%astemi_patch (begp:endp)) ; this%astemi_patch (:) = nan allocate(this%aleaf_patch (begp:endp)) ; this%aleaf_patch (:) = nan allocate(this%astem_patch (begp:endp)) ; this%astem_patch (:) = nan @@ -249,6 +267,7 @@ subroutine InitAllocate(this, bounds) allocate(this%onset_gdd_patch (begp:endp)) ; this%onset_gdd_patch (:) = nan allocate(this%onset_swi_patch (begp:endp)) ; this%onset_swi_patch (:) = nan allocate(this%offset_flag_patch (begp:endp)) ; this%offset_flag_patch (:) = nan + allocate(this%offset2_flag_patch (begp:endp)) ; this%offset2_flag_patch (:) = nan allocate(this%offset_counter_patch (begp:endp)) ; this%offset_counter_patch (:) = nan allocate(this%offset_fdd_patch (begp:endp)) ; this%offset_fdd_patch (:) = nan allocate(this%offset_swi_patch (begp:endp)) ; this%offset_swi_patch (:) = nan @@ -258,6 +277,14 @@ subroutine InitAllocate(this, bounds) allocate(this%bgtr_patch (begp:endp)) ; this%bgtr_patch (:) = nan allocate(this%c_allometry_patch (begp:endp)) ; this%c_allometry_patch (:) = nan allocate(this%n_allometry_patch (begp:endp)) ; this%n_allometry_patch (:) = nan + allocate(this%chill_day_patch (begp:endp)) ; this%chill_day_patch (:) = nan + allocate(this%anti_chill_day_patch (begp:endp)) ; this%anti_chill_day_patch (:) = nan + allocate(this%chill_flag_patch (begp:endp)) ; this%chill_flag_patch (:) = nan + + + allocate(this%harvest_flag_patch (begp:endp)) ; this%harvest_flag_patch (:) = nan + allocate(this%prune_flag_patch (begp:endp)) ; this%prune_flag_patch (:) = nan + allocate(this%storage_flag_patch (begp:endp)) ; this%storage_flag_patch (:) = nan allocate(this%tempsum_potential_gpp_patch (begp:endp)) ; this%tempsum_potential_gpp_patch (:) = nan allocate(this%annsum_potential_gpp_patch (begp:endp)) ; this%annsum_potential_gpp_patch (:) = nan allocate(this%tempmax_retransn_patch (begp:endp)) ; this%tempmax_retransn_patch (:) = nan @@ -321,17 +348,17 @@ subroutine InitHistory(this, bounds) ptr_col=this%nfire_col) this%farea_burned_col(begc:endc) = spval - call hist_addfld1d (fname='FAREA_BURNED', units='s-1', & + call hist_addfld1d (fname='FAREA_BURNED', units='proportion/sec', & avgflag='A', long_name='timestep fractional area burned', & ptr_col=this%farea_burned_col) this%baf_crop_col(begc:endc) = spval - call hist_addfld1d (fname='BAF_CROP', units='s-1', & + call hist_addfld1d (fname='BAF_CROP', units='proportion/sec', & avgflag='A', long_name='fractional area burned for crop', & ptr_col=this%baf_crop_col) this%baf_peatf_col(begc:endc) = spval - call hist_addfld1d (fname='BAF_PEATF', units='s-1', & + call hist_addfld1d (fname='BAF_PEATF', units='proportion/sec', & avgflag='A', long_name='fractional area burned in peatland', & ptr_col=this%baf_peatf_col) @@ -390,6 +417,10 @@ subroutine InitHistory(this, bounds) avgflag='A', long_name='offset flag', & ptr_patch=this%offset_flag_patch, default='inactive') + this%offset2_flag_patch(begp:endp) = spval + call hist_addfld1d (fname='OFFSET2_FLAG', units='none', & + avgflag='A', long_name='orchard rotation flag', & + ptr_patch=this%offset2_flag_patch, default='inactive') this%offset_counter_patch(begp:endp) = spval call hist_addfld1d (fname='OFFSET_COUNTER', units='days', & avgflag='A', long_name='offset days counter', & @@ -430,6 +461,30 @@ subroutine InitHistory(this, bounds) avgflag='A', long_name='N allocation index', & ptr_patch=this%n_allometry_patch, default='inactive') + this%chill_day_patch(begp:endp) = spval + call hist_addfld1d (fname='CHILL_DAY', units='days', & + avgflag='A', long_name='Chill days needed for bud break of fruit tree crops', & + ptr_patch=this%chill_day_patch, default='inactive') + + this%anti_chill_day_patch(begp:endp) = spval + call hist_addfld1d (fname='ANTI_CHILL_DAY', units='days', & + avgflag='A', long_name='Anti-chill days needed for bud break of fruit tree crops', & + ptr_patch=this%anti_chill_day_patch, default='inactive') + + this%chill_flag_patch(begp:endp) = spval + call hist_addfld1d (fname='CHILL_FLAG', units='none', & + avgflag='A', long_name='Chill requirements flag for bud break of fruit tree crops', & + ptr_patch=this%chill_flag_patch, default='inactive') + + this%harvest_flag_patch(begp:endp) = spval + call hist_addfld1d (fname='HARVEST_FLAG', units='none', & + avgflag='A', long_name='harvest flag (perennial crops)', & + ptr_patch=this%harvest_flag_patch, default='inactive') + + this%storage_flag_patch(begp:endp) = spval + call hist_addfld1d (fname='STORAGE_FLAG', units='none', & + avgflag='A', long_name='storage growth flag (perennial crops)', & + ptr_patch=this%storage_flag_patch, default='inactive') this%tempsum_potential_gpp_patch(begp:endp) = spval call hist_addfld1d (fname='TEMPSUM_POTENTIAL_GPP', units='gC/m^2/yr', & avgflag='A', long_name='temporary annual sum of potential GPP', & @@ -464,6 +519,25 @@ subroutine InitHistory(this, bounds) call hist_addfld1d (fname='PLANTCN', units='unitless', & avgflag='A', long_name='Plant C:N used by FUN', & ptr_patch=this%plantCN_patch, default='inactive') + this%aleaf_patch(begp:endp) = spval + call hist_addfld1d (fname='A_LEAF', units='unitless', & + avgflag='A', long_name='Leaf allocation coefficient', & + ptr_patch=this%aleaf_patch, default='inactive') + +! this%arepr_patch(begp:endp) = spval +! call hist_addfld1d (fname='A_REPR', units='unitless', & +! avgflag='A', long_name='Fruit allocation coefficient', & +! ptr_patch=this%arepr_patch, default='inactive') + + this%astem_patch(begp:endp) = spval + call hist_addfld1d (fname='A_STEM', units='unitless', & + avgflag='A', long_name='Stem allocation coefficient', & + ptr_patch=this%astem_patch, default='inactive') + +! this%aroot_patch(begp:endp) = spval +! call hist_addfld1d (fname='A_ROOT', units='unitless', & +! avgflag='A', long_name='Root allocation coefficient', & +! ptr_patch=this%aroot_patch, default='inactive') end subroutine InitHistory !----------------------------------------------------------------------- @@ -607,6 +681,7 @@ subroutine initCold(this, bounds) this%onset_gdd_patch(p) = spval this%onset_swi_patch(p) = spval this%offset_flag_patch(p) = spval + this%offset2_flag_patch(p) = spval this%offset_counter_patch(p) = spval this%offset_fdd_patch(p) = spval this%offset_swi_patch(p) = spval @@ -616,6 +691,12 @@ subroutine initCold(this, bounds) this%bgtr_patch(p) = spval this%c_allometry_patch(p) = spval this%n_allometry_patch(p) = spval + this%chill_day_patch(p) = spval + this%anti_chill_day_patch(p) = spval + this%chill_flag_patch(p) = spval + this%harvest_flag_patch(p) = spval + this%prune_flag_patch(p) = spval + this%storage_flag_patch(p) = spval this%tempsum_potential_gpp_patch(p) = spval this%annsum_potential_gpp_patch(p) = spval this%tempmax_retransn_patch(p) = spval @@ -636,12 +717,19 @@ subroutine initCold(this, bounds) this%onset_gdd_patch(p) = 0._r8 this%onset_swi_patch(p) = 0._r8 this%offset_flag_patch(p) = 0._r8 + this%offset2_flag_patch(p) = 0._r8 this%offset_counter_patch(p) = 0._r8 this%offset_fdd_patch(p) = 0._r8 this%offset_swi_patch(p) = 0._r8 this%lgsf_patch(p) = 0._r8 this%bglfr_patch(p) = 0._r8 this%bgtr_patch(p) = 0._r8 + this%chill_day_patch(p) = 0._r8 + this%anti_chill_day_patch(p) = 0._r8 + this%chill_flag_patch(p) = 0._r8 + this%harvest_flag_patch(p) = 0._r8 + this%prune_flag_patch(p) = 0._r8 + this%storage_flag_patch(p) = 0._r8 this%annavg_t2m_patch(p) = 280._r8 this%tempavg_t2m_patch(p) = 0._r8 this%grain_flag_patch(p) = 0._r8 @@ -745,6 +833,10 @@ subroutine Restart(this, bounds, ncid, flag, cnveg_carbonstate, & dim1name='pft', & long_name='offset flag', units='unitless' , & interpinic_flag='interp', readvar=readvar, data=this%offset_flag_patch) + call restartvar(ncid=ncid, flag=flag, varname='offset2_flag', xtype=ncd_double, & + dim1name='pft', & + long_name='orchard rotation flag', units='unitless' , & + interpinic_flag='interp', readvar=readvar, data=this%offset2_flag_patch) call restartvar(ncid=ncid, flag=flag, varname='offset_counter', xtype=ncd_double, & dim1name='pft', & @@ -875,6 +967,17 @@ subroutine Restart(this, bounds, ncid, flag, cnveg_carbonstate, & dim1name='pft', long_name='Saved leaf allocation coefficient from phase 2', units='', & interpinic_flag='interp', readvar=readvar, data=this%aleafi_patch) + call restartvar(ncid=ncid, flag=flag, varname='arooti2', xtype=ncd_double, & + dim1name='pft', long_name='Saved root allocation coefficient from phase 2', units='', & + interpinic_flag='interp', readvar=readvar, data=this%arooti2_patch) + + call restartvar(ncid=ncid, flag=flag, varname='arooti3', xtype=ncd_double, & + dim1name='pft', long_name='Saved root allocation coefficient from phase 3', units='', & + interpinic_flag='interp', readvar=readvar, data=this%arooti3_patch) + + call restartvar(ncid=ncid, flag=flag, varname='aleafi3', xtype=ncd_double, & + dim1name='pft', long_name='Saved leaf allocation coefficient from phase 3', units='', & + interpinic_flag='interp', readvar=readvar, data=this%aleafi3_patch) call restartvar(ncid=ncid, flag=flag, varname='astem', xtype=ncd_double, & dim1name='pft', long_name='stem allocation coefficient', units='', & interpinic_flag='interp', readvar=readvar, data=this%astem_patch) @@ -903,9 +1006,39 @@ subroutine Restart(this, bounds, ncid, flag, cnveg_carbonstate, & dim1name='pft', long_name='heat unit index needed to reach vegetative maturity', units='', & interpinic_flag='interp', readvar=readvar, data=this%huigrain_patch) + call restartvar(ncid=ncid, flag=flag, varname='huilfmat', xtype=ncd_double, & + dim1name='pft', long_name='heat unit index needed to reach canopy maturity', units='', & + interpinic_flag='interp', readvar=readvar, data=this%huilfmat_patch) + + call restartvar(ncid=ncid, flag=flag, varname='huiripe', xtype=ncd_double, & + dim1name='pft', long_name='heat unit index needed to reach fruit cell expansion', units='', & + interpinic_flag='interp', readvar=readvar, data=this%huiripe_patch) call restartvar(ncid=ncid, flag=flag, varname='grain_flag', xtype=ncd_double, & dim1name='pft', long_name='', units='', & interpinic_flag='interp', readvar=readvar, data=this%grain_flag_patch) + call restartvar(ncid=ncid, flag=flag, varname='chill_day', xtype=ncd_double, & + dim1name='pft', long_name='', units='days', & + interpinic_flag='interp', readvar=readvar, data=this%chill_day_patch) + + call restartvar(ncid=ncid, flag=flag, varname='anti_chill_day', xtype=ncd_double, & + dim1name='pft', long_name='', units='days', & + interpinic_flag='interp', readvar=readvar, data=this%anti_chill_day_patch) + + call restartvar(ncid=ncid, flag=flag, varname='chill_flag', xtype=ncd_double, & + dim1name='pft', long_name='', units='', & + interpinic_flag='interp', readvar=readvar, data=this%chill_flag_patch) + + call restartvar(ncid=ncid, flag=flag, varname='harvest_flag', xtype=ncd_double, & + dim1name='pft', long_name='harvest flag (perennial crops)', units='unitless', & + interpinic_flag='interp', readvar=readvar, data=this%harvest_flag_patch) + + call restartvar(ncid=ncid, flag=flag, varname='prune_flag', xtype=ncd_double, & + dim1name='pft', long_name='pruning flag for perenneial crops', units='unitless', & + interpinic_flag='interp', readvar=readvar, data=this%prune_flag_patch) + + call restartvar(ncid=ncid, flag=flag, varname='storage_flag', xtype=ncd_double, & + dim1name='pft', long_name='storage growth flag for perenneial crops', units='unitless', & + interpinic_flag='interp', readvar=readvar, data=this%storage_flag_patch) end if if ( flag == 'read' .and. num_reseed_patch > 0 )then if ( masterproc ) write(iulog, *) 'Reseed dead plants for CNVegState' @@ -921,6 +1054,7 @@ subroutine Restart(this, bounds, ncid, flag, cnveg_carbonstate, & this%onset_gdd_patch(p) = 0._r8 this%onset_swi_patch(p) = 0._r8 this%offset_flag_patch(p) = 0._r8 + this%offset2_flag_patch(p) = 0._r8 this%offset_counter_patch(p) = 0._r8 this%offset_fdd_patch(p) = 0._r8 this%offset_swi_patch(p) = 0._r8 @@ -931,6 +1065,12 @@ subroutine Restart(this, bounds, ncid, flag, cnveg_carbonstate, & this%tempavg_t2m_patch(p) = 0._r8 this%grain_flag_patch(p) = 0._r8 + this%harvest_flag_patch(p) = 0._r8 + this%prune_flag_patch(p) = 0._r8 + this%storage_flag_patch(p) = 0._r8 + this%chill_day_patch(p) = 0._r8 + this%anti_chill_day_patch(p) = 0._r8 + this%chill_flag_patch(p) = 0._r8 this%c_allometry_patch(p) = 0._r8 this%n_allometry_patch(p) = 0._r8 this%tempsum_potential_gpp_patch(p) = 0._r8 diff --git a/src/clm5/biogeochem/CNVegStructUpdateMod.F90 b/src/clm5/biogeochem/CNVegStructUpdateMod.F90 index 27b677b04d..ec01c7ff8c 100644 --- a/src/clm5/biogeochem/CNVegStructUpdateMod.F90 +++ b/src/clm5/biogeochem/CNVegStructUpdateMod.F90 @@ -63,7 +63,6 @@ subroutine CNVegStructUpdate(num_soilp, filter_soilp, & ! !LOCAL VARIABLES: integer :: p,c,g ! indices integer :: fp ! lake filter indices - real(r8) :: taper ! ratio of height:radius_breast_height (tree allometry) real(r8) :: stocking ! #stems / ha (stocking density) real(r8) :: ol ! thickness of canopy layer covered by snow (m) real(r8) :: fb ! fraction of canopy layer covered by snow @@ -90,6 +89,7 @@ subroutine CNVegStructUpdate(num_soilp, filter_soilp, & ivt => patch%itype , & ! Input: [integer (:) ] patch vegetation type woody => pftcon%woody , & ! Input: binary flag for woody lifeform (1=woody, 0=not woody) + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types slatop => pftcon%slatop , & ! Input: specific leaf area at top of canopy, projected area basis [m^2/gC] dsladlai => pftcon%dsladlai , & ! Input: dSLA/dLAI, projected area basis [m^2/gC] z0mr => pftcon%z0mr , & ! Input: ratio of momentum roughness length to canopy top height (-) @@ -97,6 +97,8 @@ subroutine CNVegStructUpdate(num_soilp, filter_soilp, & dwood => pftcon%dwood , & ! Input: density of wood (gC/m^3) ztopmx => pftcon%ztopmx , & ! Input: laimx => pftcon%laimx , & ! Input: + nstem => pftcon%nstem , & ! Input: Tree number density (#ind/m2) (introduced by E.Kluzek (2020, unreleased code) and adopted here by O.Dombrowski) + taper => pftcon%taper , & ! Input: ratio of height:radius_breast_height (tree allometry) (introduced by E.Kluzek (2020, unreleased code) and adopted here by O.Dombrowski) allom2 => dgv_ecophyscon%allom2 , & ! Input: [real(r8) (:) ] ecophys const allom3 => dgv_ecophyscon%allom3 , & ! Input: [real(r8) (:) ] ecophys const @@ -115,6 +117,7 @@ subroutine CNVegStructUpdate(num_soilp, filter_soilp, & htmx => cnveg_state_inst%htmx_patch , & ! Output: [real(r8) (:) ] max hgt attained by a crop during yr (m) peaklai => cnveg_state_inst%peaklai_patch , & ! Output: [integer (:) ] 1: max allowed lai; 0: not at max + dormant_flag => cnveg_state_inst%dormant_flag_patch , & ! Output: [real(r8) (:) ] dormancy flag harvdate => crop_inst%harvdate_patch , & ! Input: [integer (:) ] harvest date ! *** Key Output from CN*** @@ -129,12 +132,6 @@ subroutine CNVegStructUpdate(num_soilp, filter_soilp, & dt = real( get_rad_step_size(), r8 ) - ! constant allometric parameters - taper = 200._r8 - stocking = 1000._r8 - - ! convert from stems/ha -> stems/m^2 - stocking = stocking / 10000._r8 ! patch loop do fp = 1,num_soilp @@ -177,25 +174,23 @@ subroutine CNVegStructUpdate(num_soilp, filter_soilp, & if (woody(ivt(p)) == 1._r8) then - ! trees and shrubs - - ! if shrubs have a squat taper - if (ivt(p) >= nbrdlf_evr_shrub .and. ivt(p) <= nbrdlf_dcd_brl_shrub) then - taper = 10._r8 - ! otherwise have a tall taper - else - taper = 200._r8 + if (perennial(ivt(p)) == 1._r8) then + if (dormant_flag(p) == 0._r8) then + if (tlai(p) >= laimx(ivt(p))) peaklai(p) = 1 + else if (dormant_flag(p) == 1._r8) then + peaklai(p) = 0 + end if end if - ! trees and shrubs for now have a very simple allometry, with hard-wired - ! stem taper (height:radius) and hard-wired stocking density (#individuals/area) + ! trees and shrubs for now have a very simple allometry, with + ! stem taper (height:radius) and nstem from PFT parameter file if (use_cndv) then if (fpcgrid(p) > 0._r8 .and. nind(p) > 0._r8) then stocking = nind(p)/fpcgrid(p) !#ind/m2 nat veg area -> #ind/m2 patch area htop(p) = allom2(ivt(p)) * ( (24._r8 * deadstemc(p) / & - (SHR_CONST_PI * stocking * dwood(ivt(p)) * taper))**(1._r8/3._r8) )**allom3(ivt(p)) ! lpj's htop w/ cn's stemdiam + (SHR_CONST_PI * stocking * dwood(ivt(p)) * taper(ivt(p))))**(1._r8/3._r8) )**allom3(ivt(p)) ! lpj's htop w/ cn's stemdiam else htop(p) = 0._r8 @@ -204,11 +199,19 @@ subroutine CNVegStructUpdate(num_soilp, filter_soilp, & else !correct height calculation if doing accelerated spinup if (spinup_state == 2) then - htop(p) = ((3._r8 * deadstemc(p) * 10._r8 * taper * taper)/ & - (SHR_CONST_PI * stocking * dwood(ivt(p))))**(1._r8/3._r8) + if (perennial(ivt(p)) == 1._r8 .and. dormant_flag(p) == 1._r8 .and. deadstemc(p)== 0._r8) then + htop(p) = 0.01_r8 + else + htop(p) = ((3._r8 * deadstemc(p) * 10._r8 * taper(ivt(p)) * taper(ivt(p)))/ & + (SHR_CONST_PI * nstem(ivt(p)) * dwood(ivt(p))))**(1._r8/3._r8) + end if else - htop(p) = ((3._r8 * deadstemc(p) * taper * taper)/ & - (SHR_CONST_PI * stocking * dwood(ivt(p))))**(1._r8/3._r8) + if (perennial(ivt(p)) == 1._r8 .and. dormant_flag(p) == 1._r8 .and. deadstemc(p)== 0._r8) then + htop(p) = 0.01_r8 + else + htop(p) = ((3._r8 * deadstemc(p) * taper(ivt(p)) * taper(ivt(p)))/ & + (SHR_CONST_PI * nstem(ivt(p)) * dwood(ivt(p))))**(1._r8/3._r8) + end if end if endif @@ -223,6 +226,10 @@ subroutine CNVegStructUpdate(num_soilp, filter_soilp, & ! This becomes an issue when fire mortality is pushing deadstemc ! to 0.0. htop(p) = max(htop(p), 0.01_r8) + ! for fruit trees restrict height to maximum pruned tree height + if (perennial(ivt(p)) == 1._r8) then + htop(p) = min(htop(p), ztopmx(ivt(p))) + end if hbot(p) = max(0._r8, min(3._r8, htop(p)-1._r8)) diff --git a/src/clm5/biogeochem/CropType.F90 b/src/clm5/biogeochem/CropType.F90 index 0b2c0fc1db..71112abf74 100644 --- a/src/clm5/biogeochem/CropType.F90 +++ b/src/clm5/biogeochem/CropType.F90 @@ -38,6 +38,18 @@ module CropType real(r8), pointer :: vf_patch (:) ! patch vernalization factor for cereal real(r8), pointer :: cphase_patch (:) ! phenology phase real(r8), pointer :: latbaset_patch (:) ! Latitude vary baset for gddplant (degree C) + integer , pointer :: yrop_patch (:) ! year of planting + real(r8), pointer :: lt50_patch (:) ! lethal temperature at which 50% of the individuals are damaged + real(r8), pointer :: wdd_patch (:) ! winter wheat weighted cumulated degree days + real(r8), pointer :: rateh_patch (:) ! increase of tolerance caused by hardening + real(r8), pointer :: rated_patch (:) ! loss of tolerance caused by dehardening + real(r8), pointer :: rates_patch (:) ! loss of tolerance caused by low temperature + real(r8), pointer :: rater_patch (:) ! loss of tolerance caused by respiration under snow + real(r8), pointer :: fsurv_patch (:) ! winter wheat survival rate + real(r8), pointer :: accfsurv_patch (:) ! accumulated winter wheat survival rate + real(r8), pointer :: countfsurv_patch (:) ! numbers of accumulated winter wheat survival rate + real(r8), pointer :: ck_patch (:) ! fraction of green leaf area killed + real(r8), pointer :: tcrown_patch (:) ! crown temperature character(len=20) :: baset_mapping real(r8) :: baset_latvary_intercept real(r8) :: baset_latvary_slope @@ -199,6 +211,18 @@ subroutine InitAllocate(this, bounds) allocate(this%vf_patch (begp:endp)) ; this%vf_patch (:) = 0.0_r8 allocate(this%cphase_patch (begp:endp)) ; this%cphase_patch (:) = 0.0_r8 allocate(this%latbaset_patch (begp:endp)) ; this%latbaset_patch (:) = spval + allocate(this%yrop_patch (begp:endp)) ; this%yrop_patch (:) = huge(1) + allocate(this%lt50_patch (begp:endp)) ; this%lt50_patch (:) = spval + allocate(this%wdd_patch (begp:endp)) ; this%wdd_patch (:) = spval + allocate(this%rateh_patch (begp:endp)) ; this%rateh_patch (:) = spval + allocate(this%rated_patch (begp:endp)) ; this%rated_patch (:) = spval + allocate(this%rates_patch (begp:endp)) ; this%rates_patch (:) = spval + allocate(this%rater_patch (begp:endp)) ; this%rater_patch (:) = spval + allocate(this%fsurv_patch (begp:endp)) ; this%fsurv_patch (:) = spval + allocate(this%accfsurv_patch (begp:endp)) ; this%accfsurv_patch (:) = spval + allocate(this%countfsurv_patch (begp:endp)) ; this%countfsurv_patch (:) = spval + allocate(this%ck_patch (begp:endp)) ; this%ck_patch (:) = spval + allocate(this%tcrown_patch (begp:endp)) ; this%tcrown_patch (:) = spval end subroutine InitAllocate @@ -401,6 +425,7 @@ subroutine Restart(this, bounds, ncid, flag) use ncdio_pio use PatchType, only : patch use pftconMod, only : npcropmin, npcropmax + use clm_time_manager, only : get_curr_date ! tboas-fix: yrop backwards compatibility ! ! !ARGUMENTS: class(crop_type), intent(inout) :: this @@ -413,6 +438,8 @@ subroutine Restart(this, bounds, ncid, flag) integer :: restyear integer :: p logical :: readvar ! determine if variable is on initial file + logical :: readvar_hard ! tboas-fix: cold-hardening block present on restart file + integer :: kyr, kmo, kda, mcsec ! tboas-fix: current date for yrop fallback character(len=*), parameter :: subname = 'Restart' !----------------------------------------------------------------------- @@ -505,6 +532,97 @@ subroutine Restart(this, bounds, ncid, flag) dim1name='pft', long_name='crop phenology phase', & units='0-not planted, 1-planted, 2-leaf emerge, 3-grain fill, 4-harvest', & interpinic_flag='interp', readvar=readvar, data=this%cphase_patch) + !-------------------------------------------------------------------- + ! tboas-fix: the winter-cereal cold-hardening state (Lu 2017 scheme, + ! evolved every timestep in CNPhenologyMod::coldtolerance) and the + ! perennial planting year are prognostic and MUST survive a restart. + ! Before this fix they were allocated with spval / huge(1) defaults and + ! never written, so every restart fed spval into + ! rateh = Hparam*(10-tcrown)*(lt50-lt50max) + ! fsurv = 2**(-(|tcrown|/|lt50|)**4) + ! and huge(1) into idpp = dayspyr*(kyr-yrop) + jday - idop, + ! silently corrupting litterfall and perennial crop age. + !-------------------------------------------------------------------- + call restartvar(ncid=ncid, flag=flag, varname='yrop', xtype=ncd_int, & + dim1name='pft', long_name='year of planting', units='yr', & + interpinic_flag='interp', readvar=readvar, data=this%yrop_patch) + if (flag == 'read' .and. .not. readvar) then + ! BACKWARDS_COMPATIBILITY: pre-fix restart files carry no yrop. + ! huge(1) would overflow (kyr - yrop), so fall back to the current + ! year, i.e. treat every perennial as newly planted. + call get_curr_date(kyr, kmo, kda, mcsec) + do p = bounds%begp, bounds%endp + if (this%yrop_patch(p) == huge(1)) this%yrop_patch(p) = kyr + end do + if (masterproc) write(iulog,*) subname// & + ': yrop absent from restart file - reset to current year ', kyr + end if + + call restartvar(ncid=ncid, flag=flag, varname='lt50', xtype=ncd_double, & + dim1name='pft', long_name='lethal temperature at which 50% of individuals are damaged', & + units='degC', interpinic_flag='interp', readvar=readvar_hard, data=this%lt50_patch) + + call restartvar(ncid=ncid, flag=flag, varname='wdd', xtype=ncd_double, & + dim1name='pft', long_name='winter cereal weighted cumulative degree days', & + units='ddays', interpinic_flag='interp', readvar=readvar, data=this%wdd_patch) + + call restartvar(ncid=ncid, flag=flag, varname='rateh', xtype=ncd_double, & + dim1name='pft', long_name='gain of frost tolerance by hardening', & + units='degC/hr', interpinic_flag='interp', readvar=readvar, data=this%rateh_patch) + + call restartvar(ncid=ncid, flag=flag, varname='rated', xtype=ncd_double, & + dim1name='pft', long_name='loss of frost tolerance by dehardening', & + units='degC/hr', interpinic_flag='interp', readvar=readvar, data=this%rated_patch) + + call restartvar(ncid=ncid, flag=flag, varname='rates', xtype=ncd_double, & + dim1name='pft', long_name='loss of frost tolerance by low temperature', & + units='degC/hr', interpinic_flag='interp', readvar=readvar, data=this%rates_patch) + + call restartvar(ncid=ncid, flag=flag, varname='rater', xtype=ncd_double, & + dim1name='pft', long_name='loss of frost tolerance by respiration under snow', & + units='degC/hr', interpinic_flag='interp', readvar=readvar, data=this%rater_patch) + + call restartvar(ncid=ncid, flag=flag, varname='fsurv', xtype=ncd_double, & + dim1name='pft', long_name='winter cereal survival rate', units='', & + interpinic_flag='interp', readvar=readvar, data=this%fsurv_patch) + + call restartvar(ncid=ncid, flag=flag, varname='accfsurv', xtype=ncd_double, & + dim1name='pft', long_name='accumulated winter cereal survival rate', units='', & + interpinic_flag='interp', readvar=readvar, data=this%accfsurv_patch) + + call restartvar(ncid=ncid, flag=flag, varname='countfsurv', xtype=ncd_double, & + dim1name='pft', long_name='count of accumulated survival rate samples', units='', & + interpinic_flag='interp', readvar=readvar, data=this%countfsurv_patch) + + call restartvar(ncid=ncid, flag=flag, varname='ck', xtype=ncd_double, & + dim1name='pft', long_name='fraction of green leaf area killed by frost', units='', & + interpinic_flag='interp', readvar=readvar, data=this%ck_patch) + + call restartvar(ncid=ncid, flag=flag, varname='tcrown', xtype=ncd_double, & + dim1name='pft', long_name='crown temperature', units='degC', & + interpinic_flag='interp', readvar=readvar, data=this%tcrown_patch) + + if (flag == 'read' .and. .not. readvar_hard) then + ! BACKWARDS_COMPATIBILITY: pre-fix restart files carry none of the + ! cold-hardening state. Seed it with the same values CropPhenology + ! assigns at planting (CNPhenologyMod ~2374 and ~2430) rather than + ! leaving spval, which is not a valid operand for the rate equations. + do p = bounds%begp, bounds%endp + this%lt50_patch(p) = -5._r8 + this%wdd_patch(p) = 0._r8 + this%rateh_patch(p) = 0._r8 + this%rated_patch(p) = 0._r8 + this%rates_patch(p) = 0._r8 + this%rater_patch(p) = 0._r8 + this%fsurv_patch(p) = 1._r8 + this%accfsurv_patch(p) = 1._r8 + this%countfsurv_patch(p) = 1._r8 + this%ck_patch(p) = 0._r8 + this%tcrown_patch(p) = 0._r8 + end do + if (masterproc) write(iulog,*) subname// & + ': cold-hardening state absent from restart file - reset to planting defaults' + end if if (flag=='read' )then call this%checkDates( ) ! Check that restart date is same calendar date (even if year is different) ! This is so that it properly goes through diff --git a/src/clm5/biogeochem/NutrientCompetitionCLM45defaultMod.F90 b/src/clm5/biogeochem/NutrientCompetitionCLM45defaultMod.F90 index 5d29efbeb5..d427d22ade 100644 --- a/src/clm5/biogeochem/NutrientCompetitionCLM45defaultMod.F90 +++ b/src/clm5/biogeochem/NutrientCompetitionCLM45defaultMod.F90 @@ -498,7 +498,7 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & ! !USES: use pftconMod , only : npcropmin, pftcon use pftconMod , only : ntmp_soybean, nirrig_tmp_soybean - use pftconMod , only : ntrp_soybean, nirrig_trp_soybean + !use pftconMod , only : ntrp_soybean, nirrig_trp_soybean use clm_varcon , only : secspday use clm_varctl , only : use_c13, use_c14 use clm_time_manager , only : get_step_size @@ -855,8 +855,8 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & !they all seemed to be going through the retranslocation loop for soybean - good news. if (astem(p) == astemf(ivt(p)) .or. & - (ivt(p) /= ntmp_soybean .and. ivt(p) /= nirrig_tmp_soybean .and.& - ivt(p) /= ntrp_soybean .and. ivt(p) /= nirrig_trp_soybean)) then + (ivt(p) /= ntmp_soybean .and. ivt(p) /= nirrig_tmp_soybean)) then ! .and.& + !ivt(p) /= ntrp_soybean .and. ivt(p) /= nirrig_trp_soybean)) then if (grain_flag(p) == 0._r8)then if(.not.use_fun) then t1 = 1 / dt diff --git a/src/clm5/biogeochem/NutrientCompetitionFlexibleCNMod.F90 b/src/clm5/biogeochem/NutrientCompetitionFlexibleCNMod.F90 index f404ac9611..8d91b86289 100644 --- a/src/clm5/biogeochem/NutrientCompetitionFlexibleCNMod.F90 +++ b/src/clm5/biogeochem/NutrientCompetitionFlexibleCNMod.F90 @@ -25,7 +25,6 @@ module NutrientCompetitionFlexibleCNMod use PatchType , only : patch use NutrientCompetitionMethodMod, only : nutrient_competition_method_type use NutrientCompetitionMethodMod, only : params_inst - use clm_varctl , only : iulog ! implicit none private @@ -196,7 +195,7 @@ subroutine calc_plant_cn_alloc(this, bounds, num_soilp, filter_soilp, & use clm_varctl , only : downreg_opt use clm_varctl , only : CN_residual_opt use clm_varctl , only : CN_partition_opt - use clm_time_manager , only : get_step_size + use clm_time_manager , only : get_step_size, get_curr_calday use CNVegStateType , only : cnveg_state_type use CropType , only : crop_type use CanopyStateType , only : canopystate_type @@ -240,7 +239,7 @@ subroutine calc_plant_cn_alloc(this, bounds, num_soilp, filter_soilp, & real(r8) :: f5 ! grain allocation parameter real(r8) :: cng ! C:N ratio for grain (= cnlw for now; slevis) real(r8) :: dt ! model time step - real(r8):: fsmn(bounds%begp:bounds%endp) ! A emperate variable for adjusting FUN uptakes + real(r8):: fsmn(bounds%begp:bounds%endp) ! A temperate variable for adjusting FUN uptakes real(r8):: frootcn_storage_actual real(r8):: frootcn_actual @@ -323,9 +322,12 @@ subroutine calc_plant_cn_alloc(this, bounds, num_soilp, filter_soilp, & grperc => pftcon%grperc , & ! Input: growth respiration parameter grpnow => pftcon%grpnow , & ! Input: growth respiration parameter evergreen => pftcon%evergreen , & ! Input: binary flag for evergreen leaf habit (0 or 1) + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop phenology (0 or 1) (added by O.Dombrowski) croplive => crop_inst%croplive_patch , & ! Input: [logical (:) ] flag, true if planted, not harvested + hui => crop_inst%gddplant_patch , & ! Input: [real(r8) (:) ] =gdd since planting (gddplant) + gddmaturity => cnveg_state_inst%gddmaturity_patch , & ! Input: [real(r8) (:) ] gdd until harvest peaklai => cnveg_state_inst%peaklai_patch , & ! Input: [integer (:) ] 1: max allowed lai; 0: not at max aleaf => cnveg_state_inst%aleaf_patch , & ! Output: [real(r8) (:) ] leaf allocation coefficient astem => cnveg_state_inst%astem_patch , & ! Output: [real(r8) (:) ] stem allocation coefficient @@ -333,6 +335,8 @@ subroutine calc_plant_cn_alloc(this, bounds, num_soilp, filter_soilp, & n_allometry => cnveg_state_inst%n_allometry_patch , & ! Output: [real(r8) (:) ] N allocation index (DIM) downreg => cnveg_state_inst%downreg_patch , & ! Output: [real(r8) (:) ] fractional reduction in GPP due to N limitation (DIM) + harvest_flag => cnveg_state_inst%harvest_flag_patch , & ! Output: [real(r8) (:) ] harvest flag for perennial crops + storage_flag => cnveg_state_inst%storage_flag_patch , & ! Output: [real(r8) (:) ] flag to switch to storage growth for perennials annsum_npp => cnveg_carbonflux_inst%annsum_npp_patch , & ! Input: [real(r8) (:) ] annual sum of NPP, for wood allocation gpp => cnveg_carbonflux_inst%gpp_before_downreg_patch , & ! Output: [real(r8) (:) ] GPP flux before downregulation (gC/m2/s) availc => cnveg_carbonflux_inst%availc_patch , & ! Output: [real(r8) (:) ] C flux available for allocation (gC/m2/s) @@ -546,6 +550,35 @@ subroutine calc_plant_cn_alloc(this, bounds, num_soilp, filter_soilp, & cpool_to_grainc_storage(p) = nlc * f5 * (1._r8 -fcur) end if + ! allocation for deciduous fruit trees (added by O.Dombrowski) + ! for this crop type, storage growth is considered next to photosynthetic growth + ! after harvest photosynthates are allocated to storage pool for refilling of C reserves + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1._r8) then + if (storage_flag(p) == 0._r8) then + fcur = fcur + else if (storage_flag(p) == 1._r8) then + fcur = 0._r8 + end if + cpool_to_leafc(p) = nlc * fcur + cpool_to_leafc_storage(p) = nlc * (1._r8 - fcur) + cpool_to_frootc(p) = nlc * f1 * fcur + cpool_to_frootc_storage(p) = nlc * f1 * (1._r8 - fcur) + cpool_to_livestemc(p) = nlc * f3 * f4 * fcur + cpool_to_livestemc_storage(p) = nlc * f3 * f4 * (1._r8 - fcur) + cpool_to_deadstemc(p) = nlc * f3 * (1._r8 - f4) * fcur + cpool_to_deadstemc_storage(p) = nlc * f3 * (1._r8 - f4) * (1._r8 - fcur) + cpool_to_livecrootc(p) = nlc * f2 * f3 * f4 * fcur + cpool_to_livecrootc_storage(p) = nlc * f2 * f3 * f4 * (1._r8 - fcur) + cpool_to_deadcrootc(p) = nlc * f2 * f3 * (1._r8 - f4) * fcur + cpool_to_deadcrootc_storage(p) = nlc * f2 * f3 * (1._r8 - f4) * (1._r8 - fcur) + if (harvest_flag(p) == 0._r8) then + cpool_to_grainc(p) = nlc * f5 + cpool_to_grainc_storage(p) = nlc * f5 * 0._r8 + else if (harvest_flag(p) == 1._r8) then + cpool_to_grainc(p) = nlc * f5 * 0._r8 + cpool_to_grainc_storage(p) = nlc * f5 * 0._r8 + end if + end if if (downreg_opt) then ! corresponding N fluxes npool_to_leafn(p) = (nlc / cnl) * fcur @@ -575,6 +608,21 @@ subroutine calc_plant_cn_alloc(this, bounds, num_soilp, filter_soilp, & npool_to_grainn(p) = (nlc * f5 / cng) * fcur npool_to_grainn_storage(p) = (nlc * f5 / cng) * (1._r8 -fcur) end if + ! calculating corresponding N fluxes for deciduous fruit trees + ! (added by O.Dombrowski) + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1._r8) then + cng = graincn(ivt(p)) + npool_to_livestemn(p) = (nlc * f3 * f4 / cnlw) * fcur + npool_to_livestemn_storage(p) = (nlc * f3 * f4 / cnlw) * (1._r8 - fcur) + npool_to_deadstemn(p) = (nlc * f3 * (1._r8 - f4) / cndw) * fcur + npool_to_deadstemn_storage(p) = (nlc * f3 * (1._r8 - f4) / cndw) * (1._r8 - fcur) + npool_to_livecrootn(p) = (nlc * f2 * f3 * f4 / cnlw) * fcur + npool_to_livecrootn_storage(p) = (nlc * f2 * f3 * f4 / cnlw) * (1._r8 - fcur) + npool_to_deadcrootn(p) = (nlc * f2 * f3 * (1._r8 - f4) / cndw) * fcur + npool_to_deadcrootn_storage(p) = (nlc * f2 * f3 * (1._r8 - f4) / cndw) * (1._r8 - fcur) + npool_to_grainn(p) = (nlc * f5 / cng) + npool_to_grainn_storage(p) = (nlc * f5 / cng) * (0._r8) + end if end if if (downreg_opt .eqv. .false. .AND. CN_partition_opt == 0) then @@ -735,6 +783,81 @@ subroutine calc_plant_cn_alloc(this, bounds, num_soilp, filter_soilp, & end if end if + ! calculation of N fluxes for perennial woody croptypes added by + ! O.Dombrowski + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1._r8) then + cng = graincn(ivt(p)) + npool_to_livestemn_demand(p) = (nlc * f3 * f4 / cnlw) * fcur + npool_to_livestemn_supply(p) = npool(p)/dt * fcur - npool_to_frootn(p) + npool_to_livestemn(p) = max(min(npool_to_livestemn_supply(p),npool_to_livestemn_demand(p)),0.0_r8) + + npool_to_livestemn_storage_demand(p) = (nlc * f3 * f4 / cnlw) * (1._r8 - fcur) + npool_to_livestemn_storage_supply(p) = npool(p)/dt * (1._r8 - fcur) - npool_to_frootn_storage(p) + npool_to_livestemn_storage(p) = max(min(npool_to_livestemn_storage_supply(p), & + npool_to_livestemn_storage_demand(p)),0.0_r8) + + npool_to_livecrootn_demand(p) = (nlc * f2 * f3 * f4 / cnlw) * fcur + npool_to_livecrootn_supply(p) = npool(p)/dt * fcur - npool_to_frootn(p) - npool_to_livestemn(p) + npool_to_livecrootn(p) = max(min(npool_to_livecrootn_supply(p),npool_to_livecrootn_demand(p)),0.0_r8) + + npool_to_livecrootn_storage_demand(p) = (nlc * f2 * f3 * f4 / cnlw) * (1._r8 - fcur) + npool_to_livecrootn_storage_supply(p) = npool(p)/dt * (1._r8 - fcur) - npool_to_frootn_storage(p) - & + npool_to_livestemn_storage(p) + npool_to_livecrootn_storage(p) = max(min(npool_to_livecrootn_storage_supply(p), & + npool_to_livecrootn_storage_demand(p)),0.0_r8) + + npool_to_deadstemn_demand(p) = (nlc * f3 * (1._r8 - f4) / cndw) * fcur + npool_to_deadstemn_supply(p) = npool(p)/dt * fcur - npool_to_frootn(p) - npool_to_livestemn(p) - & + npool_to_livecrootn(p) + npool_to_deadstemn(p) = max(min(npool_to_deadstemn_supply(p),npool_to_deadstemn_demand(p)), 0.0_r8) + + npool_to_deadstemn_storage_demand(p) = (nlc * f3 * (1._r8 - f4) / cndw) * (1._r8 - fcur) + npool_to_deadstemn_storage_supply(p) = npool(p)/dt * (1._r8 - fcur) - npool_to_frootn_storage(p) - & + npool_to_livestemn_storage(p) - npool_to_livecrootn_storage(p) + npool_to_deadstemn_storage(p) = max(min(npool_to_deadstemn_storage_supply(p), & + npool_to_deadstemn_storage_demand(p)),0.0_r8) + + npool_to_deadcrootn_demand(p) = (nlc * f2 * f3 * (1._r8 - f4) / cndw) * fcur + npool_to_deadcrootn_supply(p) = npool(p)/dt * fcur - npool_to_frootn(p) - npool_to_livestemn(p) - & + npool_to_livecrootn(p) - npool_to_deadstemn(p) + npool_to_deadcrootn(p) = max(min(npool_to_deadcrootn_supply(p), npool_to_deadcrootn_demand(p)), 0.0_r8) + + npool_to_deadcrootn_storage_demand(p) = (nlc * f2 * f3 * (1._r8 - f4) / cndw) * (1._r8 - fcur) + npool_to_deadcrootn_storage_supply(p) = npool(p)/dt * (1._r8 - fcur) - npool_to_frootn_storage(p) - & + npool_to_livestemn_storage(p) - npool_to_livecrootn_storage(p) - npool_to_deadstemn_storage(p) + npool_to_deadcrootn_storage(p) = max(min(npool_to_deadcrootn_storage_supply(p), & + npool_to_deadcrootn_storage_demand(p)),0.0_r8) + + npool_to_grainn_demand(p) = (nlc * f5 / cng) + npool_to_grainn_supply(p) = npool(p)/dt - npool_to_frootn(p) - npool_to_livestemn(p) - & + npool_to_livecrootn(p) - npool_to_deadstemn(p) - npool_to_deadcrootn(p) + npool_to_grainn(p) = max(min(npool_to_grainn_supply(p), npool_to_grainn_demand(p)), 0.0_r8) + + npool_to_grainn_storage_demand(p) = (nlc * f5 / cng) * 0._r8 + npool_to_grainn_storage_supply(p) = npool(p)/dt * 0._r8 - npool_to_frootn_storage(p) - & + npool_to_livestemn_storage(p) - npool_to_livecrootn_storage(p) - npool_to_deadstemn_storage(p) - & + npool_to_deadcrootn_storage(p) + npool_to_grainn_storage(p) = max(min(npool_to_grainn_storage_supply(p), npool_to_grainn_storage_demand(p)), & + 0.0_r8) + + npool_to_leafn_demand(p) = (nlc / cnl) * fcur + npool_to_leafn_supply(p) = npool(p)/dt * fcur - npool_to_frootn(p) - npool_to_livestemn(p) - & + npool_to_livecrootn(p) - npool_to_deadstemn(p) - npool_to_deadcrootn(p) - npool_to_grainn(p) + npool_to_leafn(p) = max(min(npool_to_leafn_supply(p), npool_to_leafn_demand(p)), 0.0_r8) + + npool_to_leafn_storage_demand(p) = (nlc / cnl) * (1._r8 - fcur) + npool_to_leafn_storage_supply(p) = npool(p)/dt * (1._r8 - fcur) - npool_to_frootn_storage(p) - & + npool_to_livestemn_storage(p) - npool_to_livecrootn_storage(p) & + - npool_to_deadstemn_storage(p) - npool_to_deadcrootn_storage(p) - npool_to_grainn_storage(p) + npool_to_leafn_storage(p) = max(min(npool_to_leafn_storage_supply(p), npool_to_leafn_storage_demand(p)), & + 0.0_r8) + + if (CN_residual_opt == 1) then + npool_to_leafn(p) = max(npool_to_leafn_supply(p),0.0_r8) + npool_to_leafn_storage(p) = max(npool_to_leafn_storage_supply(p),0.0_r8) + end if + + end if end if @@ -760,6 +883,15 @@ subroutine calc_plant_cn_alloc(this, bounds, num_soilp, filter_soilp, & gresp_storage = gresp_storage + cpool_to_livestemc_storage(p) gresp_storage = gresp_storage + cpool_to_grainc_storage(p) end if + !recalculate total gresp_storage of vegetation parts for fruit trees (added by O.Dombrowski) + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1._r8) then + gresp_storage = cpool_to_leafc_storage(p) + cpool_to_frootc_storage(p) & + + cpool_to_livestemc_storage(p) & + + cpool_to_deadstemc_storage(p) & + + cpool_to_livecrootc_storage(p) & + + cpool_to_deadcrootc_storage(p) & + + cpool_to_grainc_storage(p) + end if cpool_to_gresp_storage(p) = gresp_storage * g1 * (1._r8 - g2) @@ -797,7 +929,22 @@ subroutine calc_plant_cn_alloc(this, bounds, num_soilp, filter_soilp, & npool_to_grainn_demand(p) = (nlc * f5 / cng) * fcur npool_to_grainn_storage_demand(p) = (nlc * f5 / cng) * (1._r8 -fcur) end if + ! computing nitrogen demand for fruit trees + ! (added by O.Dombrowski) + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1._r8) then + cng = graincn(ivt(p)) + npool_to_livestemn_demand(p) = (nlc * f3 * f4 / cnlw) * fcur + npool_to_livestemn_storage_demand(p) = (nlc * f3 * f4 / cnlw) * (1._r8 - fcur) + npool_to_deadstemn_demand(p) = (nlc * f3 * (1._r8 - f4) / cndw) * fcur + npool_to_deadstemn_storage_demand(p) = (nlc * f3 * (1._r8 - f4) / cndw) * (1._r8 - fcur) + npool_to_livecrootn_demand(p) = (nlc * f2 * f3 * f4 / cnlw) * fcur + npool_to_livecrootn_storage_demand(p) = (nlc * f2 * f3 * f4 / cnlw) * (1._r8 - fcur) + npool_to_deadcrootn_demand(p) = (nlc * f2 * f3 * (1._r8 - f4) / cndw) * fcur + npool_to_deadcrootn_storage_demand(p) = (nlc * f2 * f3 * (1._r8 - f4) / cndw) * (1._r8 - fcur) + npool_to_grainn_demand(p) = (nlc * f5 / cng) + npool_to_grainn_storage_demand(p) = (nlc * f5 / cng) * 0._r8 + end if ! computing 1.) fractional N demand for different plant parts !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -1188,12 +1335,12 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & ! !USES: use pftconMod , only : npcropmin, pftcon use pftconMod , only : ntmp_soybean, nirrig_tmp_soybean - use pftconMod , only : ntrp_soybean, nirrig_trp_soybean + !use pftconMod , only : ntrp_soybean, nirrig_trp_soybean use clm_varcon , only : secspday, dzsoi_decomp use clm_varctl , only : use_c13, use_c14 use clm_varctl , only : nscalar_opt, plant_ndemand_opt, substrate_term_opt, temp_scalar_opt use clm_varpar , only : nlevdecomp - use clm_time_manager , only : get_step_size + use clm_time_manager , only : get_step_size,get_curr_calday use CanopyStateType , only : canopystate_type use PhotosynthesisMod , only : photosyns_type use CropType , only : crop_type @@ -1266,6 +1413,7 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & ivt => patch%itype , & ! Input: [integer (:) ] patch vegetation type woody => pftcon%woody , & ! Input: binary flag for woody lifeform (1=woody, 0=not woody) + perennial => pftcon%perennial , & ! Input: binary flag for perennial crop types (1=perennial, 0=not perennial) froot_leaf => pftcon%froot_leaf , & ! Input: allocation parameter: new fine root C per new leaf C (gC/gC) croot_stem => pftcon%croot_stem , & ! Input: allocation parameter: new coarse root C per new stem C (gC/gC) stem_leaf => pftcon%stem_leaf , & ! Input: allocation parameter: new stem c per new leaf C (gC/gC) @@ -1281,9 +1429,11 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & bfact => pftcon%bfact , & ! Input: parameter used below aleaff => pftcon%aleaff , & ! Input: parameter used below arootf => pftcon%arootf , & ! Input: parameter used below + arootf2 => pftcon%arootf2 , & ! Input: parameter used below astemf => pftcon%astemf , & ! Input: parameter used below arooti => pftcon%arooti , & ! Input: parameter used below fleafi => pftcon%fleafi , & ! Input: parameter used below + aleafstor => pftcon%aleafstor , & ! Input: parameter used below allconsl => pftcon%allconsl , & ! Input: parameter used below allconss => pftcon%allconss , & ! Input: parameter used below grperc => pftcon%grperc , & ! Input: parameter used below @@ -1307,10 +1457,15 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & gddmaturity => cnveg_state_inst%gddmaturity_patch , & ! Input: [real(r8) (:) ] gdd needed to harvest huileaf => cnveg_state_inst%huileaf_patch , & ! Input: [real(r8) (:) ] heat unit index needed from planting to leaf emergence - huigrain => cnveg_state_inst%huigrain_patch , & ! Input: [real(r8) (:) ] same to reach vegetative maturity + huigrain => cnveg_state_inst%huigrain_patch , & ! Input: [real(r8) (:) ] same to reach vegetative maturity/fruit fill + huilfmat => cnveg_state_inst%huilfmat_patch , & ! Input: [real(r8) (:) ] same to reach canopy maturity + huiripe => cnveg_state_inst%huiripe_patch , & ! Input: [real(r8) (:) ] same to reach fruit cell expansion peaklai => cnveg_state_inst%peaklai_patch , & ! Input: [integer (:) ] 1: max allowed lai; 0: not at max aleafi => cnveg_state_inst%aleafi_patch , & ! Output: [real(r8) (:) ] saved allocation coefficient from phase 2 astemi => cnveg_state_inst%astemi_patch , & ! Output: [real(r8) (:) ] saved allocation coefficient from phase 2 + arooti2 => cnveg_state_inst%arooti2_patch , & ! Output: [real(r8) (:) ] saved allocation coefficient from phase 2 + arooti3 => cnveg_state_inst%arooti3_patch , & ! Output: [real(r8) (:) ] saved allocation coefficient from phase 3 + aleafi3 => cnveg_state_inst%aleafi3_patch , & ! Output: [real(r8) (:) ] saved allocation coefficient from phase 3 aleaf => cnveg_state_inst%aleaf_patch , & ! Output: [real(r8) (:) ] leaf allocation coefficient astem => cnveg_state_inst%astem_patch , & ! Output: [real(r8) (:) ] stem allocation coefficient grain_flag => cnveg_state_inst%grain_flag_patch , & ! Output: [real(r8) (:) ] 1: grain fill stage; 0: not @@ -1321,6 +1476,8 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & annsum_potential_gpp => cnveg_state_inst%annsum_potential_gpp_patch , & ! Output: [real(r8) (:) ] annual sum of potential GPP annmax_retransn => cnveg_state_inst%annmax_retransn_patch , & ! Output: [real(r8) (:) ] annual max of retranslocated N pool + dormant_flag => cnveg_state_inst%dormant_flag_patch , & ! Output: [real(r8) (:) ] dormancy flag + harvest_flag => cnveg_state_inst%harvest_flag_patch , & ! Input: [real(r8) (:) ] harvest flag xsmrpool => cnveg_carbonstate_inst%xsmrpool_patch , & ! Input: [real(r8) (:) ] (gC/m2) temporary photosynthate C pool leafc => cnveg_carbonstate_inst%leafc_patch , & ! Input: [real(r8) (:) ] frootc => cnveg_carbonstate_inst%frootc_patch , & ! Input: [real(r8) (:) ] @@ -1413,9 +1570,14 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & mr = leaf_mr(p) + froot_mr(p) if (woody(ivt(p)) == 1.0_r8) then mr = mr + livestem_mr(p) + livecroot_mr(p) + !include all mr terms for woody crop types + if (perennial(ivt(p)) == 1._r8) then + mr = mr + grain_mr(p) + end if else if (ivt(p) >= npcropmin) then if (croplive(p)) mr = mr + livestem_mr(p) + grain_mr(p) end if ! carbon flux available for allocation + ! carbon flux available for allocation availc(p) = gpp(p) - mr ! new code added for isotope calculations, 7/1/05, PET @@ -1490,12 +1652,125 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & if (ivt(p) >= npcropmin) then ! skip 2 generic crops if (croplive(p)) then + if (perennial(ivt(p)) == 1._r8 .and. woody(ivt(p)) == 1._r8) then + ! same phases appear in subroutine CropPhenology + if (dormant_flag(p) == 0.0_r8) then + ! Phase 1 completed: + if (leafout(p) >= huileaf(p) .and. hui(p) < huigrain(p)) then + ! allocation rules for crops based on maturity and linear decrease + ! of amount allocated to roots over course of the growing season + + if (peaklai(p) == 1) then ! lai at maximum allowed + arepr(p) = 0._r8 + aleaf(p) = 1.e-5_r8 + astem(p) = astem(p) + aroot(p) = 1._r8 - arepr(p) - aleaf(p) - astem(p) + else + arepr(p) = 0._r8 + aroot(p) = max(0._r8, min(1._r8, arooti(ivt(p)) - & + (arooti(ivt(p)) - arootf(ivt(p))) * & + min(1._r8,(hui(p)-huileaf(p))/(huigrain(p)-huileaf(p))))) + fleaf = fleafi(ivt(p)) * (exp(-bfact(ivt(p))) - & + exp(-bfact(ivt(p))*(hui(p)-huileaf(p))/(huilfmat(p)-huileaf(p)))) / & + (exp(-bfact(ivt(p)))-1) ! fraction alloc to leaf (from J Norman alloc curve) + aleaf(p) = max(0.05_r8, (1._r8 - aroot(p)) * fleaf) + astem(p) = 1._r8 - arepr(p) - aleaf(p) - aroot(p) + end if + + ! AgroIBIS included here an immediate adjustment to aleaf & astem if the + ! predicted lai from the above allocation coefficients exceeded laimx. + ! We have decided to live with lais slightly higher than laimx by + ! enforcing the cap in the following tstep through the peaklai logic above. + astemi(p) = astem(p) ! save for use by equations after shift + aleafi(p) = aleaf(p) ! to reproductive phenology stage begins + arooti2(p) = aroot(p) + grain_flag(p) = 0._r8 ! setting to 0 while in phase 2 + + ! Phase 2 completed: + + else if (hui(p) >= huigrain(p) .and. hui(p) < huiripe(p)) then + + aroot(p) = max(0._r8, min(1._r8, arooti2(p) - & + (arooti2(p) - arootf2(ivt(p))) * min(1._r8, (hui(p)-huileaf(p))/(huiripe(p)-huileaf(p))))) + if (astemi(p) > astemf(ivt(p))) then + astem(p) = max(0._r8, max(astemf(ivt(p)), astem(p) * & + (1._r8 - min(((hui(p)-huileaf(p))- & + (huigrain(p)-huileaf(p)))/(((gddmaturity(p)-huileaf(p))*declfact(ivt(p)))- & + (huigrain(p)-huileaf(p))),1._r8)**allconss(ivt(p)) ))) + end if + ! If crops have hit peaklai, then set leaf allocation to small value + if (peaklai(p) == 1) then + aleaf(p) = 1.e-5_r8 + else if (aleafi(p) > aleaff(ivt(p))) then + fleaf = aleafi(p) * (exp(-bfact(ivt(p))) - & + exp(-bfact(ivt(p))*(hui(p)-huileaf(p))/(huilfmat(p)-huileaf(p)))) / & + (exp(-bfact(ivt(p)))-1) ! fraction alloc to leaf (from J Norman alloc curve) + aleaf(p) = max(1.e-5_r8, (1._r8 - aroot(p)) * fleaf) + end if + + arepr(p) = 1._r8 - aroot(p) - astem(p) - aleaf(p) + arooti3(p) = aroot(p) + aleafi3(p) = aleaf(p) + + else if (hui(p) >= huiripe(p) .and. hui(p) < huilfmat(p)) then + aroot(p) = max(0._r8, min(1._r8, arooti3(p) - & + (arooti3(p) - arootf2(ivt(p))) * min(1._r8, (hui(p)-huileaf(p))/(huilfmat(p)-huileaf(p))))) + if (astemi(p) > astemf(ivt(p))) then + astem(p) = max(0._r8, max(astemf(ivt(p)), astem(p) * & + (1._r8 - min(((hui(p)-huileaf(p))- & + (huiripe(p)-huileaf(p)))/(((gddmaturity(p)-huileaf(p))*declfact(ivt(p)))- & + (huiripe(p)-huileaf(p))),1._r8)**allconss(ivt(p))))) + end if + + ! If crops have hit peaklai, then set leaf allocation to + ! small value + if (peaklai(p) == 1) then + aleaf(p) = 1.e-5_r8 + else if (aleafi3(p) > aleaff(ivt(p))) then + fleaf = fleafi(ivt(p)) * (exp(-bfact(ivt(p))) - & + exp(-bfact(ivt(p))*(hui(p)-huileaf(p))/(huilfmat(p)-huileaf(p)))) / & + (exp(-bfact(ivt(p)))-1) ! fraction alloc to leaf (from J Norman alloc curve) + aleaf(p) = max(1.e-5_r8, (1._r8 - aroot(p)) * fleaf) + end if + + arepr(p) = 1._r8 - aroot(p) - astem(p) - aleaf(p) + + else if (hui(p) >= huilfmat(p) .and. hui(p)< gddmaturity(p)) then + aroot(p) = arootf2(ivt(p)) + if (astemi(p) > astemf(ivt(p))) then + astem(p) = max(0._r8, max(astemf(ivt(p)), astem(p) * & + (1._r8 - min(((hui(p)-huileaf(p))- & + (huilfmat(p)-huileaf(p)))/(((gddmaturity(p)-huileaf(p))*declfact(ivt(p)))- & + (huilfmat(p)-huileaf(p))),1._r8)**allconss(ivt(p))))) + end if + + ! Leaf allocation is set to small value + aleaf(p) = 1.e-5_r8 + + arepr(p) = 1._r8 - aroot(p) - astem(p) - aleaf(p) + + else if (hui(p) >= gddmaturity(p) .or. harvest_flag(p) == 1._r8) then + arepr(p) = 0._r8 + aleaf(p) = aleafstor(ivt(p)) + astem(p) = (1 - arepr(p) - aleaf(p))/2._r8 + aroot(p) = 1 - arepr(p) - aleaf(p) - astem(p) + end if + else ! when tree is dormant + aleaf(p) = 1.e-5_r8 ! allocation coefficients should be irrelevant + astem(p) = 0._r8 ! because trees have no live carbon pools + aroot(p) = 0._r8 + arepr(p) = 0._r8 + grain_flag(p) = 0._r8 !set to 0 before the next grainfill starts + end if + else ! normal crops ! same phases appear in subroutine CropPhenology ! Phase 1 completed: ! ================== - ! if hui is less than the number of gdd needed for filling of grain - ! leaf emergence also has to have taken place for lai changes to occur + ! if hui is less than the number of gdd needed for filling of + ! grain + ! leaf emergence also has to have taken place for lai changes to + ! occur ! and carbon assimilation ! Next phase: leaf emergence to start of leaf decline @@ -1532,7 +1807,8 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & ! Phase 2 completed: ! ================== - ! shift allocation either when enough gdd are accumulated or maximum number + ! shift allocation either when enough gdd are accumulated or + ! maximum number ! of days has elapsed since planting else if (hui(p) >= huigrain(p)) then @@ -1545,7 +1821,8 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & huigrain(p)),1._r8)**allconss(ivt(p)) ))) end if - ! If crops have hit peaklai, then set leaf allocation to small value + ! If crops have hit peaklai, then set leaf allocation to small + ! value if (peaklai(p) == 1) then aleaf(p) = 1.e-5_r8 else if (aleafi(p) > aleaff(ivt(p))) then @@ -1555,27 +1832,10 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & huigrain(p)),1._r8)**allconsl(ivt(p)) ))) end if - !Beth's retranslocation of leafn, stemn, rootn to organ - !Filter excess plant N to retransn pool for organ N - !Only do one time then hold grain_flag till onset next season - - ! slevis: Will astem ever = astemf exactly? - ! Beth's response: ...looks like astem can equal astemf under the right circumstances. - !It might be worth a rewrite to capture what I was trying to do, but the retranslocation for - !corn and wheat begins at the beginning of the grain fill stage, but for soybean I was holding it - !until after the leaf and stem decline were complete. Looking at how astem is calculated, once the - !stem decline is near complete, astem should (usually) be set to astemf. The reason for holding off - !on soybean is that the retranslocation scheme begins at the beginning of the grain phase, when the - !leaf and stem are still growing, but declining. Since carbon is still getting allocated and now - !there is more nitrogen available, the nitrogen can be diverted from grain. For corn and wheat - !the impact was probably enough to boost productivity, but for soybean the nitrogen was better off - !fulfilling the grain fill. It seems that if the peak lai is reached for soybean though that this - !would be bypassed altogether, not the intended outcome. I checked several of my output files and - !they all seemed to be going through the retranslocation loop for soybean - good news. if (astem(p) == astemf(ivt(p)) .or. & - (ivt(p) /= ntmp_soybean .and. ivt(p) /= nirrig_tmp_soybean .and.& - ivt(p) /= ntrp_soybean .and. ivt(p) /= nirrig_trp_soybean)) then + (ivt(p) /= ntmp_soybean .and. ivt(p) /= nirrig_tmp_soybean) ) then !.and.& + !ivt(p) /= ntrp_soybean .and. ivt(p) /= nirrig_trp_soybean)) then if (grain_flag(p) == 0._r8) then t1 = 1 / dt leafn_to_retransn(p) = t1 * max(leafn(p)- (leafc(p) / fleafcn(ivt(p))),0._r8) @@ -1596,12 +1856,19 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & aroot(p) = 0._r8 ! this applies to this "else" and to the "else" arepr(p) = 0._r8 ! a few lines down end if + end if ! perennial or normal crop f1 = aroot(p) / aleaf(p) f3 = astem(p) / aleaf(p) f5 = arepr(p) / aleaf(p) g1 = 0.25_r8 + if (perennial(ivt(p)) == 1._r8 .and. dormant_flag(p) == 1._r8) then !dormant tree has no allocation to any organs (similar to .not. croplive) + f1 = 0._r8 + f3 = 0._r8 + f5 = 0._r8 + g1 = 0.25_r8 + end if else ! .not croplive f1 = 0._r8 @@ -1615,10 +1882,17 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & ! determine N requirements if(use_fun)then ! In FUN, growth respiration is not part of the allometry calculation. if (woody(ivt(p)) == 1.0_r8) then + if (perennial(ivt(p)) == 1.0_r8) then !(added by O.Dombrowski) + cng = graincn(ivt(p)) + c_allometry(p) = (1._r8)*(1._r8+f1+f5+f3*(1._r8+f2)) + n_allometry(p) = 1._r8/cnl + f1/cnfr + f5/cng + (f3*f4*(1._r8+f2))/cnlw + & + (f3*(1._r8-f4)*(1._r8+f2))/cndw + else c_allometry(p) = (1._r8)*(1._r8+f1+f3*(1._r8+f2)) n_allometry(p) = 1._r8/cnl + f1/cnfr + (f3*f4*(1._r8+f2))/cnlw + & (f3*(1._r8-f4)*(1._r8+f2))/cndw - else if (ivt(p) >= npcropmin) then ! skip generic crops + end if + else if (ivt(p) >= npcropmin .and. perennial(ivt(p)) == 0.0_r8) then ! skip generic crops cng = graincn(ivt(p)) c_allometry(p) = (1._r8)*(1._r8+f1+f5+f3*(1._r8+f2)) n_allometry(p) = 1._r8/cnl + f1/cnfr + f5/cng + (f3*f4*(1._r8+f2))/cnlw + & @@ -1738,9 +2012,9 @@ subroutine calc_plant_nitrogen_demand(this, bounds, num_soilp, filter_soilp, & ! retransn pool has N from leaves, stems, and roots for ! retranslocation - if (ivt(p) >= npcropmin .and. grain_flag(p) == 1._r8) then + if (ivt(p) >= npcropmin .and. grain_flag(p) == 1._r8 .and. perennial(ivt(p)) == 0._r8) then avail_retransn(p) = plant_ndemand(p) - else if (ivt(p) < npcropmin .and. annsum_potential_gpp(p) > 0._r8) then + else if ((ivt(p) < npcropmin .and. annsum_potential_gpp(p) > 0._r8) .or. (perennial(ivt(p)) == 1._r8 .and. annsum_potential_gpp(p) > 0._r8)) then avail_retransn(p) = (annmax_retransn(p)/2._r8)*(gpp(p)/annsum_potential_gpp(p))/dt else avail_retransn(p) = 0.0_r8 diff --git a/src/clm5/biogeochem/dynHarvestMod.F90 b/src/clm5/biogeochem/dynHarvestMod.F90 index a9344fd5cf..065fd2dfa9 100644 --- a/src/clm5/biogeochem/dynHarvestMod.F90 +++ b/src/clm5/biogeochem/dynHarvestMod.F90 @@ -19,10 +19,16 @@ module dynHarvestMod use CNVegNitrogenStateType , only : cnveg_nitrogenstate_type use CNVegNitrogenFluxType , only : cnveg_nitrogenflux_type use SoilBiogeochemStateType , only : soilbiogeochem_state_type - use pftconMod , only : pftcon + use pftconMod , only : pftcon, ncovercrop_1, ncovercrop_2, npcropmin, nwwheat, nirrig_wwheat, nwbarley, nirrig_wbarley use clm_varcon , only : grlnd + use clm_varctl , only : use_covercropping, use_grainproduct, iulog + use clm_varctl , only : debug_covercrop ! tboas-fix + use clm_time_manager , only : get_curr_date, get_step_size ! tboas + use dynCovercropFileMod , only : covercrop_switch_ivt ! tboas use ColumnType , only : col use PatchType , only : patch + use CropType , only : crop_type + use CNVegStateType , only : cnveg_state_type ! ! !PUBLIC MEMBER FUNCTIONS: implicit none @@ -30,10 +36,12 @@ module dynHarvestMod ! public :: dynHarvest_init ! initialize data structures for harvest information public :: dynHarvest_interp ! get harvest data for current time step, if needed + public :: covercropping_update + public :: covercropping_update_patch public :: CNHarvest ! harvest mortality routine for CN code ! ! !PRIVATE MEMBER FUNCTIONS: - private :: CNHarvestPftToColumn ! gather patch-level harvest fluxes to the column level + public :: CNHarvestPftToColumn ! gather patch-level harvest fluxes to the column level ! ! !PRIVATE TYPES: @@ -173,6 +181,253 @@ subroutine dynHarvest_interp(bounds) end subroutine dynHarvest_interp + !----------------------------------------------------------------------- + subroutine covercropping_update(bounds, crop_inst, cnveg_state_inst, cnveg_carbonstate_inst) + ! + ! !DESCRIPTION: + ! Apply the cover-crop rotation after the transient land-use / harvest update when + ! the optional cover-cropping switch is enabled. + ! + ! !ARGUMENTS: + type(bounds_type), intent(in) :: bounds + type(crop_type) , intent(inout) :: crop_inst + type(cnveg_state_type), intent(inout) :: cnveg_state_inst + type(cnveg_carbonstate_type), intent(inout) :: cnveg_carbonstate_inst + ! + ! !LOCAL VARIABLES: + integer :: p, curr_yr, curr_mon, curr_day, curr_sec + !------------------------------------------------------------------------ + + if (.not. use_covercropping) return + call get_curr_date(curr_yr, curr_mon, curr_day, curr_sec) + + ! tboas: nothing happens except on a switch date and only on the first + ! timestep of that day. Testing here rather than inside the patch routine + ! avoids walking every patch on every timestep. + if (curr_sec >= int(get_step_size())) return + if (.not. is_rotation_switch_date(curr_mon, curr_day)) return + + do p = bounds%begp, bounds%endp + call covercropping_update_patch(p, curr_mon, curr_day, curr_sec, & + crop_inst, cnveg_state_inst, cnveg_carbonstate_inst) + end do + + end subroutine covercropping_update + + !----------------------------------------------------------------------- + logical function is_rotation_switch_date(mon, day) + ! tboas: every date on which the rotation logic can act. + ! Keep in step with the branches in covercropping_update_patch. + integer, intent(in) :: mon, day + is_rotation_switch_date = & + (mon == 3 .and. day == 31) .or. & ! terminate cover crop + (mon == 4 .and. day == 1) .or. & ! switch to this year's crop + (mon == 8 .and. day == 15) .or. & ! sow cover crop + (mon == 9 .and. day == 1) .or. & ! sow cover crop + (mon == 10 .and. day == 1) .or. & ! sow cover crop, late window + (mon == 10 .and. day == 15) .or. & ! clear cover crop before winter crop + (mon == 10 .and. day == 20) .or. & ! sow cover crop, last attempt + (mon == 11 .and. day == 1) .or. & ! sow autumn-sown main crop + (mon == 11 .and. day == 15) ! second attempt + end function is_rotation_switch_date + + !----------------------------------------------------------------------- + subroutine covercropping_update_patch(p, curr_mon, curr_day, curr_sec, & + crop_inst, cnveg_state_inst, cnveg_carbonstate_inst) + ! + ! !DESCRIPTION: + ! Two-date calendar rotation switch --- tboas + ! + ! Mar 31 : if the standing crop is NOT this year's crop in the rotation + ! file, it is a cover crop. Force it through harvest by zeroing + ! gddmaturity/huigrain (same idiom as the cold-kill path in + ! CNPhenologyMod). itype is left alone so CNHarvestPftToColumn + ! partitions the residue with the COVER CROP's lf_flab/fcel/flig. + ! + ! Apr 1 : switch itype to this year's crop (pct_cft_cur). CropPhenology + ! then plants it inside its own min/max planting window. + ! + ! Sep 1 : if the patch is bare, look ahead to next year's crop + ! (pct_cft_next). Switch only if that crop is autumn-sown + ! (min_NH_planting_date > 0700, i.e. July onwards). A spring-sown + ! successor is left for the Apr 1 branch. If a summer crop is + ! still standing (late beet/potato) we skip and let it finish. + ! + ! !USES: + use CNVegCarbonStateType , only : cnveg_carbonstate_type + use dynCovercropFileMod , only : covercrop_target_ivt + ! + ! !ARGUMENTS: + integer , intent(in) :: p + integer , intent(in) :: curr_mon + integer , intent(in) :: curr_day + integer , intent(in) :: curr_sec + type(crop_type) , intent(inout) :: crop_inst + type(cnveg_state_type) , intent(inout) :: cnveg_state_inst + type(cnveg_carbonstate_type), intent(inout) :: cnveg_carbonstate_inst + ! + ! !LOCAL VARIABLES: + integer :: target_ivt + integer :: next_ivt ! tboas + integer :: mmdd ! tboas: date as month*100 + day + !------------------------------------------------------------------------ + + if (.not. use_covercropping) return + if (patch%itype(p) < npcropmin) return + ! tboas: act only on the first timestep of the day, otherwise every branch + ! fires ~48x and floods the log + if (curr_sec >= int(get_step_size())) return + + ! ---- Mar 31: terminate a standing cover crop ------------------------- + if (curr_mon == 3 .and. curr_day == 31) then + target_ivt = covercrop_target_ivt(p, use_next=.false.) + if (target_ivt > 0 .and. target_ivt /= patch%itype(p) .and. & + crop_inst%croplive_patch(p)) then + if (debug_covercrop) then + write(iulog,*) 'CCROT: Mar31 terminate covercrop p=',p, & + ' itype=',patch%itype(p),' target=',target_ivt + end if + cnveg_state_inst%gddmaturity_patch(p) = 0._r8 + cnveg_state_inst%huigrain_patch(p) = 0._r8 + end if + return + end if + + ! ---- Apr 1: switch to this year's crop ------------------------------- + if (curr_mon == 4 .and. curr_day == 1) then + target_ivt = covercrop_target_ivt(p, use_next=.false.) + if (target_ivt > 0 .and. target_ivt /= patch%itype(p)) then + if (debug_covercrop) then + write(iulog,*) 'CCROT: Apr1 switch p=',p, & + ' itype=',patch%itype(p),' target=',target_ivt + end if + call covercrop_switch_ivt(p, crop_inst, cnveg_state_inst, & + cnveg_carbonstate_inst, use_next=.false.) + end if + return + end if + + ! ---- cover-crop sowing: four attempts, gated by the crop's own window -- + ! tboas: the cover crop for the coming winter is taken from PCT_CFT_WINTER + ! of the CURRENT year. Rather than hardcoding when each cover crop may be + ! sown, every attempt is tested against that PFT's own planting window from + ! the parameter file. An early catch crop (window 0801-0930) is therefore + ! sown after a cereal; a late one (window 0901-1130) can follow a root crop + ! lifted in October. Which is used is decided in the land-use file. + if ((curr_mon == 8 .and. curr_day == 15) .or. & + (curr_mon == 9 .and. curr_day == 1) .or. & + (curr_mon == 10 .and. curr_day == 1) .or. & + (curr_mon == 10 .and. curr_day == 20)) then + + if (crop_inst%croplive_patch(p)) then + if (debug_covercrop) then + write(iulog,*) 'CCROT: cover-crop sowing skipped, crop live p=',p, & + ' mon=',curr_mon,' day=',curr_day,' itype=',patch%itype(p) + end if + return + end if + + target_ivt = covercrop_target_ivt(p, use_next=.false., use_winter=.true.) + if (target_ivt <= 0) return ! no cover crop this winter + + ! date as MMDD, matching the parameter-file convention + mmdd = curr_mon * 100 + curr_day + if (mmdd < pftcon%mnNHplantdate(target_ivt) .or. & + mmdd > pftcon%mxNHplantdate(target_ivt)) then + if (debug_covercrop) then + write(iulog,*) 'CCROT: cover-crop sowing outside its window p=',p, & + ' mmdd=',mmdd,' target=',target_ivt, & + ' window=',pftcon%mnNHplantdate(target_ivt), & + pftcon%mxNHplantdate(target_ivt) + end if + return + end if + + ! a late sowing must not occupy the patch when an autumn-sown main crop + ! is due in November + if (curr_mon >= 10) then + next_ivt = covercrop_target_ivt(p, use_next=.true.) + if (next_ivt > 0) then + if (pftcon%mnNHplantdate(next_ivt) > 700) then + if (debug_covercrop) then + write(iulog,*) 'CCROT: late cover crop suppressed, autumn-sown ', & + 'main crop follows p=',p,' next=',next_ivt + end if + return + end if + end if + end if + + if (target_ivt /= patch%itype(p)) then + if (debug_covercrop) then + write(iulog,*) 'CCROT: sow cover crop p=',p,' mon=',curr_mon, & + ' day=',curr_day,' itype=',patch%itype(p),' target=',target_ivt + end if + call covercrop_switch_ivt(p, crop_inst, cnveg_state_inst, & + cnveg_carbonstate_inst, use_next=.false., use_winter=.true.) + end if + return + end if + + ! ---- 15 Oct: clear a cover crop ahead of an autumn-sown main crop ------ + ! tboas: only fires when next year's crop is itself autumn-sown, i.e. the + ! summer -> cover crop -> winter cereal sequence. For a spring successor the + ! cover crop is left standing and terminated on 31 March instead. + if (curr_mon == 10 .and. curr_day == 15) then + target_ivt = covercrop_target_ivt(p, use_next=.true.) + if (target_ivt <= 0) return + if (pftcon%mnNHplantdate(target_ivt) > 700) then + ! tboas-fix: only force-terminate an ACTUAL cover crop here. + ! The unguarded condition fired whenever the standing crop + ! merely differed from next year's target -- e.g. a plain + ! wheat->rye rotation with no cover crop between them -- and + ! zeroed gddmaturity/huigrain on wheat mid-season, leaking + ! carbon that CNBalanceCheckMod does not account for. + if (crop_inst%croplive_patch(p) .and. target_ivt /= patch%itype(p) .and. & + (patch%itype(p) == ncovercrop_1 .or. patch%itype(p) == ncovercrop_2)) then + if (debug_covercrop) then + write(iulog,*) 'CCROT: Oct15 clear cover crop ahead of winter crop p=',p, & + ' itype=',patch%itype(p),' target=',target_ivt + end if + cnveg_state_inst%gddmaturity_patch(p) = 0._r8 + cnveg_state_inst%huigrain_patch(p) = 0._r8 + end if + end if + return + end if + + ! ---- 1 Nov / 15 Nov: sow next year's autumn-sown crop ------------------ + if ((curr_mon == 11 .and. curr_day == 1) .or. & + (curr_mon == 11 .and. curr_day == 15)) then + if (crop_inst%croplive_patch(p)) then + if (debug_covercrop) then + write(iulog,*) 'CCROT: autumn sow skipped, crop live p=',p, & + ' mon=',curr_mon,' day=',curr_day,' itype=',patch%itype(p) + end if + return + end if + target_ivt = covercrop_target_ivt(p, use_next=.true.) + if (target_ivt <= 0) return + ! only sow here if the crop is autumn-sown; a spring successor is left + ! to the 1 April branch and the patch overwinters bare + if (pftcon%mnNHplantdate(target_ivt) > 700) then + if (target_ivt /= patch%itype(p)) then + if (debug_covercrop) then + write(iulog,*) 'CCROT: autumn sow p=',p,' mon=',curr_mon, & + ' day=',curr_day,' itype=',patch%itype(p), & + ' target=',target_ivt, & + ' mnNHplantdate=',pftcon%mnNHplantdate(target_ivt) + end if + call covercrop_switch_ivt(p, crop_inst, cnveg_state_inst, & + cnveg_carbonstate_inst, use_next=.true.) + end if + end if + return + end if + + end subroutine covercropping_update_patch + + !----------------------------------------------------------------------- !----------------------------------------------------------------------- subroutine CNHarvest (num_soilc, filter_soilc, num_soilp, filter_soilp, & soilbiogeochem_state_inst, cnveg_carbonstate_inst, cnveg_nitrogenstate_inst, & diff --git a/src/clm5/biogeophys/TemperatureType.F90 b/src/clm5/biogeophys/TemperatureType.F90 index 7dfbb5d95f..c1e319ced7 100644 --- a/src/clm5/biogeophys/TemperatureType.F90 +++ b/src/clm5/biogeophys/TemperatureType.F90 @@ -87,6 +87,7 @@ module TemperatureType ! being: that way one parameterization is free to change the exact meaning of its ! accumulator without affecting the other). ! + real(r8), pointer :: t_ref24_patch (:) ! patch 24hr average 2 m air temperature (K) real(r8), pointer :: t_veg24_patch (:) ! patch 24hr average vegetation temperature (K) real(r8), pointer :: t_veg240_patch (:) ! patch 240hr average vegetation temperature (Kelvin) real(r8), pointer :: gdd0_patch (:) ! patch growing degree-days base 0C from planting (ddays) @@ -252,6 +253,7 @@ subroutine InitAllocate(this, bounds) allocate(this%t_ref2m_min_inst_u_patch (begp:endp)) ; this%t_ref2m_min_inst_u_patch (:) = nan ! Accumulated fields + allocate(this%t_ref24_patch (begp:endp)) ; this%t_ref24_patch (:) = nan allocate(this%t_veg24_patch (begp:endp)) ; this%t_veg24_patch (:) = nan allocate(this%t_veg240_patch (begp:endp)) ; this%t_veg240_patch (:) = nan allocate(this%gdd0_patch (begp:endp)) ; this%gdd0_patch (:) = spval @@ -572,6 +574,10 @@ subroutine InitHistory(this, bounds, is_simple_buildtemp, is_prog_buildtemp ) end if ! Accumulated quantities + this%t_ref24_patch(begp:endp) = spval + call hist_addfld1d (fname='TREF24', units='K', & + avgflag='A', long_name='2 m air temperature (last 24hrs)', & + ptr_patch=this%t_ref24_patch, default='inactive') this%t_veg24_patch(begp:endp) = spval call hist_addfld1d (fname='TV24', units='K', & @@ -934,6 +940,10 @@ subroutine Restart(this, bounds, ncid, flag, is_simple_buildtemp, is_prog_buildt long_name='Urban 2m height surface air temperature', units='K', & interpinic_flag='interp', readvar=readvar, data=this%t_ref2m_u_patch) + call restartvar(ncid=ncid, flag=flag, varname='T_REF24', xtype=ncd_double, & + dim1name='pft', & + long_name='daily average 2 m height surface air temperature (K)', units='K', & + interpinic_flag='interp', readvar=readvar, data=this%t_ref24_patch) call restartvar(ncid=ncid, flag=flag, varname='T_REF2M_MIN', xtype=ncd_double, & dim1name='pft', & @@ -1132,6 +1142,9 @@ subroutine InitAccBuffer (this, bounds) dtime = get_step_size() + call init_accum_field (name='T_REF24', units='K', & + desc='24hr average of 2 m air temperature', accum_type='timeavg', accum_period=-1, & + subgrid_type='pft', numlev=1, init_value=0._r8) this%t_veg24_patch(bounds%begp:bounds%endp) = spval call init_accum_field (name='T_VEG24', units='K', & desc='24hr average of vegetation temperature', accum_type='runmean', accum_period=-1, & @@ -1160,6 +1173,9 @@ subroutine InitAccBuffer (this, bounds) subgrid_type='pft', numlev=1,init_value=SHR_CONST_TKFRZ+20._r8) if ( use_crop )then + call init_accum_field (name='T24', units='K', & + desc='24-hour running mean of 2-m temperature', accum_type='runmean', accum_period=-1, & + subgrid_type='pft', numlev=1,init_value=SHR_CONST_TKFRZ+20._r8) call init_accum_field (name='TDM10', units='K', & desc='10-day running mean of min 2-m temperature', accum_type='runmean', accum_period=-10, & subgrid_type='pft', numlev=1, init_value=SHR_CONST_TKFRZ) @@ -1235,6 +1251,8 @@ subroutine InitAccVars(this, bounds) ! Determine time step nstep = get_nstep() + call extract_accum_field ('T_REF24', rbufslp, nstep) + this%t_ref24_patch(begp:endp) = rbufslp(begp:endp) call extract_accum_field ('T_VEG24', rbufslp, nstep) this%t_veg24_patch(begp:endp) = rbufslp(begp:endp) @@ -1429,6 +1447,10 @@ subroutine UpdateAccVars (this, bounds) call extract_accum_field ('T10', this%t_a10_patch, nstep) if ( use_crop )then + ! Accumulate and extract T_REF24 + + call update_accum_field ('T_REF24' , this%t_ref2m_patch, nstep) + call extract_accum_field ('T_REF24' , this%t_ref24_patch , nstep) ! Accumulate and extract TDM10 do p = begp,endp diff --git a/src/clm5/dyn_subgrid/dynCovercropFileMod.F90 b/src/clm5/dyn_subgrid/dynCovercropFileMod.F90 new file mode 100644 index 0000000000..cf39a40937 --- /dev/null +++ b/src/clm5/dyn_subgrid/dynCovercropFileMod.F90 @@ -0,0 +1,290 @@ +module dynCovercropFileMod + +#include "shr_assert.h" + + !--------------------------------------------------------------------------- + ! !DESCRIPTION: + ! Read the cover-crop rotation file and switch patch ivt after harvest. + ! + ! Rotation file format: + ! dimensions: time, cft, lndgrid + ! integer YEAR(time) -- calendar year per time slice + ! real PCT_CFT(time, cft, lndgrid) -- CFT fractions 0-100% + ! + ! After harvest of any cash crop, covercrop_switch_ivt finds the dominant + ! CFT in the next year slice for this gridcell and switches ivt(p). + ! Works identically for point and regional/global domains. + ! + ! Backward compatibility: + ! use_covercropping = .false. -> never called, zero overhead + ! use_covercropping = .true. -> transient_landuse_file must be set + ! tboas + ! + ! !USES: + use shr_kind_mod , only : r8 => shr_kind_r8 + use shr_log_mod , only : errMsg => shr_log_errMsg + use decompMod , only : bounds_type, BOUNDS_LEVEL_PROC + use dynFileMod , only : dyn_file_type + use clm_varctl , only : iulog, use_covercropping, transient_landuse_file + use clm_varctl , only : debug_covercrop ! tboas-fix + use pftconMod , only : nwwheat, nirrig_wwheat, nwbarley, nirrig_wbarley, ncovercrop_1, ncovercrop_2 ! tboas + use CNVegCarbonStateType , only : cnveg_carbonstate_type ! tboas + use CNVegNitrogenStateType , only : cnveg_nitrogenstate_type ! tboas + use clm_varcon , only : grlnd + use clm_varpar , only : cft_size, cft_lb + use abortutils , only : endrun + use histFileMod , only : hist_addfld1d + use spmdMod , only : masterproc + use PatchType , only : patch + use pftconMod , only : pftcon, ncovercrop_1, ncovercrop_2 + ! + implicit none + private + save + + public :: dyncovercrop_init + public :: dyncovercrop_interp + public :: covercrop_switch_ivt + public :: covercrop_target_ivt ! tboas + + !--------------------------------------------------------------------------- + type(dyn_file_type), target :: dyncovercrop_file + real(r8), allocatable :: pct_cft_cur (:,:) ! (begg:endg, cft_size) + real(r8), allocatable :: pct_cft_next(:,:) ! (begg:endg, cft_size) + real(r8), allocatable :: pct_cft_winter(:,:) ! (begg:endg, cft_size) tboas + logical :: has_winter_slot = .false. ! tboas + integer :: last_year_index = -1 ! tboas: read cache + real(r8), pointer :: active_ivt_patch(:) => null() ! (begp:endp) active itype for history ! tboas + + character(len=*), parameter, private :: sourcefile = __FILE__ + +contains + + !----------------------------------------------------------------------- + subroutine dyncovercrop_init(bounds) + use dynTimeInfoMod , only : YEAR_POSITION_START_OF_TIMESTEP + use dynVarTimeUninterpMod , only : dyn_var_time_uninterp_type + use ncdio_pio , only : check_dim + type(bounds_type), intent(in) :: bounds + type(dyn_var_time_uninterp_type) :: wtcft_obj + integer :: num_points, pct_cft_shape(2), pi + character(len=*), parameter :: subname = "dyncovercrop_init" + !----------------------------------------------------------------------- + SHR_ASSERT_ALL(bounds%level == BOUNDS_LEVEL_PROC, & + subname // ": argument must be PROC-level bounds") + if (.not. use_covercropping) return + if (trim(transient_landuse_file) == "" .or. & + trim(transient_landuse_file) == " ") then + call endrun(msg=" ERROR: use_covercropping=.true. but transient_landuse_file" // & + " is not set in lnd_in." // errMsg(sourcefile, __LINE__)) + end if + if (masterproc) write(iulog,*) & + "dyncovercrop_init: opening ", trim(transient_landuse_file) + dyncovercrop_file = dyn_file_type( & + trim(transient_landuse_file), YEAR_POSITION_START_OF_TIMESTEP) + call check_dim(dyncovercrop_file, "cft", cft_size) + num_points = bounds%endg - bounds%begg + 1 + pct_cft_shape = [num_points, cft_size] + allocate(pct_cft_cur (bounds%begg:bounds%endg, cft_size)) + allocate(pct_cft_next(bounds%begg:bounds%endg, cft_size)) + allocate(pct_cft_winter(bounds%begg:bounds%endg, cft_size)) + pct_cft_cur = 0._r8 + pct_cft_next = 0._r8 + pct_cft_winter = 0._r8 + call dyncovercrop_interp(bounds) + + ! Register IVT as history field for rotation diagnostics --- tboas + allocate(active_ivt_patch(bounds%begp:bounds%endp)) + do pi = bounds%begp, bounds%endp + active_ivt_patch(pi) = real(patch%itype(pi), r8) + end do + call hist_addfld1d(fname='IVT', units='unitless', & + avgflag='I', long_name='current patch vegetation type index', & + ptr_patch=active_ivt_patch, default='active') + end subroutine dyncovercrop_init + + !----------------------------------------------------------------------- + subroutine dyncovercrop_interp(bounds) + use dynVarTimeUninterpMod , only : dyn_var_time_uninterp_type + use ncdio_pio , only : ncd_io + type(bounds_type), intent(in) :: bounds + type(dyn_var_time_uninterp_type) :: wtcft_obj + integer :: num_points, pct_cft_shape(2), pi + integer :: idx_next, ntimes + integer :: cur_year_index ! tboas + real(r8), pointer :: raw_next(:,:) ! (lndgrid, cft) pointer for ncd_io_2d + logical :: readvar + !----------------------------------------------------------------------- + if (.not. use_covercropping) return + if (.not. allocated(pct_cft_cur)) return + call dyncovercrop_file%time_info%set_current_year() + + ! tboas: the file only changes when the year index changes. Without this + ! guard the slices below are re-read on every timestep -- 17520 reads per + ! simulated year at dtime=1800s, which dominates runtime on a regional grid. + cur_year_index = dyncovercrop_file%time_info%get_time_index_lower() + if (cur_year_index /= last_year_index) then + num_points = bounds%endg - bounds%begg + 1 + pct_cft_shape = [num_points, cft_size] + + ! Read current year PCT_CFT via standard mechanism + wtcft_obj = dyn_var_time_uninterp_type( & + dyn_file = dyncovercrop_file, & + varname = "PCT_CFT", & + dim1name = grlnd, & + conversion_factor = 100._r8, & + do_check_sums_equal_1 = .false., & + data_shape = pct_cft_shape) + call wtcft_obj%get_current_data(pct_cft_cur(bounds%begg:bounds%endg, :)) + + ! Read next year PCT_CFT directly via ncd_io_2d at time_index_lower + 1 + ! This is needed for post-harvest planting of winter crops/cover crops + ! which are sown in fall of current year but belong to next year's rotation + ntimes = dyncovercrop_file%time_info%get_time_index_upper() + idx_next = min(dyncovercrop_file%time_info%get_time_index_lower() + 1, ntimes) + nullify(raw_next) + allocate(raw_next(num_points, cft_size)) + call ncd_io(varname="PCT_CFT", data=raw_next, dim1name=grlnd, & + flag="read", ncid=dyncovercrop_file, nt=idx_next, readvar=readvar) + if (readvar) then + pct_cft_next(bounds%begg:bounds%endg, :) = raw_next * 100._r8 + else + ! Fallback: end of timeseries — use current year + pct_cft_next(bounds%begg:bounds%endg, :) = pct_cft_cur(bounds%begg:bounds%endg, :) + if (masterproc) write(iulog,*) "dyncovercrop_interp: end of timeseries, using current year for pct_cft_next" + end if + deallocate(raw_next) + + ! tboas: optional winter cover-crop slot, read at the CURRENT year index. + ! PCT_CFT_WINTER(year N) is the cover crop sown in autumn of year N. + allocate(raw_next(num_points, cft_size)) + call ncd_io(varname="PCT_CFT_WINTER", data=raw_next, dim1name=grlnd, & + flag="read", ncid=dyncovercrop_file, & + nt=dyncovercrop_file%time_info%get_time_index_lower(), readvar=readvar) + if (readvar) then + pct_cft_winter(bounds%begg:bounds%endg, :) = raw_next * 100._r8 + has_winter_slot = .true. + else + pct_cft_winter(bounds%begg:bounds%endg, :) = 0._r8 + has_winter_slot = .false. + end if + deallocate(raw_next) + last_year_index = cur_year_index + end if + + ! Update IVT history field with current patch itype --- tboas + if (associated(active_ivt_patch)) then + do pi = bounds%begp, bounds%endp + active_ivt_patch(pi) = real(patch%itype(pi), r8) + ! tboas: debug write disabled for regional runs + !if (pi == 2) write(iulog,*) 'IVT_TRACK: pi=',pi,' itype=',patch%itype(pi) ! tboas + end do + end if + end subroutine dyncovercrop_interp + + !----------------------------------------------------------------------- + subroutine covercrop_switch_ivt(p, crop_inst, cnveg_state_inst, cnveg_carbonstate_inst, use_next, use_winter) + use CropType , only : crop_type + use CNVegStateType , only : cnveg_state_type + integer , intent(in) :: p + logical , intent(in) :: use_next ! .true. = use pct_cft_next + logical , intent(in), optional :: use_winter ! tboas + type(crop_type) , intent(inout) :: crop_inst + type(cnveg_state_type), intent(inout) :: cnveg_state_inst + type(cnveg_carbonstate_type), intent(inout) :: cnveg_carbonstate_inst + integer :: new_ivt + integer, parameter :: NOT_Planted = 999 + !----------------------------------------------------------------------- + if (.not. use_covercropping) return + if (.not. allocated(pct_cft_cur)) return + new_ivt = covercrop_target_ivt(p, use_next, use_winter) + if (new_ivt <= 0) return + if (debug_covercrop) then + write(iulog,*) 'SWITCH_DEBUG: new_ivt=',new_ivt,' patch%itype=',patch%itype(p),' use_next=',use_next ! tboas + end if + if (new_ivt == patch%itype(p)) return + ! tboas: no crop-type restriction — any crop can be switched to post-harvest + patch%itype(p) = new_ivt + if (associated(active_ivt_patch)) active_ivt_patch(p) = real(new_ivt, r8) + crop_inst%croplive_patch(p) = .false. + crop_inst%cropplant_patch(p) = .false. + cnveg_state_inst%idop_patch(p) = NOT_Planted + ! Reset phenology GDD state so new crop starts fresh --- tboas + crop_inst%gddplant_patch(p) = 0._r8 + ! tboas: huigrain/gddmaturity NOT zeroed — CropPhenology derives them at + ! planting; zeroing them makes 'hui < huigrain' impossible and locks the + ! crop out of phase 2 permanently. + ! cnveg_state_inst%huigrain_patch(p) = 0._r8 + ! cnveg_state_inst%gddmaturity_patch(p) = 0._r8 + crop_inst%harvdate_patch(p) = NOT_Planted + crop_inst%cphase_patch(p) = 0._r8 + ! tboas: peaklai MUST be reset — if it carries over as 1 from the previous + ! crop, CNPhenologyMod line ~2731 clamps hui up to huigrain on the first + ! live timestep, making 'hui < huigrain' permanently false and locking the + ! new crop out of phase 2 (no leaf emergence, no onset, leafc_xfer never drains). + cnveg_state_inst%peaklai_patch(p) = 0 + ! onset/offset flags NOT reset — onset_counter must go negative for crop onset to fire --- tboas + ! Clear the previous crop's excess-maintenance-respiration pool --- tboas + ! tboas-fix: xsmrpool is part of totc_patch, so assigning 0 here destroyed + ! (or, for a negative pool, created) carbon with no matching flux, which is + ! what forced the CNBalanceCheckMod tolerance up to 100 gC/m2/timestep. + ! Move it into xsmrpool_loss instead: that pool is also inside totc_patch, so + ! the transfer conserves carbon, and CNCStateUpdate1Mod releases it to the + ! atmosphere through xsmrpool_to_atm, which the C balance already counts as + ! an output. + cnveg_carbonstate_inst%xsmrpool_loss_patch(p) = & + cnveg_carbonstate_inst%xsmrpool_loss_patch(p) + & + cnveg_carbonstate_inst%xsmrpool_patch(p) + cnveg_carbonstate_inst%xsmrpool_patch(p) = 0._r8 + ! tboas: remaining C/N pools are kept from the previous crop + ! tboas: use_grainproduct is a namelist flag and is NOT rewritten here. + ! Mutating it made the last patch switched determine the setting for the + ! whole domain. Grain-product suppression for cover crops is now decided + ! per patch at the point of use, via pftconMod::is_covercrop. + end subroutine covercrop_switch_ivt + + !----------------------------------------------------------------------- + integer function covercrop_target_ivt(p, use_next, use_winter) + ! tboas: return the dominant CFT for patch p as a global PFT index. + ! Returns -1 if covercropping is off or the arrays are not allocated. + integer, intent(in) :: p + logical, intent(in) :: use_next ! .true. = pct_cft_next, .false. = pct_cft_cur + logical, intent(in), optional :: use_winter ! tboas: PCT_CFT_WINTER slot + integer :: g, cft, best_cft + real(r8) :: best_pct + logical :: want_winter + !----------------------------------------------------------------------- + covercrop_target_ivt = -1 + want_winter = .false. + if (present(use_winter)) want_winter = use_winter .and. has_winter_slot + if (.not. use_covercropping) return + if (.not. allocated(pct_cft_cur)) return + if (use_next .and. .not. allocated(pct_cft_next)) return + g = patch%gridcell(p) + best_cft = 1 + best_pct = -1._r8 + do cft = 1, cft_size + if (want_winter) then + if (pct_cft_winter(g, cft) > best_pct) then + best_pct = pct_cft_winter(g, cft) + best_cft = cft + end if + else if (use_next) then + if (pct_cft_next(g, cft) > best_pct) then + best_pct = pct_cft_next(g, cft) + best_cft = cft + end if + else + if (pct_cft_cur(g, cft) > best_pct) then + best_pct = pct_cft_cur(g, cft) + best_cft = cft + end if + end if + end do + ! tboas: an empty slot yields no target + if (best_pct <= 0._r8) return + ! cft_lb = first crop PFT index = natpft_ub + 1 + covercrop_target_ivt = cft_lb + best_cft - 1 + end function covercrop_target_ivt + +end module dynCovercropFileMod diff --git a/src/clm5/dyn_subgrid/dynSubgridDriverMod.F90 b/src/clm5/dyn_subgrid/dynSubgridDriverMod.F90 index 8703fcb2d9..388c40b41f 100644 --- a/src/clm5/dyn_subgrid/dynSubgridDriverMod.F90 +++ b/src/clm5/dyn_subgrid/dynSubgridDriverMod.F90 @@ -19,7 +19,9 @@ module dynSubgridDriverMod use dynColumnStateUpdaterMod , only : column_state_updater_type use dynpftFileMod , only : dynpft_init, dynpft_interp use dyncropFileMod , only : dyncrop_init, dyncrop_interp - use dynHarvestMod , only : dynHarvest_init, dynHarvest_interp + use dynHarvestMod , only : dynHarvest_init, dynHarvest_interp, covercropping_update + use dynCovercropFileMod , only : dyncovercrop_init, dyncovercrop_interp ! tboas + use clm_varctl , only : use_covercropping ! tboas use dynLandunitAreaMod , only : update_landunit_weights use subgridWeightsMod , only : compute_higher_order_weights, set_subgrid_diagnostic_fields use reweightMod , only : reweight_wrapup @@ -120,6 +122,7 @@ subroutine dynSubgrid_init(bounds_proc, glc_behavior, crop_inst) if (get_do_harvest()) then call dynHarvest_init(bounds_proc, harvest_filename=get_flanduse_timeseries()) end if + if (use_covercropping) call dyncovercrop_init(bounds_proc) ! tboas ! ------------------------------------------------------------------------ ! Set initial subgrid weights for aspects that are read from file. This is relevant @@ -133,6 +136,7 @@ subroutine dynSubgrid_init(bounds_proc, glc_behavior, crop_inst) if (get_do_transient_crops()) then call dyncrop_interp(bounds_proc, crop_inst) end if + if (use_covercropping) call dyncovercrop_interp(bounds_proc) ! tboas ! (We don't bother calling dynHarvest_interp, because the harvest information isn't ! needed until the run loop. Harvest has nothing to do with subgrid weights, and in @@ -172,7 +176,7 @@ subroutine dynSubgrid_driver(bounds_proc, ! OUTSIDE any loops over clumps in the driver. ! ! !USES: - use clm_varctl , only : use_cn, use_fates + use clm_varctl , only : use_cn, use_fates, use_covercropping use dynInitColumnsMod , only : initialize_new_columns use dynConsBiogeophysMod , only : dyn_hwcontent_init, dyn_hwcontent_final use dynEDMod , only : dyn_ED @@ -248,6 +252,12 @@ subroutine dynSubgrid_driver(bounds_proc, call dynHarvest_interp(bounds_proc) end if + if (use_covercropping) then + call dyncovercrop_interp(bounds_proc) ! tboas: update pct_cft_cur/next each timestep + call covercropping_update(bounds_proc, crop_inst, bgc_vegetation_inst%cnveg_state_inst, & + bgc_vegetation_inst%cnveg_carbonstate_inst) + end if + ! ========================================================================== ! Do land cover change that does not require I/O ! ========================================================================== diff --git a/src/clm5/main/PatchType.F90 b/src/clm5/main/PatchType.F90 index d00f5588b0..e3d558d752 100644 --- a/src/clm5/main/PatchType.F90 +++ b/src/clm5/main/PatchType.F90 @@ -41,8 +41,8 @@ module PatchType ! 32 => irrigated_winter_rye ! 33 => cassava ! 34 => irrigated_cassava - ! 35 => citrus - ! 36 => irrigated_citrus + ! 35 => apple + ! 36 => irrigated_apple ! 37 => cocoa ! 38 => irrigated_cocoa ! 39 => coffee @@ -83,8 +83,8 @@ module PatchType ! 74 => irrigated_switchgrass ! 75 => tropical_corn ! 76 => irrigated_tropical_corn - ! 77 => tropical_soybean - ! 78 => irrigated_tropical_soybean + ! 77 => covercrop_1 + ! 78 => covercrop_2 ! -------------------------------------------------------- ! use shr_kind_mod , only : r8 => shr_kind_r8 diff --git a/src/clm5/main/clm_varctl.F90 b/src/clm5/main/clm_varctl.F90 index 314d9b5be7..87c69d2ebe 100644 --- a/src/clm5/main/clm_varctl.F90 +++ b/src/clm5/main/clm_varctl.F90 @@ -119,6 +119,10 @@ module clm_varctl ! If prognostic crops are turned on logical, public :: use_crop = .false. +logical, public :: use_covercropping = .false. +logical, public :: use_fruittree = .false. ! tboas: apple/perennial crop phenology +character(len=256), public :: transient_landuse_file = ' ' ! tboas +character(len=fname_len), public :: covercrop_paramfile = ' ' ! tboas ! true => separate crop landunit is not created by default logical, public :: create_crop_landunit = .false. @@ -357,6 +361,39 @@ module clm_varctl logical, public :: use_nguardrail = .false. +! tboas-fix: compile-time switch for the per-patch crop-rotation / crop-phenology +! debug writes. These fire once per patch, per MPI rank, with no masterproc guard; +! at regional resolution that is O(10^5) log lines per rank on every rotation date +! (and every timestep for the coldtolerance trace). Declared as a PARAMETER so the +! compiler eliminates the write statements entirely when it is .false. +! Set to .true. only for single-point debugging, then rebuild. +logical, public, parameter :: debug_covercrop = .false. + +! tboas-fix: C and N mass-conservation error tolerances (gC or gN /m2/timestep). +! These are the thresholds above which CNBalanceCheckMod aborts the run. The +! defaults are the stock CLM5 values; they are exposed here only so that a +! tolerance can be widened DELIBERATELY and visibly while debugging, instead of +! being hardcoded loose in the source. A loosened value is logged at startup. +real(r8), public :: cn_balance_tol_c = 1.e-7_r8 +real(r8), public :: cn_balance_tol_n = 1.e-7_r8 + +! tboas: namelist parameter for optional organic carbon fertilizer from manure +logical, public :: use_cfert = .false. + real(r8), public :: manure_CN_ratio = 25.0_r8 ! tboas: C:N ratio for farmyard manure (cfert_inparm) + ! tboas-fix: ammoniacal (immediately plant-available) fraction of the applied + ! manure N. The remainder enters the litter pools as organic N together with + ! the manure C at manure_CN_ratio, and is mineralised by the decomposition + ! cascade. 0.25 is typical for solid farmyard manure; ~0.5-0.6 for slurry. + ! Setting this to 1.0 reproduces the previous behaviour (all manure N applied + ! as mineral N) but then no organic N accompanies the manure C. + real(r8), public :: manure_nh4_frac = 0.25_r8 ! tboas-fix: NH4-N fraction of manure N (cfert_inparm) + real(r8), public :: manure_fmet = 0.60_r8 ! tboas: metabolic litter fraction of manure C (cfert_inparm) + real(r8), public :: manure_fcel = 0.30_r8 ! tboas: cellulose litter fraction of manure C (cfert_inparm) + real(r8), public :: manure_flig = 0.10_r8 ! tboas: lignin litter fraction of manure C (cfert_inparm) + real(r8), public :: manure_injection_depth = 0.0_r8 ! tboas: manure C injection depth [m] (cfert_inparm); 0=surface only + integer, public :: manure_freq_years = 1 ! tboas: apply manure every N years (cfert_inparm); 1=every year + integer, public :: manure_apply_month = 0 ! tboas: calendar month for manure application (cfert_inparm); 0=at planting + integer, public :: manure_apply_day = 1 ! tboas: calendar day for manure application (cfert_inparm) !---------------------------------------------------------- ! To retrieve namelist !---------------------------------------------------------- @@ -371,22 +408,16 @@ module clm_varctl subroutine clm_varctl_set( caseid_in, ctitle_in, brnch_retain_casename_in, & single_column_in, scmlat_in, scmlon_in, nsrest_in, & version_in, hostname_in, username_in) - ! - ! !DESCRIPTION: - ! Set input control variables. - ! - ! !ARGUMENTS: - character(len=256), optional, intent(IN) :: caseid_in ! case id - character(len=256), optional, intent(IN) :: ctitle_in ! case title - logical, optional, intent(IN) :: brnch_retain_casename_in ! true => allow case name to remain the - ! same for branch run - logical, optional, intent(IN) :: single_column_in ! true => single column mode - real(r8), optional, intent(IN) :: scmlat_in ! single column lat - real(r8), optional, intent(IN) :: scmlon_in ! single column lon - integer, optional, intent(IN) :: nsrest_in ! 0: initial run. 1: restart: 3: branch - character(len=256), optional, intent(IN) :: version_in ! model version - character(len=256), optional, intent(IN) :: hostname_in ! hostname running on - character(len=256), optional, intent(IN) :: username_in ! username running job + character(len=256), optional, intent(IN) :: caseid_in + character(len=256), optional, intent(IN) :: ctitle_in + logical, optional, intent(IN) :: brnch_retain_casename_in + logical, optional, intent(IN) :: single_column_in + real(r8), optional, intent(IN) :: scmlat_in + real(r8), optional, intent(IN) :: scmlon_in + integer, optional, intent(IN) :: nsrest_in + character(len=256), optional, intent(IN) :: version_in + character(len=256), optional, intent(IN) :: hostname_in + character(len=256), optional, intent(IN) :: username_in !----------------------------------------------------------------------- if ( clmvarctl_isset )then diff --git a/src/clm5/main/controlMod.F90 b/src/clm5/main/controlMod.F90 index c10c348692..84ed4b2a5d 100644 --- a/src/clm5/main/controlMod.F90 +++ b/src/clm5/main/controlMod.F90 @@ -224,6 +224,11 @@ subroutine control_init( ) ! FATES Flags + namelist /clm_inparm/ use_fruittree ! tboas + namelist /clm_inparm/ covercrop_paramfile ! tboas: param file for covercrop PFTs + namelist /clm_inparm/ transient_landuse_file ! tboas: cover-crop rotation file + namelist /clm_inparm/ covercrop_paramfile ! tboas + namelist /clm_inparm/ transient_landuse_file ! tboas namelist /clm_inparm/ fates_paramfile, use_fates, & use_fates_spitfire, use_fates_logging, & use_fates_planthydro, use_fates_ed_st3, & @@ -264,9 +269,14 @@ subroutine control_init( ) namelist /clm_inparm/ & use_lch4, use_nitrif_denitrif, use_vertsoilc, use_extralakelayers, & - use_vichydro, use_century_decomp, use_cn, use_cndv, use_crop, use_fertilizer, use_ozone, & + use_vichydro, use_century_decomp, use_cn, use_cndv, use_crop, use_covercropping, use_fertilizer, use_cfert, use_ozone, & use_grainproduct, use_snicar_frc, use_vancouver, use_mexicocity, use_noio, & use_nguardrail + namelist /cfert_inparm/ manure_CN_ratio, manure_fmet, manure_fcel, manure_flig, & + manure_injection_depth, manure_freq_years, manure_apply_month, & + manure_apply_day, & ! tboas: manure C parameters + manure_nh4_frac, & ! tboas-fix: NH4-N fraction of applied manure N + cn_balance_tol_c, cn_balance_tol_n ! tboas-fix: mass-balance tolerances ! ---------------------------------------------------------------------- @@ -316,6 +326,16 @@ subroutine control_init( ) else call endrun(msg='ERROR finding clm_inparm namelist'//errMsg(sourcefile, __LINE__)) end if + ! tboas: read optional cfert_inparm namelist (default manure_CN_ratio=25 if absent) + rewind(unitn) + call shr_nl_find_group_name(unitn, 'cfert_inparm', status=ierr) + if (ierr == 0) then + read(unitn, cfert_inparm, iostat=ierr) + if (ierr /= 0) then + call endrun(msg='ERROR reading cfert_inparm namelist'//errMsg(sourcefile, __LINE__)) + end if + end if + rewind(unitn) ! tboas: rewind after cfert_inparm read call shr_nl_find_group_name(unitn, 'clm_nitrogen', status=ierr) if (ierr == 0) then read(unitn, clm_nitrogen, iostat=ierr) @@ -592,8 +612,28 @@ subroutine control_spmd() call mpi_bcast (use_cndv, 1, MPI_LOGICAL, 0, mpicom, ier) call mpi_bcast (use_nguardrail, 1, MPI_LOGICAL, 0, mpicom, ier) call mpi_bcast (use_crop, 1, MPI_LOGICAL, 0, mpicom, ier) + call mpi_bcast (use_fruittree, 1, MPI_LOGICAL, 0, mpicom, ier) ! tboas + call mpi_bcast (use_covercropping, 1, MPI_LOGICAL, 0, mpicom, ier) + call mpi_bcast (covercrop_paramfile, len(covercrop_paramfile), MPI_CHARACTER, 0, mpicom, ier) ! tboas + call mpi_bcast (transient_landuse_file, len(transient_landuse_file), MPI_CHARACTER, 0, mpicom, ier) ! tboas call mpi_bcast (use_fertilizer, 1, MPI_LOGICAL, 0, mpicom, ier) + ! tboas-fix: this broadcast was lost. use_grainproduct is read on the master + ! rank only, so without it every other rank kept the .false. default and + ! routed harvested grain C and N to litter while rank 0 sent it to the crop + ! product pool -- rank- and decomposition-dependent results. call mpi_bcast (use_grainproduct, 1, MPI_LOGICAL, 0, mpicom, ier) + call mpi_bcast (use_cfert, 1, MPI_LOGICAL, 0, mpicom, ier) ! tboas + call mpi_bcast (manure_CN_ratio, 1, MPI_REAL8, 0, mpicom, ier) ! tboas + call mpi_bcast (manure_fmet, 1, MPI_REAL8, 0, mpicom, ier) ! tboas + call mpi_bcast (manure_fcel, 1, MPI_REAL8, 0, mpicom, ier) ! tboas + call mpi_bcast (manure_flig, 1, MPI_REAL8, 0, mpicom, ier) ! tboas + call mpi_bcast (manure_injection_depth, 1, MPI_REAL8, 0, mpicom, ier) ! tboas + call mpi_bcast (manure_freq_years, 1, MPI_INTEGER, 0, mpicom, ier) ! tboas + call mpi_bcast (manure_apply_month, 1, MPI_INTEGER, 0, mpicom, ier) ! tboas + call mpi_bcast (manure_apply_day, 1, MPI_INTEGER, 0, mpicom, ier) ! tboas + call mpi_bcast (manure_nh4_frac, 1, MPI_REAL8, 0, mpicom, ier) ! tboas-fix + call mpi_bcast (cn_balance_tol_c, 1, MPI_REAL8, 0, mpicom, ier) ! tboas-fix + call mpi_bcast (cn_balance_tol_n, 1, MPI_REAL8, 0, mpicom, ier) ! tboas-fix call mpi_bcast (use_ozone, 1, MPI_LOGICAL, 0, mpicom, ier) call mpi_bcast (use_snicar_frc, 1, MPI_LOGICAL, 0, mpicom, ier) call mpi_bcast (use_vancouver, 1, MPI_LOGICAL, 0, mpicom, ier) @@ -813,6 +853,29 @@ subroutine control_print () write(iulog,*) ' use_cndv = ', use_cndv write(iulog,*) ' use_crop = ', use_crop write(iulog,*) ' use_fertilizer = ', use_fertilizer + write(iulog,*) ' use_cfert = ', use_cfert ! tboas + write(iulog,*) ' manure_CN_ratio= ', manure_CN_ratio ! tboas + write(iulog,*) ' manure_fmet= ', manure_fmet ! tboas + write(iulog,*) ' manure_fcel= ', manure_fcel ! tboas + write(iulog,*) ' manure_flig= ', manure_flig ! tboas + write(iulog,*) ' manure_injection_depth= ', manure_injection_depth ! tboas + write(iulog,*) ' manure_freq_years= ', manure_freq_years ! tboas + write(iulog,*) ' manure_apply_month= ', manure_apply_month ! tboas + write(iulog,*) ' manure_apply_day= ', manure_apply_day ! tboas + write(iulog,*) ' manure_nh4_frac= ', manure_nh4_frac ! tboas-fix + write(iulog,*) ' cn_balance_tol_c= ', cn_balance_tol_c ! tboas-fix + write(iulog,*) ' cn_balance_tol_n= ', cn_balance_tol_n ! tboas-fix + if (manure_nh4_frac < 0.0_r8 .or. manure_nh4_frac > 1.0_r8) then + call endrun(msg='ERROR: manure_nh4_frac must lie between 0 and 1') + end if + if (cn_balance_tol_c > 1.e-6_r8 .or. cn_balance_tol_n > 1.e-6_r8) then + write(iulog,*) 'WARNING: C/N mass-conservation tolerances have been widened beyond' + write(iulog,*) ' the CLM5 defaults (1e-7). Conservation errors up to the' + write(iulog,*) ' values above will NOT abort the run. Do not use for production.' + end if + if (abs(manure_fmet + manure_fcel + manure_flig - 1.0_r8) > 1.0e-6_r8) then + call endrun(msg='ERROR: manure_fmet + manure_fcel + manure_flig must equal 1.0') + end if write(iulog,*) ' use_grainproduct = ', use_grainproduct write(iulog,*) ' use_ozone = ', use_ozone write(iulog,*) ' use_snicar_frc = ', use_snicar_frc diff --git a/src/clm5/main/pftconMod.F90 b/src/clm5/main/pftconMod.F90 index 0efa2053eb..23ff2410d6 100644 --- a/src/clm5/main/pftconMod.F90 +++ b/src/clm5/main/pftconMod.F90 @@ -9,7 +9,7 @@ module pftconMod use shr_kind_mod, only : r8 => shr_kind_r8 use abortutils , only : endrun use clm_varpar , only : mxpft, numrad, ivis, inir, cft_lb, cft_ub - use clm_varctl , only : iulog, use_cndv, use_vertsoilc, use_crop + use clm_varctl , only : iulog, use_cndv, use_vertsoilc, use_crop, use_covercropping, covercrop_paramfile, use_fruittree ! ! !PUBLIC TYPES: implicit none @@ -51,8 +51,10 @@ module pftconMod integer :: nirrig_wrye ! value for winter rye (ir) integer :: ncassava ! ...and so on integer :: nirrig_cassava - integer :: ncitrus - integer :: nirrig_citrus + integer :: napple = -1 ! tboas: -1 = inactive (use_fruittree=.false.) + integer :: nirrig_apple = -1 ! tboas: -1 = inactive + integer :: ncitrus ! citrus PFT (backward compat with old param file) + integer :: nirrig_citrus ! irrigated citrus (backward compat) integer :: ncocoa integer :: nirrig_cocoa integer :: ncoffee @@ -95,6 +97,8 @@ module pftconMod integer :: nirrig_trp_corn !value for tropical corn (ir) integer :: ntrp_soybean !value for tropical soybean (rf) integer :: nirrig_trp_soybean !value for tropical soybean (ir) + integer :: ncovercrop_1 = 0 ! optional cover-crop PFT index for rotation logic + integer :: ncovercrop_2 = 0 ! optional cover-crop PFT index for rotation logic integer :: npcropmax ! value for last prognostic crop in list integer :: nc3crop ! value for generic crop (rf) integer :: nc3irrig ! value for irrigated generic crop (ir) @@ -163,9 +167,11 @@ module pftconMod real(r8), allocatable :: bfact (:) ! parameter used in CNAllocation real(r8), allocatable :: aleaff (:) ! parameter used in CNAllocation real(r8), allocatable :: arootf (:) ! parameter used in CNAllocation + real(r8), allocatable :: arootf2 (:) ! parameter used in CNAllocation real(r8), allocatable :: astemf (:) ! parameter used in CNAllocation real(r8), allocatable :: arooti (:) ! parameter used in CNAllocation real(r8), allocatable :: fleafi (:) ! parameter used in CNAllocation + real(r8), allocatable :: aleafstor (:) ! parameter used in CNAllocation real(r8), allocatable :: allconsl (:) ! parameter used in CNAllocation real(r8), allocatable :: allconss (:) ! parameter used in CNAllocation real(r8), allocatable :: ztopmx (:) ! parameter used in CNVegStructUpdate @@ -175,13 +181,21 @@ module pftconMod real(r8), allocatable :: lfemerg (:) ! parameter used in CNPhenology real(r8), allocatable :: grnfill (:) ! parameter used in CNPhenology integer , allocatable :: mxmat (:) ! parameter used in CNPhenology + real(r8), allocatable :: transplant (:) ! parameter used in CNPhenology (added by O.Dombrowski) + real(r8), allocatable :: lfmat (:) ! parameter used in CNPhenology (added by O.Dombrowski) + real(r8), allocatable :: grnrp (:) ! parameter used in CNPhenology (added by O.Dombrowski) + real(r8), allocatable :: crequ (:) ! Chill requirements for fruit tree crops (added by O.Dombrowski) + real(r8), allocatable :: crit_temp (:) ! Critical temperature to initiate leaf offset for fruit tree crops (added by O.Dombrowski) + real(r8), allocatable :: ndays_stor (:) ! Length of period for storage growth for fruit tree crops (added by O.Dombrowski) real(r8), allocatable :: mbbopt (:) ! Ball-Berry equation slope used in Photosynthesis real(r8), allocatable :: medlynslope (:) ! Medlyn equation slope used in Photosynthesis real(r8), allocatable :: medlynintercept(:) ! Medlyn equation intercept used in Photosynthesis integer , allocatable :: mnNHplantdate (:) ! minimum planting date for NorthHemisphere (YYYYMMDD) integer , allocatable :: mxNHplantdate (:) ! maximum planting date for NorthHemisphere (YYYYMMDD) + integer , allocatable :: mxNHharvdate (:) ! maximum harvest date for NorthHemishere (YYYYMMDD) (added by O.Dombrowski) integer , allocatable :: mnSHplantdate (:) ! minimum planting date for SouthHemisphere (YYYYMMDD) integer , allocatable :: mxSHplantdate (:) ! maximum planting date for SouthHemisphere (YYYYMMDD) + integer , allocatable :: mxSHharvdate (:) ! maximum harvest date for SouthHemishere (YYYYMMDD) (added by O.Dombrowski) real(r8), allocatable :: planttemp (:) ! planting temperature used in CNPhenology (K) real(r8), allocatable :: minplanttemp (:) ! mininum planting temperature used in CNPhenology (K) real(r8), allocatable :: froot_leaf (:) ! allocation parameter: new fine root C per new leaf C (gC/gC) @@ -200,11 +214,16 @@ module pftconMod real(r8), allocatable :: evergreen (:) ! binary flag for evergreen leaf habit (0 or 1) real(r8), allocatable :: stress_decid (:) ! binary flag for stress-deciduous leaf habit (0 or 1) real(r8), allocatable :: season_decid (:) ! binary flag for seasonal-deciduous leaf habit (0 or 1) + real(r8), allocatable :: perennial (:) ! binary flag for perennial crop phenology (0 or 1) (added by O.Dombrowski) + real(r8), allocatable :: mulch_pruning (:) ! binary flag for mulching or exporting pruning material (0 or 1) (added by O.Dombrowski) real(r8), allocatable :: pconv (:) ! proportion of deadstem to conversion flux real(r8), allocatable :: pprod10 (:) ! proportion of deadstem to 10-yr product pool real(r8), allocatable :: pprod100 (:) ! proportion of deadstem to 100-yr product pool real(r8), allocatable :: pprodharv10 (:) ! harvest mortality proportion of deadstem to 10-yr pool + real(r8), allocatable :: prune_fr (:) ! fraction of deadstem that is pruned (added by O.Dombrowski) + real(r8), allocatable :: nstem (:) ! stem density (#/m2) (added by O.Dombrowski) + real(r8), allocatable :: taper (:) ! tapering ratio of height:radius_breast_height (added by O.Dombrowski) ! pft paraemeters for fire code real(r8), allocatable :: cc_leaf (:) real(r8), allocatable :: cc_lstem (:) @@ -256,9 +275,12 @@ module pftconMod real(r8), allocatable :: fun_cn_flex_c (:) ! Parameter b of FUN-flexcn link code (def 80) real(r8), allocatable :: FUN_fracfixers(:) ! Fraction of C that can be used for fixation. + integer , allocatable :: covercrop (:) ! Cover crop flag ! pft parameters for dynamic root code real(r8), allocatable :: root_dmx(:) !maximum root depth + ! pft parameters for cover crop routine + !integer, allocatable :: covercrop(:) !cover crop flag contains @@ -273,6 +295,7 @@ module pftconMod end type pftcon_type type(pftcon_type), public :: pftcon ! pft type constants structure + public :: is_covercrop ! tboas integer, parameter :: pftname_len = 40 ! max length of pftname character(len=pftname_len) :: pftname(0:mxpft) ! PFT description @@ -372,9 +395,11 @@ subroutine InitAllocate (this) allocate( this%bfact (0:mxpft) ) allocate( this%aleaff (0:mxpft) ) allocate( this%arootf (0:mxpft) ) + allocate( this%arootf2 (0:mxpft) ) allocate( this%astemf (0:mxpft) ) allocate( this%arooti (0:mxpft) ) allocate( this%fleafi (0:mxpft) ) + allocate( this%aleafstor (0:mxpft) ) allocate( this%allconsl (0:mxpft) ) allocate( this%allconss (0:mxpft) ) allocate( this%ztopmx (0:mxpft) ) @@ -387,10 +412,18 @@ subroutine InitAllocate (this) allocate( this%medlynslope (0:mxpft) ) allocate( this%medlynintercept(0:mxpft) ) allocate( this%mxmat (0:mxpft) ) + allocate( this%transplant (0:mxpft) ) + allocate( this%lfmat (0:mxpft) ) + allocate( this%grnrp (0:mxpft) ) + allocate( this%crequ (0:mxpft) ) + allocate( this%crit_temp (0:mxpft) ) + allocate( this%ndays_stor (0:mxpft) ) allocate( this%mnNHplantdate (0:mxpft) ) allocate( this%mxNHplantdate (0:mxpft) ) + allocate( this%mxNHharvdate (0:mxpft) ) allocate( this%mnSHplantdate (0:mxpft) ) allocate( this%mxSHplantdate (0:mxpft) ) + allocate( this%mxSHharvdate (0:mxpft) ) allocate( this%planttemp (0:mxpft) ) allocate( this%minplanttemp (0:mxpft) ) allocate( this%froot_leaf (0:mxpft) ) @@ -409,6 +442,8 @@ subroutine InitAllocate (this) allocate( this%evergreen (0:mxpft) ) allocate( this%stress_decid (0:mxpft) ) allocate( this%season_decid (0:mxpft) ) + allocate( this%perennial (0:mxpft) ) + allocate( this%mulch_pruning (0:mxpft) ) allocate( this%dwood (0:mxpft) ) allocate( this%root_density (0:mxpft) ) allocate( this%root_radius (0:mxpft) ) @@ -416,6 +451,9 @@ subroutine InitAllocate (this) allocate( this%pprod10 (0:mxpft) ) allocate( this%pprod100 (0:mxpft) ) allocate( this%pprodharv10 (0:mxpft) ) + allocate( this%prune_fr (0:mxpft) ) + allocate( this%nstem (0:mxpft) ) + allocate( this%taper (0:mxpft) ) allocate( this%cc_leaf (0:mxpft) ) allocate( this%cc_lstem (0:mxpft) ) allocate( this%cc_dstem (0:mxpft) ) @@ -460,6 +498,7 @@ subroutine InitAllocate (this) allocate( this%fun_cn_flex_c (0:mxpft) ) allocate( this%FUN_fracfixers(0:mxpft) ) + allocate( this%covercrop (0:mxpft) ) end subroutine InitAllocate @@ -489,10 +528,12 @@ subroutine InitRead(this) integer :: dimid ! netCDF dimension id integer :: npft ! number of pfts on pft-physiology file logical :: readv ! read variable in or not + logical :: readv_taper, readv_nstem ! tboas-fix: optional woody allometry params character(len=32) :: subname = 'InitRead' ! subroutine name character(len=pftname_len) :: expected_pftnames(0:mxpft) character(len=512) :: msg !----------------------------------------------------------------------- + expected_pftnames(:) = ' ' ! tboas: init blank so unset slots skip validation ! ! Expected PFT names: The names expected on the paramfile file and the order they are expected to be in. ! NOTE: similar types are assumed to be together, first trees (ending with broadleaf_deciduous_boreal_tree @@ -500,6 +541,7 @@ subroutine InitRead(this) ! and finally crops, ending with irrigated_tropical_soybean ! DO NOT CHANGE THE ORDER -- WITHOUT MODIFYING OTHER PARTS OF THE CODE WHERE THE ORDER MATTERS! + expected_pftnames(:) = ' ' ! tboas: init blank so unset slots skip validation expected_pftnames( 0) = 'not_vegetated ' expected_pftnames( 1) = 'needleleaf_evergreen_temperate_tree' expected_pftnames( 2) = 'needleleaf_evergreen_boreal_tree ' @@ -535,8 +577,13 @@ subroutine InitRead(this) expected_pftnames(32) = 'irrigated_winter_rye ' expected_pftnames(33) = 'cassava ' expected_pftnames(34) = 'irrigated_cassava ' + if (use_fruittree) then + expected_pftnames(35) = 'apple ' + expected_pftnames(36) = 'irrigated_apple ' + else expected_pftnames(35) = 'citrus ' expected_pftnames(36) = 'irrigated_citrus ' + end if expected_pftnames(37) = 'cocoa ' expected_pftnames(38) = 'irrigated_cocoa ' expected_pftnames(39) = 'coffee ' @@ -577,8 +624,13 @@ subroutine InitRead(this) expected_pftnames(74) = 'irrigated_switchgrass ' expected_pftnames(75) = 'tropical_corn ' expected_pftnames(76) = 'irrigated_tropical_corn ' + if (use_covercropping) then + expected_pftnames(77) = 'covercrop_1 ' + expected_pftnames(78) = 'covercrop_2 ' + else expected_pftnames(77) = 'tropical_soybean ' expected_pftnames(78) = 'irrigated_tropical_soybean ' + end if ! Set specific vegetation type values @@ -739,10 +791,22 @@ subroutine InitRead(this) call ncd_io('season_decid', this%season_decid, 'read', ncid, readvar=readv, posNOTonfile=.true.) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + if (use_fruittree) then + call ncd_io('perennial', this%perennial, 'read', ncid, readvar=readv, posNOTonfile=.true.) + if ( .not. readv ) call endrun(msg=' ERROR: perennial not in param file'//errMsg(sourcefile, __LINE__)) + call ncd_io('mulch_pruning', this%mulch_pruning, 'read', ncid, readvar=readv, posNOTonfile=.true.) + if ( .not. readv ) call endrun(msg=' ERROR: mulch_pruning not in param file'//errMsg(sourcefile, __LINE__)) call ncd_io('pftpar20', this%pftpar20, 'read', ncid, readvar=readv, posNOTonfile=.true.) - if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + if ( .not. readv ) call endrun(msg=' ERROR: pftpar20 not in param file'//errMsg(sourcefile, __LINE__)) call ncd_io('pftpar28', this%pftpar28, 'read', ncid, readvar=readv, posNOTonfile=.true.) + if ( .not. readv ) call endrun(msg=' ERROR: pftpar28 not in param file'//errMsg(sourcefile, __LINE__)) + else + this%perennial(:) = 0._r8 + this%mulch_pruning(:) = 0._r8 + this%pftpar20(:) = 0._r8 + this%pftpar28(:) = 0._r8 + end if if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) call ncd_io('pftpar29', this%pftpar29, 'read', ncid, readvar=readv, posNOTonfile=.true.) @@ -850,6 +914,12 @@ subroutine InitRead(this) call ncd_io('arootf', this%arootf, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + if (use_fruittree) then + call ncd_io('arootf2', this%arootf2, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: arootf2 not in param file'//errMsg(sourcefile, __LINE__)) + else + this%arootf2(:) = 0._r8 + end if call ncd_io('astemf', this%astemf, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) @@ -858,6 +928,12 @@ subroutine InitRead(this) call ncd_io('fleafi', this%fleafi, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + if (use_fruittree) then + call ncd_io('aleafstor', this%aleafstor, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: aleafstor not in param file'//errMsg(sourcefile, __LINE__)) + else + this%aleafstor(:) = 0._r8 + end if call ncd_io('allconsl', this%allconsl, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) @@ -906,62 +982,147 @@ subroutine InitRead(this) call ncd_io('mxmat', this%mxmat, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - call ncd_io('cc_leaf', this% cc_leaf, 'read', ncid, readvar=readv) - if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + if (use_fruittree) then + call ncd_io('transplant', this%transplant, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: transplant not in param file'//errMsg(sourcefile, __LINE__)) + call ncd_io('lfmat', this%lfmat, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: lfmat not in param file'//errMsg(sourcefile, __LINE__)) + call ncd_io('grnrp', this%grnrp, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: grnrp not in param file'//errMsg(sourcefile, __LINE__)) + call ncd_io('crequ', this%crequ, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: crequ not in param file'//errMsg(sourcefile, __LINE__)) + call ncd_io('crit_temp', this%crit_temp, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: crit_temp not in param file'//errMsg(sourcefile, __LINE__)) + call ncd_io('ndays_stor', this%ndays_stor, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: ndays_stor not in param file'//errMsg(sourcefile, __LINE__)) + else + this%transplant(:) = 0._r8 + this%lfmat(:) = 0._r8 + this%grnrp(:) = 0._r8 + this%crequ(:) = 0._r8 + this%crit_temp(:) = 0._r8 + this%ndays_stor(:) = 0._r8 + end if - call ncd_io('cc_lstem', this%cc_lstem, 'read', ncid, readvar=readv) + if (use_fruittree) then + call ncd_io('prune_fr', this%prune_fr, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - call ncd_io('cc_dstem', this%cc_dstem, 'read', ncid, readvar=readv) + call ncd_io('planting_temp', this%planttemp, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - call ncd_io('cc_other', this%cc_other, 'read', ncid, readvar=readv) + call ncd_io('min_planting_temp', this%minplanttemp, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - call ncd_io('fm_leaf', this% fm_leaf, 'read', ncid, readvar=readv) + call ncd_io('min_NH_planting_date', this%mnNHplantdate, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - call ncd_io('fm_lstem', this%fm_lstem, 'read', ncid, readvar=readv) + call ncd_io('min_SH_planting_date', this%mnSHplantdate, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - call ncd_io('fm_dstem', this%fm_dstem, 'read', ncid, readvar=readv) + call ncd_io('max_NH_planting_date', this%mxNHplantdate, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - call ncd_io('fm_other', this%fm_other, 'read', ncid, readvar=readv) + call ncd_io('max_NH_harvest_date', this%mxNHharvdate, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + + call ncd_io('max_SH_harvest_date', this%mxSHharvdate, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + call ncd_io('max_SH_planting_date', this%mxSHplantdate, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + else + this%prune_fr(:) = 0._r8 + end if - call ncd_io('fm_root', this% fm_root, 'read', ncid, readvar=readv) + !-------------------------------------------------------------------------- + ! tboas-fix: fire behaviour and woody allometry are NOT fruit-tree features. + ! These parameters used to be read inside the use_fruittree block and zeroed + ! in its else branch, so with the default use_fruittree = .false. every + ! combustion completeness and fire mortality parameter was identically zero + ! (fire silently disabled), and taper = nstem = 0 made the woody height + ! allometry + ! htop = (3*deadstemc*taper^2 / (pi*nstem*dwood))^(1/3) + ! evaluate 0/0 for every tree and shrub. They are read unconditionally now, + ! as in the base model. + !-------------------------------------------------------------------------- + call ncd_io('cc_leaf', this%cc_leaf, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - - call ncd_io('fm_lroot', this%fm_lroot, 'read', ncid, readvar=readv) + call ncd_io('cc_lstem', this%cc_lstem, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - - call ncd_io('fm_droot', this%fm_droot, 'read', ncid, readvar=readv) + call ncd_io('cc_dstem', this%cc_dstem, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - - call ncd_io('fsr_pft', this% fsr_pft, 'read', ncid, readvar=readv) + call ncd_io('cc_other', this%cc_other, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - - call ncd_io('fd_pft', this% fd_pft, 'read', ncid, readvar=readv) + call ncd_io('fm_leaf', this%fm_leaf, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - - call ncd_io('planting_temp', this%planttemp, 'read', ncid, readvar=readv) + call ncd_io('fm_lstem', this%fm_lstem, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - - call ncd_io('min_planting_temp', this%minplanttemp, 'read', ncid, readvar=readv) + call ncd_io('fm_dstem', this%fm_dstem, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - - call ncd_io('min_NH_planting_date', this%mnNHplantdate, 'read', ncid, readvar=readv) + call ncd_io('fm_other', this%fm_other, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - - call ncd_io('min_SH_planting_date', this%mnSHplantdate, 'read', ncid, readvar=readv) + call ncd_io('fm_root', this%fm_root, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - - call ncd_io('max_NH_planting_date', this%mxNHplantdate, 'read', ncid, readvar=readv) + call ncd_io('fm_lroot', this%fm_lroot, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + call ncd_io('fm_droot', this%fm_droot, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + call ncd_io('fsr_pft', this%fsr_pft, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + call ncd_io('fd_pft', this%fd_pft, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) - call ncd_io('max_SH_planting_date', this%mxSHplantdate, 'read', ncid, readvar=readv) + ! taper and nstem are optional: the fruit-tree parameter files supply them, + ! the standard CLM5 file does not. The fallback is applied further down, + ! once the shrub PFT indices have been resolved from pftname. + call ncd_io('taper', this%taper, 'read', ncid, readvar=readv_taper) + call ncd_io('nstem', this%nstem, 'read', ncid, readvar=readv_nstem) + ! Read crop planting/harvest params for all crops (not fruittree-specific) --- tboas + call ncd_io('planting_temp', this%planttemp, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + call ncd_io('min_planting_temp', this%minplanttemp, 'read', ncid, readvar=readv) if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + call ncd_io('min_NH_planting_date', this%mnNHplantdate, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + call ncd_io('min_SH_planting_date', this%mnSHplantdate, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + call ncd_io('max_NH_planting_date', this%mxNHplantdate, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + call ncd_io('max_SH_planting_date', this%mxSHplantdate, 'read', ncid, readvar=readv) + if ( .not. readv ) call endrun(msg=' ERROR: error in reading in pft data'//errMsg(sourcefile, __LINE__)) + ! harvest dates only in apple param file --- tboas + call ncd_io('max_NH_harvest_date', this%mxNHharvdate, 'read', ncid, readvar=readv) + if ( .not. readv ) this%mxNHharvdate(:) = 1231 ! default: Dec 31 + call ncd_io('max_SH_harvest_date', this%mxSHharvdate, 'read', ncid, readvar=readv) + if ( .not. readv ) this%mxSHharvdate(:) = 631 ! default: Jun 30 (SH) + +!Cover crop flag read-in --- tboas + ! Default: zero array - backward compatible with standard 79-PFT param file. + ! If use_covercropping=.true.: open covercrop_paramfile separately and read + ! covercrop flag from there. Standard paramfile is never touched. + this%covercrop(:) = 0._r8 + if (use_covercropping) then + if (trim(covercrop_paramfile) == '' .or. & + trim(covercrop_paramfile) == ' ') then + call endrun(msg=' ERROR: use_covercropping=.true. but covercrop_paramfile' // & + ' is not set in lnd_in. Add: covercrop_paramfile = /path/to/file.nc' // & + errMsg(sourcefile, __LINE__)) + end if + if (masterproc) write(iulog,*) & + 'pftconMod: reading covercrop PFT params from: ', trim(covercrop_paramfile) + block + type(file_desc_t) :: ncid_cc + character(len=256) :: locfn_cc + call getfil(covercrop_paramfile, locfn_cc, 0) + call ncd_pio_openfile(ncid_cc, trim(locfn_cc), 0) + call ncd_io('covercrop', this%covercrop, 'read', ncid_cc, readvar=readv) + if (.not. readv) call endrun( & + msg=' ERROR: variable covercrop not found in covercrop_paramfile' // & + errMsg(sourcefile, __LINE__)) + if (masterproc) write(iulog,*) 'pftconMod: covercrop flag read OK' + call ncd_pio_closefile(ncid_cc) + end block + end if ! ! Constants @@ -1009,7 +1170,8 @@ subroutine InitRead(this) do i = 0, mxpft if (.not. use_fates)then - if ( trim(adjustl(pftname(i))) /= trim(expected_pftnames(i)) )then + if ( trim(expected_pftnames(i)) /= ' ' .and. & + trim(adjustl(pftname(i))) /= trim(expected_pftnames(i)) )then write(iulog,*)'pftconrd: pftname is NOT what is expected, name = ', & trim(pftname(i)), ', expected name = ', trim(expected_pftnames(i)) call endrun(msg='pftconrd: bad name for pft on paramfile dataset'//errMsg(sourcefile, __LINE__)) @@ -1051,8 +1213,13 @@ subroutine InitRead(this) if ( trim(pftname(i)) == 'irrigated_winter_rye' ) nirrig_wrye = i if ( trim(pftname(i)) == 'cassava' ) ncassava = i if ( trim(pftname(i)) == 'irrigated_cassava' ) nirrig_cassava = i + if (use_fruittree) then + if ( trim(pftname(i)) == 'apple' ) napple = i + if ( trim(pftname(i)) == 'irrigated_apple') nirrig_apple = i + else if ( trim(pftname(i)) == 'citrus' ) ncitrus = i if ( trim(pftname(i)) == 'irrigated_citrus' ) nirrig_citrus = i + end if if ( trim(pftname(i)) == 'cocoa' ) ncocoa = i if ( trim(pftname(i)) == 'irrigated_cocoa' ) nirrig_cocoa = i if ( trim(pftname(i)) == 'coffee' ) ncoffee = i @@ -1095,11 +1262,30 @@ subroutine InitRead(this) if ( trim(pftname(i)) == 'irrigated_tropical_corn' ) nirrig_trp_corn = i if ( trim(pftname(i)) == 'tropical_soybean' ) ntrp_soybean = i if ( trim(pftname(i)) == 'irrigated_tropical_soybean' ) nirrig_trp_soybean = i + if (use_covercropping) then + if ( trim(pftname(i)) == 'covercrop_1' ) ncovercrop_1 = i + if ( trim(pftname(i)) == 'covercrop_2' ) ncovercrop_2 = i + end if end do ntree = nbrdlf_dcd_brl_tree ! value for last type of tree npcropmin = ntmp_corn ! first prognostic crop npcropmax = mxpft ! last prognostic crop in list + ! tboas-fix: deferred fallback for the optional woody-allometry parameters. + ! Placed here because it needs nbrdlf_evr_shrub / nbrdlf_dcd_brl_shrub, which + ! are only resolved by the pftname loop above. Values are the ones the base + ! model hardwired: taper 200, shrubs 10, stocking 1000 stems per hectare. + if ( .not. readv_taper ) then + this%taper(:) = 200._r8 + this%taper(nbrdlf_evr_shrub:nbrdlf_dcd_brl_shrub) = 10._r8 + if (masterproc) write(iulog,*) trim(subname)// & + ': taper absent from the parameter file - using base-model values (200, shrubs 10)' + end if + if ( .not. readv_nstem ) then + this%nstem(:) = 0.1_r8 + if (masterproc) write(iulog,*) trim(subname)// & + ': nstem absent from the parameter file - using base-model stocking (1000 ha-1)' + end if call this%set_is_pft_known_to_model() call this%set_num_cfts_known_to_model() @@ -1125,6 +1311,7 @@ subroutine InitRead(this) i == nirrig_barley .or. i == nirrig_wbarley .or. & i == nirrig_rye .or. i == nirrig_wrye .or. & i == nirrig_cassava .or. & + i == nirrig_apple .or. & i == nirrig_citrus .or. & i == nirrig_cocoa .or. i == nirrig_coffee .or. & i == nirrig_cotton .or. & @@ -1178,12 +1365,16 @@ subroutine set_is_pft_known_to_model(this) ! Set is_pft_known_to_model based on mergetoclmpft ! ! !USES: + use shr_log_mod , only : errMsg => shr_log_errMsg ! tboas-fix + use spmdMod , only : masterproc ! tboas-fix ! ! !ARGUMENTS: class(pftcon_type), intent(inout) :: this ! ! !LOCAL VARIABLES: integer :: m, merge_type + integer :: extra_known_pft(16) ! tboas-fix: PFTs marked known by name, not by literal index + character(len=512) :: msg ! tboas-fix character(len=*), parameter :: subname = 'set_is_pft_known_to_model' !----------------------------------------------------------------------- @@ -1194,6 +1385,58 @@ subroutine set_is_pft_known_to_model(this) ! so we can't handle it in the general loop below. But CLM always uses type 0, so ! handle it specially here. this%is_pft_known_to_model(0) = .true. + !-------------------------------------------------------------------------- + ! tboas-fix: the crops added by this fork have no usable mergetoclmpft entry + ! in the parameter file, so they must be marked known explicitly. This used + ! to be a list of literal indices: + ! 27, 28, 55, 56, 59, 60, 65, 66, 78, 79 + ! which had two problems. + ! + ! 1. mxpft = 78 and is_pft_known_to_model is allocated (0:mxpft), so + ! element 79 was an OUT-OF-BOUNDS WRITE. A DEBUG build with -fcheck=bounds + ! traps it; a RELEASE build silently corrupts whatever follows the array. + ! 2. Per expected_pftnames in InitRead, covercrop_1/covercrop_2 sit at 77/78, + ! not 78/79, so the intended cover-crop pair was off by one: index 78 was + ! covercrop_2 and covercrop_1 at 77 was never marked at all. + ! + ! The indices are now resolved by name through the same n variables that + ! InitRead fills, which is the idiom already used elsewhere in this module + ! (see 'apple' and 'covercrop_1'). This keeps working when the parameter file + ! ordering changes -- e.g. the 81-PFT covercrop_paramfile versus the standard + ! file -- instead of silently marking the wrong slots. + ! + ! The list covers every CFT used in the German rotations: maize, spring + ! barley, winter barley, winter rye, potatoes, rapeseed, sugar beet (each + ! rainfed + irrigated) and the two cover crops. Extend it here when a new + ! CFT enters a rotation, using the n name-resolved index. + !-------------------------------------------------------------------------- + extra_known_pft = (/ ntmp_corn, nirrig_tmp_corn, & ! maize + nbarley, nirrig_barley, & ! spring barley + nwbarley, nirrig_wbarley, & ! winter barley + nwrye, nirrig_wrye, & ! winter rye + npotatoes, nirrig_potatoes, & + nrapeseed, nirrig_rapeseed, & + nsugarbeet, nirrig_sugarbeet, & + ncovercrop_1, ncovercrop_2 /) + + do m = 1, size(extra_known_pft) + ! index 0 means the name was not found in this parameter file (the + ! cover-crop PFTs only exist when use_covercropping = .true.) + if (extra_known_pft(m) <= 0) cycle + ! every entry above is a prognostic crop; anything else means the name + ! lookup in InitRead did not run or the parameter file is inconsistent + if (extra_known_pft(m) > mxpft .or. extra_known_pft(m) < npcropmin) then + write(msg,'(a,i0,a,i0,a,i0,a)') trim(subname)//': resolved PFT index ', & + extra_known_pft(m), ' is outside the crop range [', npcropmin, & + ',', mxpft, ']. The parameter file does not match this build.' + call endrun(msg=trim(msg)//errMsg(sourcefile, __LINE__)) + end if + this%is_pft_known_to_model(extra_known_pft(m)) = .true. + if (masterproc) then + write(iulog,*) trim(subname)//': marking PFT known to model: index ', & + extra_known_pft(m), ' name ', trim(pftname(extra_known_pft(m))) + end if + end do ! NOTE(wjs, 2015-10-04) Currently, mergetoclmpft is only used for crop types. ! However, we handle it more generally here (treating ALL pft types), in case its use @@ -1287,9 +1530,11 @@ subroutine Clean(this) deallocate( this%bfact) deallocate( this%aleaff) deallocate( this%arootf) + deallocate( this%arootf2) deallocate( this%astemf) deallocate( this%arooti) deallocate( this%fleafi) + deallocate( this%aleafstor) deallocate( this%allconsl) deallocate( this%allconss) deallocate( this%ztopmx) @@ -1302,10 +1547,21 @@ subroutine Clean(this) deallocate( this%medlynslope) deallocate( this%medlynintercept) deallocate( this%mxmat) + deallocate( this%transplant) + deallocate( this%lfmat) + deallocate( this%grnrp) + deallocate( this%crequ) + deallocate( this%crit_temp) + deallocate( this%ndays_stor) + deallocate( this%prune_fr) + deallocate( this%nstem) + deallocate( this%taper) deallocate( this%mnNHplantdate) deallocate( this%mxNHplantdate) + deallocate( this%mxNHharvdate) deallocate( this%mnSHplantdate) deallocate( this%mxSHplantdate) + deallocate( this%mxSHharvdate) deallocate( this%planttemp) deallocate( this%minplanttemp) deallocate( this%froot_leaf) @@ -1324,6 +1580,8 @@ subroutine Clean(this) deallocate( this%evergreen) deallocate( this%stress_decid) deallocate( this%season_decid) + deallocate( this%perennial) + deallocate( this%mulch_pruning) deallocate( this%dwood) deallocate( this%root_density) deallocate( this%root_radius) @@ -1374,8 +1632,23 @@ subroutine Clean(this) deallocate( this%fun_cn_flex_b) deallocate( this%fun_cn_flex_c) deallocate( this%FUN_fracfixers) + deallocate( this%covercrop) end subroutine Clean + !----------------------------------------------------------------------- + logical function is_covercrop(ivt) + ! tboas: true if this PFT is a cover crop. Used instead of mutating the + ! global use_grainproduct flag, which is a namelist setting and must not + ! be rewritten per patch. + integer, intent(in) :: ivt + is_covercrop = .false. + if (ncovercrop_1 > 0) then + if (ivt == ncovercrop_1) is_covercrop = .true. + end if + if (ncovercrop_2 > 0) then + if (ivt == ncovercrop_2) is_covercrop = .true. + end if + end function is_covercrop end module pftconMod