Skip to content

Commit

Permalink
Merge pull request #194 from gold2718/fix_dms
Browse files Browse the repository at this point in the history
Summary: Fix SFDMS history output restart error
Contributors: gold2718
Reviewers: oyvindseland
Purpose of changes: FAIL ERR_Ld3.ne30pg3_tn14.N1850.betzy_intel.allactive-defaultio COMPARE_base_rest failing with latest alpha tag
Github PR URL: #194

Changes made to build system: None
Changes made to the namelist: None
Changes to the defaults for the boundary datasets: None]
Substantial timing or memory changes: None

    Add fdms, fbrf, fn2o_ocn and fnh3_ocn to the restart file
    Remove bad outfld call in atm_import_export

ERR_Ld3.ne30pg3_tn14.N1850.betzy_intel.allactive-defaultio
    Still fails COMPARE_base_rest but due only to a BLOM field
  • Loading branch information
gold2718 authored Feb 12, 2025
2 parents 5cfc071 + 81be009 commit d40f4e2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/cpl/nuopc/atm_import_export.F90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module atm_import_export
use cam_logfile , only : iulog
use cam_history , only: outfld
use spmd_utils , only : masterproc, mpicom
use constituents , only : cnst_get_ind, sflxnam
use srf_field_check , only : set_active_Sl_ram1
use srf_field_check , only : set_active_Sl_fv
use srf_field_check , only : set_active_Sl_soilw
Expand Down Expand Up @@ -555,7 +554,6 @@ subroutine import_fields( gcomp, cam_in, restart_init, rc)
! local variables
type(ESMF_State) :: importState
integer :: i,n,c,g, num ! indices
integer :: ncols ! number of columns
integer :: nstep
logical :: overwrite_flds
logical :: exists
Expand Down Expand Up @@ -893,7 +891,6 @@ subroutine import_fields( gcomp, cam_in, restart_init, rc)

call state_getfldptr(importState, 'Faoo_fdms_ocn', fldptr=fldptr1d, exists=exists, rc=rc)
if (exists) then
call cnst_get_ind('DMS', pndx_fdms, abort=.true.)
! Ideally what should happen below is that
! cam_in%cflx(icol,pndx_fdms) should be set directly from
! fldptr1d. However, the code initializes the chemistry
Expand All @@ -908,8 +905,6 @@ subroutine import_fields( gcomp, cam_in, restart_init, rc)
cam_in(c)%fdms(i) = -fldptr1d(g) * med2mod_areacor(g)
g = g + 1
end do
ncols = get_ncols_p(c)
call outfld( sflxnam(pndx_fdms), cam_in(c)%fdms, ncols, c)
end do
end if

Expand Down Expand Up @@ -1046,7 +1041,6 @@ subroutine export_fields( gcomp, model_mesh, model_clock, cam_out, rc)
type(ESMF_State) :: importState
type(ESMF_Clock) :: clock
integer :: i,m,c,n,g ! indices
integer :: ncols ! Number of columns
integer :: nstep
logical :: exists
real(r8) :: scale_ndep
Expand Down
72 changes: 71 additions & 1 deletion src/physics/cam/restart_physics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ module restart_physics
type(var_desc_t) :: wsy_desc
type(var_desc_t) :: shf_desc

type(var_desc_t) :: fdms_desc
type(var_desc_t) :: fbrf_desc
type(var_desc_t) :: fn2o_ocn_desc
type(var_desc_t) :: fnh3_ocn_desc

CONTAINS
subroutine init_restart_physics ( File, pbuf2d)

Expand Down Expand Up @@ -128,6 +133,11 @@ subroutine init_restart_physics ( File, pbuf2d)
ierr = pio_def_var(File, 'wsy', pio_double, hdimids, wsy_desc)
ierr = pio_def_var(File, 'shf', pio_double, hdimids, shf_desc)

ierr = pio_def_var(File, 'fdms', pio_double, hdimids, fdms_desc)
ierr = pio_def_var(File, 'fbrf', pio_double, hdimids, fbrf_desc)
ierr = pio_def_var(File, 'fn2o_ocn', pio_double, hdimids, fn2o_ocn_desc)
ierr = pio_def_var(File, 'fnh3_ocn', pio_double, hdimids, fnh3_ocn_desc)

call radiation_define_restart(file)

if (is_subcol_on()) then
Expand Down Expand Up @@ -328,6 +338,30 @@ subroutine write_restart_physics (File, cam_in, cam_out, pbuf2d)
end do
call pio_write_darray(File, shf_desc, iodesc, tmpfield, ierr)

do i = begchunk, endchunk
ncol = cam_in(i)%ncol
tmpfield(:ncol,i) = cam_in(i)%fdms(:ncol)
end do
call pio_write_darray(File, fdms_desc, iodesc, tmpfield, ierr)

do i = begchunk, endchunk
ncol = cam_in(i)%ncol
tmpfield(:ncol,i) = cam_in(i)%fbrf(:ncol)
end do
call pio_write_darray(File, fbrf_desc, iodesc, tmpfield, ierr)

do i = begchunk, endchunk
ncol = cam_in(i)%ncol
tmpfield(:ncol,i) = cam_in(i)%fn2o_ocn(:ncol)
end do
call pio_write_darray(File, fn2o_ocn_desc, iodesc, tmpfield, ierr)

do i = begchunk, endchunk
ncol = cam_in(i)%ncol
tmpfield(:ncol,i) = cam_in(i)%fnh3_ocn(:ncol)
end do
call pio_write_darray(File, fnh3_ocn_desc, iodesc, tmpfield, ierr)

call radiation_write_restart(file)

end subroutine write_restart_physics
Expand Down Expand Up @@ -583,7 +617,43 @@ subroutine read_restart_physics(File, cam_in, cam_out, pbuf2d)
cam_in(c)%shf(i) = tmpfield2(i, c)
end do
end do
endif
end if
ierr = pio_inq_varid(File, 'fdms', vardesc)
if (ierr == PIO_NOERR) then ! variable found on restart file
call pio_read_darray(File, vardesc, iodesc, tmpfield2, ierr)
do c= begchunk, endchunk
do i = 1, pcols
cam_in(c)%fdms(i) = tmpfield2(i, c)
end do
end do
end if
ierr = pio_inq_varid(File, 'fbrf', vardesc)
if (ierr == PIO_NOERR) then ! variable found on restart file
call pio_read_darray(File, vardesc, iodesc, tmpfield2, ierr)
do c= begchunk, endchunk
do i = 1, pcols
cam_in(c)%fbrf(i) = tmpfield2(i, c)
end do
end do
end if
ierr = pio_inq_varid(File, 'fn2o_ocn', vardesc)
if (ierr == PIO_NOERR) then ! variable found on restart file
call pio_read_darray(File, vardesc, iodesc, tmpfield2, ierr)
do c= begchunk, endchunk
do i = 1, pcols
cam_in(c)%fn2o_ocn(i) = tmpfield2(i, c)
end do
end do
end if
ierr = pio_inq_varid(File, 'fnh3_ocn', vardesc)
if (ierr == PIO_NOERR) then ! variable found on restart file
call pio_read_darray(File, vardesc, iodesc, tmpfield2, ierr)
do c= begchunk, endchunk
do i = 1, pcols
cam_in(c)%fnh3_ocn(i) = tmpfield2(i, c)
end do
end do
end if
call pio_seterrorhandling(File, err_handling)

deallocate(tmpfield2)
Expand Down

0 comments on commit d40f4e2

Please sign in to comment.