Skip to content

Commit

Permalink
fix some issues in derecho regression tests
Browse files Browse the repository at this point in the history
	modified:   bld/build-namelist
	modified:   bld/namelist_files/namelist_defaults_cam.xml
	modified:   bld/namelist_files/namelist_definition.xml
	modified:   bld/namelist_files/use_cases/2010_cam6.xml
	modified:   bld/namelist_files/use_cases/sd_cam6.xml
	modified:   bld/namelist_files/use_cases/waccm_sc_1850_cam6.xml
	modified:   src/chemistry/geoschem/chemistry.F90
	modified:   src/chemistry/pp_terminator/chemistry.F90
	modified:   src/control/camsrfexch.F90
  • Loading branch information
fvitt committed Dec 19, 2024
1 parent fa69b87 commit b70cfea
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 41 deletions.
13 changes: 13 additions & 0 deletions bld/build-namelist
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,19 @@ if ($phys_mode_flags > 1) {
my $simple_phys = 0;
if ($adia_mode or $ideal_mode) { $simple_phys = 1; }

# Setup default ndep streams only if not simple_phys or aqua_mode and
# the chemistry cannot produce the nitrogen depostion fluxes
if (!($simple_phys or $aqua_mode)) {
my $chem_nitrodep = chem_has_species($cfg, 'NO') and chem_has_species($cfg, 'NH3');
if (!$chem_nitrodep) {
add_default($nl, 'stream_ndep_data_filename');
add_default($nl, 'stream_ndep_mesh_filename');
add_default($nl, 'stream_ndep_year_first');
add_default($nl, 'stream_ndep_year_last');
add_default($nl, 'stream_ndep_year_align');
}
}

# Single column mode
my $scam = $cfg->get('scam');
my $scam_iop = $cfg->get('scam_iop');
Expand Down
3 changes: 3 additions & 0 deletions bld/namelist_files/namelist_defaults_cam.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,9 @@
<!-- nitrogen deposition to surface models -->
<stream_ndep_data_filename>lnd/clm2/ndepdata/fndep_clm_hist_b.e21.BWHIST.f09_g17.CMIP6-historical-WACCM.ensmean_1849-2015_monthly_0.9x1.25_c180926.nc</stream_ndep_data_filename>
<stream_ndep_mesh_filename>share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc</stream_ndep_mesh_filename>
<stream_ndep_year_first sim_year="1850-2000">1850</stream_ndep_year_first>
<stream_ndep_year_last sim_year="1850-2000">2015</stream_ndep_year_last>
<stream_ndep_year_align sim_year="1850-2000">1850</stream_ndep_year_align>
<stream_ndep_year_first>2000</stream_ndep_year_first>
<stream_ndep_year_last>2000</stream_ndep_year_last>
<stream_ndep_year_align>1</stream_ndep_year_align>
Expand Down
6 changes: 6 additions & 0 deletions bld/namelist_files/namelist_definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7609,6 +7609,12 @@ Bubble-mediated sea-air transfer. See ocean_emis.F90 for details.
Default: FALSE
</entry>

<entry id="ndep_list" type="char*16(2)" category="Nitrogen Deposition"
group="ndep_inparm" valid_values="" >
List of nitrogen deposition fluxes to be sent from CAM to surface models.
Default: set by build-namelist.
</entry>

<entry id="stream_ndep_year_first" type="integer" category="Nitrogen Deposition"
group="ndep_stream_nl" valid_values="" >
Year first to use in nitrogen deposition stream data.
Expand Down
4 changes: 4 additions & 0 deletions bld/namelist_files/use_cases/2010_cam6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@
<flbc_type> 'CYCLICAL' </flbc_type>
<flbc_cycle_yr> 2010 </flbc_cycle_yr>

<stream_ndep_year_first>2010</stream_ndep_year_first>
<stream_ndep_year_last>2010</stream_ndep_year_last>
<stream_ndep_year_align>1</stream_ndep_year_align>

</namelist_defaults>
6 changes: 5 additions & 1 deletion bld/namelist_files/use_cases/sd_cam6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@

<prescribed_strataero_type > 'SERIAL' </prescribed_strataero_type>
<prescribed_strataero_datapath> 'atm/cam/ozone_strataero' </prescribed_strataero_datapath>
<prescribed_strataero_file> 'ozone_strataero_WACCM_L70_zm5day_18500101-20150103_CMIP6ensAvg_c180923.nc' </prescribed_strataero_file>
<prescribed_strataero_file> 'ozone_strataero_WACCM_L70_zm5day_18500101-20150103_CMIP6ensAvg_c180923.nc' </prescribed_strataero_file>
<prescribed_strataero_use_chemtrop> .true. </prescribed_strataero_use_chemtrop>

<scenario_ghg > 'CHEM_LBC_FILE' </scenario_ghg>
<flbc_file>atm/waccm/lb/LBC_1750-2015_CMIP6_GlobAnnAvg_c180926.nc</flbc_file>
<flbc_type>'SERIAL'</flbc_type>
<flbc_list>'CO2','CH4','N2O','CFC11eq','CFC12'</flbc_list>

<stream_ndep_year_first>1850</stream_ndep_year_first>
<stream_ndep_year_last>2015</stream_ndep_year_last>
<stream_ndep_year_align>1850</stream_ndep_year_align>

</namelist_defaults>
7 changes: 7 additions & 0 deletions bld/namelist_files/use_cases/waccm_sc_1850_cam6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,11 @@
'UTEND4', 'UTEND5', 'FRONTGF', 'FRONTGFA', 'EKGW', 'QNO', 'QRLNLTE', 'QRL_TOT', 'DUV', 'DVV', 'TTPXMLC'
</fexcl1>

<!-- prescribed nitrogen deposition fluxes -->
<stream_ndep_data_filename>lnd/clm2/ndepdata/fndep_clm_WACCM6_CMIP6piControl001_y21-50avg_1850monthly_0.95x1.25_c180802.nc</stream_ndep_data_filename>
<stream_ndep_mesh_filename>share/meshes/fv0.9x1.25_141008_polemod_ESMFmesh.nc</stream_ndep_mesh_filename>
<stream_ndep_year_first>1850</stream_ndep_year_first>
<stream_ndep_year_last>1850</stream_ndep_year_last>
<stream_ndep_year_align>1</stream_ndep_year_align>

</namelist_defaults>
31 changes: 17 additions & 14 deletions src/chemistry/geoschem/chemistry.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module chemistry
#if defined( MODAL_AERO )
use modal_aero_data, only : ntot_amode
#endif

! GEOS-Chem derived types
USE DiagList_Mod, ONLY : DgnList ! Diagnostics list object
use GeosChem_History_Mod, ONLY : HistoryConfigObj ! History diagnostic object
Expand Down Expand Up @@ -59,6 +59,7 @@ module chemistry
public :: chem_readnl ! read chem namelist
public :: chem_emissions
public :: chem_timestep_init
public :: chem_has_ndep_flx

!
! Private routines:
Expand Down Expand Up @@ -166,6 +167,8 @@ module chemistry
! For dry deposition
character(len=shr_kind_cl) :: depvel_lnd_file = 'depvel_lnd_file'

! for nitrogen deposition fluxes to surface models
logical, parameter :: chem_has_ndep_flx = .false.

contains

Expand Down Expand Up @@ -515,11 +518,11 @@ subroutine chem_register
CALL cnst_get_ind('Q', cQ, abort=.True.)
CALL cnst_get_ind('H2O', cH2O, abort=.True.)
CALL cnst_get_ind('H2SO4', cH2SO4, abort=.True.)

!------------------------------------------------------------
! Get mapping between dry deposition species and species set
!------------------------------------------------------------

nIgnored = 0

if (debug .and. masterproc) write(iulog,'(a,i4,a)') 'chem_register: looping over gas dry deposition list with ', nddvels, ' species'
Expand Down Expand Up @@ -831,7 +834,7 @@ subroutine chem_readnl(nlfile)
! Now go through the KPP mechanism and add any species not
! implemented by the tracer list in geoschem_config.yml
!----------------------------------------------------------

IF ( nSpec > nSlsMax ) THEN
CALL ENDRUN('chem_readnl: too many species - increase nSlsmax')
ENDIF
Expand Down Expand Up @@ -1022,7 +1025,7 @@ subroutine chem_init(phys_state, pbuf2d)
use Time_Mod, only : Accept_External_Date_Time
use Ucx_Mod, only : Init_Ucx
use Unitconv_Mod, only : MOLES_SPECIES_PER_MOLES_DRY_AIR
use Vdiff_Mod, only : Max_PblHt_For_Vdiff
use Vdiff_Mod, only : Max_PblHt_For_Vdiff

TYPE(physics_state), INTENT(IN ) :: phys_state(BEGCHUNK:ENDCHUNK)
TYPE(physics_buffer_desc), POINTER, INTENT(INOUT) :: pbuf2d(:,:)
Expand Down Expand Up @@ -1143,7 +1146,7 @@ subroutine chem_init(phys_state, pbuf2d)
! on State_Grid(BEGCHUNK).
! To go around this, we define all of GEOS-Chem arrays with
! size PCOLS x PVER, which is the largest possible number of
! grid cells.
! grid cells.
CALL Init_State_Grid( Input_Opt = Input_Opt, &
State_Grid = maxGrid, &
RC = RC )
Expand Down Expand Up @@ -1484,7 +1487,7 @@ subroutine chem_init(phys_state, pbuf2d)
! Init_Drydep
! Thibaud M. Fritz - 04 Mar 2020
!----------------------------------------------------------

ALLOCATE(map2GC_dryDep(nddvels), STAT=IERR)
IF ( IERR .NE. 0 ) CALL ENDRUN('Failed to allocate map2GC_dryDep')

Expand Down Expand Up @@ -1754,7 +1757,7 @@ subroutine chem_timestep_init(phys_state, pbuf2d)
use mo_flbc, only : flbc_chk
use mo_ghg_chem, only : ghg_chem_timestep_init
use physics_buffer, only : physics_buffer_desc

TYPE(physics_state), INTENT(IN):: phys_state(begchunk:endchunk)
TYPE(physics_buffer_desc), POINTER :: pbuf2d(:,:)

Expand Down Expand Up @@ -2019,7 +2022,7 @@ subroutine chem_timestep_tend( state, ptend, cam_in, cam_out, dT, pbuf, fh2o )
REAL(r8) :: mmr_tend(state%NCOL,PVER,gas_pcnst)
REAL(r8) :: wk_out(state%NCOL)
LOGICAL :: Found

CHARACTER(LEN=shr_kind_cl) :: tagName

REAL(r8), PARAMETER :: zlnd = 0.01_r8 ! Roughness length for soil [m]
Expand Down Expand Up @@ -2364,7 +2367,7 @@ subroutine chem_timestep_tend( state, ptend, cam_in, cam_out, dT, pbuf, fh2o )
ENDDO

! Deal with secondary organic aerosols (SOAs). This mapping is using the
! complex SOA option in GEOS-Chem.
! complex SOA option in GEOS-Chem.
! MAM uses five volatility bins spanning saturation concentrations from 0.01
! to 100 ug/m3 (logarithmically). The complex SOA option has four volatility
! bins that 0.1 to 100 ug/m3. We lump the lowest two bins in CESM2 to the
Expand Down Expand Up @@ -3692,7 +3695,7 @@ subroutine chem_timestep_tend( state, ptend, cam_in, cam_out, dT, pbuf, fh2o )
! Compute the surface flux for the non-local mixing,
! (which means getting emissions & drydep from HEMCO)
! and store it in State_Chm%Surface_Flux
!
!
! For CESM-GC, Surface_Flux will be equal to the opposite of the
! dry deposition flux since emissions are loaded externally
! ( SurfaceFlux = eflx - dflx = - dflx )
Expand Down Expand Up @@ -3739,10 +3742,10 @@ subroutine chem_timestep_tend( state, ptend, cam_in, cam_out, dT, pbuf, fh2o )
! Get the species ID from the drydep ID
N = State_Chm(BEGCHUNK)%Map_DryDep(ND)
IF ( N <= 0 ) CYCLE

M = map2GCinv(N)
IF ( M <= 0 ) CYCLE

cam_in%cflx(1:nY,M) = cam_in%cflx(1:nY,M) &
+ State_Chm(LCHNK)%SurfaceFlux(1,1:nY,N)
ENDDO
Expand All @@ -3763,7 +3766,7 @@ subroutine chem_timestep_tend( state, ptend, cam_in, cam_out, dT, pbuf, fh2o )
new_units = KG_SPECIES_PER_M2, &
previous_units = previous_units, &
RC = RC )


IF ( RC /= GC_SUCCESS ) THEN
ErrMsg = 'Error encountered in "Convert_Spc_Units"!'
Expand Down
49 changes: 26 additions & 23 deletions src/chemistry/pp_terminator/chemistry.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ module chemistry
public :: chem_write_restart
public :: chem_read_restart
public :: chem_init_restart
public :: chem_readnl ! read chem namelist
public :: chem_readnl ! read chem namelist
public :: chem_reset_fluxes
public :: chem_emissions
public :: chem_has_ndep_flx

interface chem_write_restart
module procedure chem_write_restart_bin
Expand All @@ -45,9 +46,11 @@ module chemistry
module procedure chem_read_restart_pio
end interface

logical, parameter :: chem_has_ndep_flx = .false.

! Private data
integer, parameter :: nspecies = 3

integer :: idx_cl =-1
integer :: idx_cl2=-1

Expand Down Expand Up @@ -75,21 +78,21 @@ end function chem_is
!================================================================================================

subroutine chem_register
!-----------------------------------------------------------------------
!
!-----------------------------------------------------------------------
!
! Purpose: register advected constituents for parameterized greenhouse gas chemistry
!
!
!-----------------------------------------------------------------------

real(r8), parameter :: cptmp = 666._r8
real(r8), parameter :: qmin = -1.e36_r8

logical :: camout
integer :: i, n

do i = 1, nspecies
camout = trim(species(i)) .eq. 'RHO'
call cnst_add( species(i), adv_mass(i), cptmp, qmin, n, &
call cnst_add( species(i), adv_mass(i), cptmp, qmin, n, &
readiv=.true.,mixtype='dry',cam_outfld=camout)
indices(i) = n
map2chm(n) = i
Expand Down Expand Up @@ -123,12 +126,12 @@ end function chem_is_active
!================================================================================================

function chem_implements_cnst(name)
!-----------------------------------------------------------------------
!
!-----------------------------------------------------------------------
!
! Purpose: return true if specified constituent is implemented by this package
!
!
! Author: B. Eaton
!
!
!-----------------------------------------------------------------------
implicit none
!-----------------------------Arguments---------------------------------
Expand All @@ -137,7 +140,7 @@ function chem_implements_cnst(name)
logical :: chem_implements_cnst ! return value

integer :: i

chem_implements_cnst = .false.

do i = 1, nspecies
Expand All @@ -150,13 +153,13 @@ function chem_implements_cnst(name)
end function chem_implements_cnst

!===============================================================================

subroutine chem_init(phys_state, pbuf2d)
!-----------------------------------------------------------------------
!
!-----------------------------------------------------------------------
!
! Purpose: initialize parameterized greenhouse gas chemistry
! (declare history variables)
!
!
!-----------------------------------------------------------------------
use physics_buffer, only: physics_buffer_desc
use cam_history, only: addfld, add_default, horiz_only
Expand Down Expand Up @@ -196,7 +199,7 @@ end subroutine chem_init
subroutine chem_timestep_init(phys_state, pbuf2d)
use physics_buffer, only: physics_buffer_desc

type(physics_state), intent(in):: phys_state(begchunk:endchunk)
type(physics_state), intent(in):: phys_state(begchunk:endchunk)
type(physics_buffer_desc), pointer :: pbuf2d(:,:)

end subroutine chem_timestep_init
Expand All @@ -222,7 +225,7 @@ subroutine chem_timestep_tend( state, ptend, cam_in, cam_out, dt, pbuf, fh2o )
real(r8), optional, intent(out) :: fh2o(pcols) ! h2o flux to balance source from chemistry

real(r8) :: a(pver),b(pver),c(pver),d(pver)

real(r8) :: k1(pcols)
real(r8) :: k2(pcols)

Expand Down Expand Up @@ -278,7 +281,7 @@ subroutine chem_timestep_tend( state, ptend, cam_in, cam_out, dt, pbuf, fh2o )
l(i,:) = (1._r8 - e(i,:))/det(i,:)/dt
elsewhere
l(i,:) = 4._r8*k2(i)
endwhere
endwhere

cl_f(i,:) = -l(i,:)*(cl(i,:) - det(i,:) + r(i) )*(cl(i,:) + det(i,:) + r(i)) / ( 1._r8 +e(i,:) + dt*l(i,:)*(cl(i,:) + r(i)))
cl2_f(i,:) = -cl_f(i,:) / 2._r8
Expand Down Expand Up @@ -325,7 +328,7 @@ subroutine chem_init_cnst(name, latvals, lonvals, mask, q)
real(r8) :: q_vmr(size(q, 1)) ! volume mixing ratio (ncol)
real(r8) :: det(size(q, 1))
real(r8) :: krat(size(q, 1))

real(r8) :: k1(size(q, 1))
real(r8) :: k2(size(q, 1))

Expand All @@ -347,7 +350,7 @@ subroutine chem_init_cnst(name, latvals, lonvals, mask, q)
krat(:) = k1(:) / (4._r8 * k2(:))

h = init_vmr_cl + 2._r8 * init_vmr_cl2

det(:) = sqrt(krat(:) * krat(:) + 2._r8 * h * krat(:))

if (trim(name) == trim(species(1)) ) then
Expand Down Expand Up @@ -412,15 +415,15 @@ subroutine chem_init_restart(File)
end subroutine chem_init_restart
!================================================================================
subroutine chem_reset_fluxes( fptr, cam_in )
use camsrfexch, only : cam_in_t
use camsrfexch, only : cam_in_t

real(r8), pointer :: fptr(:,:) ! pointer into array data
type(cam_in_t), intent(inout) :: cam_in(begchunk:endchunk)

end subroutine chem_reset_fluxes
!================================================================================
subroutine chem_emissions( state, cam_in, pbuf )
use camsrfexch, only: cam_in_t
use camsrfexch, only: cam_in_t
use physics_buffer, only: physics_buffer_desc

! Arguments:
Expand Down
6 changes: 3 additions & 3 deletions src/control/camsrfexch.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module camsrfexch
use constituents, only: pcnst
use ppgrid, only: pcols, begchunk, endchunk
use phys_grid, only: get_ncols_p, phys_grid_initialized
use infnan, only: nan, posinf, assignment(=)
use infnan, only: posinf, assignment(=)
use cam_abortutils, only: endrun
use cam_logfile, only: iulog
use srf_field_check, only: active_Sl_ram1, active_Sl_fv, active_Sl_soilw, &
Expand Down Expand Up @@ -329,11 +329,11 @@ subroutine atm2hub_alloc( cam_out )

allocate (cam_out(c)%nhx_nitrogen_flx(pcols), stat=ierror)
if ( ierror /= 0 ) call endrun(sub//': allocation error nhx_nitrogen_flx')
cam_out(c)%nhx_nitrogen_flx(:) = nan
cam_out(c)%nhx_nitrogen_flx(:) = 0._r8

allocate (cam_out(c)%noy_nitrogen_flx(pcols), stat=ierror)
if ( ierror /= 0 ) call endrun(sub//': allocation error noy_nitrogen_flx')
cam_out(c)%noy_nitrogen_flx(:) = nan
cam_out(c)%noy_nitrogen_flx(:) = 0._r8

endif

Expand Down

0 comments on commit b70cfea

Please sign in to comment.