Skip to content

Commit

Permalink
get_fraction_tilled() receives layer_bottom, not layer_top.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsrabin committed Sep 18, 2023
1 parent c0d8784 commit 77d0c7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/soilbiogeochem/TillageMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 4 additions & 4 deletions src/soilbiogeochem/test/tillage_test/test_tillage.pf
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 77d0c7d

Please sign in to comment.