Skip to content

Commit

Permalink
added ability to read in multi-level docn data
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariana Vertenstein committed Apr 19, 2024
1 parent 6673b85 commit 1e9220b
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 13 deletions.
1 change: 1 addition & 0 deletions docn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(SRCFILES ocn_comp_nuopc.F90
docn_datamode_aquaplanet_mod.F90
docn_datamode_iaf_mod.F90
docn_datamode_cplhist_mod.F90
docn_datamode_multilev_mod.F90
docn_import_data_mod.F90)

foreach(FILE ${SRCFILES})
Expand Down
6 changes: 4 additions & 2 deletions docn/cime_config/config_component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
This file may have ocn desc entries.
-->
<description modifier_mode="1">
<desc ocn="DOCN[%DOM][%SOM][%SOMAQP][%IAF][%SST_AQUAP][%AQP1][%AQP2][%AQP3][%AQP4][%AQP5][%AQP6][%AQP7][%AQP8][%AQP9][%AQP10][%AQPFILE][%AQPCONST][%CPLHIST]">DOCN </desc>
<desc ocn="DOCN[%DOM][%SOM][%SOMAQP][%IAF][%SST_AQUAP][%AQP1][%AQP2][%AQP3][%AQP4][%AQP5][%AQP6][%AQP7][%AQP8][%AQP9][%AQP10][%AQPFILE][%AQPCONST][%CPLHIST][%MULTILEV]">DOCN </desc>
<desc option="DOM"> prescribed ocean mode</desc>
<desc option="SOM"> slab ocean mode</desc>
<desc option="SOMAQP"> aquaplanet slab ocean mode</desc>
Expand All @@ -32,6 +32,7 @@
<desc option="AQPFILE"> file input aquaplanet sst </desc>
<desc option="AQPCONST"> globally constant SST for idealized experiments, such as RCE </desc>
<desc option="CPLHIST"> mediator history output for ocean fields imported to mediator </desc>
<desc option="MULTILEV"> input stream files have multi level data</desc>
</description>

<entry id="COMP_OCN">
Expand All @@ -45,7 +46,7 @@

<entry id="DOCN_MODE">
<type>char</type>
<valid_values>prescribed,sst_aquap1,sst_aquap2,sst_aquap3,sst_aquap4,sst_aquap5,sst_aquap6,sst_aquap7,sst_aquap8,sst_aquap9,sst_aquap10,sst_aquapfile,som,som_aquap,sst_aquap_constant,interannual,cplhist</valid_values>
<valid_values>prescribed,sst_aquap1,sst_aquap2,sst_aquap3,sst_aquap4,sst_aquap5,sst_aquap6,sst_aquap7,sst_aquap8,sst_aquap9,sst_aquap10,sst_aquapfile,som,som_aquap,sst_aquap_constant,interannual,cplhist,multilev</valid_values>
<default_value>prescribed</default_value>
<values match="last">
<value compset="_DOCN%DOM_" >prescribed</value>
Expand All @@ -65,6 +66,7 @@
<value compset="_DOCN%AQPFILE_">sst_aquapfile</value>
<value compset="_DOCN%AQPCONST_">sst_aquap_constant</value>
<value compset="_DOCN%CPLHIST">cplhist</value>
<value compset="_DOCN%MULTILEV">multilev</value>
</values>
<group>run_component_docn</group>
<file>env_run.xml</file>
Expand Down
4 changes: 3 additions & 1 deletion docn/cime_config/namelist_definition_docn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
<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>
</values>
</entry>

<entry id="datamode">
<type>char</type>
<category>docn</category>
<group>docn_nml</group>
<valid_values>sstdata,sst_aquap1,sst_aquap2,sst_aquap3,sst_aquap4,sst_aquap5,sst_aquap6,sst_aquap7,sst_aquap8,sst_aquap9,sst_aquap10,sst_aquapfile,sst_aquap_constant,som,som_aquap,iaf,cplhist</valid_values>
<valid_values>sstdata,sst_aquap1,sst_aquap2,sst_aquap3,sst_aquap4,sst_aquap5,sst_aquap6,sst_aquap7,sst_aquap8,sst_aquap9,sst_aquap10,sst_aquapfile,sst_aquap_constant,som,som_aquap,iaf,cplhist,multilev</valid_values>
<desc>
General method that operates on the data for a given docn_mode.
==> dataMode = "sstdata"
Expand Down Expand Up @@ -107,6 +108,7 @@
<value docn_mode="sst_aquapfile$">sst_aquap_file</value>
<value docn_mode="sst_aquap_constant$">sst_aquap_constant</value>
<value docn_mode="cplhist">cplhist</value>
<value docn_mode="multilev">multilev</value>
</values>
</entry>

Expand Down
65 changes: 64 additions & 1 deletion docn/cime_config/stream_definition_docn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,69 @@
<stream_dtlimit>
<dtlimit>1.e30</dtlimit>
</stream_dtlimit>
<stream_readmode>single</stream_readmode></stream_entry>
<stream_readmode>single</stream_readmode>
</stream_entry>

<stream_entry name="sst_depth">
<stream_meshfile>
<meshfile model_grid="oi%gx1v7">$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>
</stream_datafiles>
<stream_datavars>
<var>thetao So_t_depth</var>
</stream_datavars>
<stream_lev_dimname>lev</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>245</stream_year_first>
<stream_year_last>245</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_entry name="salinity_depth">
<stream_meshfile>
<meshfile model_grid="oi%gx1v7">$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>
</stream_datafiles>
<stream_datavars>
<var>so So_s_depth</var>
</stream_datavars>
<stream_lev_dimname>lev</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>245</stream_year_first>
<stream_year_last>245</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>
35 changes: 31 additions & 4 deletions docn/ocn_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module cdeps_docn_comp
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_cal_mod , only : shr_cal_ymd2date
use shr_log_mod , only : shr_log_setLogUnit
use shr_log_mod , only : shr_log_setLogUnit
use dshr_methods_mod , only : dshr_state_diagnose, chkerr, memcheck
use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_advance, shr_strdata_init_from_config
use dshr_mod , only : dshr_model_initphase, dshr_init, dshr_mesh_init
Expand Down Expand Up @@ -58,6 +58,11 @@ module cdeps_docn_comp
use docn_datamode_cplhist_mod , only : docn_datamode_cplhist_advance
use docn_datamode_cplhist_mod , only : docn_datamode_cplhist_restart_read
use docn_datamode_cplhist_mod , only : docn_datamode_cplhist_restart_write
use docn_datamode_multilev_mod , only : docn_datamode_multilev_advertise
use docn_datamode_multilev_mod , only : docn_datamode_multilev_init_pointers
use docn_datamode_multilev_mod , only : docn_datamode_multilev_advance
use docn_datamode_multilev_mod , only : docn_datamode_multilev_restart_read
use docn_datamode_multilev_mod , only : docn_datamode_multilev_restart_write
use docn_import_data_mod , only : docn_import_data_advertise

implicit none
Expand Down Expand Up @@ -193,6 +198,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
integer :: bcasttmp(4)
real(r8) :: rtmp(1)
type(ESMF_VM) :: vm
integer :: nlev = 60 !DEBUG - remove this and put into namelist
character(len=*),parameter :: subname=trim(module_name)//':(InitializeAdvertise) '
character(*) ,parameter :: F00 = "('(" // trim(module_name) // ") ',8a)"
character(*) ,parameter :: F01 = "('(" // trim(module_name) // ") ',a,2x,i8)"
Expand Down Expand Up @@ -300,7 +306,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
trim(datamode) == 'som_aquap' .or. & ! read stream, needs import data
trim(datamode) == 'cplhist' .or. & ! read stream, needs import data
trim(datamode) == 'sst_aquap_analytic' .or. & ! analytic, no streams, import or export data
trim(datamode) == 'sst_aquap_constant' ) then ! analytic, no streams, import or export data
trim(datamode) == 'sst_aquap_constant' .or. & ! analytic, no streams, import or export data
trim(datamode) == 'multilev') then ! multilevel ocean input
! success do nothing
else
call shr_sys_abort(' ERROR illegal docn datamode = '//trim(datamode))
Expand All @@ -323,6 +330,9 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
else if (trim(datamode) == 'cplhist') then
call docn_datamode_cplhist_advertise(exportState, fldsExport, flds_scalar_name, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else if (trim(datamode) == 'multilev') then
call docn_datamode_multilev_advertise(exportState, fldsExport, flds_scalar_name, nlev, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

if (trim(import_data_fields) /= 'none') then
Expand Down Expand Up @@ -550,6 +560,9 @@ subroutine docn_comp_run(importState, exportState, clock, target_ymd, target_tod
case('cplhist')
call docn_datamode_cplhist_init_pointers(exportState, model_frac, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
case('multilev')
call docn_datamode_multilev_init_pointers(exportState, model_frac, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end select

! Read restart if needed
Expand Down Expand Up @@ -607,6 +620,9 @@ subroutine docn_comp_run(importState, exportState, clock, target_ymd, target_tod
case('cplhist')
call docn_datamode_cplhist_advance(rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
case('multilev')
call docn_datamode_multilev_advance(rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end select

! Write restarts if needed (no restarts for aquaplanet analytic or aquaplanet input file)
Expand Down Expand Up @@ -650,8 +666,10 @@ subroutine docn_init_dfields(importState, exportState, rc)
! local variables
integer :: n
integer :: fieldcount
integer :: dimcount
type(ESMF_Field) :: lfield
character(ESMF_MAXSTR) ,pointer :: lfieldnamelist(:)
character(ESMF_MAXSTR) :: fieldname(1)
character(*), parameter :: subName = "(docn_init_dfields) "
!-------------------------------------------------------------------------------

Expand All @@ -668,9 +686,18 @@ subroutine docn_init_dfields(importState, exportState, rc)
call ESMF_StateGet(exportState, itemName=trim(lfieldNameList(n)), field=lfield, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (trim(lfieldnamelist(n)) /= flds_scalar_name) then
call dshr_dfield_add( dfields, sdat, trim(lfieldnamelist(n)), trim(lfieldnamelist(n)), exportState, &
logunit, mainproc, rc)
call ESMF_FieldGet(lfield, dimcount=dimCount, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (dimcount == 2) then
fieldname(1) = trim(lfieldnamelist(n))
call dshr_dfield_add( dfields, sdat, trim(lfieldnamelist(n)), fieldname, exportState, &
logunit, mainproc, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
else
call dshr_dfield_add( dfields, sdat, trim(lfieldnamelist(n)), trim(lfieldnamelist(n)), exportState, &
logunit, mainproc, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
endif
end if
end do
end subroutine docn_init_dfields
Expand Down
7 changes: 4 additions & 3 deletions dshr/dshr_dfield_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ subroutine dshr_dfield_copy(dfields, sdat, rc)
type(ESMF_field) :: lfield
type(dfield_type), pointer :: dfield
real(r8), pointer :: data1d(:)
real(r8), pointer :: data2d(:,:)
integer :: nf
integer :: fldbun_index
integer :: stream_index
Expand All @@ -464,13 +465,13 @@ subroutine dshr_dfield_copy(dfields, sdat, rc)
do nf = 1,size(dfield%stream_indices)
stream_index = dfield%stream_indices(nf)
fldbun_index = dfield%fldbun_indices(nf)
if(stream_index > 0) then
if (stream_index > 0) then
fldbun_model = shr_strdata_get_stream_fieldbundle(sdat, stream_index, 'model')
call dshr_fldbun_getfieldn(fldbun_model, fldbun_index, lfield, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call dshr_field_getfldptr(lfield, fldptr1=data1d, rc=rc)
call dshr_field_getfldptr(lfield, fldptr2=data2d, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
dfield%state_data2d(nf,:) = data1d(:)
dfield%state_data2d(:,:) = data2d(:,:)
endif
end do
end if
Expand Down
4 changes: 2 additions & 2 deletions streams/dshr_methods_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ subroutine dshr_field_getfldptr(field, fldptr1, fldptr2, rank, abort, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (ungriddedUBound(1) > 0) then
if (.not.present(fldptr2)) then
call ESMF_LogWrite(trim(subname)//": ERROR missing rank=2 array ", &
call ESMF_LogWrite(trim(subname)//": ERROR missing rank=2 array for "//trim(name), &
ESMF_LOGMSG_ERROR, line=__LINE__, file=u_FILE_u)
rc = ESMF_FAILURE
return
Expand All @@ -578,7 +578,7 @@ subroutine dshr_field_getfldptr(field, fldptr1, fldptr2, rank, abort, rc)
lrank = 2
else
if (.not.present(fldptr1)) then
call ESMF_LogWrite(trim(subname)//": ERROR missing rank=1 array ", &
call ESMF_LogWrite(trim(subname)//": ERROR missing rank=1 array for "//trim(name), &
ESMF_LOGMSG_ERROR, line=__LINE__, file=u_FILE_u)
rc = ESMF_FAILURE
return
Expand Down

0 comments on commit 1e9220b

Please sign in to comment.