Skip to content

Commit

Permalink
Don't allow interpolation from a non-ciso case to a ciso case
Browse files Browse the repository at this point in the history
Due to ESCOMP#67, interpolation from a
case without carbon isotopes to a case with carbon isotopes yields
incorrect initialization values for the carbon isotopes. Now that we're
turning carbon isotopes on via some semi-out-of-the-box usermods (for
cmip6), it is becoming more important to check to make sure someone
doesn't shoot themselves in the foot this way.

This commit should be backed out once ESCOMP#67 is resolved
  • Loading branch information
billsacks committed Oct 25, 2018
1 parent 19f2c3f commit ccdba18
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 2 deletions.
10 changes: 10 additions & 0 deletions bld/namelist_files/namelist_definition_clm4_5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,16 @@ Flag to use the atmospheric time series of C13 concentrations from natural abund
Filename with time series of atmospheric Delta C13 data, which use CMIP6 format. variables in file are "time" and "delta13co2_in_air". time variable is in format: years since 1850-01-01 0:0:0.0. units are permil.
</entry>

<!-- BUG(wjs, 2018-10-25, ESCOMP/ctsm#67) -->
<entry id="for_testing_allow_interp_non_ciso_to_ciso" type="logical" category="clm_isotope"
group="clm_inparm" valid_values="" >
There is a bug that causes incorrect values for C isotopes if running
init_interp from a case without C isotopes to a case with C isotopes
(https://github.com/ESCOMP/ctsm/issues/67). Normally, an error-check
prevents you from doing this interpolation (until we have fixed that
bug). However, we sometimes want to bypass this error-check in system
tests. This namelist flag bypasses this error-check.
</entry>

<!-- permfrost-specific flags -->

Expand Down
8 changes: 8 additions & 0 deletions cime_config/testdefs/testmods_dirs/clm/ciso/user_nl_clm
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
use_c13 = .true.
use_c14 = .true.

! BUG(wjs, 2018-10-25, ESCOMP/ctsm#67) There is a bug that causes incorrect values for C
! isotopes if running init_interp from a case without C isotopes to a case with C
! isotopes (https://github.com/ESCOMP/ctsm/issues/67). Normally, an error-check prevents
! you from doing this interpolation (until we have fixed that bug). However, we
! sometimes want to bypass this error-check in system tests. This namelist flag bypasses
! this error-check.
for_testing_allow_interp_non_ciso_to_ciso = .true.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
use_c14 = .true.
use_fun = .true.
use_flexibleCN = .true.

! BUG(wjs, 2018-10-25, ESCOMP/ctsm#67) There is a bug that causes incorrect values for C
! isotopes if running init_interp from a case without C isotopes to a case with C
! isotopes (https://github.com/ESCOMP/ctsm/issues/67). Normally, an error-check prevents
! you from doing this interpolation (until we have fixed that bug). However, we
! sometimes want to bypass this error-check in system tests. This namelist flag bypasses
! this error-check.
for_testing_allow_interp_non_ciso_to_ciso = .true.
67 changes: 66 additions & 1 deletion src/init_interp/initInterp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module initInterpMod
private :: interp_1d_int
private :: interp_2d_double
private :: limit_snlsno
private :: check_interp_non_ciso_to_ciso

! Private data

Expand Down Expand Up @@ -227,12 +228,14 @@ subroutine initInterp (filei, fileo, bounds, glc_behavior)
end if

! --------------------------------------------
! Open input and output initial conditions files (both just for reading now)
! Open input and output initial conditions files
! --------------------------------------------

call ncd_pio_openfile (ncidi, trim(filei) , 0)
call ncd_pio_openfile (ncido, trim(fileo), ncd_write)

call check_interp_non_ciso_to_ciso(ncidi)

! --------------------------------------------
! Determine dimensions and error checks on dimensions
! --------------------------------------------
Expand Down Expand Up @@ -1258,4 +1261,66 @@ subroutine limit_snlsno(ncido, bounds_o)
deallocate(snlsno)
end subroutine limit_snlsno

!-----------------------------------------------------------------------
subroutine check_interp_non_ciso_to_ciso(ncidi)
!
! !DESCRIPTION:
! BUG(wjs, 2018-10-25, ESCOMP/ctsm#67) There is a bug that causes incorrect values for
! C isotopes if running init_interp from a case without C isotopes to a case with C
! isotopes (https://github.com/ESCOMP/ctsm/issues/67). Here we check that the user
! isn't trying to do an interpolation in that case. This check should be removed once
! bug #67 is resolved.
!
! !USES:
use clm_varctl, only : use_c13, use_c14, for_testing_allow_interp_non_ciso_to_ciso
!
! !ARGUMENTS:
type(file_desc_t), intent(inout) :: ncidi
!
! !LOCAL VARIABLES:
type(Var_desc_t) :: vardesc ! pio variable descriptor
integer :: status ! return code

character(len=*), parameter :: subname = 'check_interp_non_ciso_to_ciso'
!-----------------------------------------------------------------------

if (.not. for_testing_allow_interp_non_ciso_to_ciso) then
if (use_c13) then
call pio_seterrorhandling(ncidi, PIO_BCAST_ERROR)
! arbitrarily check leafc_13 (we could pick any c13 restart field)
status = pio_inq_varid(ncidi, name='leafc_13', vardesc=vardesc)
call pio_seterrorhandling(ncidi, PIO_INTERNAL_ERROR)
if (status /= PIO_noerr) then
if (masterproc) then
write(iulog,*) 'Cannot interpolate from a run without c13 to a run with c13,'
write(iulog,*) 'due to <https://github.com/ESCOMP/ctsm/issues/67>.'
write(iulog,*) 'Either use an input initial conditions file with c13 information,'
write(iulog,*) 'or re-spinup from cold start.'
end if
call endrun(msg='Cannot interpolate from a run without c13 to a run with c13', &
additional_msg=errMsg(sourcefile, __LINE__))
end if
end if

if (use_c14) then
call pio_seterrorhandling(ncidi, PIO_BCAST_ERROR)
! arbitrarily check leafc_14 (we could pick any c14 restart field)
status = pio_inq_varid(ncidi, name='leafc_14', vardesc=vardesc)
call pio_seterrorhandling(ncidi, PIO_INTERNAL_ERROR)
if (status /= PIO_noerr) then
if (masterproc) then
write(iulog,*) 'Cannot interpolate from a run without c14 to a run with c14,'
write(iulog,*) 'due to <https://github.com/ESCOMP/ctsm/issues/67>.'
write(iulog,*) 'Either use an input initial conditions file with c14 information,'
write(iulog,*) 'or re-spinup from cold start.'
end if
call endrun(msg='Cannot interpolate from a run without c14 to a run with c14', &
additional_msg=errMsg(sourcefile, __LINE__))
end if
end if
end if

end subroutine check_interp_non_ciso_to_ciso


end module initInterpMod
8 changes: 8 additions & 0 deletions src/main/clm_varctl.F90
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ module clm_varctl
logical, public :: use_c13 = .false. ! true => use C-13 model
logical, public :: use_c14 = .false. ! true => use C-14 model

! BUG(wjs, 2018-10-25, ESCOMP/ctsm#67) There is a bug that causes incorrect values for C
! isotopes if running init_interp from a case without C isotopes to a case with C
! isotopes (https://github.com/ESCOMP/ctsm/issues/67). Normally, an error-check prevents
! you from doing this interpolation (until we have fixed that bug). However, we
! sometimes want to bypass this error-check in system tests. This namelist flag bypasses
! this error-check.
logical, public :: for_testing_allow_interp_non_ciso_to_ciso = .false.

!----------------------------------------------------------
! FATES switches
!----------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/main/controlMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ subroutine control_init( )

namelist /clm_inparm/ no_frozen_nitrif_denitrif

namelist /clm_inparm/ use_c13, use_c14
namelist /clm_inparm/ use_c13, use_c14, for_testing_allow_interp_non_ciso_to_ciso


! FATES Flags
Expand Down Expand Up @@ -624,6 +624,7 @@ subroutine control_spmd()
! isotopes
call mpi_bcast (use_c13, 1, MPI_LOGICAL, 0, mpicom, ier)
call mpi_bcast (use_c14, 1, MPI_LOGICAL, 0, mpicom, ier)
call mpi_bcast (for_testing_allow_interp_non_ciso_to_ciso, 1, MPI_LOGICAL, 0, mpicom, ier)

call mpi_bcast (use_fates, 1, MPI_LOGICAL, 0, mpicom, ier)

Expand Down Expand Up @@ -860,6 +861,7 @@ subroutine control_print ()
write(iulog, *) ' use_c14 : ', use_c14
write(iulog, *) ' use_c14_bombspike : ', use_c14_bombspike
write(iulog, *) ' atm_c14_filename : ', atm_c14_filename
write(iulog, *) ' for_testing_allow_interp_non_ciso_to_ciso : ', for_testing_allow_interp_non_ciso_to_ciso
end if

if (fsnowoptics == ' ') then
Expand Down

0 comments on commit ccdba18

Please sign in to comment.