Skip to content

Commit

Permalink
updates for dglc features required
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariana Vertenstein committed Mar 30, 2024
1 parent a5f6ecb commit e88f40c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 112 deletions.
4 changes: 2 additions & 2 deletions dglc/cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path
scol_lat = float(case.get_value('PTS_LAT'))
else:
scol_lat = -999.
if (scol_lon > -999. and scol_lat > 999.):
if (scol_lon > -999. or scol_lat > -999.):
expect(False,
"single column mode for DGLC is not currently allowed")

Expand All @@ -80,7 +80,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path
nmlgen.write_output_file(namelist_file, data_list_path, groups=['dglc_nml'])

# Generate dglc.streams.xml
print("dglc_mode is {}".format(dglc_mode))
logger.debug("dglc_mode is {}".format(dglc_mode))

if 'noevolve' in dglc_mode:
generate_stream_file = False
Expand Down
13 changes: 1 addition & 12 deletions dglc/cime_config/config_component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</values>
<group>run_component_dglc</group>
<file>env_run.xml</file>
<desc>
<desc>
NOEVOLVE mode is used in CESM as follows.
In typical runs, CISM is not evolving; CLM computes the surface mass
balance (SMB) and sends it to CISM, but CISM’s ice sheet geometry
Expand All @@ -43,17 +43,6 @@
</desc>
</entry>

<entry id="DGLC_GET_IMPORT_DATA">
<type>logical</type>
<default_value>FALSE</default_value>
<group>run_component_dglc</group>
<file>env_run.xml</file>
<desc>
If true, have the mediator calculate import values that are sent back to
GLC even in GLC is in NOEVOLVE mode
</desc>
</entry>

<entry id="DGLC_USE_GREENLAND">
<type>logical</type>
<default_value>FALSE</default_value>
Expand Down
37 changes: 11 additions & 26 deletions dglc/cime_config/namelist_definition_dglc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<group>dglc_nml</group>
<values>
<value glc_grid="ais8:gris4">$DIN_LOC_ROOT/glc/cism/Antarctica/ISMIP6_Antarctica_8km.init.c210908.nc:$DIN_LOC_ROOT/glc/cism/Greenland/greenland_4km_epsg3413_c171126.nc</value>
<value glc_grid="gris20">$DIN_LOC_ROOT/glc/cism/Greenland/gland20.input_c150415.nc</value>
<value glc_grid="gris4" >$DIN_LOC_ROOT/glc/cism/Greenland/greenland_4km_epsg3413_c171126.nc</value>
<value glc_grid="ais8" >$DIN_LOC_ROOT/glc/cism/Antarctica/ISMIP6_Antarctica_8km.init.c210908.nc</value>
</values>
Expand All @@ -65,18 +64,19 @@
</desc>
</entry>

<entry id="model_areas">
<entry id="model_internal_gridsize">
<type>real(20)</type>
<category>streams</category>
<group>dglc_nml</group>
<values>
<value glc_grid="ais8:gris4">3.94162024004361e-07,1.57664809601744e-06</value>
<value glc_grid="gris20">1.</value>
<value glc_grid="gris4" >3.94162024004361e-07</value>
<value glc_grid="ais8" >1.57664809601744e-06</value>
<value glc_grid="ais8:gris4">8000,4000</value>
<value glc_grid="gris4" >4000</value>
<value glc_grid="ais8" >8000</value>
</values>
<desc>
colon deliminted string of inputdata files
model internal grid size(s) in m which is used to compute the internal model
model area in radians**2 using the formula (model_internal_gridsize/shr_const_rearth)**2 -
for more than one ice sheet this will contain an array of model_internal_gridsize values.
</desc>
</entry>

Expand All @@ -91,8 +91,8 @@
<value glc_grid="gris20">76</value>
</values>
<desc>
global size(s) of nx
for more than one ice sheets this will contain an array of nx values
global size(s) of nx where for more than one ice sheet this
will contain an array of nx values
</desc>
</entry>

Expand All @@ -107,8 +107,8 @@
<value glc_grid="gris20">141</value>
</values>
<desc>
global size(s) of ny
for more than one ice sheets this will contain an array of ny values
global size(s) of ny where for more than one ice sheet this
will contain an array of ny values
</desc>
</entry>

Expand All @@ -124,21 +124,6 @@
</values>
</entry>

<entry id="get_import_data" modify_via_xml="DGLC_GET_IMPORT_DATA">
<type>logical</type>
<category>dglc</category>
<group>dglc_nml</group>
<desc>
If set to true, than dglc will advertise and realize import
fields even if it does not do anything with them. This
capability is used, for example, in generating coupler history
data for GLC spinup runs.
</desc>
<values>
<value>$DGLC_GET_IMPORT_DATA</value>
</values>
</entry>

<entry id="skip_restart_read" modify_via_xml="DGLC_SKIP_RESTART_READ">
<type>logical</type>
<category>dglc</category>
Expand Down
96 changes: 45 additions & 51 deletions dglc/dglc_datamode_noevolve_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module dglc_datamode_noevolve_mod
use NUOPC , only : NUOPC_Advertise, NUOPC_IsConnected
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_const_mod , only : SHR_CONST_RHOICE, SHR_CONST_RHOSW
use shr_const_mod , only : SHR_CONST_RHOICE, SHR_CONST_RHOSW, SHR_CONST_REARTH
use dshr_methods_mod , only : dshr_state_getfldptr, dshr_fldbun_getfldptr, chkerr
use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add
use dshr_strdata_mod , only : shr_strdata_type
Expand All @@ -27,7 +27,6 @@ module dglc_datamode_noevolve_mod
logical :: initialized_noevolve = .false.
integer :: num_icesheets
real(r8) :: thk0 = 1._r8
logical :: get_import_data

! Data structure to enable multiple ice sheets
type icesheet_ptr_t
Expand Down Expand Up @@ -65,13 +64,12 @@ module dglc_datamode_noevolve_mod
!===============================================================================

subroutine dglc_datamode_noevolve_advertise(NStateExp, fldsexport, NStateImp, fldsimport, &
get_import_data_in, flds_scalar_name, rc)
flds_scalar_name, rc)

! input/output variables
type(ESMF_State) , intent(inout) :: NStateExp(:)
type(fldlist_type), pointer :: fldsexport
type(ESMF_State) , intent(inout) :: NStateImp(:)
logical , intent(in) :: get_import_data_in
type(fldlist_type), pointer :: fldsimport
character(len=*) , intent(in) :: flds_scalar_name
integer , intent(out) :: rc
Expand All @@ -84,9 +82,6 @@ subroutine dglc_datamode_noevolve_advertise(NStateExp, fldsexport, NStateImp, fl

rc = ESMF_SUCCESS

! Set module vraiable
get_import_data = get_import_data_in

!--------------------------------
! Create nested state for active ice sheets only
!--------------------------------
Expand Down Expand Up @@ -114,22 +109,20 @@ subroutine dglc_datamode_noevolve_advertise(NStateExp, fldsexport, NStateImp, fl
enddo

! Advertise import fields if appropriate
if (get_import_data) then
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)

do ns = 1,num_icesheets
write(cnum,'(i0)') ns
fldlist => fldsImport ! the head of the linked list
do while (associated(fldlist))
call NUOPC_Advertise(NStateImp(ns), standardName=fldlist%stdname, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite('(dglc_comp_advertise): To_glc'//trim(cnum)//"_"//trim(fldList%stdname), ESMF_LOGMSG_INFO)
fldList => fldList%next
end do
enddo
end if
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)

do ns = 1,num_icesheets
write(cnum,'(i0)') ns
fldlist => fldsImport ! the head of the linked list
do while (associated(fldlist))
call NUOPC_Advertise(NStateImp(ns), standardName=fldlist%stdname, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite('(dglc_comp_advertise): To_glc'//trim(cnum)//"_"//trim(fldList%stdname), ESMF_LOGMSG_INFO)
fldList => fldList%next
end do
enddo

end subroutine dglc_datamode_noevolve_advertise

Expand Down Expand Up @@ -172,39 +165,37 @@ subroutine dglc_datamode_noevolve_init_pointers(NStateExp, NstateImp, rc)
end do

! initialize pointers to import fields if appropriate
if (get_import_data) then
allocate(Sl_tsrf(num_icesheets))
allocate(Flgl_qice(num_icesheets))

do ns = 1,num_icesheets
! NOTE: the field is connected ONLY if the MED->GLC entry is in the nuopc.runconfig file
! This restriction occurs even if the field was advertised
if (NUOPC_IsConnected(NStateImp(ns), fieldName=field_in_tsrf)) then
call dshr_state_getfldptr(NStateImp(ns), field_in_tsrf, fldptr1=Sl_tsrf(ns)%ptr, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if
if (NUOPC_IsConnected(NStateImp(ns), fieldName=field_in_qice)) then
call dshr_state_getfldptr(NStateImp(ns), field_in_qice, fldptr1=Flgl_qice(ns)%ptr, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if
end do
end if
allocate(Sl_tsrf(num_icesheets))
allocate(Flgl_qice(num_icesheets))

do ns = 1,num_icesheets
! NOTE: the field is connected ONLY if the MED->GLC entry is in the nuopc.runconfig file
! This restriction occurs even if the field was advertised
if (NUOPC_IsConnected(NStateImp(ns), fieldName=field_in_tsrf)) then
call dshr_state_getfldptr(NStateImp(ns), field_in_tsrf, fldptr1=Sl_tsrf(ns)%ptr, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if
if (NUOPC_IsConnected(NStateImp(ns), fieldName=field_in_qice)) then
call dshr_state_getfldptr(NStateImp(ns), field_in_qice, fldptr1=Flgl_qice(ns)%ptr, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if
end do

end subroutine dglc_datamode_noevolve_init_pointers

!===============================================================================
subroutine dglc_datamode_noevolve_advance(pio_subsystem, io_type, io_format, &
model_meshes, model_areas, input_files, rc)
model_meshes, model_internal_gridsize, model_datafiles, rc)

! Assume that the model mesh is the same as the input data mesh

! input/output variables
type(iosystem_desc_t) , pointer :: pio_subsystem ! pio info
integer , intent(in) :: io_type ! pio info
integer , intent(in) :: io_format ! pio info
type(ESMF_Mesh) , intent(in) :: model_meshes(:) ! ice sheets meshes
real(r8) , intent(in) :: model_areas(:) ! internal model ice sheets areas (radians**2)
character(len=*) , intent(in) :: input_files(:) ! input file names
type(iosystem_desc_t) , pointer :: pio_subsystem ! pio info
integer , intent(in) :: io_type ! pio info
integer , intent(in) :: io_format ! pio info
type(ESMF_Mesh) , intent(in) :: model_meshes(:) ! ice sheets meshes
real(r8) , intent(in) :: model_internal_gridsize(:) ! internal model gridsizes (m)
character(len=*) , intent(in) :: model_datafiles(:) ! input file names
integer , intent(out) :: rc

! local variables
Expand Down Expand Up @@ -251,8 +242,11 @@ subroutine dglc_datamode_noevolve_advance(pio_subsystem, io_type, io_format, &
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! Determine "glc_area" ;
! Sg_areas is in radians
! SHR_CONST_REARTH is the radius of earth in m
! model_internal_gridsize is the internal model gridsize in m
do ng = 1,lsize
Sg_area(ns)%ptr(ng) = model_areas(ns)
Sg_area(ns)%ptr(ng) = (model_internal_gridsize(ns)/SHR_CONST_REARTH)**2
end do

! Create module level field bundle
Expand All @@ -271,12 +265,12 @@ subroutine dglc_datamode_noevolve_advance(pio_subsystem, io_type, io_format, &
if (chkerr(rc,__LINE__,u_FILE_u)) return

! Create pioid and pio_iodesc at the module level
inquire(file=trim(input_files(ns)), exist=exists)
inquire(file=trim(model_datafiles(ns)), exist=exists)
if (.not.exists) then
write(6,'(a)')' ERROR: model input file '//trim(input_files(ns))//' does not exist'
write(6,'(a)')' ERROR: model input file '//trim(model_datafiles(ns))//' does not exist'
call shr_sys_abort()
end if
rcode = pio_openfile(pio_subsystem, pioid, io_type, trim(input_files(ns)), pio_nowrite)
rcode = pio_openfile(pio_subsystem, pioid, io_type, trim(model_datafiles(ns)), pio_nowrite)
call pio_seterrorhandling(pioid, PIO_BCAST_ERROR)
rcode = pio_inq_varid(pioid, 'thk', varid)
rcode = pio_inq_varndims(pioid, varid, ndims)
Expand Down
37 changes: 16 additions & 21 deletions dglc/glc_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ module cdeps_dglc_comp
character(*) , parameter :: nullstr = 'null'
integer , parameter :: max_icesheets = 10 ! maximum number of ice sheets for namelist input
integer :: num_icesheets ! actual number of ice sheets
logical :: get_import_data = .false.

! namelist input
character(CL) :: model_meshfiles(max_icesheets) = nullstr
character(CL) :: model_datafiles(max_icesheets) = nullstr
integer :: nx_global(max_icesheets) = 0
integer :: ny_global(max_icesheets) = 0
real(r8) :: model_areas(max_icesheets) = 1.e36
real(r8) :: model_internal_gridsize(max_icesheets) = 1.e36

! module variables for multiple ice sheets
type(shr_strdata_type) , allocatable :: sdat(:)
Expand Down Expand Up @@ -184,7 +183,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
integer :: inst_index ! number of current instance (ie. 1)
integer :: nu ! unit number
integer :: ierr ! error code
integer :: bcasttmp(3)
integer :: bcasttmp(2)
integer :: ns
character(len=CS) :: cnum
character(len=ESMF_MAXSTR) :: model_datafiles_list ! colon separated string containing input datafiles
Expand All @@ -194,8 +193,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)

! Note that the suffix '-list' refers to a colon delimited string of names
namelist / dglc_nml / datamode, &
model_meshfiles_list, model_datafiles_list, model_areas, nx_global, ny_global, &
get_import_data, restfilm, skip_restart_read
model_meshfiles_list, model_datafiles_list, model_internal_gridsize, nx_global, ny_global, &
restfilm, skip_restart_read

rc = ESMF_SUCCESS

Expand Down Expand Up @@ -238,22 +237,19 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
write(logunit,'(a,a)')' case_name = ',trim(case_name)
write(logunit,'(a,a)')' datamode = ',trim(datamode)
do ns = 1,num_icesheets
write(logunit,'(a,i4 )') ' ice_sheet index = ',ns
write(logunit,'(a,a )') ' model_meshfile = ',trim(model_meshfiles(ns))
write(logunit,'(a,a )') ' model_datafile = ',trim(model_datafiles(ns))
write(logunit,'(a,i10)') ' nx_global = ',nx_global(ns)
write(logunit,'(a,i10)') ' ny_global = ',ny_global(ns)
write(logunit,'(a,d13.5)')' model_areas = ',model_areas(ns)
write(logunit,'(a,i4 )') ' ice_sheet index = ',ns
write(logunit,'(a,a )') ' model_meshfile = ',trim(model_meshfiles(ns))
write(logunit,'(a,a )') ' model_datafile = ',trim(model_datafiles(ns))
write(logunit,'(a,d13.5)')' model_internal_gridsize = ',model_internal_gridsize(ns)
write(logunit,'(a,i10)') ' nx_global = ',nx_global(ns)
write(logunit,'(a,i10)') ' ny_global = ',ny_global(ns)
end do
write(logunit,'(a,a )')' restfilm = ',trim(restfilm)
write(logunit,'(a,l6)')' get_import_data = ',get_import_data
write(logunit,'(a,l6)')' skip_restart_read = ',skip_restart_read

bcasttmp(1) = 0
if(skip_restart_read) bcasttmp(1) = 1
bcasttmp(2) = 0
if(get_import_data) bcasttmp(2) = 1
bcasttmp(3) = num_icesheets
bcasttmp(2) = num_icesheets
endif

! Broadcast namelist input
Expand All @@ -267,17 +263,16 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadcast(vm, model_datafiles, CL*max_icesheets, main_task, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadcast(vm, model_internal_gridsize, max_icesheets, main_task, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadcast(vm, nx_global, max_icesheets, main_task, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadcast(vm, ny_global, max_icesheets, main_task, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadcast(vm, model_areas, max_icesheets, main_task, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMBroadcast(vm, bcasttmp, 3, main_task, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
skip_restart_read = (bcasttmp(1) == 1)
get_import_data = (bcasttmp(2) == 1)
num_icesheets = bcasttmp(3)
num_icesheets = bcasttmp(2)

! Validate datamode
if ( trim(datamode) == 'noevolve') then ! read stream, no import data
Expand All @@ -304,7 +299,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
! Advertise dglc fields
if (trim(datamode)=='noevolve') then
call dglc_datamode_noevolve_advertise(NStateExp, fldsexport, NStateImp, fldsimport, &
get_import_data, flds_scalar_name, rc)
flds_scalar_name, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

Expand Down Expand Up @@ -571,7 +566,7 @@ subroutine dglc_comp_run(clock, target_ymd, target_tod, restart_write, rc)
select case (trim(datamode))
case('noevolve')
call dglc_datamode_noevolve_advance(sdat(1)%pio_subsystem, sdat(1)%io_type, sdat(1)%io_format, &
model_meshes, model_areas, model_datafiles, rc)
model_meshes, model_internal_gridsize, model_datafiles, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end select

Expand Down

0 comments on commit e88f40c

Please sign in to comment.