@@ -3783,11 +3783,34 @@ subroutine WetRemovalUFS( km, klid, bin_ind, cdt, aero_type, kin, grav, radius,
37833783 do j = jl, ju
37843784 do i = il, iu
37853785 ! -- compute column quantities
3786- do k = ktop, kbot
3786+ ! ---- TOP LAYER (k = 1) ----
3787+ k = ktop
3788+ km1 = k ! prevents k=0 indexing
3789+
3790+ ! layer pressure thickness (use k and k+1)
3791+ delp = ple(i,j,k+1 ) - ple(i,j,k)
3792+ dpog(k) = delp / grav
3793+ delz = dpog(k) / rhoa(i,j,k)
3794+ delz_cm(k) = delz * m_to_cm
3795+
3796+ ! no precipitation entering from above
3797+ qq(k) = 0.0
3798+ pdwn(k) = 0.0
3799+
3800+ ! initialize aerosol column mass and wet-deposition accumulator
3801+ conc(k) = aerosol(i,j,k) * dpog(k)
3802+ dconc(k) = 0.0
3803+ ! ---- REMAINING LAYERS (k = 2 .. km) ----
3804+ do k = ktop+1 , kbot
37873805 km1 = k - 1
37883806
37893807 ! -- initialize auxiliary arrays
3790- delp = ple(i,j,k) - ple(i,j,km1)
3808+ if (k < kbot) then
3809+ delp = ple(i,j,k+1 ) - ple(i,j,k)
3810+ else
3811+ delp = ple(i,j,k) - ple(i,j,k-1 ) ! bottom-most layer
3812+ end if
3813+
37913814 dpog(k) = delp / grav
37923815 delz = dpog(k) / rhoa(i,j,k) ! thickness of layer [m]
37933816 delz_cm(k) = delz * m_to_cm ! thickness of layer [cm]
@@ -3816,7 +3839,11 @@ subroutine WetRemovalUFS( km, klid, bin_ind, cdt, aero_type, kin, grav, radius,
38163839 dconc(k) = zero
38173840
38183841 ! -- compute mixing ratio of saturated water vapour over ice
3819- pres = 0.5 * ( ple(i,j,km1) + ple(i,j,k) )
3842+ if (k < kbot) then
3843+ pres = 0.5 * ( ple(i,j,k) + ple(i,j,k+1 ) )
3844+ else
3845+ pres = 0.5 * ( ple(i,j,k-1 ) + ple(i,j,k) )
3846+ end if
38203847 c_h2o(k) = 10._dp ** (- 2663.5_dp / tmpu(i,j,k) + 12.537_dp ) / pres
38213848
38223849 ! -- estimate cloud ice and liquid water content
@@ -3836,18 +3863,25 @@ subroutine WetRemovalUFS( km, klid, bin_ind, cdt, aero_type, kin, grav, radius,
38363863 if (qq(k) > qq_thr) then
38373864 ! -- compute rainout rate
38383865 k_rain = k_min + qq(k) / cwc
3839- f = qq(k) / ( k_rain * cwc )
3866+ ! f = qq(k) / ( k_rain * cwc )
3867+
3868+ ! -- Safety check: ensure denominator is positive
3869+ if (k_rain * cwc > 1.0e-12 ) then
3870+ f = qq(k) / ( k_rain * cwc )
3871+ f = min (one, max (zero, f)) ! Bound f between 0 and 1
3872+ else
3873+ f = zero
3874+ end if
38403875
38413876 call rainout( kin, rainout_eff, f, k_rain, dt, tmpu(i,j,k), delz_cm(k), &
38423877 pdwn(k), c_h2o(k), cldice(k), cldliq(k), spc, lossfrac )
38433878
38443879 ! -- compute and apply effective loss fraction
38453880 wetloss = lossfrac * conc(k)
3881+ wetloss = max (zero, min (wetloss, conc(k)))
38463882 conc(k) = conc(k) - wetloss
38473883 dconc(k) = wetloss
38483884
3849- ! -- add to total column deposition flux
3850- dconc(k) = wetloss
38513885 end if
38523886
38533887 ! -- middle layers
@@ -3860,6 +3894,7 @@ subroutine WetRemovalUFS( km, klid, bin_ind, cdt, aero_type, kin, grav, radius,
38603894 if (qq(k) > qq_thr) then
38613895 k_rain = k_min + qq(k) / cwc
38623896 f_prime = qq(k) / ( k_rain * cwc )
3897+ f_prime = min (one, max (zero, f_prime))
38633898 end if
38643899
38653900 ! -- account for precipitation flux
@@ -3882,6 +3917,13 @@ subroutine WetRemovalUFS( km, klid, bin_ind, cdt, aero_type, kin, grav, radius,
38823917 wetloss = lossfrac * conc(k)
38833918 conc(k) = conc(k) - wetloss
38843919 dconc(k) = dconc(km1) + wetloss
3920+ ! If precipitation evaporates significantly before reaching next level
3921+ if (k < kbot .and. pdwn(k+1 ) < 0.5 * pdwn(k) .and. pdwn(k) > pdwn_thr) then
3922+ ! Partial re-evaporation anticipated
3923+ alpha = (pdwn(k) - pdwn(k+1 )) / pdwn(k)
3924+ alpha = min (one, max (zero, alpha))
3925+ ! This will be handled in next level, just note it here if needed
3926+ end if
38853927 end if
38863928 if ( f_washout > zero ) then
38873929 if ( f_rainout > zero ) then
@@ -3897,11 +3939,21 @@ subroutine WetRemovalUFS( km, klid, bin_ind, cdt, aero_type, kin, grav, radius,
38973939 if ( kin ) then
38983940 ! -- adjust loss fraction for aerosols
38993941 lossfrac = lossfrac * f_washout / f
3900-
3901- alpha = abs ( qq(k) ) * delz_cm(k) / pdwn(km1)
3902- alpha = min ( one, alpha )
3903- gain = 0.5 * alpha * dconc(km1)
3904- wetloss = conc(k) * lossfrac - gain
3942+ gain = zero
3943+ if ( f_rainout > zero ) then
3944+ ! Washout from precipitation entering from top
3945+ if (pdwn(km1) > pdwn_thr) then
3946+ alpha = abs ( qq(k) ) * delz_cm(k) / pdwn(km1)
3947+ alpha = min ( one, alpha )
3948+ gain = 0.5 * alpha * dconc(km1)
3949+ end if
3950+ else
3951+ ! Washout from precipitation leaving through bottom
3952+ ! No re-evaporation gain in this case (precipitation already present)
3953+ gain = zero
3954+ end if
3955+ wetloss = conc(k) * lossfrac - gain
3956+ wetloss = max (zero, wetloss) ! Prevent negative loss
39053957 ! -- skip sulfate
39063958 else
39073959 washed = f_washout * conc(k) + dconc(km1)
@@ -3915,16 +3967,28 @@ subroutine WetRemovalUFS( km, klid, bin_ind, cdt, aero_type, kin, grav, radius,
39153967 end if
39163968 end if
39173969 else
3918- ! -- complete resuspension of rainout + washout from level above
3919- conc(k) = conc(k) + dconc(km1)
3920- end if
3921-
3970+ !- - complete resuspension of rainout + washout from level above
3971+ ! conc(k) = conc(k) + dconc(km1)
3972+ ! Check for actual evaporation: negative formation rate OR decreasing flux
3973+ ! Re-evaporation only if precip enters the layer and flux decreases
3974+ if ( (pdwn(km1) > 1.0e-20 ) .and. (pdwn(k) < pdwn(km1)) ) then
3975+ alpha = max (zero, min (one, (pdwn(km1) - pdwn(k)) / pdwn(km1)))
3976+ conc(k) = conc(k) + alpha * dconc(km1)
3977+ dconc(k) = (one - alpha) * dconc(km1)
3978+ else
3979+ ! No evaporation here: just carry scavenged mass downward
3980+ dconc(k) = dconc(km1)
3981+ ! conc(k) unchanged
3982+ end if
3983+ end if
3984+
39223985 ftop = f
39233986
39243987 end do
39253988
39263989 ! -- surface level
39273990 k = kbot
3991+ km1= k-1
39283992 if (pdwn(km1) > pdwn_thr) then
39293993 f = ftop
39303994 if ( f > zero ) then
@@ -3948,7 +4012,7 @@ subroutine WetRemovalUFS( km, klid, bin_ind, cdt, aero_type, kin, grav, radius,
39484012 aerosol(i,j,k) = conc(k) / dpog(k)
39494013 end do
39504014
3951- if (associated (fluxout)) fluxout(i,j,bin_ind) = sum ( dconc) / dt
4015+ if (associated (fluxout)) fluxout(i,j,bin_ind) = dconc(kbot ) / dt
39524016
39534017 end do
39544018 end do
0 commit comments