CCPP SciDoc v7.0.0  v7.0.0
Common Community Physics Package Developed at DTC
 
Loading...
Searching...
No Matches
test_tempo_main_suite.F90
2 !! unit test suite for module_mp_tempo_main
3 use testdrive, only : new_unittest, unittest_type, error_type, check
4 use module_mp_tempo_params, only : wp, sp, dp, r_c, t_nc, r_s, tc, t0, &
5 r_r, n0r_exp, crg, org2, org1, bm_r, org1, am_r, cre, mu_r, &
6 idx_bg1, r_g, n0g_exp, cgg, ogg2, ogg1, bm_g, am_g, cge, r_i, nt_i
7 use module_mp_tempo_main, only : get_cloud_table_index, get_snow_table_index, &
8 get_temperature_table_index, get_rain_table_index, get_graupel_table_index, &
9 get_ice_table_index
10 implicit none
11 private
12
13 public :: collect_tempo_main_suite
14
15 contains
16
17 ! collect all exported unit tests
18 subroutine collect_tempo_main_suite(testsuite)
19 ! collection of tests
20 type(unittest_type), allocatable, intent(out) :: testsuite(:)
21
22 testsuite = [ &
23 new_unittest("get_cloud_table_index(rc=1.2345e-5) returns index where rc is between r_c(index) and r_c(index+1)", &
24 getcloudtableindex_massindexcorrect), &
25 new_unittest("get_cloud_table_index(nc=54.321e6) returns index where nc is between t_nc(index-1) and t_nc(index)", &
26 getcloudtableindex_numberindexcorrect), &
27 new_unittest("get_snow_table_index(rs=2.3456e-4) returns index where rs is between r_(index) and r_s(index+1)", &
28 getsnowtableindex_massindexcorrect), &
29 new_unittest("get_temperature_table_index(temp=-23.4) returns index where temp is between tc(index-1) and tc(index)", &
30 gettemperaturetableindex_indexcorrect), &
31 new_unittest("get_rain_table_index(rr=1.2345e-3) returns index where rr is between r_r(index) and r_r(index+1)", &
32 getraintableindex_massindexcorrect), &
33 new_unittest("get_rain_table_index(mvd = 1.234e-3) returns index where mvd is between mvd(index) and mvd(index+1)", &
34 getraintableindex_n0expindexcorrectmvd), &
35 new_unittest("get_graupel_table_index(rg=1.2345e-4) returns index where rg is between r_g(index) and r_g(index+1)", &
36 getgraupeltableindex_massindexcorrect), &
37 new_unittest("get_graupel_table_index(mvd = 5.6789e-3) returns index where mvd is between mvd(index) and mvd(index+1)", &
38 getgraupeltableindex_n0expindexcorrectmvd), &
39 new_unittest("get_ice_table_index(ri=1.2345e-5) returns index where ri is between r_i(index) and r_i(index+1)", &
40 geticetableindex_massindexcorrect), &
41 new_unittest("get_ice_table_index(ni=100000.) returns index where ni is between nt_i(index) and nt_i(index+1)", &
42 geticetableindex_numberindexcorrect) &
43 ]
44
45 end subroutine collect_tempo_main_suite
46
47 subroutine getcloudtableindex_massindexcorrect(error)
48 !! test get_cloud_table_index
49 type(error_type), allocatable, intent(out) :: error
50 integer :: idx_c, idx_n
51 real(wp) :: mass, number
52 mass = 1.2345e-4
53 number = 54.321e6
54 call get_cloud_table_index(mass, number, idx_c, idx_n)
55 write(*,*) 'idx_c=', idx_c, ' mass=', mass, ' r_c(idx_c)=', r_c(idx_c), &
56 ' r_c(idx_c+1)=', r_c(idx_c+1)
57 call check(error, (mass >= r_c(idx_c) .and. mass <= r_c(idx_c+1)))
58 if (allocated(error)) return
59 end subroutine getcloudtableindex_massindexcorrect
60
61
62 subroutine getcloudtableindex_numberindexcorrect(error)
63 !! test get_cloud_table_index
64 type(error_type), allocatable, intent(out) :: error
65 integer :: idx_c, idx_n
66 real(wp) :: mass, number
67 mass = 1.2345e-4
68 number = 54.321e6
69 call get_cloud_table_index(mass, number, idx_c, idx_n)
70 write(*,*) 'idx_n=', idx_n, ' number=', number, ' t_nc(idx_n-1)=', t_nc(idx_n-1), &
71 ' t_nc(idx_n)=', t_nc(idx_n)
72 call check(error, (number >= t_nc(idx_n-1) .and. number <= t_nc(idx_n)))
73 if (allocated(error)) return
74 end subroutine getcloudtableindex_numberindexcorrect
75
76
77 subroutine getsnowtableindex_massindexcorrect(error)
78 !! test get_snow_table_index
79 type(error_type), allocatable, intent(out) :: error
80 integer :: idx_s
81 real(wp) :: mass
82 mass = 2.3456e-4
83 call get_snow_table_index(mass, idx_s)
84 write(*,*) 'idx_s=', idx_s, ' mass=', mass, ' r_s(idx_s)=', r_s(idx_s), &
85 ' r_s(idx_s+1)=', r_s(idx_s+1)
86 call check(error, (mass >= r_s(idx_s) .and. mass <= r_s(idx_s+1)))
87 if (allocated(error)) return
88 end subroutine getsnowtableindex_massindexcorrect
89
90
91 subroutine gettemperaturetableindex_indexcorrect(error)
92 !! test get_temperature_table_index
93 type(error_type), allocatable, intent(out) :: error
94 integer :: idx_t
95 real(wp) :: temp
96 temp = t0 - 23.4_wp
97 call get_temperature_table_index(temp, idx_t)
98 write(*,*) 'idx_t=', idx_t, ' temp=', temp-t0, ' tc(idx_t-1)=', tc(idx_t-1), &
99 ' tc(idx_t)=', tc(idx_t)
100 call check(error, (temp-t0 <= tc(idx_t-1) .and. temp-t0 >= tc(idx_t)))
101 if (allocated(error)) return
102 end subroutine gettemperaturetableindex_indexcorrect
103
104
105 subroutine getraintableindex_massindexcorrect(error)
106 !! test get_rain_table_index
107 type(error_type), allocatable, intent(out) :: error
108 integer :: idx_r, idx_r1
109 real(wp) :: mass, ilam
110 mass = 1.2345e-4_wp
111 ilam = 3.4567e8_wp
112 call get_rain_table_index(mass, ilam, idx_r, idx_r1)
113 write(*,*) 'idx_r=', idx_r, ' mass=', mass, ' r_r(idx_r)=', r_r(idx_r), &
114 ' r_r(idx_r+1)=', r_r(idx_r+1)
115 call check(error, (mass >= r_c(idx_r) .and. mass <= r_r(idx_r+1)))
116 if (allocated(error)) return
117 end subroutine getraintableindex_massindexcorrect
118
119
120 subroutine getraintableindex_n0expindexcorrectmvd(error)
121 !! test get_rain_table_index
122 type(error_type), allocatable, intent(out) :: error
123 integer :: idx_r, idx_r1
124 real(wp) :: mass, ilam, lam, mvd, lam_exp_lower, lam_exp_upper, &
125 lam_lower, lam_upper, mvd_lower, mvd_upper
126 mass = 1.2345e-3_wp
127 mvd = 1.234e-3_wp ! 1.234 mm
128 lam = (3.0_wp + mu_r + 0.672_wp) / mvd
129 ilam = 1._wp/lam
130 call get_rain_table_index(mass, ilam, idx_r, idx_r1)
131 lam_exp_upper = (n0r_exp(idx_r1)/(org1*mass/am_r))**(1._wp/cre(1))
132 lam_exp_lower = (n0r_exp(idx_r1+1)/(org1*mass/am_r))**(1._wp/cre(1))
133 lam_upper = lam_exp_upper / ((crg(3)*org2*org1)**bm_r)
134 lam_lower = lam_exp_lower / ((crg(3)*org2*org1)**bm_r)
135 mvd_upper = (3.0_wp + mu_r + 0.672_wp) / lam_upper
136 mvd_lower = (3.0_wp + mu_r + 0.672_wp) / lam_lower
137 write(*,*) 'idx_r1=', idx_r1, ' mvd=', mvd*1.e3_wp, ' mm', &
138 ' mvd_lower=', mvd_lower*1.e3_wp, ' mm', ' mvd_upper=', mvd_upper*1.e3_wp, ' mm'
139 call check(error, (mvd >= mvd_lower .and. mvd <= mvd_upper))
140 if (allocated(error)) return
141 end subroutine getraintableindex_n0expindexcorrectmvd
142
143
144 subroutine getgraupeltableindex_massindexcorrect(error)
145 !! test get_graupel_table_index
146 type(error_type), allocatable, intent(out) :: error
147 integer :: idx_g, idx_g1
148 real(wp) :: mass, ilam
149 integer :: idx
150 mass = 1.2345e-4_wp
151 ilam = 3.4567e8_wp
152 idx = idx_bg1
153 call get_graupel_table_index(mass, ilam, idx, idx_g, idx_g1)
154 write(*,*) 'idx_g=', idx_g, ' mass=', mass, ' r_g(idx_g)=', r_g(idx_g), &
155 ' r_g(idx_g+1)=', r_g(idx_g+1)
156 call check(error, (mass >= r_g(idx_g) .and. mass <= r_g(idx_g+1)))
157 if (allocated(error)) return
158 end subroutine getgraupeltableindex_massindexcorrect
159
160
161 subroutine getgraupeltableindex_n0expindexcorrectmvd(error)
162 !! test get_graupel_table_index
163 type(error_type), allocatable, intent(out) :: error
164 integer :: idx_g, idx_g1
165 integer :: idx
166 real(wp) :: mass, ilam, lam, mvd, lam_exp_lower, lam_exp_upper, &
167 lam_lower, lam_upper, mvd_lower, mvd_upper
168 mass = 1.2345e-3_wp
169 mvd = 5.6789e-3_wp ! 5.6789 mm
170 idx = idx_bg1
171 lam = (3.0_wp + mu_r + 0.672_wp) / mvd
172 ilam = 1._wp/lam
173 call get_graupel_table_index(mass, ilam, idx, idx_g, idx_g1)
174 lam_exp_upper = (n0g_exp(idx_g1)/(ogg1*mass/am_g(idx)))**(1._wp/cge(1,1))
175 lam_exp_lower = (n0g_exp(idx_g1+1)/(ogg1*mass/am_g(idx)))**(1._wp/cge(1,1))
176 lam_upper = lam_exp_upper / ((cgg(3,1)*ogg2*ogg1)**bm_g)
177 lam_lower = lam_exp_lower / ((cgg(3,1)*ogg2*ogg1)**bm_g)
178 mvd_upper = (3.0_wp + mu_r + 0.672_wp) / lam_upper
179 mvd_lower = (3.0_wp + mu_r + 0.672_wp) / lam_lower
180 write(*,*) 'idx_g1=', idx_g1, ' mvd=', mvd*1.e3_wp, ' mm', &
181 ' mvd_lower=', mvd_lower*1.e3_wp, ' mm', ' mvd_upper=', mvd_upper*1.e3_wp, ' mm'
182 call check(error, (mvd >= mvd_lower .and. mvd <= mvd_upper))
183 if (allocated(error)) return
184 end subroutine getgraupeltableindex_n0expindexcorrectmvd
185
186
187 subroutine geticetableindex_massindexcorrect(error)
188 !! test get_ice_table_index
189 type(error_type), allocatable, intent(out) :: error
190 integer :: idx_i, idx_i1
191 real(wp) :: mass, number
192 mass = 1.2345e-6
193 number = 100000. ! 100 / L
194 call get_ice_table_index(mass, number, idx_i, idx_i1)
195 write(*,*) 'idx_i=', idx_i, ' mass=', mass, ' r_i(idx_i)=', r_i(idx_i), &
196 ' r_i(idx_i+1)=', r_i(idx_i+1)
197 call check(error, (mass >= r_i(idx_i) .and. mass <= r_i(idx_i+1)))
198 if (allocated(error)) return
199 end subroutine geticetableindex_massindexcorrect
200
201
202 subroutine geticetableindex_numberindexcorrect(error)
203 !! test get_ice_table_index
204 type(error_type), allocatable, intent(out) :: error
205 integer :: idx_i, idx_i1
206 real(wp) :: mass, number
207 mass = 1.2345e-6
208 number = 100000. ! 100 / L
209 call get_ice_table_index(mass, number, idx_i, idx_i1)
210 write(*,*) 'idx_i1=', idx_i1, ' number=', number, ' nt_i(idx_i1)=', nt_i(idx_i1), &
211 ' nt_i(idx_i1+1)=', nt_i(idx_i1+1)
212 call check(error, (number >= nt_i(idx_i1) .and. number <= nt_i(idx_i1+1)))
213 if (allocated(error)) return
214 end subroutine geticetableindex_numberindexcorrect
215
216end module test_tempo_main_suite