Skip to content

Commit

Permalink
more cleanup of ufs and cesm differences
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariana Vertenstein committed Nov 15, 2021
1 parent 8824b2e commit 345d808
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 61 deletions.
46 changes: 24 additions & 22 deletions cesm/flux_atmocn/shr_flux_mod.F90
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module flux_atmocn_mod
module shr_flux_mod

! atm/ocn/flux calculations

! !USES:

use shr_kind_mod , only : R8=>SHR_KIND_R8, IN=>SHR_KIND_IN ! shared kinds
use med_internalstate_mod , only : logunit
use shr_kind_mod, only : R8=>SHR_KIND_R8, IN=>SHR_KIND_IN ! shared kinds
use shr_const_mod ! shared constants
use shr_sys_mod ! shared system routines

Expand All @@ -23,10 +22,10 @@ module flux_atmocn_mod
public :: flux_atmOcn_diurnal ! computes atm/ocn fluxes with diurnal cycle
public :: flux_atmOcn_UA ! computes atm/ocn fluxes using University of Ariz algorithm (Zeng et al., 1998)
public :: flux_MOstability ! boundary layer stability scales/functions
public :: flux_adjust_constants ! adjust constant values used in flux calculations.
public :: shr_flux_adjust_constants ! adjust constant values used in flux calculations. (used by CAM as well)

! !PRIVATE MEMBER FUNCTIONS:
private :: psi_ua
private :: psi_ua
private :: qsat_ua
private :: rough_ua
private :: cuberoot
Expand Down Expand Up @@ -78,7 +77,7 @@ module flux_atmocn_mod
contains
!===============================================================================

subroutine flux_adjust_constants( &
subroutine shr_flux_adjust_constants( &
zvir, cpair, cpvir, karman, gravit, &
latvap, latice, stebol, flux_convergence_tolerance, &
flux_convergence_max_iteration, &
Expand Down Expand Up @@ -111,7 +110,7 @@ subroutine flux_adjust_constants( &
if (present(flux_convergence_max_iteration)) flux_con_max_iter = flux_convergence_max_iteration
if (present(coldair_outbreak_mod)) use_coldair_outbreak_mod = coldair_outbreak_mod

end subroutine flux_adjust_constants
end subroutine shr_flux_adjust_constants

!===============================================================================
! !IROUTINE: flux_atmOcn -- internal atm/ocn flux calculation
Expand All @@ -133,7 +132,7 @@ end subroutine flux_adjust_constants
! (ocn_surface_flux_scheme .eq. 1) based on code from
! Thomas Toniazzo (Bjerknes Centre, Bergen) ”
!===============================================================================
SUBROUTINE flux_atmOcn(nMax ,zbot ,ubot ,vbot ,thbot , &
SUBROUTINE flux_atmOcn(logunit, nMax ,zbot ,ubot ,vbot ,thbot , &
& qbot ,s16O ,sHDO ,s18O ,rbot , &
& tbot ,us ,vs , &
& ts ,mask , seq_flux_atmocn_minwind, &
Expand All @@ -142,8 +141,8 @@ SUBROUTINE flux_atmOcn(nMax ,zbot ,ubot ,vbot ,thbot , &
& evap ,evap_16O, evap_HDO, evap_18O, &
& taux ,tauy ,tref ,qref , &
& ocn_surface_flux_scheme, &
& duu10n, ustar_sv ,re_sv ,ssq_sv, &
& missval )
& duu10n, ustar_sv ,re_sv ,ssq_sv, &
& missval)

! !USES:
use water_isotopes, only: wiso_flxoce !subroutine used to calculate water isotope fluxes.
Expand All @@ -153,7 +152,8 @@ SUBROUTINE flux_atmOcn(nMax ,zbot ,ubot ,vbot ,thbot , &
! !INPUT/OUTPUT PARAMETERS:

!--- input arguments --------------------------------
integer(IN),intent(in) :: nMax ! data vector length
integer ,intent(in) :: logunit
integer(IN),intent(in) :: nMax ! data vector length
integer(IN),intent(in) :: mask (nMax) ! ocn domain mask 0 <=> out of domain
integer(IN),intent(in) :: ocn_surface_flux_scheme
real(R8) ,intent(in) :: zbot (nMax) ! atm level height (m)
Expand Down Expand Up @@ -192,7 +192,7 @@ SUBROUTINE flux_atmOcn(nMax ,zbot ,ubot ,vbot ,thbot , &
real(R8),intent(out),optional :: re_sv (nMax) ! diag: sqrt of exchange coefficient (water)
real(R8),intent(out),optional :: ssq_sv (nMax) ! diag: sea surface humidity (kg/kg)

real(R8),intent(in) ,optional :: missval ! masked value
real(R8),intent(in) ,optional :: missval ! masked value

!--- local constants --------------------------------
real(R8),parameter :: zref = 10.0_R8 ! reference height (m)
Expand Down Expand Up @@ -584,7 +584,7 @@ END subroutine flux_atmOcn
! 2019-May-08 - J. Reeves Eyre - remove convective gustiness
! and add cold air outbreak modification.
!===============================================================================
SUBROUTINE flux_atmOcn_UA( &
SUBROUTINE flux_atmOcn_UA(logunit, &
& nMax ,zbot ,ubot ,vbot ,thbot , &
& qbot ,s16O ,sHDO ,s18O ,rbot , &
& tbot , pslv ,us , vs , &
Expand All @@ -593,7 +593,7 @@ SUBROUTINE flux_atmOcn_UA( &
& evap ,evap_16O, evap_HDO, evap_18O, &
& taux ,tauy ,tref ,qref , &
& duu10n, ustar_sv ,re_sv ,ssq_sv, &
& missval )
& missval)


! !USES:
Expand All @@ -604,8 +604,9 @@ SUBROUTINE flux_atmOcn_UA( &
! !INPUT/OUTPUT PARAMETERS:

!--- input arguments --------------------------------
integer(IN),intent(in) :: nMax ! data vector length
integer(IN),intent(in) :: mask (nMax) ! ocn domain mask 0 <=> out of domain
integer ,intent(in) :: logunit
integer ,intent(in) :: nMax ! data vector length
integer ,intent(in) :: mask (nMax) ! ocn domain mask 0 <=> out of domain
real(R8) ,intent(in) :: zbot (nMax) ! atm level height (m)
real(R8) ,intent(in) :: ubot (nMax) ! atm u wind (m/s)
real(R8) ,intent(in) :: vbot (nMax) ! atm v wind (m/s)
Expand Down Expand Up @@ -1128,7 +1129,7 @@ end function cuberoot
! 2006-Nov-07 - B. Kauffman - code migrated from cpl6 to share
!===============================================================================
SUBROUTINE flux_atmOcn_diurnal &
(nMax ,zbot ,ubot ,vbot ,thbot , &
(logunit, nMax ,zbot ,ubot ,vbot ,thbot , &
qbot ,s16O ,sHDO ,s18O ,rbot , &
tbot ,us ,vs , &
ts ,mask , seq_flux_atmocn_minwind, &
Expand All @@ -1155,7 +1156,8 @@ SUBROUTINE flux_atmOcn_diurnal &
! !INPUT/OUTPUT PARAMETERS:

!--- input arguments --------------------------------
integer(IN),intent(in) :: nMax ! data vector length
integer ,intent(in) :: logunit
integer(IN),intent(in) :: nMax ! data vector length
integer(IN),intent(in) :: mask (nMax) ! ocn domain mask 0 <=> out of domain
real(R8) ,intent(in) :: zbot (nMax) ! atm level height (m)
real(R8) ,intent(in) :: ubot (nMax) ! atm u wind (m/s)
Expand Down Expand Up @@ -1891,15 +1893,15 @@ END subroutine flux_atmOcn_diurnal
! !REVISION HISTORY:
! 2007-Sep-19 - B. Kauffman, Bill Large - first version
!===============================================================================
subroutine flux_MOstability(option,arg1,arg2,arg3,arg4,arg5)
subroutine flux_MOstability(logunit,option,arg1,arg2,arg3,arg4,arg5)

! !USES:

implicit none

! !INPUT/OUTPUT PARAMETERS:

integer(IN),intent(in) :: option ! shr_flux_MOwScales or MOfunctions
integer ,intent(in) :: logunit
integer ,intent(in) :: option ! shr_flux_MOwScales or MOfunctions
real(R8) ,intent(in) :: arg1 ! scales: uStar (in) funct: zeta (in)
real(R8) ,intent(inout) :: arg2 ! scales: zkB (in) funct: phim (out)
real(R8) ,intent(out) :: arg3 ! scales: phim (out) funct: phis (out)
Expand Down Expand Up @@ -2294,4 +2296,4 @@ real (R8) function psit_30(zet)
endif
end FUNCTION psit_30

end module flux_atmocn_mod
end module shr_flux_mod
28 changes: 23 additions & 5 deletions mediator/med_phases_aofluxes_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,11 @@ subroutine med_aofluxes_init(gcomp, aoflux_in, aoflux_out, rc)
use ESMF , only : ESMF_Field, ESMF_FieldGet, ESMF_FieldBundle
use esmFlds , only : coupling_mode
use med_methods_mod , only : FB_fldchk => med_methods_FB_FldChk
#ifdef CESMCOUPLED
use shr_flux_mod , only : shr_flux_adjust_constants
#else
use flux_atmocn_mod , only : flux_adjust_constants

#endif
!-----------------------------------------------------------------------
! Initialize pointers to the module variables
!-----------------------------------------------------------------------
Expand Down Expand Up @@ -421,10 +424,18 @@ subroutine med_aofluxes_init(gcomp, aoflux_in, aoflux_out, rc)
else
flux_convergence = 0.0_r8
end if

#ifdef CESMCOUPLED
call shr_flux_adjust_constants(&
flux_convergence_tolerance=flux_convergence, &
flux_convergence_max_iteration=flux_max_iteration, &
coldair_outbreak_mod=coldair_outbreak_mod)
#else
call flux_adjust_constants(&
flux_convergence_tolerance=flux_convergence, &
flux_convergence_max_iteration=flux_max_iteration, &
coldair_outbreak_mod=coldair_outbreak_mod)
#endif

if (dbug_flag > 5) then
call ESMF_LogWrite(trim(subname)//": done", ESMF_LOGMSG_INFO)
Expand Down Expand Up @@ -858,7 +869,11 @@ subroutine med_aofluxes_update(gcomp, aoflux_in, aoflux_out, rc)
use ESMF , only : ESMF_GridComp
use ESMF , only : ESMF_LogWrite, ESMF_LogMsg_Info, ESMF_SUCCESS
use med_map_mod , only : med_map_field_packed, med_map_rh_is_created
#ifdef CESMCOUPLED
use shr_flux_mod , only : flux_atmocn
#else
use flux_atmocn_mod, only : flux_atmocn
#endif

! Arguments
type(ESMF_GridComp) :: gcomp
Expand Down Expand Up @@ -1002,7 +1017,8 @@ subroutine med_aofluxes_update(gcomp, aoflux_in, aoflux_out, rc)
!----------------------------------

#ifdef CESMCOUPLED
call flux_atmocn (&

call flux_atmocn (logunit=logunit, &
nMax=aoflux_in%lsize, &
zbot=aoflux_in%zbot, ubot=aoflux_in%ubot, vbot=aoflux_in%vbot, thbot=aoflux_in%thbot, qbot=aoflux_in%shum, &
s16O=aoflux_in%shum_16O, sHDO=aoflux_in%shum_HDO, s18O=aoflux_in%shum_18O, rbot=aoflux_in%dens, &
Expand All @@ -1014,17 +1030,19 @@ subroutine med_aofluxes_update(gcomp, aoflux_in, aoflux_out, rc)
taux=aoflux_out%taux, tauy=aoflux_out%tauy, tref=aoflux_out%tref, qref=aoflux_out%qref, &
ocn_surface_flux_scheme=ocn_surface_flux_scheme, &
duu10n=aoflux_out%duu10n, ustar_sv=aoflux_out%ustar, re_sv=aoflux_out%re, ssq_sv=aoflux_out%ssq, &
missval = 0.0_r8)
missval=0.0_r8)

#else
call flux_atmocn (&

call flux_atmocn (logunit=logunit, &
nMax=aoflux_in%lsize, mask=aoflux_in%mask, &
zbot=aoflux_in%zbot, ubot=aoflux_in%ubot, vbot=aoflux_in%vbot, thbot=aoflux_in%thbot, qbot=aoflux_in%shum, &
rbot=aoflux_in%dens, tbot=aoflux_in%tbot, us=aoflux_in%uocn, vs=aoflux_in%vocn, ts=aoflux_in%tocn, &
ocn_surface_flux_scheme=ocn_surface_flux_scheme, &
sen=aoflux_out%sen, lat=aoflux_out%lat, lwup=aoflux_out%lwup, evap=aoflux_out%evap, &
taux=aoflux_out%taux, tauy=aoflux_out%tauy, tref=aoflux_out%tref, qref=aoflux_out%qref, &
duu10n=aoflux_out%duu10n, missval = 0.0_r8)
duu10n=aoflux_out%duu10n, missval=0.0_r8)

#endif

do n = 1,aoflux_in%lsize
Expand Down
45 changes: 11 additions & 34 deletions ufs/flux_atmocn_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module flux_atmocn_mod

use med_kind_mod ! shared kinds
use ufs_const_mod ! shared constants
use med_internalstate_mod , only : logunit
use ESMF , only : ESMF_FINALIZE, ESMF_END_ABORT
use ESMF, only : ESMF_FINALIZE, ESMF_END_ABORT

implicit none

Expand All @@ -18,11 +17,8 @@ module flux_atmocn_mod
integer,parameter :: R8 = SHR_KIND_R8 ! 8 byte real
integer,parameter :: IN = SHR_KIND_IN ! native/default integer

! The follow variables are not declared as parameters so that they can be
! adjusted to support aquaplanet and potentially other simple model modes.
! The shr_flux_adjust_constants subroutine is called to set the desired
! values. The default values are from shr_const_mod. Currently they are
! only used by the flux_atmocn routine.
! The follow variables are not declared as parameters so that they can be adjusted.
! The default values are from ufs_const_mod.
real(R8) :: loc_zvir = shr_const_zvir
real(R8) :: loc_cpdair = shr_const_cpdair
real(R8) :: loc_cpvir = shr_const_cpvir
Expand Down Expand Up @@ -51,43 +47,23 @@ module flux_atmocn_mod
contains
!===============================================================================

subroutine flux_adjust_constants( &
zvir, cpair, cpvir, karman, gravit, &
latvap, latice, stebol, flux_convergence_tolerance, &
flux_convergence_max_iteration, &
coldair_outbreak_mod)
subroutine flux_adjust_constants( flux_convergence_tolerance, &
flux_convergence_max_iteration, coldair_outbreak_mod)

! Adjust local constants. Used to support simple models.

real(R8), optional, intent(in) :: zvir
real(R8), optional, intent(in) :: cpair
real(R8), optional, intent(in) :: cpvir
real(R8), optional, intent(in) :: karman
real(R8), optional, intent(in) :: gravit
real(R8), optional, intent(in) :: latvap
real(R8), optional, intent(in) :: latice
real(R8), optional, intent(in) :: stebol
real(r8), optional, intent(in) :: flux_convergence_tolerance
integer(in), optional, intent(in) :: flux_convergence_max_iteration
logical, optional, intent(in) :: coldair_outbreak_mod
real(r8) , optional, intent(in) :: flux_convergence_tolerance
integer(in) , optional, intent(in) :: flux_convergence_max_iteration
logical , optional, intent(in) :: coldair_outbreak_mod
!----------------------------------------------------------------------------

if (present(zvir)) loc_zvir = zvir
if (present(cpair)) loc_cpdair = cpair
if (present(cpvir)) loc_cpvir = cpvir
if (present(karman)) loc_karman = karman
if (present(gravit)) loc_g = gravit
if (present(latvap)) loc_latvap = latvap
if (present(latice)) loc_latice = latice
if (present(stebol)) loc_stebol = stebol
if (present(flux_convergence_tolerance)) flux_con_tol = flux_convergence_tolerance
if (present(flux_convergence_max_iteration)) flux_con_max_iter = flux_convergence_max_iteration
if(present(coldair_outbreak_mod)) use_coldair_outbreak_mod = coldair_outbreak_mod
if (present(coldair_outbreak_mod)) use_coldair_outbreak_mod = coldair_outbreak_mod

end subroutine flux_adjust_constants

!===============================================================================
subroutine flux_atmOcn(nMax,zbot ,ubot ,vbot ,thbot , &
subroutine flux_atmOcn(logunit, nMax,zbot ,ubot ,vbot ,thbot , &
& qbot , rbot ,tbot ,us ,vs , &
& ts , mask ,sen ,lat ,lwup , &
& evap , taux ,tauy ,tref ,qref , &
Expand All @@ -96,6 +72,7 @@ subroutine flux_atmOcn(nMax,zbot ,ubot ,vbot ,thbot , &
implicit none

!--- input arguments --------------------------------
integer ,intent(in) :: logunit
integer(IN),intent(in) :: nMax ! data vector length
integer(IN),intent(in) :: mask (nMax) ! ocn domain mask 0 <=> out of domain
real(R8) ,intent(in) :: zbot (nMax) ! atm level height (m)
Expand Down

0 comments on commit 345d808

Please sign in to comment.