Skip to content

Commit

Permalink
Merge pull request ESCOMP#651 from ekluzek/newsrfdataAntwetlndsfix
Browse files Browse the repository at this point in the history
New datasets and capability to run CMIP6 future scenarios...
  • Loading branch information
ekluzek authored Mar 12, 2019
2 parents eb12aeb + 3f6d1b8 commit 53807f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 61 deletions.
70 changes: 10 additions & 60 deletions src/biogeochem/ch4Mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ module ch4Mod
real(r8), pointer, private :: qflx_surf_lag_col (:) ! col time-lagged surface runoff (mm H2O /s)
real(r8), pointer, private :: finundated_lag_col (:) ! col time-lagged fractional inundated area
real(r8), pointer, private :: layer_sat_lag_col (:,:) ! col Lagged saturation status of soil layer in the unsaturated zone (1 = sat)
real(r8), pointer, private :: zwt0_col (:) ! col coefficient for determining finundated (m)
real(r8), pointer, private :: f0_col (:) ! col maximum inundated fraction for a gridcell (for methane code)
real(r8), pointer, private :: p3_col (:) ! col coefficient for determining finundated (m)
real(r8), pointer, private :: pH_col (:) ! col pH values for methane production
!
real(r8), pointer, private :: dyn_ch4bal_adjustments_col (:) ! adjustments to each column made in this timestep via dynamic column area adjustments (only makes sense at the column-level: meaningless if averaged to the gridcell-level) (g C / m^2)
Expand Down Expand Up @@ -316,9 +313,6 @@ subroutine InitAllocate(this, bounds)
allocate(this%qflx_surf_lag_col (begc:endc)) ; this%qflx_surf_lag_col (:) = nan
allocate(this%finundated_lag_col (begc:endc)) ; this%finundated_lag_col (:) = nan
allocate(this%layer_sat_lag_col (begc:endc,1:nlevgrnd)) ; this%layer_sat_lag_col (:,:) = nan
allocate(this%zwt0_col (begc:endc)) ; this%zwt0_col (:) = nan
allocate(this%f0_col (begc:endc)) ; this%f0_col (:) = nan
allocate(this%p3_col (begc:endc)) ; this%p3_col (:) = nan
allocate(this%pH_col (begc:endc)) ; this%pH_col (:) = nan
allocate(this%ch4_surf_flux_tot_col (begc:endc)) ; this%ch4_surf_flux_tot_col (:) = nan
allocate(this%dyn_ch4bal_adjustments_col (begc:endc)) ; this%dyn_ch4bal_adjustments_col (:) = nan
Expand Down Expand Up @@ -752,9 +746,6 @@ subroutine InitCold(this, bounds, cellorg_col, fsurdat)
! !LOCAL VARIABLES:
integer :: j ,g, l,c,p ! indices
type(file_desc_t) :: ncid ! netcdf id
real(r8) ,pointer :: zwt0_in (:) ! read in - zwt0
real(r8) ,pointer :: f0_in (:) ! read in - f0
real(r8) ,pointer :: p3_in (:) ! read in - p3
real(r8) ,pointer :: pH_in (:) ! read in - pH
character(len=256) :: locfn ! local file name
logical :: readvar ! If read variable from file or not
Expand All @@ -766,32 +757,12 @@ subroutine InitCold(this, bounds, cellorg_col, fsurdat)
! Initialize time constant variables
!----------------------------------------

allocate(zwt0_in (bounds%begg:bounds%endg))
allocate(f0_in (bounds%begg:bounds%endg))
allocate(p3_in (bounds%begg:bounds%endg))
if (usephfact) allocate(ph_in(bounds%begg:bounds%endg))

! Methane code parameters for finundated

call getfil( fsurdat, locfn, 0 )
call ncd_pio_openfile (ncid, trim(locfn), 0)
if ( finundation_mtd == finundation_mtd_zwt_inversion ) then
call ncd_io(ncid=ncid, varname='ZWT0', flag='read', data=zwt0_in, dim1name=grlnd, readvar=readvar)
if (.not. readvar) then
call endrun(msg=' ERROR: Running with CH4 Model but ZWT0 not on surfdata file'//&
errMsg(sourcefile, __LINE__))
end if
call ncd_io(ncid=ncid, varname='F0', flag='read', data=f0_in, dim1name=grlnd, readvar=readvar)
if (.not. readvar) then
call endrun(msg=' ERROR: Running with CH4 Model but F0 not on surfdata file'//&
errMsg(sourcefile, __LINE__))
end if
call ncd_io(ncid=ncid, varname='P3', flag='read', data=p3_in, dim1name=grlnd, readvar=readvar)
if (.not. readvar) then
call endrun(msg=' ERROR: Running with CH4 Model but P3 not on surfdata file'//&
errMsg(sourcefile, __LINE__))
end if
end if

! pH factor for methane model
if (usephfact) then
Expand All @@ -803,18 +774,14 @@ subroutine InitCold(this, bounds, cellorg_col, fsurdat)
end if
call ncd_pio_closefile(ncid)

do c = bounds%begc, bounds%endc
g = col%gridcell(c)
if ( usephfact )then
do c = bounds%begc, bounds%endc
g = col%gridcell(c)

if (finundation_mtd == finundation_mtd_ZWT_inversion ) then
this%zwt0_col(c) = zwt0_in(g)
this%f0_col(c) = f0_in(g)
this%p3_col(c) = p3_in(g)
end if
if (usephfact) this%pH_col(c) = pH_in(g)
end do
this%pH_col(c) = pH_in(g)
end do
end if

deallocate(zwt0_in, f0_in, p3_in)
if (usephfact) deallocate(pH_in)

!----------------------------------------
Expand Down Expand Up @@ -1686,7 +1653,7 @@ subroutine ch4 (bounds, num_soilc, filter_soilc, num_lakec, filter_lakec, &
real(r8) :: rootfraction(bounds%begp:bounds%endp, 1:nlevgrnd)
real(r8) :: fsat_bef(bounds%begc:bounds%endc) ! finundated from previous timestep
real(r8) :: errch4 ! g C / m^2
real(r8) :: zwt_actual
!real(r8) :: zwt_actual
real(r8) :: qflxlags ! Time to lag qflx_surf_lag (s)
real(r8) :: redoxlag ! Redox time lag
real(r8) :: redoxlag_vertical ! Vertical redox lag time
Expand Down Expand Up @@ -1716,8 +1683,8 @@ subroutine ch4 (bounds, num_soilc, filter_soilc, num_lakec, filter_lakec, &
forc_pco2 => atm2lnd_inst%forc_pco2_grc , & ! Input: [real(r8) (:) ] CO2 partial pressure (Pa)
forc_pch4 => atm2lnd_inst%forc_pch4_grc , & ! Input: [real(r8) (:) ] CH4 partial pressure (Pa)

zwt => soilhydrology_inst%zwt_col , & ! Input: [real(r8) (:) ] water table depth (m)
zwt_perched => soilhydrology_inst%zwt_perched_col , & ! Input: [real(r8) (:) ] perched water table depth (m)
!zwt => soilhydrology_inst%zwt_col , & ! Input: [real(r8) (:) ] water table depth (m)
!zwt_perched => soilhydrology_inst%zwt_perched_col , & ! Input: [real(r8) (:) ] perched water table depth (m)

rootfr => soilstate_inst%rootfr_patch , & ! Input: [real(r8) (:,:) ] fraction of roots in each soil layer (nlevgrnd)
rootfr_col => soilstate_inst%rootfr_col , & ! Output: [real(r8) (:,:) ] fraction of roots in each soil layer (nlevgrnd) (p2c)
Expand All @@ -1728,9 +1695,6 @@ subroutine ch4 (bounds, num_soilc, filter_soilc, num_lakec, filter_lakec, &
qflx_surf => waterflux_inst%qflx_surf_col , & ! Input: [real(r8) (:) ] surface runoff (mm H2O /s)

conc_o2_sat => ch4_inst%conc_o2_sat_col , & ! Input: [real(r8) (:,:) ] O2 conc in each soil layer (mol/m3) (nlevsoi)
zwt0 => ch4_inst%zwt0_col , & ! Input: [real(r8) (:) ] decay factor for finundated (m)
f0 => ch4_inst%f0_col , & ! Input: [real(r8) (:) ] maximum gridcell fractional inundated area
p3 => ch4_inst%p3_col , & ! Input: [real(r8) (:) ] coefficient for qflx_surf_lag for finunated (s/mm)
totcolch4_bef => ch4_inst%totcolch4_bef_col , & ! Input: [real(r8) (:) ] total methane in soil column, start of timestep (g C / m^2)

grnd_ch4_cond_patch => ch4_inst%grnd_ch4_cond_patch , & ! Input: [real(r8) (:) ] tracer conductance for boundary layer [m/s]
Expand Down Expand Up @@ -1847,21 +1811,7 @@ subroutine ch4 (bounds, num_soilc, filter_soilc, num_lakec, filter_lakec, &
qflx_surf_lag(begc:endc), finundated(begc:endc) )
else

! Calculate finundated with ZWT inversion from surface dataset
do fc = 1, num_soilc
c = filter_soilc(fc)
if (zwt0(c) > 0._r8) then
if (zwt_perched(c) < z(c,nlevsoi)-1.e-5_r8 .and. zwt_perched(c) < zwt(c)) then
zwt_actual = zwt_perched(c)
else
zwt_actual = zwt(c)
end if
finundated(c) = f0(c) * exp(-zwt_actual/zwt0(c)) + p3(c)*qflx_surf_lag(c)
else
finundated(c) = p3(c)*qflx_surf_lag(c)
end if

end do
call endrun( "ERROR:: finundation method MUST now use a streams file to run, it can no longer read from the fsurdat file" )
end if

! Calculate finundated before snow and lagged version of finundated
Expand Down
2 changes: 1 addition & 1 deletion src/biogeophys/WaterfluxType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ subroutine InitHistory(this, bounds)
this%qflx_ev_snow_patch(begp:endp) = spval
call hist_addfld1d (fname='QSNOEVAP', units='mm/s', &
avgflag='A', long_name='evaporation from snow', &
ptr_patch=this%qflx_tran_veg_patch, set_lake=0._r8, c2l_scale_type='urbanf')
ptr_patch=this%qflx_ev_snow_patch, set_lake=0._r8, c2l_scale_type='urbanf')

this%qflx_snowindunload_patch(begp:endp) = spval
call hist_addfld1d (fname='QSNO_WINDUNLOAD', units='mm/s', &
Expand Down

0 comments on commit 53807f1

Please sign in to comment.