FV3 Bundle
fv3jedi_lm_utils_mod.F90
Go to the documentation of this file.
2 
5 
6 implicit none
7 private
8 
12 
13 !> Fortran derived type to hold the linearized model configuration
15  real(kind_real) :: dt !<Model time step
16  logical :: saveltraj = .false. !<Option to save local trajectories (physics)
17  integer :: n = 1 !<Current time step in window
18  integer :: nt = 1 !<Number of timesteps in window
19  real(kind_real) :: ptop !<Pressure of top level
20  integer :: isc,iec,jsc,jec !<Cube grid, compute region
21  integer :: isd,ied,jsd,jed !<Cube grid, with halo
22  integer :: npx, npy, npz !<Number of grid points, dynamics
23  integer :: im, jm, lm !<Number of grid points, physics, 1:im etc
24  integer :: do_dyn = 1 !<Dynamics switch
25  integer :: do_phy = 1 !<Physics switch
26  integer :: do_phy_trb = 1 !<Physics switch for BL turb
27  integer :: do_phy_mst = 1 !<Physics switch for convection and cloud
28  real(kind_real), allocatable, dimension(:) :: ak, bk !<Vertical grid
29  logical :: hydrostatic !<Hydrostatic dy core
30  logical :: rpe !<True if root process
31 end type fv3jedi_lm_conf
32 
33 !> Fortran derived type to hold the linearized model increment
35  real(kind_real), allocatable, dimension(:,:,:) :: u, v, t, delp !Dynamics
36  real(kind_real), allocatable, dimension(:,:,:) :: qv, ql, qi, o3 !Tracers
37  real(kind_real), allocatable, dimension(:,:,:) :: w, delz !nh vars
38  real(kind_real), allocatable, dimension(:,:,:) :: ua, va, cfcn !Internal not part of increment
39 end type fv3jedi_lm_pert
40 
41 !> Fortran derived type to hold the linearized model trajectory
43  real(kind_real), allocatable, dimension(:,:,:) :: u, v, t, delp !Dynamics
44  real(kind_real), allocatable, dimension(:,:,:) :: qv, ql, qi, o3 !Tracers
45  real(kind_real), allocatable, dimension(:,:,:) :: w, delz !nh vars
46  real(kind_real), allocatable, dimension(:,:,:) :: ua, va, cfcn !Internal not part of increment
47  real(kind_real), allocatable, dimension(:,:,:) :: qls, qcn
48  real(kind_real), allocatable, dimension(:,:) :: phis, ps
49  real(kind_real), allocatable, dimension(:,:) :: frocean, frland
50  real(kind_real), allocatable, dimension(:,:) :: varflt, ustar, bstar
51  real(kind_real), allocatable, dimension(:,:) :: zpbl, cm, ct, cq
52  real(kind_real), allocatable, dimension(:,:) :: kcbl, ts, khl, khu
53 end type fv3jedi_lm_traj
54 
55 !> Compute ice fraction from temperature
56 public icefraction
57 interface icefraction
58  module procedure icefraction_r4
59  module procedure icefraction_r8
60 end interface
61 
62 !> Compute pressures from delp
63 public compute_pressures
65  module procedure compute_pressures_r4
66  module procedure compute_pressures_r8
67 end interface
68 
69 
70 ! ------------------------------------------------------------------------------
71 contains
72 ! ------------------------------------------------------------------------------
73 
74 subroutine allocate_pert(pert,isc,iec,jsc,jec,npz,hydrostatic)
75 
76  implicit none
77  type(fv3jedi_lm_pert), intent(inout) :: pert
78  logical, intent(in ) :: hydrostatic
79  integer, intent(in ) :: isc, iec, jsc, jec, npz
80 
81  allocate(pert%u (isc:iec, jsc:jec, npz))
82  allocate(pert%v (isc:iec, jsc:jec, npz))
83  allocate(pert%ua (isc:iec, jsc:jec, npz))
84  allocate(pert%va (isc:iec, jsc:jec, npz))
85  allocate(pert%t (isc:iec, jsc:jec, npz))
86  allocate(pert%delp (isc:iec, jsc:jec, npz))
87  allocate(pert%qv (isc:iec, jsc:jec, npz))
88  allocate(pert%ql (isc:iec, jsc:jec, npz))
89  allocate(pert%qi (isc:iec, jsc:jec, npz))
90  allocate(pert%o3 (isc:iec, jsc:jec, npz))
91 
92  allocate(pert%cfcn (isc:iec, jsc:jec, npz))
93 
94  if (.not. hydrostatic) then
95  allocate(pert%w (isc:iec, jsc:jec, npz))
96  allocate(pert%delz (isc:iec, jsc:jec, npz))
97  endif
98 
99 end subroutine allocate_pert
100 
101 ! ------------------------------------------------------------------------------
102 
103 subroutine deallocate_pert(pert)
105  implicit none
106  type(fv3jedi_lm_pert), intent(inout) :: pert
107 
108  if(allocated(pert%u) ) deallocate(pert%u)
109  if(allocated(pert%v) ) deallocate(pert%v)
110  if(allocated(pert%ua) ) deallocate(pert%ua)
111  if(allocated(pert%va) ) deallocate(pert%va)
112  if(allocated(pert%t) ) deallocate(pert%t)
113  if(allocated(pert%delp)) deallocate(pert%delp)
114  if(allocated(pert%qv) ) deallocate(pert%qv)
115  if(allocated(pert%ql) ) deallocate(pert%ql)
116  if(allocated(pert%qi) ) deallocate(pert%qi)
117  if(allocated(pert%o3) ) deallocate(pert%o3)
118  if(allocated(pert%cfcn)) deallocate(pert%cfcn)
119  if(allocated(pert%w) ) deallocate(pert%w)
120  if(allocated(pert%delz)) deallocate(pert%delz)
121 
122 end subroutine deallocate_pert
123 
124 ! ------------------------------------------------------------------------------
125 
126 subroutine allocate_traj(traj,isc,iec,jsc,jec,npz,hydrostatic,dpm)
128  implicit none
129  type(fv3jedi_lm_traj), intent(inout) :: traj
130  logical, intent(in ) :: hydrostatic
131  integer, intent(in ) :: dpm
132  integer, intent(in ) :: isc, iec, jsc, jec, npz
133 
134  allocate(traj%u (isc:iec, jsc:jec, npz))
135  allocate(traj%v (isc:iec, jsc:jec, npz))
136  allocate(traj%ua (isc:iec, jsc:jec, npz))
137  allocate(traj%va (isc:iec, jsc:jec, npz))
138  allocate(traj%t (isc:iec, jsc:jec, npz))
139  allocate(traj%delp (isc:iec, jsc:jec, npz))
140  allocate(traj%qv (isc:iec, jsc:jec, npz))
141  allocate(traj%ql (isc:iec, jsc:jec, npz))
142  allocate(traj%qi (isc:iec, jsc:jec, npz))
143  allocate(traj%o3 (isc:iec, jsc:jec, npz))
144 
145  if (.not. hydrostatic) then
146  allocate(traj%w (isc:iec, jsc:jec, npz))
147  allocate(traj%delz (isc:iec, jsc:jec, npz))
148  endif
149 
150  if (dpm .ne. 0) then
151  allocate(traj%qls (isc:iec, jsc:jec, npz))
152  allocate(traj%qcn (isc:iec, jsc:jec, npz))
153  allocate(traj%cfcn (isc:iec, jsc:jec, npz))
154  endif
155 
156  allocate(traj%phis (isc:iec, jsc:jec))
157  allocate(traj%ps (isc:iec, jsc:jec))
158  allocate(traj%frocean(isc:iec, jsc:jec))
159  allocate(traj%frland (isc:iec, jsc:jec))
160  allocate(traj%varflt (isc:iec, jsc:jec))
161  allocate(traj%ustar (isc:iec, jsc:jec))
162  allocate(traj%bstar (isc:iec, jsc:jec))
163  allocate(traj%zpbl (isc:iec, jsc:jec))
164  allocate(traj%cm (isc:iec, jsc:jec))
165  allocate(traj%ct (isc:iec, jsc:jec))
166  allocate(traj%cq (isc:iec, jsc:jec))
167  allocate(traj%kcbl (isc:iec, jsc:jec))
168  allocate(traj%ts (isc:iec, jsc:jec))
169  allocate(traj%khl (isc:iec, jsc:jec))
170  allocate(traj%khu (isc:iec, jsc:jec))
171 
172 end subroutine allocate_traj
173 
174 ! ------------------------------------------------------------------------------
175 
176 subroutine deallocate_traj(traj)
178  implicit none
179  type(fv3jedi_lm_traj), intent(inout) :: traj
180 
181  if (allocated(traj%u )) deallocate(traj%u )
182  if (allocated(traj%v )) deallocate(traj%v )
183  if (allocated(traj%ua )) deallocate(traj%ua )
184  if (allocated(traj%va )) deallocate(traj%va )
185  if (allocated(traj%t )) deallocate(traj%t )
186  if (allocated(traj%delp )) deallocate(traj%delp )
187  if (allocated(traj%qv )) deallocate(traj%qv )
188  if (allocated(traj%ql )) deallocate(traj%ql )
189  if (allocated(traj%qi )) deallocate(traj%qi )
190  if (allocated(traj%o3 )) deallocate(traj%o3 )
191  if (allocated(traj%w )) deallocate(traj%w )
192  if (allocated(traj%delz )) deallocate(traj%delz )
193  if (allocated(traj%qls )) deallocate(traj%qls )
194  if (allocated(traj%qcn )) deallocate(traj%qcn )
195  if (allocated(traj%cfcn )) deallocate(traj%cfcn )
196  if (allocated(traj%phis )) deallocate(traj%phis )
197  if (allocated(traj%ps )) deallocate(traj%ps )
198  if (allocated(traj%frocean)) deallocate(traj%frocean)
199  if (allocated(traj%frland )) deallocate(traj%frland )
200  if (allocated(traj%varflt )) deallocate(traj%varflt )
201  if (allocated(traj%ustar )) deallocate(traj%ustar )
202  if (allocated(traj%bstar )) deallocate(traj%bstar )
203  if (allocated(traj%zpbl )) deallocate(traj%zpbl )
204  if (allocated(traj%cm )) deallocate(traj%cm )
205  if (allocated(traj%ct )) deallocate(traj%ct )
206  if (allocated(traj%cq )) deallocate(traj%cq )
207  if (allocated(traj%kcbl )) deallocate(traj%kcbl )
208  if (allocated(traj%ts )) deallocate(traj%ts )
209  if (allocated(traj%khl )) deallocate(traj%khl )
210  if (allocated(traj%khu )) deallocate(traj%khu )
211 
212 end subroutine deallocate_traj
213 
214 ! ------------------------------------------------------------------------------
215 
216 subroutine copy_traj( traj_in, traj_out, hydrostatic, dpm )
218  implicit none
219  type(fv3jedi_lm_traj), intent(in) :: traj_in
220  type(fv3jedi_lm_traj), intent(inout) :: traj_out
221  logical, intent(in) :: hydrostatic
222  integer, intent(in) :: dpm
223 
224  traj_out%u = traj_in%u
225  traj_out%v = traj_in%v
226  traj_out%ua = traj_in%ua
227  traj_out%va = traj_in%va
228  traj_out%t = traj_in%t
229  traj_out%delp = traj_in%delp
230  traj_out%qv = traj_in%qv
231  traj_out%ql = traj_in%ql
232  traj_out%qi = traj_in%qi
233  traj_out%o3 = traj_in%o3
234 
235  if (.not. hydrostatic) then
236  traj_out%w = traj_in%w
237  traj_out%delz = traj_in%delz
238  endif
239 
240  if (dpm /= 0) then
241  traj_out%qls = traj_in%qls
242  traj_out%qcn = traj_in%qcn
243  traj_out%cfcn = traj_in%cfcn
244  endif
245 
246  traj_out%phis = traj_in%phis
247  traj_out%ps = traj_in%ps
248  traj_out%frocean = traj_in%frocean
249  traj_out%frland = traj_in%frland
250  traj_out%varflt = traj_in%varflt
251  traj_out%ustar = traj_in%ustar
252  traj_out%bstar = traj_in%bstar
253  traj_out%zpbl = traj_in%zpbl
254  traj_out%cm = traj_in%cm
255  traj_out%ct = traj_in%ct
256  traj_out%cq = traj_in%cq
257  traj_out%kcbl = traj_in%kcbl
258  traj_out%ts = traj_in%ts
259  traj_out%khl = traj_in%khl
260  traj_out%khu = traj_in%khu
261 
262 end subroutine copy_traj
263 
264 ! ------------------------------------------------------------------------------
265 
266 subroutine icefraction_r4(temp, icefrct)
268  implicit none
269 
270  !arguments
271  real(4), intent(in) :: temp
272  real(4), intent(out) :: icefrct
273 
274  !locals
275  real(4), parameter :: t_ice_all = 233.16_4, t_ice_max = 273.16_4
276  integer, parameter :: icefrpwr = 4
277 
278  icefrct = 0.00_4
279  if ( temp <= t_ice_all ) then
280  icefrct = 1.000_4
281  else if ( (temp > t_ice_all) .and. (temp <= t_ice_max) ) then
282  icefrct = 1.00_4 - ( temp - t_ice_all ) / ( t_ice_max - t_ice_all )
283  end if
284 
285  icefrct = min(icefrct,1.00_4)
286  icefrct = max(icefrct,0.00_4)
287 
288  icefrct = icefrct**icefrpwr
289 
290 end subroutine icefraction_r4
291 
292 ! ------------------------------------------------------------------------------
293 
294 subroutine icefraction_r8(temp, icefrct)
296  implicit none
297 
298  !arguments
299  real(8), intent(in) :: temp
300  real(8), intent(out) :: icefrct
301 
302  !locals
303  real(8), parameter :: t_ice_all = 233.16_8, t_ice_max = 273.16_8
304  integer, parameter :: icefrpwr = 4
305 
306  icefrct = 0.0_8
307  if ( temp <= t_ice_all ) then
308  icefrct = 1.000_8
309  else if ( (temp > t_ice_all) .and. (temp <= t_ice_max) ) then
310  icefrct = 1.00_8 - ( temp - t_ice_all ) / ( t_ice_max - t_ice_all )
311  end if
312 
313  icefrct = min(icefrct,1.00_8)
314  icefrct = max(icefrct,0.00_8)
315 
316  icefrct = icefrct**icefrpwr
317 
318 end subroutine icefraction_r8
319 
320 ! ------------------------------------------------------------------------------
321 
322 subroutine compute_pressures_r4(im,jm,lm,ptop,delp,pe,p,pk)
324  integer, intent(in) :: im,jm,lm
325  real(4), intent(in) :: ptop
326  real(4), intent(in) :: delp(1:im,1:jm,1:lm) !Pressure thickness
327  real(4), intent(out) :: pe (1:im,1:jm,0:lm) !Pressure at edges
328  real(4), intent(out) :: p (1:im,1:jm,1:lm) !Pressure at mid-point
329  real(4), intent(out) :: pk (1:im,1:jm,1:lm) !Pressure to the kappa at mid-point
330 
331  real(4) :: lpe(1:im,1:jm,0:lm)
332  real(4) :: pek(1:im,1:jm,0:lm)
333 
334  integer :: l
335 
336  !Pressure at the level edge
337  pe(:,:,0) = ptop
338  do l=1,lm
339  pe(:,:,l) = pe(:,:,l-1) + delp(:,:,l)
340  end do
341 
342  !Pressure mid-point
343  p(:,:,1:lm) = 0.5_4 * (pe(:,:,1:lm) + pe(:,:,0:lm-1))
344 
345  !Log of edge pressure
346  lpe = log(pe)
347 
348  !pe to the kappa at edge
349  pek = pe**kappa
350 
351  !p to the kappa
352  pk(:,:,1:lm) = (pek(:,:,1:lm)-pek(:,:,0:lm-1))/(kappa*(lpe(:,:,1:lm)-lpe(:,:,0:lm-1)))
353 
354 endsubroutine compute_pressures_r4
355 
356 ! ------------------------------------------------------------------------------
357 
358 subroutine compute_pressures_r8(im,jm,lm,ptop,delp,pe,p,pk)
360  integer, intent(in) :: im,jm,lm
361  real(8), intent(in) :: ptop
362  real(8), intent(in) :: delp(1:im,1:jm,1:lm) !Pressure thickness
363  real(8), intent(out) :: pe (1:im,1:jm,0:lm) !Pressure at edges
364  real(8), intent(out) :: p (1:im,1:jm,1:lm) !Pressure at mid-point
365  real(8), intent(out) :: pk (1:im,1:jm,1:lm) !Pressure to the kappa at mid-point
366 
367  real(8) :: lpe(1:im,1:jm,0:lm)
368  real(8) :: pek(1:im,1:jm,0:lm)
369 
370  integer :: l
371 
372  !Pressure at the level edge
373  pe(:,:,0) = ptop
374  do l=1,lm
375  pe(:,:,l) = pe(:,:,l-1) + delp(:,:,l)
376  end do
377 
378  !Pressure mid-point
379  p(:,:,1:lm) = 0.5_8 * (pe(:,:,1:lm) + pe(:,:,0:lm-1))
380 
381  !Log of edge pressure
382  lpe = log(pe)
383 
384  !pe to the kappa at edge
385  pek = pe**kappa
386 
387  !p to the kappa
388  pk(:,:,1:lm) = (pek(:,:,1:lm)-pek(:,:,0:lm-1))/(kappa*(lpe(:,:,1:lm)-lpe(:,:,0:lm-1)))
389 
390 endsubroutine compute_pressures_r8
391 
392 end module fv3jedi_lm_utils_mod
Compute ice fraction from temperature.
subroutine icefraction_r4(temp, icefrct)
subroutine, public allocate_traj(traj, isc, iec, jsc, jec, npz, hydrostatic, dpm)
subroutine icefraction_r8(temp, icefrct)
Fortran derived type to hold the linearized model increment.
subroutine, public deallocate_traj(traj)
subroutine compute_pressures_r8(im, jm, lm, ptop, delp, pe, p, pk)
subroutine, public deallocate_pert(pert)
subroutine compute_pressures_r4(im, jm, lm, ptop, delp, pe, p, pk)
subroutine, public copy_traj(traj_in, traj_out, hydrostatic, dpm)
Fortran derived type to hold the linearized model trajectory.
#define max(a, b)
Definition: mosaic_util.h:33
Fortran derived type to hold the linearized model configuration.
#define min(a, b)
Definition: mosaic_util.h:32
real(kind=kind_real), parameter, public kappa
subroutine, public allocate_pert(pert, isc, iec, jsc, jec, npz, hydrostatic)
Constants for the FV3 model.