diff --git a/src/soilbiogeochem/TillageMod.F90 b/src/soilbiogeochem/TillageMod.F90 index f35dff5bab..0ce3c4f96e 100644 --- a/src/soilbiogeochem/TillageMod.F90 +++ b/src/soilbiogeochem/TillageMod.F90 @@ -247,29 +247,35 @@ subroutine get_tillage_multipliers(tillage_mults, idop) end subroutine get_tillage_multipliers - function get_fraction_tilled(layer_top, layer_thickness, max_tillage_depth_gft) result(fraction_tilled) + function get_fraction_tilled(layer_bottom, layer_thickness, max_tillage_depth_gft) result(fraction_tilled) ! !ARGUMENTS - real(r8), intent(in) :: layer_top ! Soil layer interface depth (zisoi) + real(r8), intent(in) :: layer_bottom ! Soil layer interface (between j and j+1) depth (zisoi) real(r8), intent(in) :: layer_thickness ! Soil layer thickness (dzsoi_decomp) real(r8) :: max_tillage_depth_gft ! Maximum tillage depth + ! !LOCAL VARIABLES + real(r8) :: layer_top ! !RESULT real(r8) :: fraction_tilled ! Fraction of this layer that's within the tillage depth + ! If the top of the layer is below the max tillage depth, do not till. + layer_top = layer_bottom - layer_thickness if (layer_top > max_tillage_depth_gft) then fraction_tilled = 0._r8 return end if + ! Handle zero-thickness layers. This may not be necessary. if (layer_thickness == 0._r8) then - if (layer_top <= max_tillage_depth_gft) then + if (layer_bottom <= max_tillage_depth_gft) then fraction_tilled = 1._r8 else fraction_tilled = 0._r8 end if - else - fraction_tilled = max(0._r8, min(1._r8, (max_tillage_depth_gft - layer_top) / layer_thickness)) + return end if + fraction_tilled = max(0._r8, min(1._r8, (max_tillage_depth_gft - layer_top) / layer_thickness)) + end function get_fraction_tilled diff --git a/src/soilbiogeochem/test/tillage_test/test_tillage.pf b/src/soilbiogeochem/test/tillage_test/test_tillage.pf index 710541fd3d..77721aedd4 100644 --- a/src/soilbiogeochem/test/tillage_test/test_tillage.pf +++ b/src/soilbiogeochem/test/tillage_test/test_tillage.pf @@ -23,12 +23,12 @@ contains integer :: j ! Soil layer real(r8), parameter :: max_tillage_depth = 0.21_r8 - zisoi = [0._r8, 0.01_r8, 0.05_r8, 0.1_r8, 0.5_r8] - dzsoi_decomp = [zisoi(2) - zisoi(1), & + zisoi = [0.01_r8, 0.05_r8, 0.1_r8, 0.5_r8, 1._r8] + dzsoi_decomp = [zisoi(1) - 0._r8, & + zisoi(2) - zisoi(1), & zisoi(3) - zisoi(2), & zisoi(4) - zisoi(3), & - zisoi(5) - zisoi(4), & - 0.5_r8] + zisoi(5) - zisoi(4)] @assertEqual(1._r8, get_fraction_tilled(zisoi(1), dzsoi_decomp(1), max_tillage_depth)) @assertEqual(1._r8, get_fraction_tilled(zisoi(2), dzsoi_decomp(2), max_tillage_depth))