Skip to content

Commit

Permalink
Merge remote-tracking branch 'escomp/main' into feature/add_blom
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertens committed Jul 11, 2024
2 parents 5bf3de0 + e4a5e58 commit 3862218
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
15 changes: 13 additions & 2 deletions cime_config/namelist_definition_drv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -872,17 +872,28 @@
<value COMP_LND="xlnd">off</value>
</values>
</entry>
<entry id="remove_negative_runoff">
<entry id="remove_negative_runoff_lnd">
<type>logical</type>
<category>control</category>
<group>MED_attributes</group>
<desc>
If true, remove negative runoff by downweighting all positive runoff globally.
If true, remove negative runoff generated from the land component by downweighting all positive runoff globally.
</desc>
<values>
<value>.true.</value>
</values>
</entry>
<entry id="remove_negative_runoff_glc">
<type>logical</type>
<category>control</category>
<group>MED_attributes</group>
<desc>
If true, remove negative runoff generated from the glc (ice sheet) component by downweighting all positive runoff globally.
</desc>
<values>
<value>.false.</value>
</values>
</entry>

<entry id="info_debug" modify_via_xml="INFO_DBUG">
<type>integer</type>
Expand Down
10 changes: 9 additions & 1 deletion mediator/med_io_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,15 @@ subroutine med_io_write_FB(io_file, FB, whead, wdata, nx, ny, nt, &
call pio_syncfile(io_file)
call pio_freedecomp(io_file, iodesc)
endif
deallocate(ownedElemCoords, ownedElemCoords_x, ownedElemCoords_y)
if(allocated(ownedElemCoords)) then
deallocate(ownedElemCoords)
endif
if(allocated(ownedElemCoords_x)) then
deallocate(ownedElemCoords_x)
endif
if(allocated(ownedElemCoords_y)) then
deallocate(ownedElemCoords_y)
endif

if (dbug_flag > 5) then
call ESMF_LogWrite(trim(subname)//": done", ESMF_LOGMSG_INFO)
Expand Down
4 changes: 4 additions & 0 deletions mediator/med_phases_aofluxes_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,10 @@ subroutine set_aoflux_in_pointers(fldbun_a, fldbun_o, aoflux_in, lsize, xgrid, r
if (add_gusts) then
call fldbun_getfldptr(fldbun_a, 'Faxa_rainc', aoflux_in%rainc, xgrid=xgrid, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
else
! rainc is not used without add_gusts but some compilers complain about the unallocated pointer
! in the subroutine interface
allocate(aoflux_in%rainc(1))
end if
end if

Expand Down
55 changes: 38 additions & 17 deletions mediator/med_phases_post_rof_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ module med_phases_post_rof_mod
integer :: num_rof_fields
character(len=CS), allocatable :: rof_field_names(:)

logical :: remove_negative_runoff

character(len=13), parameter :: fields_to_remove_negative_runoff(4) = &
['Forr_rofl ', &
'Forr_rofi ', &
'Forr_rofl_glc', &
logical :: remove_negative_runoff_lnd
logical :: remove_negative_runoff_glc

character(len=9), parameter :: fields_to_remove_negative_runoff_lnd(2) = &
['Forr_rofl', &
'Forr_rofi']
character(len=13), parameter :: fields_to_remove_negative_runoff_glc(2) = &
['Forr_rofl_glc', &
'Forr_rofi_glc']

character(*) , parameter :: u_FILE_u = &
__FILE__

Expand Down Expand Up @@ -77,12 +79,20 @@ subroutine med_phases_post_rof_init(gcomp, rc)
call med_phases_post_rof_create_rof_field_bundle(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call NUOPC_CompAttributeGet(gcomp, name='remove_negative_runoff', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name='remove_negative_runoff_lnd', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) remove_negative_runoff_lnd
else
remove_negative_runoff_lnd = .false.
end if

call NUOPC_CompAttributeGet(gcomp, name='remove_negative_runoff_glc', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) remove_negative_runoff
read(cvalue,*) remove_negative_runoff_glc
else
remove_negative_runoff = .false.
remove_negative_runoff_glc = .false.
end if

! remove_negative_runoff isn't yet set up to handle isotope fields, so ensure that
Expand All @@ -94,12 +104,13 @@ subroutine med_phases_post_rof_init(gcomp, rc)
else
flds_wiso = .false.
end if
if (remove_negative_runoff .and. flds_wiso) then
call shr_sys_abort('remove_negative_runoff must be set to false when flds_wiso is true')
if ((remove_negative_runoff_lnd .or. remove_negative_runoff_glc) .and. flds_wiso) then
call shr_sys_abort('remove_negative_runoff_lnd and remove_negative_runoff_glc must be set to false when flds_wiso is true')
end if

if (maintask) then
write(logunit,'(a,l7)') trim(subname)//' remove_negative_runoff = ', remove_negative_runoff
write(logunit,'(a,l7)') trim(subname)//' remove_negative_runoff_lnd = ', remove_negative_runoff_lnd
write(logunit,'(a,l7)') trim(subname)//' remove_negative_runoff_glc = ', remove_negative_runoff_glc
end if

if (dbug_flag > 20) then
Expand Down Expand Up @@ -143,12 +154,22 @@ subroutine med_phases_post_rof(gcomp, rc)
data_copy(:) = data_orig(:)
end do

if (remove_negative_runoff) then
do n = 1, size(fields_to_remove_negative_runoff)
call ESMF_FieldBundleGet(FBrof_r, fieldName=trim(fields_to_remove_negative_runoff(n)), isPresent=exists, rc=rc)
if (remove_negative_runoff_lnd) then
do n = 1, size(fields_to_remove_negative_runoff_lnd)
call ESMF_FieldBundleGet(FBrof_r, fieldName=trim(fields_to_remove_negative_runoff_lnd(n)), isPresent=exists, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (exists) then
call med_phases_post_rof_remove_negative_runoff(gcomp, fields_to_remove_negative_runoff_lnd(n), rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
end do
end if
if (remove_negative_runoff_glc) then
do n = 1, size(fields_to_remove_negative_runoff_glc)
call ESMF_FieldBundleGet(FBrof_r, fieldName=trim(fields_to_remove_negative_runoff_glc(n)), isPresent=exists, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (exists) then
call med_phases_post_rof_remove_negative_runoff(gcomp, fields_to_remove_negative_runoff(n), rc)
call med_phases_post_rof_remove_negative_runoff(gcomp, fields_to_remove_negative_runoff_glc(n), rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
end do
Expand Down

0 comments on commit 3862218

Please sign in to comment.