From 10e171f6d3d2e28bb4a921c272a21f596310635c Mon Sep 17 00:00:00 2001 From: Zhang Date: Fri, 5 May 2017 09:31:36 -0700 Subject: [PATCH 1/3] Bugfix for the IEFLX fixer Fixed a bug in check_energy.F90, which will cause runtime error if subcol treatment is used. Also cleaned up the IEFLX code and added more comments [BFB] --- .../namelist_files/namelist_definition.xml | 6 ----- .../cam/src/physics/cam/cam_diagnostics.F90 | 3 --- .../cam/src/physics/cam/check_energy.F90 | 22 +++++++++++++------ .../cam/src/physics/cam/phys_control.F90 | 6 ----- components/cam/src/physics/cam/physpkg.F90 | 5 ++--- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/components/cam/bld/namelist_files/namelist_definition.xml b/components/cam/bld/namelist_files/namelist_definition.xml index fbd2548d4eb1..10cbf51e27d5 100644 --- a/components/cam/bld/namelist_files/namelist_definition.xml +++ b/components/cam/bld/namelist_files/namelist_definition.xml @@ -1122,12 +1122,6 @@ IEFLX fixer options Default: 0 - -Whether or not to fix ieflx -Default: .false. - - 0 +!! !! Author: Kai Zhang !!................................................................... @@ -658,8 +659,6 @@ subroutine ieflx_gmean(state, tend, pbuf2d, cam_in, cam_out, nstep) use cam_history, only: outfld use phys_control, only: ieflx_opt - ! Compute global mean qflx - integer , intent(in) :: nstep ! current timestep number type(physics_state), intent(in ), dimension(begchunk:endchunk) :: state type(physics_tend ), intent(in ), dimension(begchunk:endchunk) :: tend @@ -696,10 +695,17 @@ subroutine ieflx_gmean(state, tend, pbuf2d, cam_in, cam_out, nstep) snow(:ncol,lchnk) = cam_out(lchnk)%precsc(:ncol) + cam_out(lchnk)%precsl(:ncol) rain(:ncol,lchnk) = cam_out(lchnk)%precc(:ncol) + cam_out(lchnk)%precl(:ncol) - snow(:ncol,lchnk) - !! the calculation below (rhow*) converts the unit of precipitation from m/s to kg/m2/s - select case (ieflx_opt) + !!..................................................................................... + !! Calculate the internal energy flux at surface (imitate what is considered in the ocean model) + !! + !! ieflx_opt = 1 : air temperature in the lowest model layer will be used + !! ieflx_opt = 2 : skin temperature (from lnd/ocn/ice components) will be used + !! + !! (rhow*) converts the unit of precipitation from m/s to kg/m2/s + !!..................................................................................... + case(1) ienet(:ncol,lchnk) = cpsw * qflx(:ncol,lchnk) * cam_in(lchnk)%ts(:ncol) - & cpsw * rhow * ( rain(:ncol,lchnk) + snow(:ncol,lchnk) ) * cam_out(lchnk)%tbot(:ncol) @@ -735,8 +741,10 @@ end subroutine ieflx_gmean subroutine check_ieflx_fix(lchnk, ncol, nstep, shflx) !! -!! Add implied internal energy flux to the sensible heat flux +!! Add the global mean internal energy flux to the sensible heat flux !! +!! This subroutien is called only when ieflx_opt > 0 +!! !! Called by typhsac !! diff --git a/components/cam/src/physics/cam/phys_control.F90 b/components/cam/src/physics/cam/phys_control.F90 index 9accf1f67738..e62db4a155b2 100644 --- a/components/cam/src/physics/cam/phys_control.F90 +++ b/components/cam/src/physics/cam/phys_control.F90 @@ -106,7 +106,6 @@ module phys_control logical, public, protected :: print_fixer_message = .false. ! switch on error message printout in log file integer, public, protected :: ieflx_opt = 0 -logical, public, protected :: l_ieflx_fix = .false. ! Macro/micro-physics co-substeps integer :: cld_macmic_num_steps = 1 @@ -174,7 +173,6 @@ subroutine phys_ctl_readnl(nlfile) history_eddy, history_budget, history_budget_histfile_num, history_waccm, & conv_water_in_rad, history_clubb, do_clubb_sgs, do_tms, state_debug_checks, & use_mass_borrower, & - l_ieflx_fix, & ieflx_opt, & use_qqflx_fixer, & print_fixer_message, & @@ -229,7 +227,6 @@ subroutine phys_ctl_readnl(nlfile) call mpibcast(conv_water_in_rad, 1 , mpiint, 0, mpicom) call mpibcast(do_tms, 1 , mpilog, 0, mpicom) call mpibcast(use_mass_borrower, 1 , mpilog, 0, mpicom) - call mpibcast(l_ieflx_fix, 1 , mpilog, 0, mpicom) call mpibcast(ieflx_opt, 1 , mpiint, 0, mpicom) call mpibcast(use_qqflx_fixer, 1 , mpilog, 0, mpicom) call mpibcast(print_fixer_message, 1 , mpilog, 0, mpicom) @@ -400,7 +397,6 @@ subroutine phys_getopts(deep_scheme_out, shallow_scheme_out, eddy_scheme_out, mi history_clubb_out, ieflx_opt_out, conv_water_in_rad_out, cam_chempkg_out, prog_modal_aero_out, macrop_scheme_out, & do_clubb_sgs_out, do_tms_out, state_debug_checks_out, & use_mass_borrower_out, & - l_ieflx_fix_out, & use_qqflx_fixer_out, & print_fixer_message_out, & cld_macmic_num_steps_out, micro_do_icesupersat_out, & @@ -445,7 +441,6 @@ subroutine phys_getopts(deep_scheme_out, shallow_scheme_out, eddy_scheme_out, mi logical, intent(out), optional :: prog_modal_aero_out logical, intent(out), optional :: do_tms_out logical, intent(out), optional :: use_mass_borrower_out - logical, intent(out), optional :: l_ieflx_fix_out logical, intent(out), optional :: use_qqflx_fixer_out logical, intent(out), optional :: print_fixer_message_out logical, intent(out), optional :: state_debug_checks_out @@ -507,7 +502,6 @@ subroutine phys_getopts(deep_scheme_out, shallow_scheme_out, eddy_scheme_out, mi if ( present(prog_modal_aero_out ) ) prog_modal_aero_out = prog_modal_aero if ( present(do_tms_out ) ) do_tms_out = do_tms if ( present(use_mass_borrower_out ) ) use_mass_borrower_out = use_mass_borrower - if ( present(l_ieflx_fix_out ) ) l_ieflx_fix_out = l_ieflx_fix if ( present(use_qqflx_fixer_out ) ) use_qqflx_fixer_out = use_qqflx_fixer if ( present(print_fixer_message_out ) ) print_fixer_message_out = print_fixer_message if ( present(state_debug_checks_out ) ) state_debug_checks_out = state_debug_checks diff --git a/components/cam/src/physics/cam/physpkg.F90 b/components/cam/src/physics/cam/physpkg.F90 index 10b440a34b18..00328f1cb2d4 100644 --- a/components/cam/src/physics/cam/physpkg.F90 +++ b/components/cam/src/physics/cam/physpkg.F90 @@ -1130,9 +1130,8 @@ subroutine phys_run2(phys_state, ztodt, phys_tend, pbuf2d, cam_out, & use metdata, only: get_met_srf2 #endif use time_manager, only: get_nstep - use check_energy, only: ieflx_gmean - use check_energy, only: check_ieflx_fix - use phys_control, only: ieflx_opt !!l_ieflx_fix + use check_energy, only: ieflx_gmean, check_ieflx_fix + use phys_control, only: ieflx_opt ! ! Input arguments ! From a27a1baaa34f3a1c6b807a864dbc29afc10fd2d4 Mon Sep 17 00:00:00 2001 From: Zhang Date: Fri, 5 May 2017 09:36:16 -0700 Subject: [PATCH 2/3] minor comment --- components/cam/src/physics/cam/check_energy.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/cam/src/physics/cam/check_energy.F90 b/components/cam/src/physics/cam/check_energy.F90 index 6da7d877b055..9334bf1c293a 100644 --- a/components/cam/src/physics/cam/check_energy.F90 +++ b/components/cam/src/physics/cam/check_energy.F90 @@ -703,6 +703,8 @@ subroutine ieflx_gmean(state, tend, pbuf2d, cam_in, cam_out, nstep) !! ieflx_opt = 1 : air temperature in the lowest model layer will be used !! ieflx_opt = 2 : skin temperature (from lnd/ocn/ice components) will be used !! + !! ieflx_opt = 2 is recommended for now. + !! !! (rhow*) converts the unit of precipitation from m/s to kg/m2/s !!..................................................................................... From 920864c42812b71b4f3a8017525f0fdae9280d06 Mon Sep 17 00:00:00 2001 From: Kai Zhang Date: Fri, 19 May 2017 15:12:51 -0700 Subject: [PATCH 3/3] Further modifications to check_energy.F90 to address the need from the coupled team. SHFLXFIX was removed. Instead, we output SHFLXORI (SHFLX before applying the IEFLX fixer). IEFLX is now a constant field (global mean IEFLX). Also removed the pbuf variable for IEFLX, since it is not used at this time. [BFB] for prognostic fields, but IEFLX and SHFLXFIX are changed/removed. --- .../cam/src/physics/cam/check_energy.F90 | 37 ++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/components/cam/src/physics/cam/check_energy.F90 b/components/cam/src/physics/cam/check_energy.F90 index 9334bf1c293a..f69569bb1088 100644 --- a/components/cam/src/physics/cam/check_energy.F90 +++ b/components/cam/src/physics/cam/check_energy.F90 @@ -78,7 +78,6 @@ module check_energy ! Physics buffer indices - integer :: ieflx_idx = 0 ! teout index in physics buffer integer :: teout_idx = 0 ! teout index in physics buffer integer :: dtcore_idx = 0 ! dtcore index in physics buffer @@ -149,13 +148,6 @@ subroutine check_energy_register() call pbuf_register_subcol('DTCORE', 'phys_register', dtcore_idx) end if - if(ieflx_opt>0) then - call pbuf_add_field('IEFLX', 'global',dtype_r8 , (/pcols,dyn_time_lvls/), ieflx_idx) - if(is_subcol_on()) then - call pbuf_register_subcol('IEFLX', 'phys_register', ieflx_idx) - end if - end if - end subroutine check_energy_register !=============================================================================== @@ -236,8 +228,8 @@ subroutine check_energy_init() if(ieflx_opt>0) then call addfld('IEFLX', horiz_only, 'A', 'W/m2', 'Implied internal energy flux') - call addfld('SHFLXFIX', horiz_only, 'A', 'W/m2', 'SHFLX after adding IEFLX') - call add_default ('SHFLXFIX', 1, ' ') + call addfld('SHFLXORI', horiz_only, 'A', 'W/m2', 'SHFLX before adding IEFLX') + call add_default ('IEFLX', 1, ' ') end if end subroutine check_energy_init @@ -264,8 +256,6 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type) real(r8) :: wl(state%ncol) ! vertical integral of water (liquid) real(r8) :: wi(state%ncol) ! vertical integral of water (ice) - real(r8) :: ieflx(pcols) ! vertical integral of kinetic energy - real(r8),allocatable :: cpairv_loc(:,:,:) integer lchnk ! chunk identifier @@ -308,8 +298,6 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type) wr = 0._r8 ws = 0._r8 - ieflx(1:ncol) = 0._r8 - do k = 1, pver do i = 1, ncol ke(i) = ke(i) + 0.5_r8*(state%u(i,k)**2 + state%v(i,k)**2)*state%pdel(i,k)/gravit @@ -361,9 +349,6 @@ subroutine check_energy_timestep_init(state, tend, pbuf, col_type) ! initialize physics buffer if (is_first_step()) then call pbuf_set_field(pbuf, teout_idx, state%te_ini, col_type=col_type) - if(ieflx_opt>0) then - call pbuf_set_field(pbuf, ieflx_idx, ieflx, col_type=col_type) - end if end if deallocate(cpairv_loc) @@ -672,7 +657,7 @@ subroutine ieflx_gmean(state, tend, pbuf2d, cam_in, cam_out, nstep) integer :: ncol ! number of active columns integer :: lchnk ! chunk index - real(r8), pointer :: ieflx(:) + real(r8) :: ieflx(pcols) real(r8) :: qflx(pcols,begchunk:endchunk) !qflx [kg/m2/s] real(r8) :: rain(pcols,begchunk:endchunk) !rain [m/s] @@ -718,18 +703,20 @@ subroutine ieflx_gmean(state, tend, pbuf2d, cam_in, cam_out, nstep) call endrun('*** incorrect ieflx_opt ***') end select - !! put it to pbuf for more comprehensive treatment in the future - call pbuf_get_field(pbuf_get_chunk(pbuf2d,lchnk),ieflx_idx, ieflx) + end do - ieflx(:ncol) = ienet(:ncol,lchnk) + call gmean(ienet, ieflx_glob) + +!DIR$ CONCURRENT + do lchnk = begchunk, endchunk + + ieflx(:ncol) = ieflx_glob call outfld('IEFLX', ieflx(:ncol), pcols, lchnk) end do - call gmean(ienet, ieflx_glob) - !!! if (begchunk .le. endchunk) then !!! if (masterproc) then !!! write(iulog,'(1x,a12,1x,i8,4(1x,e25.17))') "nstep, ieflx, ieup, iedn ", nstep, ieflx_glob, ieup_glob, iedn_glob @@ -759,14 +746,14 @@ subroutine check_ieflx_fix(lchnk, ncol, nstep, shflx) integer :: i + call outfld('SHFLXORI', shflx, pcols, lchnk) + if(nstep>1) then do i = 1, ncol shflx(i) = shflx(i) + ieflx_glob end do end if - call outfld('SHFLXFIX', shflx, pcols, lchnk) - return end subroutine check_ieflx_fix