FV3-JEDI
height_variables_mod.f90
Go to the documentation of this file.
1 ! (C) Copyright 2018-2019 UCAR
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 
7 
11 
12 implicit none
13 private
14 ! Constants from GSI
15 ! Constants for compressibility factor (Davis et al 1992)
16 real(kind_real),parameter :: cpf_a0 = 1.58123e-6_kind_real ! K/Pa
17 real(kind_real),parameter :: cpf_a1 = -2.9331e-8_kind_real ! 1/Pa
18 real(kind_real),parameter :: cpf_a2 = 1.1043e-10_kind_real ! 1/K 1/Pa
19 real(kind_real),parameter :: cpf_b0 = 5.707e-6_kind_real ! K/Pa
20 real(kind_real),parameter :: cpf_b1 = -2.051e-8_kind_real ! 1/Pa
21 real(kind_real),parameter :: cpf_c0 = 1.9898e-4_kind_real ! K/Pa
22 real(kind_real),parameter :: cpf_c1 = -2.376e-6_kind_real ! 1/Pa
23 real(kind_real),parameter :: cpf_d = 1.83e-11_kind_real ! K2/Pa2
24 real(kind_real),parameter :: cpf_e = -0.765e-8_kind_real ! K2/Pa2
25 
26 real(kind_real),parameter :: psv_a = 1.2378847e-5_kind_real ! (1/K2)
27 real(kind_real),parameter :: psv_b = -1.9121316e-2_kind_real ! (1/K)
28 real(kind_real),parameter :: psv_c = 33.93711047_kind_real !
29 real(kind_real),parameter :: psv_d = -6.3431645e+3_kind_real ! (K)
30 ! Constants for enhancement factor to calculating the mole fraction of water vapor
31 real(kind_real),parameter :: ef_alpha = 1.00062_kind_real !
32 real(kind_real),parameter :: ef_beta = 3.14e-8_kind_real ! (1/Pa)
33 real(kind_real),parameter :: ef_gamma = 5.6e-7_kind_real
34 
35 public geop_height
36 public geop_height_levels
37 
38 contains
39 
40 subroutine geop_height(geom,prs,prsi,T,q,phis,use_compress,gph)
41 
42 implicit none
43 type(fv3jedi_geom) , intent(in ) :: geom !Geometry for the model
44 real(kind_real), intent(in ) :: prs(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz) !mid layerpressure
45 real(kind_real), intent(in ) :: prsi(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz+1) !interface pressure
46 real(kind_real), intent(in ) :: phis(geom%isc:geom%iec,geom%jsc:geom%jec) !Surface geopotential (grav*Z_sfc)
47 real(kind_real), intent(in ) :: t(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz)
48 real(kind_real), intent(in ) :: q(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz) ! specific humidity
49 real(kind_real), intent(out) :: gph(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz) !geopotential height (meters)
50 
51 !locals
52 real(kind_real) :: tv(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz)
53 real(kind_real) :: qmr(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz) ! mixing ratio|kg/kg
54 logical :: use_compress
55 integer :: isc,iec,jsc,jec,npz,i,j,k
56 real(kind=kind_real) :: tkk,tvk,tc, qmk,pak,dpk,dz
57 real(kind=kind_real) :: prs_sv, prs_v
58 real(kind=kind_real) :: ehn_fct,x_v,cmpr
59 
60 isc = geom%isc
61 iec = geom%iec
62 jsc = geom%jsc
63 jec = geom%jec
64 npz = geom%npz
65 
66 
67 !get qmr--mixing ratio and virtual temeprature
68 qmr(isc:iec,jsc:jec,:) = q(isc:iec,jsc:jec,:)/(1.0 - q(isc:iec,jsc:jec,:))
69 tv(isc:iec,jsc:jec,:) = t(isc:iec,jsc:jec,:)*(1.0 + zvir*qmr(isc:iec,jsc:jec,:))
70 
71 if (use_compress) then
72 
73 ! Compute compressibility factor (Picard et al 2008) and geopotential heights at midpoint
74  do j = jsc,jec
75  do i = isc,iec
76 
77  do k = geom%npz, 1, -1
78  if ( k == geom%npz) then
79  tkk = t(i,j,k)
80  tvk = tv(i,j,k)
81  pak = exp(0.5_kind_real*(log(prsi(i,j,k+1)*0.01)+log(prs(i,j,k)*0.01)))
82  dpk = prsi(i,j,k+1)/prs(i,j,k)
83  else
84  tkk = 0.5_kind_real * ( t(i,j,k+1) + t(i,j,k) )
85  tvk = 0.5_kind_real * (tv(i,j,k+1) + tv(i,j,k) )
86  pak = exp(0.5_kind_real*(log(prs(i,j,k+1)*0.01)+log(prs(i,j,k)*0.01)))
87  dpk = prs(i,j,k+1)/prs(i,j,k)
88  end if
89 
90  tc = tkk - tice
91  qmk = qmr(i,j,k)
92  prs_sv = exp(psv_a*tkk**2 + psv_b*tkk + psv_c + psv_d/tkk ) ! Pvap sat, eq A1.1 (Pa)
93  ehn_fct = ef_alpha + ef_beta*pak + ef_gamma*tc**2 ! enhancement factor (eq. A1.2)
94  prs_v = qmk* pak/(1.0+qmk*rdry/rvap) ! vapor pressure (Pa)
95  x_v = prs_v/prs_sv * ehn_fct * prs_sv/pak ! molar fraction of water vapor (eq. A1.3)
96 ! Compressibility factor (eq A1.4 from Picard et al 2008)
97  cmpr = 1.0_kind_real - (pak/tkk) * (cpf_a0 + cpf_a1*tc + cpf_a2*tc**2 &
98  + (cpf_b0 + cpf_b1*tc)*x_v + (cpf_c0 + cpf_c1*tc)*x_v**2 ) &
99  + (pak**2/tkk**2) * (cpf_d + cpf_e*x_v**2)
100  dz = rdry/grav * tvk * cmpr * log(dpk)
101  if ( k == geom%npz) then
102  gph(i,j,k) = phis(i,j)/grav + dz
103  else
104  gph(i,j,k) = gph(i,j,k+1) + dz
105  end if
106  end do ! end k loop
107 
108  end do ! end i loop
109  end do ! end j loop
110 
111 else ! not use compressivity
112 
113  do j = jsc,jec
114  do i = isc,iec
115 
116  k = geom%npz
117  dz = rdry/grav * tv(i,j,k) * log(prsi(i,j,k+1)/prs(i,j,k))
118  gph(i,j,k) = phis(i,j)/grav + dz
119 
120  do k = geom%npz-1, 1, -1
121  dz = rdry/grav * 0.5_kind_real * (tv(i,j,k+1)+tv(i,j,k)) * log(prs(i,j,k+1)/prs(i,j,k))
122  gph(i,j,k) = gph(i,j,k+1) + dz
123  end do
124 
125  end do
126  end do
127 
128 end if
129 
130 end subroutine geop_height
131 
132 subroutine geop_height_levels(geom,prs,prsi,T,q,phis,use_compress,gphi)
133 
134 implicit none
135 type(fv3jedi_geom) , intent(in ) :: geom !Geometry for the model
136 
137 real(kind_real), intent(in ) :: prs(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz) !mid layerpressure
138 real(kind_real), intent(in ) :: prsi(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz+1) !interface pressure
139 real(kind_real), intent(in ) :: phis(geom%isc:geom%iec,geom%jsc:geom%jec) !Surface geopotential (grav*Z_sfc)
140 real(kind_real), intent(in ) :: t(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz)
141 real(kind_real), intent(in ) :: q(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz) !specific humidity
142 real(kind_real), intent(out) :: gphi(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz+1) !geopotential height at interface levels (m)
143 
144 !locals
145 real(kind_real) :: tv(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz)
146 real(kind_real) :: qmr(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz) ! mixing ratio|kg/kg
147 logical :: use_compress
148 
149 integer :: isc,iec,jsc,jec,npz,i,j,k
150 real(kind=kind_real) :: tkk,tvk,tc, qmk,pak,dpk,dz
151 real(kind=kind_real) :: prs_sv, prs_v
152 real(kind=kind_real) :: ehn_fct,x_v,cmpr
153 
154 isc = geom%isc
155 iec = geom%iec
156 jsc = geom%jsc
157 jec = geom%jec
158 npz = geom%npz
159 !get qmr--mixing ratio and virtual temeprature
160 qmr(isc:iec,jsc:jec,:) = q(isc:iec,jsc:jec,:)/(1.0 - q(isc:iec,jsc:jec,:))
161 tv(isc:iec,jsc:jec,:) = t(isc:iec,jsc:jec,:)*(1.0 + zvir*qmr(isc:iec,jsc:jec,:))
162 
163 if (use_compress) then
164 
165 ! Compute compressibility factor (Picard et al 2008) and geopotential heights at midpoint
166  do j = jsc,jec
167  do i = isc,iec
168 
169  gphi(i,j,geom%npz+1) = phis(i,j)/grav !phis is gh? or gopoential
170  do k = geom%npz, 1, -1
171  if ( k == 1) then
172  pak = exp(0.5_kind_real*(log(prsi(i,j,k+1)*0.01)+log(prs(i,j,k)*0.01)))
173  dpk = prsi(i,j,k+1)/prs(i,j,k)
174  else
175  pak = exp(0.5_kind_real*(log(prsi(i,j,k+1)*0.01)+log(prsi(i,j,k)*0.01)))
176  dpk = prsi(i,j,k+1)/prsi(i,j,k)
177  end if
178  tkk = t(i,j,k)
179  tvk = tv(i,j,k)
180  tc = tkk - tice
181  qmk = qmr(i,j,k)
182  prs_sv = exp(psv_a*tkk**2 + psv_b*tkk + psv_c + psv_d/tkk ) ! Pvap sat, eq A1.1 (Pa)
183  ehn_fct = ef_alpha + ef_beta*pak + ef_gamma*tc**2 ! enhancement factor (eq. A1.2)
184  prs_v = qmk* pak/(1.0+qmk*rdry/rvap) ! vapor pressure (Pa)
185  x_v = prs_v/prs_sv * ehn_fct * prs_sv/pak ! molar fraction of water vapor (eq. A1.3)
186 ! Compressibility factor (eq A1.4 from Picard et al 2008)
187 
188  cmpr = 1.0_kind_real - (pak/tkk) * (cpf_a0 + cpf_a1*tc + cpf_a2*tc**2 &
189  + (cpf_b0 + cpf_b1*tc)*x_v + (cpf_c0 + cpf_c1*tc)*x_v**2 ) &
190  + (pak**2/tkk**2) * (cpf_d + cpf_e*x_v**2)
191  dz = rdry/grav * tvk * cmpr * log(dpk)
192  gphi(i,j,k) = gphi(i,j,k+1) + dz
193  end do ! end k loop
194 
195  end do ! end i loop
196  end do ! end j loop
197 
198 else ! not use compressivity
199  do j = jsc,jec
200  do i = isc,iec
201 
202  gphi(i,j, geom%npz+1) = phis(i,j)/grav
203 
204  do k = geom%npz, 1, -1
205  if(k ==1) then
206  dz = rdry/grav * tv(i,j,k) * log(prsi(i,j,k+1)/prs(i,j,k))
207  else
208  dz = rdry/grav * tv(i,j,k) * log(prsi(i,j,k+1)/prsi(i,j,k))
209  end if
210  gphi(i,j,k) = gphi(i,j,k+1) + dz
211  end do
212 
213  end do
214  end do
215 
216 end if
217 
218 end subroutine geop_height_levels
219 end module height_vt_mod
height_vt_mod::cpf_c1
real(kind_real), parameter cpf_c1
Definition: height_variables_mod.f90:22
height_vt_mod::ef_beta
real(kind_real), parameter ef_beta
Definition: height_variables_mod.f90:32
height_vt_mod::psv_a
real(kind_real), parameter psv_a
Definition: height_variables_mod.f90:26
fv3jedi_constants_mod::tice
real(kind=kind_real), parameter, public tice
Definition: fv3jedi_constants_mod.f90:49
height_vt_mod::psv_d
real(kind_real), parameter psv_d
Definition: height_variables_mod.f90:29
fv3jedi_geom_mod
Fortran module handling geometry for the FV3 model.
Definition: fv3jedi_geom_mod.f90:8
height_vt_mod::geop_height_levels
subroutine, public geop_height_levels(geom, prs, prsi, T, q, phis, use_compress, gphi)
Definition: height_variables_mod.f90:133
height_vt_mod::cpf_b0
real(kind_real), parameter cpf_b0
Definition: height_variables_mod.f90:19
height_vt_mod::psv_c
real(kind_real), parameter psv_c
Definition: height_variables_mod.f90:28
fv3jedi_geom_mod::fv3jedi_geom
Fortran derived type to hold geometry data for the FV3JEDI model.
Definition: fv3jedi_geom_mod.f90:46
height_vt_mod::cpf_e
real(kind_real), parameter cpf_e
Definition: height_variables_mod.f90:24
height_vt_mod::cpf_a0
real(kind_real), parameter cpf_a0
Definition: height_variables_mod.f90:16
height_vt_mod::ef_gamma
real(kind_real), parameter ef_gamma
Definition: height_variables_mod.f90:33
height_vt_mod::cpf_b1
real(kind_real), parameter cpf_b1
Definition: height_variables_mod.f90:20
height_vt_mod::cpf_a1
real(kind_real), parameter cpf_a1
Definition: height_variables_mod.f90:17
fv3jedi_constants_mod
Definition: fv3jedi_constants_mod.f90:6
height_vt_mod::cpf_c0
real(kind_real), parameter cpf_c0
Definition: height_variables_mod.f90:21
fv3jedi_constants_mod::zvir
real(kind=kind_real), parameter, public zvir
Definition: fv3jedi_constants_mod.f90:41
height_vt_mod::cpf_d
real(kind_real), parameter cpf_d
Definition: height_variables_mod.f90:23
fv3jedi_kinds_mod::kind_real
integer, parameter, public kind_real
Definition: fv3jedi_kinds_mod.f90:14
height_vt_mod::cpf_a2
real(kind_real), parameter cpf_a2
Definition: height_variables_mod.f90:18
fv3jedi_constants_mod::rdry
real(kind=kind_real), parameter, public rdry
Definition: fv3jedi_constants_mod.f90:28
fv3jedi_constants_mod::rvap
real(kind=kind_real), parameter, public rvap
Definition: fv3jedi_constants_mod.f90:31
height_vt_mod
Definition: height_variables_mod.f90:6
height_vt_mod::ef_alpha
real(kind_real), parameter ef_alpha
Definition: height_variables_mod.f90:31
height_vt_mod::geop_height
subroutine, public geop_height(geom, prs, prsi, T, q, phis, use_compress, gph)
Definition: height_variables_mod.f90:41
fv3jedi_kinds_mod
Definition: fv3jedi_kinds_mod.f90:6
height_vt_mod::psv_b
real(kind_real), parameter psv_b
Definition: height_variables_mod.f90:27
fv3jedi_constants_mod::grav
real(kind=kind_real), parameter, public grav
Definition: fv3jedi_constants_mod.f90:17