Skip to content

Commit

Permalink
more updates to have new code working on ogrid
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariana Vertenstein committed Jul 18, 2021
1 parent b4a1983 commit d30c9c1
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 58 deletions.
2 changes: 1 addition & 1 deletion cime_config/namelist_definition_drv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@
<type>char</type>
<category>mapping</category>
<group>MED_attributes</group>
<valid_values>ogrid,agrrid,xgrid</valid_values>
<valid_values>ogrid,agrid,xgrid</valid_values>
<desc>
Grid for atm ocn flux calc (untested)
default: ocn
Expand Down
116 changes: 89 additions & 27 deletions mediator/esmFldsExchange_cesm_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -321,34 +321,96 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
! to lnd: Pressure at the lowest model level from atm
! to lnd: specific humidity at the lowest model level from atm
! ---------------------------------------------------------------------

allocate(flds(9))
flds = (/'Sa_z ',&
'Sa_topo ',&
'Sa_u ',&
'Sa_v ',&
'Sa_tbot ',&
'Sa_ptem ',&
'Sa_pbot ',&
'Sa_shum ',&
'Sa_shum_wiso'/)

do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, trim(fldname))
call addfld(fldListTo(complnd)%flds, trim(fldname))
else
if ( fldchk(is_local%wrap%FBexp(complnd) , trim(fldname), rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), trim(fldname), rc=rc)) then
call addmap(fldListFr(compatm)%flds, trim(fldname), &
complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, trim(fldname), &
mrg_from=compatm, mrg_fld=trim(fldname), mrg_type='copy')
end if
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, 'Sa_z')
call addfld(fldListTo(complnd)%flds, 'Sa_z')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_z', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_z', rc=rc)) then
call addmap(fldListFr(compatm)%flds, 'Sa_z', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, 'Sa_z', mrg_from=compatm, mrg_fld='Sa_z', mrg_type='copy')
end if
end do
deallocate(flds)
end if
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, 'Sa_topo')
call addfld(fldListTo(complnd)%flds, 'Sa_topo')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_topo', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_topo', rc=rc)) then
call addmap(fldListFr(compatm)%flds, 'Sa_topo', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, 'Sa_topo', mrg_from=compatm, mrg_fld='Sa_topo', mrg_type='copy')
end if
end if
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, 'Sa_u')
call addfld(fldListTo(complnd)%flds, 'Sa_u')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_u', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_u', rc=rc)) then
call addmap(fldListFr(compatm)%flds, 'Sa_u', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, 'Sa_u', mrg_from=compatm, mrg_fld='Sa_u', mrg_type='copy')
end if
end if
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, 'Sa_v')
call addfld(fldListTo(complnd)%flds, 'Sa_v')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_v', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_v', rc=rc)) then
call addmap(fldListFr(compatm)%flds, 'Sa_v', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, 'Sa_v', mrg_from=compatm, mrg_fld='Sa_v', mrg_type='copy')
end if
end if
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, 'Sa_pbot')
call addfld(fldListTo(complnd)%flds, 'Sa_pbot')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_pbot', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_pbot', rc=rc)) then
call addmap(fldListFr(compatm)%flds, 'Sa_pbot', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, 'Sa_pbot', mrg_from=compatm, mrg_fld='Sa_pbot', mrg_type='copy')
end if
end if
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, 'Sa_tbot')
call addfld(fldListTo(complnd)%flds, 'Sa_tbot')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_tbot', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_tbot', rc=rc)) then
call addmap(fldListFr(compatm)%flds, 'Sa_tbot', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, 'Sa_tbot', mrg_from=compatm, mrg_fld='Sa_tbot', mrg_type='copy')
end if
end if
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, 'Sa_ptem')
call addfld(fldListTo(complnd)%flds, 'Sa_ptem')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_ptem', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_ptem', rc=rc)) then
call addmap(fldListFr(compatm)%flds, 'Sa_ptem', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, 'Sa_ptem', mrg_from=compatm, mrg_fld='Sa_ptem', mrg_type='copy')
end if
end if
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, 'Sa_shum')
call addfld(fldListTo(complnd)%flds, 'Sa_shum')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_shum', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_shum', rc=rc)) then
call addmap(fldListFr(compatm)%flds, 'Sa_shum', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, 'Sa_shum', mrg_from=compatm, mrg_fld='Sa_shum', mrg_type='copy')
end if
end if
if (phase == 'advertise') then
call addfld(fldListFr(compatm)%flds, 'Sa_shum_wiso')
call addfld(fldListTo(complnd)%flds, 'Sa_shum_wiso')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_shum_wiso', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_shum_wiso', rc=rc)) then
call addmap(fldListFr(compatm)%flds, 'Sa_shum_wiso', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg(fldListTo(complnd)%flds, 'Sa_shum_wiso', mrg_from=compatm, mrg_fld='Sa_shum_wiso', mrg_type='copy')
end if
end if

! ---------------------------------------------------------------------
! to lnd: convective and large scale precipitation rate water equivalent from atm
Expand Down
64 changes: 34 additions & 30 deletions mediator/med_phases_aofluxes_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,9 @@ subroutine med_aofluxes_init(gcomp, aoflux, rc)
!----------------------------------

if (trim(coupling_mode) == 'nems_orig_data' .and. ocn_surface_flux_scheme == -1) then
! TODO: fix this
allocate(fldnames_atm_in(8))
! fldnames_atm_in = (/'Sa_z ','Sa_u10m ','Sa_v10m ','Sa_t2m ',&
! 'Sa_q2m ','Sa_pbot ','Sa_dens ','Sa_ptem'/)
! fldnames_atm_in = (/'Sa_u10m','Sa_v10m','Sa_t2m ','Sa_q2m '/)
allocate(fldnames_atm_in(10))
fldnames_atm_in = (/'Sa_u ','Sa_v ','Sa_z ','Sa_tbot','Sa_pbot','Sa_shum', &
'Sa_u10m','Sa_v10m','Sa_t2m','Sa_q2m '/)
else if (flds_wiso) then
allocate(fldnames_atm_in(9))
fldnames_atm_in = (/'Sa_z ','Sa_u ','Sa_v ','Sa_tbot ',&
Expand Down Expand Up @@ -1127,7 +1125,7 @@ subroutine med_aofluxes_update(gcomp, aoflux, rc)
use ESMF , only : ESMF_GridComp
use ESMF , only : ESMF_LogWrite, ESMF_LogMsg_Info, ESMF_SUCCESS
use ESMF , only : ESMF_TERMORDER_SRCSEQ, ESMF_REGION_TOTAL
use esmFlds , only : mapconsd
use esmFlds , only : mapconsd, mapconsf
use med_map_mod , only : med_map_field_packed
use shr_flux_mod , only : shr_flux_atmocn

Expand Down Expand Up @@ -1173,23 +1171,25 @@ subroutine med_aofluxes_update(gcomp, aoflux, rc)
call ESMF_FieldBundleGet(FBocn_a, fldnames_ocn_in(nf), field=field_dst, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

write(6,*)'DEBUG: mapping to atm nf ',nf,trim(fldnames_ocn_in(nf))
! Map ocn->atm conservatively without fractions
call ESMF_FieldRegrid(field_src, field_dst, &
routehandle=is_local%wrap%RH(compocn,compatm,mapconsd), &
termorderflag=ESMF_TERMORDER_SRCSEQ, zeroregion=ESMF_REGION_TOTAL, rc=rc)
write(6,*)'DEBUG: finished mapping to atm'

! One normalization
call ESMF_FieldGet(is_local%wrap%field_normOne(compatm,compatm,mapconsd), farrayPtr=data_normdst, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_FieldGet(field_dst, farrayptr=data_dst, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
do n = 1,size(data_dst)
if (data_normdst(n) == 0.0_r8) then
data_dst(n) = 0.0_r8
else
data_dst(n) = data_dst(n)/data_normdst(n)
end if
end do
! call ESMF_FieldGet(is_local%wrap%field_normOne(compocn,compatm,mapconsd), farrayPtr=data_normdst, rc=rc)
! if (chkerr(rc,__LINE__,u_FILE_u)) return
! call ESMF_FieldGet(field_dst, farrayptr=data_dst, rc=rc)
! if (chkerr(rc,__LINE__,u_FILE_u)) return
! do n = 1,size(data_dst)
! if (data_normdst(n) == 0.0_r8) then
! data_dst(n) = 0.0_r8
! else
! data_dst(n) = data_dst(n)/data_normdst(n)
! end if
! end do
end do


Expand Down Expand Up @@ -1265,7 +1265,6 @@ subroutine med_aofluxes_update(gcomp, aoflux, rc)
aoflux%u10(n) = sqrt(aoflux%duu10n(n))
end if
enddo
call t_stopf('MED:'//subname)

!----------------------------------
! map aoflux to output to relevant atm/ocn grid(s)
Expand All @@ -1287,23 +1286,26 @@ subroutine med_aofluxes_update(gcomp, aoflux, rc)
call ESMF_FieldBundleGet(is_local%wrap%FBMed_aoflux_o, fldnames_aoflux_out(nf), field=field_dst, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

write(6,*)'DEBUG: mapping to ocn nf ',nf,trim(fldnames_aoflux_out(nf))
! Map atm->ocn conservatively WITHOUT fractions
call ESMF_FieldRegrid(field_src, field_dst, &
routehandle=is_local%wrap%RH(compatm, compocn, mapconsd), &
!routehandle=is_local%wrap%RH(compatm, compocn, mapconsd), &
routehandle=is_local%wrap%RH(compatm, compocn, mapconsf), &
termorderflag=ESMF_TERMORDER_SRCSEQ, zeroregion=ESMF_REGION_TOTAL, rc=rc)
write(6,*)'DEBUG: finished mapping to ocn '

! One normalization
call ESMF_FieldGet(is_local%wrap%field_normOne(compatm,compocn,mapconsd), farrayPtr=data_normdst, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_FieldGet(field_dst, farrayptr=data_dst, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
do n = 1,size(data_dst)
if (data_normdst(n) == 0.0_r8) then
data_dst(n) = 0.0_r8
else
data_dst(n) = data_dst(n)/data_normdst(n)
end if
end do
! call ESMF_FieldGet(is_local%wrap%field_normOne(compatm,compocn,mapconsd), farrayPtr=data_normdst, rc=rc)
! if (chkerr(rc,__LINE__,u_FILE_u)) return
! call ESMF_FieldGet(field_dst, farrayptr=data_dst, rc=rc)
! if (chkerr(rc,__LINE__,u_FILE_u)) return
! do n = 1,size(data_dst)
! if (data_normdst(n) == 0.0_r8) then
! data_dst(n) = 0.0_r8
! else
! data_dst(n) = data_dst(n)/data_normdst(n)
! end if
! end do
end do

else if (is_local%wrap%aoflux_grid == 'xgrid') then
Expand Down Expand Up @@ -1331,6 +1333,8 @@ subroutine med_aofluxes_update(gcomp, aoflux, rc)

end if

call t_stopf('MED:'//subname)

end subroutine med_aofluxes_update

end module med_phases_aofluxes_mod

0 comments on commit d30c9c1

Please sign in to comment.