Skip to content

Commit

Permalink
Pull k-loop: compute_Zprime
Browse files Browse the repository at this point in the history
Loop over zoo_ind, use vector notation for k dimension. Also, compute
f_loss_thres with min(max(..., c0), c1) rather than where statements (in
both compute_Zprime and compute_Pprime, which had been vectorized in a
previous commit)
  • Loading branch information
mnlevy1981 committed Oct 19, 2018
1 parent 1a059c1 commit e4680ae
Showing 1 changed file with 11 additions and 27 deletions.
38 changes: 11 additions & 27 deletions src/marbl_interior_tendency_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1248,13 +1248,7 @@ subroutine compute_Pprime(km, zt, autotroph_local, temperature, Pprime)
!-----------------------------------------------------------------------

! calculate the loss threshold interpolation factor
where (zt >= thres_z2_auto)
f_loss_thres = c0
else where (zt > thres_z1_auto)
f_loss_thres = (thres_z2_auto - zt)/(thres_z2_auto - thres_z1_auto)
else where
f_loss_thres = c1
end where
f_loss_thres(:) = min(max((thres_z2_auto - zt(:))/(thres_z2_auto - thres_z1_auto), c0), c1)

! Compute Pprime for all autotrophs, used for loss terms
do auto_ind = 1, autotroph_cnt
Expand Down Expand Up @@ -1685,35 +1679,25 @@ subroutine compute_Zprime(km, zt, zooC, Tfunc, zooplankton_derived_terms)
!-----------------------------------------------------------------------
! local variables
!-----------------------------------------------------------------------
integer :: k, zoo_ind
real(r8) :: f_loss_thres
real(r8) :: C_loss_thres
integer :: zoo_ind
real(r8) :: f_loss_thres(km)
real(r8) :: C_loss_thres(km)
!-----------------------------------------------------------------------

associate( &
Zprime => zooplankton_derived_terms%Zprime(:,:), & !(zooplankton_cnt)
zoo_loss => zooplankton_derived_terms%zoo_loss(:,:) & !(zooplankton_cnt) output
)

do k=1,km
! calculate the loss threshold interpolation factor
if (zt(k) > thres_z1_zoo) then
if (zt(k) < thres_z2_zoo) then
f_loss_thres = (thres_z2_zoo - zt(k))/(thres_z2_zoo - thres_z1_zoo)
else
f_loss_thres = c0
endif
else
f_loss_thres = c1
endif
! calculate the loss threshold interpolation factor
f_loss_thres(:) = min(max((thres_z2_zoo - zt(:))/(thres_z2_zoo - thres_z1_zoo), c0), c1)

do zoo_ind = 1, zooplankton_cnt
C_loss_thres = f_loss_thres * zooplankton_settings(zoo_ind)%loss_thres
Zprime(zoo_ind,k) = max(zooC(zoo_ind,k) - C_loss_thres, c0)
do zoo_ind = 1, zooplankton_cnt
C_loss_thres(:) = f_loss_thres(:) * zooplankton_settings(zoo_ind)%loss_thres
Zprime(zoo_ind,:) = max(zooC(zoo_ind,:) - C_loss_thres, c0)

zoo_loss(zoo_ind,k) = (zooplankton_settings(zoo_ind)%z_mort2_0 * Zprime(zoo_ind,k)**1.5_r8 &
+ zooplankton_settings(zoo_ind)%z_mort_0 * Zprime(zoo_ind,k)) * Tfunc(k)
end do
zoo_loss(zoo_ind,:) = (zooplankton_settings(zoo_ind)%z_mort2_0 * Zprime(zoo_ind,:)**1.5_r8 &
+ zooplankton_settings(zoo_ind)%z_mort_0 * Zprime(zoo_ind,:)) * Tfunc(:)
end do

end associate
Expand Down

0 comments on commit e4680ae

Please sign in to comment.