FV3 Bundle
Slope_Variance.f90
Go to the documentation of this file.
1 !
2 ! Helper module containing the slope variance routines for the
3 ! CRTM implementation of FASTEM4
4 !
5 !
6 ! CREATION HISTORY:
7 ! Written by: Original FASTEM1/2/3 authors
8 !
9 ! Modified by: Quanhua Liu, Quanhua.Liu@noaa.gov
10 ! Stephen English, Stephen.English@metoffice.gov.uk
11 ! July, 2009
12 !
13 ! Refactored by: Paul van Delst, October 2010
14 ! paul.vandelst@noaa.gov
15 !
16 
18 
19  ! -----------------
20  ! Environment setup
21  ! -----------------
22  ! Module use
23  USE type_kinds , ONLY: fp
24  USE hyperbolic_step, ONLY: step, step_tl, step_ad
25  ! Disable implicit typing
26  IMPLICIT NONE
27 
28 
29  ! ------------
30  ! Visibilities
31  ! ------------
32  PRIVATE
33  ! Data types
34  PUBLIC :: ivar_type
35  ! Science routines
36  PUBLIC :: compute_slope_variance
39 
40 
41  ! -----------------
42  ! Module parameters
43  ! -----------------
44  CHARACTER(*), PARAMETER :: module_version_id = &
45  '$Id: Slope_Variance.f90 60152 2015-08-13 19:19:13Z paul.vandelst@noaa.gov $'
46 
47  ! Literal constants
48  REAL(fp), PARAMETER :: zero = 0.0_fp
49  REAL(fp), PARAMETER :: one = 1.0_fp
50  REAL(fp), PARAMETER :: two = 2.0_fp
51 
52  ! Wave slope variance parameters
53  REAL(fp), PARAMETER :: var_coeffs(2) = (/0.0030_fp, 0.00512_fp/) ! Cox-Munk coeffs
54  REAL(fp), PARAMETER :: f_coeffs(3) = (/1.0000_fp, 0.02000_fp, 0.30000_fp/)
55 
56  ! Scale factor for x-input to hyperbolic step function
57  REAL(fp), PARAMETER :: xscale = 1000000.0_fp
58 
59 
60  ! --------------------------------------
61  ! Structure definition to hold internal
62  ! variables across FWD, TL, and AD calls
63  ! --------------------------------------
64  TYPE :: ivar_type
65  PRIVATE
66  REAL(fp) :: vara = zero
67  REAL(fp) :: varb = zero
68  REAL(fp) :: fterm = zero
69  REAL(fp) :: x1 = zero, g1 = zero, var1 = zero
70  REAL(fp) :: x2 = zero, g2 = zero
71  REAL(fp) :: variance = zero
72  END TYPE ivar_type
73 
74 
75 CONTAINS
76 
77 
78  ! =============================================
79  ! Procedures to compute the wave slope variance
80  ! =============================================
81  ! Forward model
82  SUBROUTINE compute_slope_variance( &
83  Frequency , & ! Input
84  Wind_Speed, & ! Input
85  iVar , & ! Internal variable output
86  Variance ) ! Output
87  ! Arguments
88  REAL(fp) , INTENT(IN) :: frequency
89  REAL(fp) , INTENT(IN) :: wind_speed
90  TYPE(ivar_type), INTENT(OUT) :: ivar
91  REAL(fp) , INTENT(OUT) :: variance
92  ! Local variables
93  REAL(fp) :: c
94  ! Compute the frequency term
95  ivar%Fterm = (f_coeffs(2)*frequency + f_coeffs(3))
96  ! Compute the slope variances
97  c = (var_coeffs(1) + var_coeffs(2)*wind_speed) * f_coeffs(1)
98  ivar%vara = c
99  ivar%varb = c * ivar%Fterm
100  ! Return required value
101  ! ...First IF statement
102  ! ...IF ( iVar%varb >= iVar%vara ) THEN
103  ivar%x1 = xscale*(ivar%varb - ivar%vara)
104  CALL step(ivar%x1,ivar%g1)
105  ivar%var1 = ivar%vara*ivar%g1 + ivar%varb*(one-ivar%g1)
106  ! ...Second IF statement
107  ! ...IF ( iVar%varb <= ZERO ) THEN
108  ivar%x2 = xscale*ivar%varb
109  CALL step(ivar%x2,ivar%g2)
110  variance = ivar%var1*ivar%g2
111  END SUBROUTINE compute_slope_variance
112 
113 
114  ! Tangent-linear model
115  SUBROUTINE compute_slope_variance_tl( &
116  Wind_Speed_TL, & ! Input
117  iVar , & ! Internal variable input
118  Variance_TL ) ! Output
119  ! Arguments
120  REAL(fp) , INTENT(IN) :: wind_speed_tl
121  TYPE(ivar_type), INTENT(IN) :: ivar
122  REAL(fp) , INTENT(OUT) :: variance_tl
123  ! Local variables
124  REAL(fp) :: c
125  REAL(fp) :: vara_tl, varb_tl
126  REAL(fp) :: x1_tl, g1_tl, var1_tl
127  REAL(fp) :: x2_tl, g2_tl
128  ! Compute slope variances
129  c = var_coeffs(2) * f_coeffs(1)
130  vara_tl = c * wind_speed_tl
131  varb_tl = c * ivar%Fterm * wind_speed_tl
132  ! Return required value
133  ! ...First IF statement
134  ! ...IF ( iVar%varb >= iVar%vara ) THEN
135  x1_tl = xscale*(varb_tl - vara_tl)
136  CALL step_tl(ivar%x1,x1_tl,g1_tl)
137  var1_tl = (ivar%vara - ivar%varb)*g1_tl + &
138  ivar%g1*vara_tl + &
139  (one-ivar%g1)*varb_tl
140  ! ...Second IF statement
141  ! ...IF ( iVar%varb <= ZERO ) THEN
142  x2_tl = xscale*varb_tl
143  CALL step_tl(ivar%x2,x2_tl,g2_tl)
144  variance_tl = ivar%var1*g2_tl + ivar%g2*var1_tl
145  END SUBROUTINE compute_slope_variance_tl
146 
147 
148  ! Adjoint model
149  SUBROUTINE compute_slope_variance_ad( &
150  Variance_AD , & ! Input
151  iVar , & ! Internal variable input
152  Wind_Speed_AD ) ! Output
153  ! Arguments
154  REAL(fp) , INTENT(IN OUT) :: variance_ad
155  TYPE(ivar_type), INTENT(IN) :: ivar
156  REAL(fp) , INTENT(IN OUT) :: wind_speed_ad
157  ! Local variables
158  REAL(fp) :: c
159  REAL(fp) :: vara_ad, varb_ad
160  REAL(fp) :: x1_ad, g1_ad, var1_ad
161  REAL(fp) :: x2_ad, g2_ad
162  ! Second IF statement
163  ! ...IF ( iVar%varb <= ZERO ) THEN
164  var1_ad = ivar%g2 * variance_ad
165  g2_ad = ivar%var1 * variance_ad
166  variance_ad = zero
167 
168  x2_ad = zero
169  CALL step_ad(ivar%x2, g2_ad, x2_ad)
170  varb_ad = xscale * x2_ad
171 
172  ! First IF statement
173  ! ...IF ( iVar%varb >= iVar%vara ) THEN
174  varb_ad = varb_ad + (one-ivar%g1) * var1_ad
175  vara_ad = ivar%g1 * var1_ad
176  g1_ad = (ivar%vara - ivar%varb) * var1_ad
177 
178  x1_ad = zero
179  CALL step_ad(ivar%x1, g1_ad, x1_ad)
180 
181  vara_ad = vara_ad - xscale * x1_ad
182  varb_ad = varb_ad + xscale * x1_ad
183 
184  ! Compute the adjoint of the slope variances
185  c = var_coeffs(2) * f_coeffs(1)
186  wind_speed_ad = wind_speed_ad + c * ivar%Fterm * varb_ad
187  wind_speed_ad = wind_speed_ad + c * vara_ad
188  END SUBROUTINE compute_slope_variance_ad
189 
190 END MODULE slope_variance
real(fp), parameter, public zero
integer, parameter, public fp
Definition: Type_Kinds.f90:124
subroutine, public compute_slope_variance(Frequency, Wind_Speed, iVar, Variance)
character(*), parameter module_version_id
real(fp), dimension(2), parameter var_coeffs
subroutine, public step_ad(x, g_AD, x_AD)
real(fp), dimension(3), parameter f_coeffs
real(fp), parameter xscale
real(fp), parameter, public one
real(fp), parameter, public two
subroutine, public step(x, g)
subroutine, public compute_slope_variance_tl(Wind_Speed_TL, iVar, Variance_TL)
subroutine, public compute_slope_variance_ad(Variance_AD, iVar, Wind_Speed_AD)
subroutine, public step_tl(x, x_TL, g_TL)