Skip to content

Commit

Permalink
change to allow USE_MGBF be able to be off
Browse files Browse the repository at this point in the history
  • Loading branch information
TingLei-daprediction committed Jul 9, 2024
1 parent 529bb79 commit 61c3a99
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/gsi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ endif()
if(USE_GSDCLOUD)
list(APPEND GSI_Fortran_defs RR_CLOUDANALYSIS)
endif()
if(USE_MGBF)
list(APPEND GSI_Fortran_defs USE_MGBF_def)
endif()

# Create a library of GSI C sources
add_library(gsi_c_obj OBJECT ${GSI_SRC_C})
Expand Down
26 changes: 25 additions & 1 deletion src/gsi/hybrid_ensemble_isotropic.F90
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ module hybrid_ensemble_isotropic
integer(r_kind) :: nval_loc_en

! For MGBF
#ifdef USE_MGBF_def
type (mg_intstate_type), allocatable, dimension(:) :: obj_mgbf
#endif /* End of USE_MGBF_def block */
real(r_kind), allocatable, dimension(:,:,:) :: work_mgbf

! following is for special subdomain to slab variables used when internally generating ensemble members
Expand Down Expand Up @@ -1761,7 +1763,9 @@ subroutine destroy_ensemble
enddo
deallocate(ps_bar)
deallocate(en_perts)
#ifdef USE_MGBF_def
if(l_mgbf_loc) call print_mg_timers("mgbf_timing_cpu.csv", print_cpu, mype)
#endif /* End of USE_MGBF_def block */
end if
return

Expand Down Expand Up @@ -3735,6 +3739,8 @@ subroutine bkgcov_a_en_new_factorization(ig,a_en)
! because recursive filter is applied for ig>naensgrp
! to separate scales for scale-dependent localization
! even in MGBF-based localization)

#ifdef USE_MGBF_def
if(l_mgbf_loc.and.ig<=naensgrp) then

! Apply vertical smoother on each ensemble member
Expand Down Expand Up @@ -3774,6 +3780,7 @@ subroutine bkgcov_a_en_new_factorization(ig,a_en)
! Recursive/Spectral filter-based localization(ig<=naensgrp)
! or scale-separation(ig>naensgrp)
else
#endif /* End of USE_MGBF_def block */

! Apply vertical smoother on each ensemble member
! To avoid my having to touch the general sub2grid and grid2sub,
Expand Down Expand Up @@ -3824,7 +3831,9 @@ subroutine bkgcov_a_en_new_factorization(ig,a_en)
enddo
deallocate(a_en_work)

#ifdef USE_MGBF_def
endif
#endif /* End of USE_MGBF_def block */

return
end subroutine bkgcov_a_en_new_factorization
Expand Down Expand Up @@ -3892,6 +3901,7 @@ subroutine ckgcov_a_en_new_factorization(ig,z,a_en)
endif

! MGBF-based localization (now available only in regional=.true.)
#ifdef USE_MGBF_def
if(l_mgbf_loc) then

! Apply horizontal smoother for number of horizontal scales
Expand Down Expand Up @@ -3925,6 +3935,7 @@ subroutine ckgcov_a_en_new_factorization(ig,z,a_en)

! Recursive/Spectral filter-based localization
else
#endif /* End of USE_MGBF_def block */

if(grd_loc%kend_loc+1-grd_loc%kbegin_loc==0) then
! no work to be done on this processor, but hwork still has allocated space, since
Expand Down Expand Up @@ -3973,8 +3984,9 @@ subroutine ckgcov_a_en_new_factorization(ig,z,a_en)
call new_factorization_rf_z(a_en(k)%r3(ipnt)%q,iadvance,iback,ig)

enddo

#ifdef USE_MGBF_def
endif
#endif /* End of USE_MGBF_def block */

return
end subroutine ckgcov_a_en_new_factorization
Expand Down Expand Up @@ -4047,6 +4059,7 @@ subroutine ckgcov_a_en_new_factorization_ad(ig,z,a_en)
endif

! MGBF-based localization (now available only in regional=.true.)
#ifdef USE_MGBF_def
if(l_mgbf_loc) then

! Apply vertical smoother on each ensemble member
Expand Down Expand Up @@ -4080,6 +4093,7 @@ subroutine ckgcov_a_en_new_factorization_ad(ig,z,a_en)

! Recursive/Spectral filter-based localization
else
#endif /* End of USE_MGBF_def block */

! Apply vertical smoother on each ensemble member
iadvance=1 ; iback=2
Expand Down Expand Up @@ -4125,11 +4139,14 @@ subroutine ckgcov_a_en_new_factorization_ad(ig,z,a_en)
end if
end if

#ifdef USE_MGBF_def
endif
#endif /* End of USE_MGBF_def block */

return
end subroutine ckgcov_a_en_new_factorization_ad

#ifdef USE_MGBF_def
subroutine map_work_mgbf(f,g,iadvance,ig)
!$$$ subprogram documentation block
! . . .
Expand Down Expand Up @@ -4198,6 +4215,7 @@ subroutine map_work_mgbf(f,g,iadvance,ig)
return

end subroutine map_work_mgbf
#endif /* End of USE_MGBF_def block */

! ------------------------------------------------------------------------------
! ------------------------------------------------------------------------------
Expand Down Expand Up @@ -4538,13 +4556,15 @@ subroutine hybens_localization_setup
call normal_new_factorization_rf_z

if ( regional ) then ! convert s_ens_h from km to grid units.
#ifdef USE_MGBF_def
if ( l_mgbf_loc ) then
allocate(obj_mgbf(naensgrp))
do ig=1,naensgrp
write(mgbfname(9:10),'(i2.2)') ig
call obj_mgbf(ig)%mg_initialize(trim(mgbfname))
enddo
endif
#endif /* End of USE_MGBF_def block */
! Even for MGBF-localization, recursive filter is applied for scale-separation
! in scale-dependent localization, so init_rf_[xy] should be called in nsclgrp>1
if( .not. l_mgbf_loc .or. nsclgrp > 1 ) then
Expand Down Expand Up @@ -4767,13 +4787,17 @@ subroutine hybens_localization_setup
! nval_loc_en is the number of horizontally-filtered variables in the domain of each processor,
! which is the same as nval_lenz_en (horizontally-global and vertically-local) in recursive/spectral filter
! but horizontally-local and vertically-global in MGBF.
#ifdef USE_MGBF_def
if ( l_mgbf_loc ) then
nval_loc_en = maxval( obj_mgbf(1:naensgrp)%km_all &
& * (obj_mgbf(1:naensgrp)%im + obj_mgbf(1:naensgrp)%hx*2) &
& * (obj_mgbf(1:naensgrp)%jm + obj_mgbf(1:naensgrp)%hy*2) )
else
#endif /* End of USE_MGBF_def block */
nval_loc_en = nval_lenz_en
#ifdef USE_MGBF_def
endif
#endif /* End of USE_MGBF_def block */

! setup vertical weighting for ensemble contribution to psfc
call setup_pwgt
Expand Down

0 comments on commit 61c3a99

Please sign in to comment.