Skip to content

Commit

Permalink
Merge remote-tracking branch 'mvdev/feature/update_docn' into feature…
Browse files Browse the repository at this point in the history
…/update_docn
  • Loading branch information
jedwards4b committed May 14, 2024
2 parents 017e6a9 + 27726a1 commit ca2d62b
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 18 deletions.
6 changes: 3 additions & 3 deletions dglc/cime_config/testdefs/testlist_dglc.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<testlist version="2.0">

<test compset="2000_SATM_SLND_SICE_SGLC_SROF_DGLC%NOEVOLVE_SWAV" grid="f10_f10_ais8gris4_mg37" name="SMS_Ln5">
<test compset="2000_SATM_SLND_SICE_SGLC_SROF_DGLC%NOEVOLVE_SWAV" grid="f10_f10_ais8gris4_mg37" name="SMS_Ly3">
<machines>
<machine name="derecho" compiler="intel" category="aux_cdeps"/>
<machine name="betzy" compiler="intel" category="aux_cdeps_noresm"/>
Expand All @@ -10,7 +10,7 @@
<option name="wallclock"> 00:10:00 </option>
</options>
</test>
<test compset="2000_SATM_SLND_SICE_SGLC_SROF_DGLC%NOEVOLVE_SWAV" grid="f10_f10_ais8_mg37" name="SMS_Ln5">
<test compset="2000_SATM_SLND_SICE_SGLC_SROF_DGLC%NOEVOLVE_SWAV" grid="f10_f10_ais8_mg37" name="SMS_Ly3">
<machines>
<machine name="derecho" compiler="intel" category="aux_cdeps"/>
<machine name="betzy" compiler="intel" category="aux_cdeps_noresm"/>
Expand All @@ -19,7 +19,7 @@
<option name="wallclock"> 00:10:00 </option>
</options>
</test>
<test compset="2000_SATM_SLND_SICE_SGLC_SROF_DGLC%NOEVOLVE_SWAV" grid="f19_g17_gris4" name="SMS_Ln5">
<test compset="2000_SATM_SLND_SICE_SGLC_SROF_DGLC%NOEVOLVE_SWAV" grid="f19_g17_gris4" name="SMS_Ly3">
<machines>
<machine name="derecho" compiler="intel" category="aux_cdeps"/>
<machine name="betzy" compiler="intel" category="aux_cdeps_noresm"/>
Expand Down
11 changes: 10 additions & 1 deletion dglc/dglc_datamode_noevolve_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module dglc_datamode_noevolve_mod

! Data structure to enable multiple ice sheets
type icesheet_ptr_t
real(r8), pointer :: ptr(:) => null() ! pointer to array
real(r8), pointer :: ptr(:) => null() ! pointer to array
real(r8), pointer :: ptr2d(:,:) => null() ! pointer to 2d array
endtype icesheet_ptr_t

! Export fields
Expand All @@ -42,8 +43,11 @@ module dglc_datamode_noevolve_mod
type(icesheet_ptr_t), allocatable :: Fogg_rofi(:)

! Import fields
integer, parameter :: nlev_import = 30
type(icesheet_ptr_t), allocatable :: Sl_tsrf(:)
type(icesheet_ptr_t), allocatable :: Flgl_qice(:)
type(icesheet_ptr_t), allocatable :: So_t(:)
type(icesheet_ptr_t), allocatable :: So_q(:)

! Export Field names
character(len=*), parameter :: field_out_area = 'Sg_area'
Expand All @@ -56,6 +60,8 @@ module dglc_datamode_noevolve_mod
! Import Field names
character(len=*), parameter :: field_in_tsrf = 'Sl_tsrf'
character(len=*), parameter :: field_in_qice = 'Flgl_qice'
character(len=*), parameter :: field_in_so_t_depth = 'So_t_depth'
character(len=*), parameter :: field_in_so_s_depth = 'So_s_depth'

character(*) , parameter :: rpfile = 'rpointer.glc'
character(*) , parameter :: u_FILE_u = &
Expand Down Expand Up @@ -115,6 +121,9 @@ subroutine dglc_datamode_noevolve_advertise(NStateExp, fldsexport, NStateImp, fl
call dshr_fldList_add(fldsImport, trim(flds_scalar_name))
call dshr_fldList_add(fldsImport, field_in_tsrf)
call dshr_fldList_add(fldsImport, field_in_qice)
! TODO: Add namelist for this
call dshr_fldList_add(fldsImport, field_in_so_t_depth, ungridded_lbound=1, ungridded_ubound=nlev_import)
call dshr_fldList_add(fldsImport, field_in_so_s_depth, ungridded_lbound=1, ungridded_ubound=nlev_import)

do ns = 1,num_icesheets
write(cnum,'(i0)') ns
Expand Down
2 changes: 1 addition & 1 deletion docn/cime_config/namelist_definition_docn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<value docn_mode="sst_aquap8">''</value>
<value docn_mode="sst_aquap9">''</value>
<value docn_mode="sst_aquap10">''</value>
<value docn_mode="multilev">sst_depth,salinity_depth</value>
<value docn_mode="multilev">sst_salinity_depth_blom</value>
</values>
</entry>

Expand Down
45 changes: 40 additions & 5 deletions docn/cime_config/stream_definition_docn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@
<stream_readmode>single</stream_readmode>
</stream_entry>

<stream_entry name="sst_depth">
<stream_entry name="sst_depth_omip">
<stream_meshfile>
<meshfile model_grid="oi%gx1v7">$DIN_LOC_ROOT/share/meshes/gx1v7_151008_ESMFmesh.nc</meshfile>
<meshfile>$DIN_LOC_ROOT/share/meshes/gx1v7_151008_ESMFmesh.nc</meshfile>
</stream_meshfile>
<stream_datafiles>
<file model_grid="oi%gx1v7">/glade/collections/cmip/CMIP6/OMIP/NCAR/CESM2/omip2/r1i1p1f1/Omon/thetao/gn/v20190802/thetao_Omon_CESM2_omip2_r1i1p1f1_gn_024501-030512.nc</file>
<file>/glade/collections/cmip/CMIP6/OMIP/NCAR/CESM2/omip2/r1i1p1f1/Omon/thetao/gn/v20190802/thetao_Omon_CESM2_omip2_r1i1p1f1_gn_024501-030512.nc</file>
</stream_datafiles>
<stream_datavars>
<var>thetao So_t_depth</var>
Expand Down Expand Up @@ -242,10 +242,10 @@

<stream_entry name="salinity_depth">
<stream_meshfile>
<meshfile model_grid="oi%gx1v7">$DIN_LOC_ROOT/share/meshes/gx1v7_151008_ESMFmesh.nc</meshfile>
<meshfile>$DIN_LOC_ROOT/share/meshes/gx1v7_151008_ESMFmesh.nc</meshfile>
</stream_meshfile>
<stream_datafiles>
<file model_grid="oi%gx1v7">/glade/collections/cmip/CMIP6/OMIP/NCAR/CESM2/omip2/r1i1p1f1/Omon/so/gn/v20190802/so_Omon_CESM2_omip2_r1i1p1f1_gn_024501-030512.nc</file>
<file>/glade/collections/cmip/CMIP6/OMIP/NCAR/CESM2/omip2/r1i1p1f1/Omon/so/gn/v20190802/so_Omon_CESM2_omip2_r1i1p1f1_gn_024501-030512.nc</file>
</stream_datafiles>
<stream_datavars>
<var>so So_s_depth</var>
Expand All @@ -271,4 +271,39 @@
<stream_readmode>single</stream_readmode>
</stream_entry>

<stream_entry name="sst_salinity_depth_blom">
<stream_meshfile>
<meshfile>$DIN_LOC_ROOT/share/meshes/tnx1v4_20170601_cdf5_ESMFmesh.nc</meshfile>
</stream_meshfile>
<stream_datafiles>
<file>$DIN_LOC_ROOT/ocn/docn7/MULTILEV/N1850frc2G_f09_tn14_gl4_SMB1_celo.blom.hm.2300.nc</file>
<file>$DIN_LOC_ROOT/ocn/docn7/MULTILEV/N1850frc2G_f09_tn14_gl4_SMB1_celo.blom.hm.2301.nc</file>
<file>$DIN_LOC_ROOT/ocn/docn7/MULTILEV/N1850frc2G_f09_tn14_gl4_SMB1_celo.blom.hm.2302.nc</file>
<file>$DIN_LOC_ROOT/ocn/docn7/MULTILEV/N1850frc2G_f09_tn14_gl4_SMB1_celo.blom.hm.2303.nc</file>
</stream_datafiles>
<stream_datavars>
<var>templvl So_t_depth</var>
<var>salnlvl So_s_depth</var>
</stream_datavars>
<stream_lev_dimname>depth</stream_lev_dimname>
<stream_mapalgo>
<mapalgo>bilinear</mapalgo>
</stream_mapalgo>
<stream_vectors>null</stream_vectors>
<stream_year_align>1</stream_year_align>
<stream_year_first>2300</stream_year_first>
<stream_year_last>2303</stream_year_last>
<stream_offset>0</stream_offset>
<stream_tintalgo>
<tintalgo>linear</tintalgo>
</stream_tintalgo>
<stream_taxmode>
<taxmode>cycle</taxmode>
</stream_taxmode>
<stream_dtlimit>
<dtlimit>1.5</dtlimit>
</stream_dtlimit>
<stream_readmode>single</stream_readmode>
</stream_entry>

</stream_data>
229 changes: 229 additions & 0 deletions docn/docn_datamode_multilev_mod.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
module docn_datamode_multilev_mod
use ESMF , only : ESMF_State, ESMF_LOGMSG_INFO, ESMF_LogWrite, ESMF_SUCCESS
use NUOPC , only : NUOPC_Advertise
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_const_mod , only : shr_const_TkFrz, shr_const_pi, shr_const_ocn_ref_sal, shr_const_spval
use shr_sys_mod , only : shr_sys_abort
use dshr_methods_mod , only : dshr_state_getfldptr, dshr_fldbun_getfldptr, chkerr
use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add
use dshr_mod , only : dshr_restart_read, dshr_restart_write
use dshr_strdata_mod , only : shr_strdata_get_stream_pointer, shr_strdata_type

implicit none
private ! except

public :: docn_datamode_multilev_advertise
public :: docn_datamode_multilev_init_pointers
public :: docn_datamode_multilev_advance
public :: docn_datamode_multilev_restart_read
public :: docn_datamode_multilev_restart_write

! pointers to export fields
real(r8), pointer :: So_omask(:) => null() ! real ocean fraction sent to mediator
real(r8), pointer :: So_t_depth(:,:) => null()
real(r8), pointer :: So_s_depth(:,:) => null()

! pointers to stream fields
real(r8), pointer :: stream_So_t_depth(:,:) => null()
real(r8), pointer :: stream_So_s_depth(:,:) => null()

integer, parameter :: nlev_export = 30
real(r8) :: vertical_levels(nlev_export) = (/ &
30., 90., 150., 210., 270., 330., 390., 450., 510., 570., &
630., 690., 750., 810., 870., 930., 990., 1050., 1110., 1170., &
1230., 1290., 1350., 1410., 1470., 1530., 1590., 1650., 1710., 1770. /)

! constants
character(*) , parameter :: nullstr = 'null'
character(*) , parameter :: rpfile = 'rpointer.ocn'
character(*) , parameter :: u_FILE_u = &
__FILE__

!===============================================================================
contains
!===============================================================================

subroutine docn_datamode_multilev_advertise(exportState, fldsexport, flds_scalar_name, rc)

! input/output variables
type(esmf_State) , intent(inout) :: exportState
type(fldlist_type) , pointer :: fldsexport
character(len=*) , intent(in) :: flds_scalar_name
integer , intent(out) :: rc

! local variables
type(fldlist_type), pointer :: fldList
!-------------------------------------------------------------------------------

rc = ESMF_SUCCESS

! Advertise export fields
call dshr_fldList_add(fldsExport, trim(flds_scalar_name))
call dshr_fldList_add(fldsExport, 'So_omask')
call dshr_fldList_add(fldsExport, 'So_t_depth', ungridded_lbound=1, ungridded_ubound=nlev_export)
call dshr_fldList_add(fldsExport, 'So_s_depth', ungridded_lbound=1, ungridded_ubound=nlev_export)

fldlist => fldsExport ! the head of the linked list
do while (associated(fldlist))
call NUOPC_Advertise(exportState, standardName=fldlist%stdname, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite('(docn_comp_advertise): Fr_ocn'//trim(fldList%stdname), ESMF_LOGMSG_INFO)
fldList => fldList%next
enddo

end subroutine docn_datamode_multilev_advertise

!===============================================================================
subroutine docn_datamode_multilev_init_pointers(exportState, sdat, ocn_fraction, rc)

! input/output variables
type(ESMF_State) , intent(inout) :: exportState
type(shr_strdata_type) , intent(in) :: sdat
real(r8) , intent(in) :: ocn_fraction(:)
integer , intent(out) :: rc

! local variables
character(len=*), parameter :: subname='(docn_init_pointers): '
!-------------------------------------------------------------------------------

rc = ESMF_SUCCESS

! initialize pointers to stream fields
! this has the full set of leveles in the stream data
call shr_strdata_get_stream_pointer( sdat, 'So_t_depth', stream_So_t_depth, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call shr_strdata_get_stream_pointer( sdat, 'So_s_depth', stream_So_s_depth, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

! initialize pointers to export fields
! the export state has only nlev_export levels
call dshr_state_getfldptr(exportState, 'So_omask' , fldptr1=So_omask , rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'So_t_depth' , fldptr2=So_t_depth , rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call dshr_state_getfldptr(exportState, 'So_s_depth' , fldptr2=So_s_depth , rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

! Initialize export state pointers to non-zero
So_t_depth(:,:) = shr_const_TkFrz
So_s_depth(:,:) = shr_const_ocn_ref_sal

! Set export state ocean fraction (So_omask)
So_omask(:) = ocn_fraction(:)

end subroutine docn_datamode_multilev_init_pointers

!===============================================================================
subroutine docn_datamode_multilev_advance(sdat, logunit, mainproc, rc)

! input/output variables
type(shr_strdata_type) , intent(in) :: sdat
integer , intent(in) :: logunit
logical , intent(in) :: mainproc
integer , intent(out) :: rc

! local variables
integer :: i,ki,ko
integer :: nlev_stream
integer :: stream_index
logical :: level_found
real(r8) :: factor
real(r8), allocatable :: stream_vlevs(:)
logical :: first_time = .true.
character(len=*), parameter :: subname='(docn_datamode_multilev): '
!-------------------------------------------------------------------------------

rc = ESMF_SUCCESS

! For now assume that all the streams have the same vertical levels
stream_index = 1

nlev_stream = sdat%pstrm(stream_index)%stream_nlev
allocate(stream_vlevs(nlev_stream))
stream_vlevs(:) = sdat%pstrm(stream_index)%stream_vlevs(:)

do ko = 1,nlev_export
level_found = .false.
do ki = 1,nlev_stream-1
if (vertical_levels(ko) > stream_vlevs(ki) .and. vertical_levels(ko) <= stream_vlevs(ki+1)) then
if (mainproc .and. first_time) then
write(logunit,'(a,3(i5,2x),3(f13.5,2x))') &
'vertical interpolation: ki,ko,ki+1,lev(ki),lev(ko),lev(ki+1) = ',&
ki,ko,ki+1,stream_vlevs(ki), vertical_levels(ko), stream_vlevs(ki+1)
end if
level_found = .true.
do i = 1,size(So_omask)
if (So_omask(i) == 0.) then
So_t_depth(ko,i) = shr_const_spval
So_s_depth(ko,i) = shr_const_spval
else
! Assume input T forcing is in degrees C
if (stream_So_t_depth(ki+1,i) > 1.e10) then
if (stream_So_t_depth(ki,i) > 1.e10) then
So_t_depth(ko,i) = shr_const_spval
So_s_depth(ko,i) = shr_const_spval
else
So_t_depth(ko,i) = stream_So_t_depth(ki,i) + shr_const_tkfrz
So_s_depth(ko,i) = stream_So_s_depth(ki,i)
end if
else
factor = (stream_So_t_depth(ki+1,i)-stream_So_t_depth(ki,i))/(stream_vlevs(ki+1)-stream_vlevs(ki))
So_t_depth(ko,i) = stream_So_t_depth(ki,i) + (vertical_levels(ko)-stream_vlevs(ki))*factor
So_t_depth(ko,i) = So_t_depth(ko,i) + shr_const_tkfrz

factor = (stream_So_s_depth(ki+1,i)-stream_So_s_depth(ki,i))/(stream_vlevs(ki+1)-stream_vlevs(ki))
So_s_depth(ko,i) = stream_So_s_depth(ki,i) + (vertical_levels(ko)-stream_vlevs(ki))*factor
end if
end if
end do
end if
end do
if (.not. level_found) then
call shr_sys_abort("ERROR: could not find level bounds for vertical interpolation")
end if
end do

first_time = .false.

end subroutine docn_datamode_multilev_advance

!===============================================================================
subroutine docn_datamode_multilev_restart_write(case_name, inst_suffix, ymd, tod, &
logunit, my_task, sdat)

! write restart file

! input/output variables
character(len=*) , intent(in) :: case_name
character(len=*) , intent(in) :: inst_suffix
integer , intent(in) :: ymd ! model date
integer , intent(in) :: tod ! model sec into model date
integer , intent(in) :: logunit
integer , intent(in) :: my_task
type(shr_strdata_type) , intent(inout) :: sdat
!-------------------------------------------------------------------------------

call dshr_restart_write(rpfile, case_name, 'docn', inst_suffix, ymd, tod, &
logunit, my_task, sdat)

end subroutine docn_datamode_multilev_restart_write

!===============================================================================
subroutine docn_datamode_multilev_restart_read(rest_filem, inst_suffix, logunit, my_task, mpicom, sdat)

! read restart file

! input/output arguments
character(len=*) , intent(inout) :: rest_filem
character(len=*) , intent(in) :: inst_suffix
integer , intent(in) :: logunit
integer , intent(in) :: my_task
integer , intent(in) :: mpicom
type(shr_strdata_type) , intent(inout) :: sdat
!-------------------------------------------------------------------------------

call dshr_restart_read(rest_filem, rpfile, inst_suffix, nullstr, logunit, my_task, mpicom, sdat)

end subroutine docn_datamode_multilev_restart_read

end module docn_datamode_multilev_mod
Loading

0 comments on commit ca2d62b

Please sign in to comment.