Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code update for HR4_roughness, background diffusivity and shallow convection #119

Merged
merged 56 commits into from
Jan 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
c18c6d4
CCPP scheme simulator.
Jan 30, 2023
f9abb73
Fix file rename typo
Jan 30, 2023
ef0d369
Added MPI commands to ccpp_scheme_simulator
Jan 31, 2023
fd72b35
Work in progress...
Feb 3, 2023
ffd26ab
Some changes
Feb 6, 2023
112ac89
Some small cleanup
Feb 7, 2023
6a4c4b1
More OO changes. Will split into load_data and ccpp_scheme components…
Feb 9, 2023
be4cc2e
More OO changes
Feb 10, 2023
7001ef9
Split scheme into load and simulator components.
Feb 13, 2023
8bc8ec9
Small bug fix to nml
Feb 13, 2023
6db4af5
Remove dimension for tracer, handle tracers individualy, not with sta…
Feb 13, 2023
147cbac
Fixed bug in interpolation routine.
Feb 14, 2023
a296389
Moew changes
Feb 17, 2023
e49f1f6
Merge branch 'main' of https://github.com/NCAR/ccpp-physics into ccpp…
Apr 5, 2023
a3933a5
CCPP scheme simulator
May 4, 2023
833b990
Merge branch 'ufs/dev-gf' into ufs-dev-PR64
grantfirl May 4, 2023
3ba2924
Merge branch 'main' into ufs-dev-PR64
grantfirl May 8, 2023
6e53907
Merge commit 'd474c2' into ufs-dev-PR26
grantfirl May 9, 2023
2515b27
Merge branch 'main' of https://github.com/NCAR/ccpp-physics into HEAD
May 30, 2023
5d49f79
Reorganization of scheme simulator. Now stateless.
Jun 1, 2023
d8a5b1f
Merge pull request #1015 from grantfirl/ufs-dev-PR64
grantfirl Jun 13, 2023
6f12331
Merge branch 'main' into ufs-dev-PR26
grantfirl Jun 13, 2023
4d69108
fix bug in scm_sfc_flux_spec.F90
grantfirl Jun 14, 2023
6cfaad5
Merge branch 'update_HR2' into ufs-dev-PR65
grantfirl Jun 26, 2023
93e0c8d
Merge commit '81e3f5e36' into ufs-dev-PR71
grantfirl Jun 26, 2023
bc94a0f
Merge remote-tracking branch 'joe-fork/mynn_snowfix' into ufs-dev-PR71
grantfirl Jun 26, 2023
92c8a9e
Merge pull request #1016 from grantfirl/ufs-dev-PR26
grantfirl Jun 29, 2023
c5566ab
Merge branch 'main' into ufs-dev-PR65
grantfirl Jun 29, 2023
ce731f2
Merge branch 'main' into ufs-dev-PR71
grantfirl Jun 29, 2023
12d4fc2
Working as expected!
Jul 7, 2023
6ceffe3
Merge branch 'main' of https://github.com/NCAR/ccpp-physics into HEAD
Jul 7, 2023
9b77c4e
Merge pull request #1020 from grantfirl/ufs-dev-PR65
grantfirl Jul 7, 2023
9465b6f
Housekeeping
Jul 11, 2023
c61a2a6
GNU bug found in SCM CI
Jul 13, 2023
8e5646e
Some cleanup.
Jul 18, 2023
7e8cd3a
Merge branch 'main' into ufs-dev-PR71
grantfirl Jul 19, 2023
e3c00d3
Renamed scheme simulator suite simulator
Jul 19, 2023
2d6d44c
Omission from previous commit
Jul 19, 2023
5ab1a5b
Add ability to use constant forcing data when one-dimensional data is…
Jul 19, 2023
07a25fe
Merge branch 'main' of https://github.com/NCAR/ccpp-physics into HEAD
Aug 1, 2023
215ba6d
Merge pull request #996 from dustinswales/ccpp_scheme_sim
dustinswales Aug 1, 2023
1e7542a
Merge branch 'main' into ufs-dev-PR71
grantfirl Aug 3, 2023
fa96015
Merge pull request #1021 from grantfirl/ufs-dev-PR71
grantfirl Aug 3, 2023
4e45989
Code update for HR4_roughness
Qingfu-Liu Oct 16, 2023
3debf89
Code update for HR4_roughness
Qingfu-Liu Oct 16, 2023
c2b1301
Code update for HR4_roughness
Qingfu-Liu Oct 16, 2023
2fc24ca
Merge remote-tracking branch 'upstream/ufs/dev' into HR4_roughness
Qingfu-Liu Nov 28, 2023
91da6a0
Merge https://github.com/Qingfu-Liu/ccpp-physics into HR4_roughness
Qingfu-Liu Nov 28, 2023
562377c
remove files from old version
Qingfu-Liu Nov 28, 2023
12cd9c6
update files satmedmfvdifq.F samfshalcnv.f sfc_diff.f
Qingfu-Liu Nov 28, 2023
225848c
Merge remote-tracking branch 'upstream/ufs/dev' into HR4_roughness
Qingfu-Liu Dec 1, 2023
d65507a
Fix CI 2
Qingfu-Liu Dec 14, 2023
fa9931a
Merge remote-tracking branch 'upstream/ufs/dev' into HR4_roughness
Qingfu-Liu Jan 10, 2024
26ecb3d
Merge remote-tracking branch 'upstream/ufs/dev' into HR4_roughness
Qingfu-Liu Jan 16, 2024
97e3b1c
update surface physics z0 from waves
Qingfu-Liu Jan 18, 2024
327fbaa
Merge remote-tracking branch 'upstream/ufs/dev' into HR4_roughness
Qingfu-Liu Jan 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More OO changes
  • Loading branch information
dustinswales committed Feb 10, 2023
commit be4cc2e5acb11c99794d465496503833a4842a45
134 changes: 75 additions & 59 deletions physics/ccpp_scheme_simulator.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,41 @@ module ccpp_scheme_simulator
#endif
implicit none

! Type containing physics tendencies for a physics process.
type phys_tend
! Type containing 1D (instantaneous) physics tendencies
type tend_inst
real(kind_phys), dimension(:), pointer :: dT
real(kind_phys), dimension(:), pointer :: du
real(kind_phys), dimension(:), pointer :: dv
real(kind_phys), dimension(:), pointer :: dq
end type tend_inst

! Type containing 2D data physics tendencies.
type phys_tend_2d
real(kind_phys), dimension(:), pointer :: time
real(kind_phys), dimension(:,:), pointer :: T
real(kind_phys), dimension(:,:), pointer :: u
real(kind_phys), dimension(:,:), pointer :: v
real(kind_phys), dimension(:,:,:), pointer :: q
end type phys_tend
end type phys_tend_2d

! This type contains the meta information and data for each physics process.
type base_physics_process
character(len=16) :: name
logical :: time_split = .false.
logical :: use_sim = .false.
integer :: order
type(phys_tend) :: tend
character(len=16) :: name
logical :: time_split = .false.
logical :: use_sim = .false.
integer :: order
type(phys_tend_2d) :: tend
type(tend_inst) :: itend
contains
generic, public :: linterp => linterp_1D
procedure, private :: linterp_1D
end type base_physics_process

! This array contains the governing information on how to advance the physics timestep.
type(base_physics_process),dimension(:), allocatable :: &
physics_process

! Number of physics process (set in namelist)
integer :: nPhysProcess

! ########################################################################################
Expand All @@ -59,7 +73,7 @@ module ccpp_scheme_simulator

! Data driven physics tendencies
integer :: nlev_data, ntime_data
real(kind_phys), allocatable, dimension(:) :: time_data
real(kind_phys), allocatable, dimension(:), target :: time_data
real(kind_phys), allocatable, dimension(:,:), target :: dTdt_LWRAD_data, &
dTdt_SWRAD_data, dTdt_PBL_data, dudt_PBL_data, dvdt_PBL_data, dTdt_GWD_data, &
dudt_GWD_data, dvdt_GWD_data, dTdt_SCNV_data, dudt_SCNV_data, dvdt_SCNV_data, &
Expand Down Expand Up @@ -482,6 +496,10 @@ subroutine ccpp_scheme_simulator_init(mpirank, mpiroot, mpicomm, nlunit, nml_fil

! Metadata
do iprc = 1,nPhysProcess
allocate(physics_process(iprc)%itend%dT(nlev_data))
allocate(physics_process(iprc)%itend%du(nlev_data))
allocate(physics_process(iprc)%itend%dv(nlev_data))
allocate(physics_process(iprc)%itend%dq(nlev_data))
if (iprc == proc_SWRAD_config(3)) then
physics_process(iprc)%order = iprc
physics_process(iprc)%name = "SWRAD"
Expand Down Expand Up @@ -555,6 +573,13 @@ subroutine ccpp_scheme_simulator_init(mpirank, mpiroot, mpicomm, nlunit, nml_fil
enddo

! Load data
physics_process(proc_LWRAD_config(3))%tend%time => time_data
physics_process(proc_SWRAD_config(3))%tend%time => time_data
physics_process(proc_PBL_config(3))%tend%time => time_data
physics_process(proc_GWD_config(3))%tend%time => time_data
physics_process(proc_DCNV_config(3))%tend%time => time_data
physics_process(proc_SCNV_config(3))%tend%time => time_data
physics_process(proc_cldMP_config(3))%tend%time => time_data
if (have_dTdt_LWRAD_data) physics_process(proc_SWRAD_config(3))%tend%T => dTdt_LWRAD_data
if (have_dTdt_SWRAD_data) physics_process(proc_LWRAD_config(3))%tend%T => dTdt_SWRAD_data
if (have_dTdt_PBL_data) physics_process(proc_PBL_config(3))%tend%T => dTdt_PBL_data
Expand Down Expand Up @@ -639,7 +664,6 @@ subroutine ccpp_scheme_simulator_run(kdt, dtp, jdat, tgrs, ugrs, vgrs, qgrs, dti
integer :: iCol, iLay, iTrc, nCol, nLay, nTrc, ti(1), tf(1), idtend, fcst_year, &
fcst_month, fcst_day, fcst_hour, fcst_min, fcst_sec, iprc, index_of_process
real(kind_phys) :: w1, w2,hrofday
real(kind_phys), dimension(:), allocatable :: dT, du, dv, dq
real(kind_phys), dimension(:,:), allocatable :: gt1, gu1, gv1, dTdt, dudt, dvdt
real(kind_phys), dimension(:,:,:), allocatable :: gq1, dqdt

Expand All @@ -649,7 +673,7 @@ subroutine ccpp_scheme_simulator_run(kdt, dtp, jdat, tgrs, ugrs, vgrs, qgrs, dti

if (.not. do_ccpp_scheme_simulator) return

! Current forecast time
! Current forecast time (Data-format specific)
fcst_year = jdat(1)
fcst_month = jdat(2)
fcst_day = jdat(3)
Expand All @@ -665,7 +689,6 @@ subroutine ccpp_scheme_simulator_run(kdt, dtp, jdat, tgrs, ugrs, vgrs, qgrs, dti
! Allocate temporaries
allocate(gt1(nCol,nLay), gu1(nCol,nLay), gv1(nCol,nLay), gq1(nCol,nLay,1))
allocate(dTdt(nCol,nLay), dudt(nCol,nLay), dvdt(nCol,nLay), dqdt(nCol,nLay,1))
allocate(dT(nLay), du(nLay), dv(nLay), dq(nLay))

! Set state
gt1(:,:) = tgrs(:,:)
Expand All @@ -680,25 +703,25 @@ subroutine ccpp_scheme_simulator_run(kdt, dtp, jdat, tgrs, ugrs, vgrs, qgrs, dti
! Model internal physics timestep evolution of "state".
do iprc = 1,nPhysProcess
do iCol = 1,nCol
!
dT = 0.
du = 0.
dv = 0.
dq = 0.
! Reset locals
physics_process(iprc)%itend%dT(:) = 0.
physics_process(iprc)%itend%du(:) = 0.
physics_process(iprc)%itend%dv(:) = 0.
physics_process(iprc)%itend%dq(:) = 0.

! Using scheme simulator (very simple, interpolate data tendency to local time)
if (physics_process(iprc)%use_sim) then
if (associated(physics_process(iprc)%tend%T)) then
call linterp_data_tend("T", physics_process(iprc)%name, iprc, fcst_year, fcst_month, fcst_day, fcst_hour, fcst_min, fcst_sec, dT)
errmsg = physics_process(iprc)%linterp("T", fcst_year, fcst_month, fcst_day, fcst_hour, fcst_min, fcst_sec)
endif
if (associated(physics_process(iprc)%tend%u)) then
call linterp_data_tend("u", physics_process(iprc)%name, iprc, fcst_year, fcst_month, fcst_day, fcst_hour, fcst_min, fcst_sec, du)
errmsg = physics_process(iprc)%linterp("u", fcst_year, fcst_month, fcst_day, fcst_hour, fcst_min, fcst_sec)
endif
if (associated(physics_process(iprc)%tend%v)) then
call linterp_data_tend("v", physics_process(iprc)%name, iprc, fcst_year, fcst_month, fcst_day, fcst_hour, fcst_min, fcst_sec, dv)
errmsg = physics_process(iprc)%linterp("v", fcst_year, fcst_month, fcst_day, fcst_hour, fcst_min, fcst_sec)
endif
if (associated(physics_process(iprc)%tend%q)) then
call linterp_data_tend("q", physics_process(iprc)%name, iprc, fcst_year, fcst_month, fcst_day, fcst_hour, fcst_min, fcst_sec, dq)
errmsg = physics_process(iprc)%linterp("q", fcst_year, fcst_month, fcst_day, fcst_hour, fcst_min, fcst_sec)
endif

! Using data tendency from "active" scheme(s).
Expand All @@ -713,34 +736,34 @@ subroutine ccpp_scheme_simulator_run(kdt, dtp, jdat, tgrs, ugrs, vgrs, qgrs, dti
if (physics_process(iprc)%name == "cldMP") index_of_process = index_of_process_mp
!
idtend = dtidx(index_of_temperature,index_of_process)
if (idtend >= 1) dT = dtend(iCol,:,idtend)/dtp
if (idtend >= 1) physics_process(iprc)%itend%dT = dtend(iCol,:,idtend)/dtp
!
idtend = dtidx(index_of_x_wind,index_of_process)
if (idtend >= 1) du = dtend(iCol,:,idtend)/dtp
if (idtend >= 1) physics_process(iprc)%itend%du = dtend(iCol,:,idtend)/dtp
!
idtend = dtidx(index_of_y_wind,index_of_process)
if (idtend >= 1) dv = dtend(iCol,:,idtend)/dtp
if (idtend >= 1) physics_process(iprc)%itend%dv = dtend(iCol,:,idtend)/dtp
!
idtend = dtidx(100+ntqv,index_of_process)
if (idtend >= 1) dq = dtend(iCol,:,idtend)/dtp
if (idtend >= 1) physics_process(iprc)%itend%dq = dtend(iCol,:,idtend)/dtp
endif

! Update state now?
if (physics_process(iprc)%time_split) then
gt1(iCol,:) = gt1(iCol,:) + (dTdt(iCol,:) + dT)*dtp
gu1(iCol,:) = gu1(iCol,:) + (dudt(iCol,:) + du)*dtp
gv1(iCol,:) = gv1(iCol,:) + (dvdt(iCol,:) + dv)*dtp
gq1(iCol,:,1) = gq1(iCol,:,1) + (dqdt(iCol,:,1) + dq)*dtp
gt1(iCol,:) = gt1(iCol,:) + (dTdt(iCol,:) + physics_process(iprc)%itend%dT)*dtp
gu1(iCol,:) = gu1(iCol,:) + (dudt(iCol,:) + physics_process(iprc)%itend%du)*dtp
gv1(iCol,:) = gv1(iCol,:) + (dvdt(iCol,:) + physics_process(iprc)%itend%dv)*dtp
gq1(iCol,:,1) = gq1(iCol,:,1) + (dqdt(iCol,:,1) + physics_process(iprc)%itend%dq)*dtp
dTdt(iCol,:) = 0.
dudt(iCol,:) = 0.
dvdt(iCol,:) = 0.
dqdt(iCol,:,1) = 0.
! Accumulate tendencies, update later?
else
dTdt(iCol,:) = dTdt(iCol,:) + dT
dudt(iCol,:) = dudt(iCol,:) + du
dvdt(iCol,:) = dvdt(iCol,:) + dv
dqdt(iCol,:,1) = dqdt(iCol,:,1) + dq
dTdt(iCol,:) = dTdt(iCol,:) + physics_process(iprc)%itend%dT
dudt(iCol,:) = dudt(iCol,:) + physics_process(iprc)%itend%du
dvdt(iCol,:) = dvdt(iCol,:) + physics_process(iprc)%itend%dv
dqdt(iCol,:,1) = dqdt(iCol,:,1) + physics_process(iprc)%itend%dq
endif
enddo
!
Expand All @@ -756,40 +779,33 @@ end subroutine ccpp_scheme_simulator_run
! ####################################################################################
! Utility functions/routines
! ####################################################################################
! The routine interpolates the data-tendencies
subroutine linterp_data_tend(var_name, process_name, iprc, year, month, day, hour, &
minute, second, var_out)
! Inputs
character(len=*), intent(in) :: var_name, process_name
integer, intent(in) :: year, month, day, hour, minute, second, iprc

! Outputs
real(kind_phys),dimension(:),intent(out) :: var_out

! Locals
function linterp_1D(this, var_name, year, month, day, hour, minute, second) result(err_message)
class(base_physics_process), intent(inout) :: this
character(len=*), intent(in) :: var_name
integer, intent(in) :: year, month, day, hour, minute, second
character(len=128) :: err_message
integer :: ti(1), tf(1)
real(kind_phys) :: w1, w2, hrofday

! Linear interpolation weights
! Interpolation weights
hrofday = hour*3600. + minute*60. + second
ti = findloc(abs(time_data-hrofday),minval(abs(time_data-hrofday)))
if (hrofday - time_data(ti(1)) .le. 0) ti = ti-1
ti = findloc(abs(this%tend%time-hrofday),minval(abs(this%tend%time-hrofday)))
if (hrofday - this%tend%time(ti(1)) .le. 0) ti = ti-1
tf = ti + 1
w1 = (time_data(tf(1))-hrofday) / (time_data(tf(1)) - time_data(ti(1)))
w1 = (this%tend%time(tf(1))-hrofday) / (this%tend%time(tf(1)) - this%tend%time(ti(1)))
w2 = 1 - w1

!
select case(var_name)
case("T")
var_out = w1*physics_process(iprc)%tend%T(:,ti(1)) + w2*physics_process(iprc)%tend%T(:,tf(1))
case("u")
var_out = w1*physics_process(iprc)%tend%u(:,ti(1)) + w2*physics_process(iprc)%tend%u(:,tf(1))
case("v")
var_out = w1*physics_process(iprc)%tend%v(:,ti(1)) + w2*physics_process(iprc)%tend%v(:,tf(1))
case("q")
var_out = w1*physics_process(iprc)%tend%q(:,ti(1),1) + w2*physics_process(iprc)%tend%q(:,tf(1),1)
case("T")
this%itend%dT = w1*this%tend%T(:,ti(1)) + w2*this%tend%T(:,tf(1))
case("u")
this%itend%du = w1*this%tend%u(:,ti(1)) + w2*this%tend%u(:,tf(1))
case("v")
this%itend%dv = w1*this%tend%v(:,ti(1)) + w2*this%tend%v(:,tf(1))
case("q")
this%itend%dq = w1*this%tend%q(:,ti(1),1) + w2*this%tend%q(:,tf(1),1)
end select

end subroutine linterp_data_tend

end function linterp_1D
end module ccpp_scheme_simulator