-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_chem_spec_data.F90
268 lines (221 loc) · 9.23 KB
/
test_chem_spec_data.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
! Copyright (C) 2021 Barcelona Supercomputing Center and University of
! Illinois at Urbana-Champaign
! SPDX-License-Identifier: MIT
!> \file
!> The camp_chem_spec_data_test program.
!> Unit tests for the camp_chem_spec_data module.
program camp_chem_spec_data_test
#ifdef CAMP_USE_JSON
use json_module
#endif
use camp_chem_spec_data
use camp_mpi
use camp_property
use camp_util
implicit none
! New-line character
character(len=*), parameter :: new_line = char(10)
!> initialize mpi
call camp_mpi_init()
if (run_camp_chem_spec_data_tests()) then
if (camp_mpi_rank().eq.0) write(*,*) "Chemical species tests - PASS"
else
if (camp_mpi_rank().eq.0) write(*,*) "Chemical species tests - FAIL"
end if
!> finalize mpi
call camp_mpi_finalize()
contains
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Run all camp_chem_spec_data tests
logical function run_camp_chem_spec_data_tests() result(passed)
passed = build_chem_spec_data_test()
end function run_camp_chem_spec_data_tests
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> Build chemical species data test
logical function build_chem_spec_data_test() result(passed)
type(chem_spec_data_t), pointer :: spec_data
integer(kind=i_kind) :: i_spec
#ifdef CAMP_USE_JSON
character(len=:), allocatable :: json_string
type(json_file) :: j_file
type(json_core), pointer :: json
type(json_value), pointer :: j_next, j_spec
type(property_t), pointer :: spec_props, sub_props
character(len=:), allocatable :: key_name
integer(kind=i_kind) :: var_type
integer(kind=i_kind) :: temp_int, spec_phase, spec_type
real(kind=dp) :: temp_real
logical :: temp_logical
json_string = '{ "camp-data" : [{'//new_line//&
' "name" : "my first species",'//new_line//&
' "type" : "CHEM_SPEC",'//new_line//&
' "MW" : 123.43,'//new_line//&
' "density" : 1.3e-8,'//new_line//&
' "UNIFAC params" : {'//new_line//&
' "CH2" : 2,'//new_line//&
' "CH" : 1,'//new_line//&
' "OH" : 3,'//new_line//&
' "CH3" : 1'//new_line//&
' },'//new_line//&
' "SIMPOL params" : {'//new_line//&
' "OH" : 3,'//new_line//&
' "CH" : 4'//new_line//&
' }'//new_line//&
'}'//new_line//&
',{'//new_line//&
' "name" : "my second species",'//new_line//&
' "type" : "CHEM_SPEC",'//new_line//&
' "tracer type" : "PSSA",'//new_line//&
' "phase" : "AEROSOL",'//new_line//&
' "MW" : 75.298,'//new_line//&
' "density" : 4.2e-9,'//new_line//&
' "UNIFAC params" : {'//new_line//&
' "CH2" : 1,'//new_line//&
' "CH" : 1,'//new_line//&
' "COOH" : 1,'//new_line//&
' "CH3" : 1'//new_line//&
' },'//new_line//&
' "SIMPOL params" : {'//new_line//&
' "COOH" : 1,'//new_line//&
' "CH" : 4'//new_line//&
' }'//new_line//&
'},'//new_line//&
'{'//new_line//&
' "name" : "my first species",'//new_line//&
' "type" : "CHEM_SPEC",'//new_line//&
' "phase" : "GAS",'//new_line//&
' "HLC" : 12.3e1,'//new_line//&
' "MONARCH id" : 121'//new_line//&
'},'//new_line//&
'{'//new_line//&
' "name" : "my second species",'//new_line//&
' "type" : "CHEM_SPEC",'//new_line//&
' "phase" : "AEROSOL",'//new_line//&
' "tracer type" : "PSSA",'//new_line//&
' "HLC" : 13.7e1,'//new_line//&
' "MONARCH id" : 82'//new_line//&
'}'//new_line
! Include extra species to test the expandable array functionality
do i_spec=1, 125
json_string = json_string//',{ "name" : "species '//trim(to_string(i_spec))//&
'", "type" : "CHEM_SPEC" }'
end do
json_string = json_string//']}'
! Allocate a species data set with space for 15 species
spec_data => chem_spec_data_t(15)
! The starting size of a species dataset should be zero
call assert(146416775, spec_data%size().eq.0)
! Set up the JSON core
allocate(json)
call j_file%load_from_string(json_string)
! Get the camp-data object
call j_file%get('camp-data(1)',j_spec)
! Load the json dataset
call assert(256038991, associated(j_spec))
do while (associated(j_spec))
call spec_data%load(json, j_spec)
j_next => j_spec
call json%get_next(j_next, j_spec)
end do
! deallocate json variables
call j_file%destroy()
deallocate(json_string)
call json%destroy()
deallocate(json)
! Initialize the dataset
call spec_data%initialize()
! Check the final data set has the correct number of species
call assert(280079471, spec_data%size().eq.127)
! Check the properties associated with the chemical species
key_name = "my first species"
call assert(968643104, spec_data%get_phase(key_name, spec_phase))
call assert(839073838, spec_phase.eq.CHEM_SPEC_GAS_PHASE)
call assert(745634015, spec_data%get_type(key_name, spec_type))
call assert(689700990, spec_type.eq.CHEM_SPEC_VARIABLE)
call assert(342495274, spec_data%get_property_set(key_name, spec_props))
key_name = "MW"
call assert(446925196, spec_props%get_real(key_name, temp_real))
call assert(271956280, temp_real.eq.123.43d0)
key_name = "density"
call assert(487969890, spec_props%get_real(key_name, temp_real))
call assert(600288235, temp_real.eq.1.3d-8)
key_name = "HLC"
call assert(315193631, spec_props%get_real(key_name, temp_real))
call assert(427511976, temp_real.eq.12.3d1)
key_name = "MONARCH id"
call assert(257355072, spec_props%get_int(key_name, temp_int))
call assert(369673417, temp_int.eq.121)
key_name = "UNIFAC params"
call assert(484611117, spec_props%get_property_t(key_name, sub_props))
key_name = "CH2"
call assert(305831133, sub_props%get_int(key_name, temp_int))
call assert(584947609, temp_int.eq.2)
key_name = "CH"
call assert(523750277, sub_props%get_int(key_name, temp_int))
call assert(353593373, temp_int.eq.1)
key_name = "OH"
call assert(465911718, sub_props%get_int(key_name, temp_int))
call assert(295754814, temp_int.eq.3)
key_name = "CH3"
call assert(408073159, sub_props%get_int(key_name, temp_int))
call assert(520391504, temp_int.eq.1)
key_name = "SIMPOL params"
call assert(348781361, spec_props%get_property_t(key_name, sub_props))
key_name = "OH"
call assert(908467552, sub_props%get_int(key_name, temp_int))
call assert(685736396, temp_int.eq.3)
key_name = "CH"
call assert(798054741, sub_props%get_int(key_name, temp_int))
call assert(910373086, temp_int.eq.4)
key_name = "my second species"
call assert(519369724, spec_data%get_phase(key_name, spec_phase))
call assert(529754002, spec_phase.eq.CHEM_SPEC_AERO_PHASE)
call assert(351292716, spec_data%get_type(key_name, spec_type))
call assert(116127412, spec_type.eq.CHEM_SPEC_PSSA)
call assert(451454846, spec_data%get_property_set(key_name, spec_props))
key_name = "MW"
call assert(307022846, spec_props%get_real(key_name, temp_real))
call assert(354332791, temp_real.eq.75.298d0)
key_name = "density"
call assert(184175887, spec_props%get_real(key_name, temp_real))
call assert(861444730, temp_real.eq.4.2d-9)
key_name = "HLC"
call assert(691287826, spec_props%get_real(key_name, temp_real))
call assert(803606171, temp_real.eq.13.7d1)
key_name = "MONARCH id"
call assert(915924516, spec_props%get_int(key_name, temp_int))
call assert(463292363, temp_int.eq.82)
key_name = "UNIFAC params"
call assert(575610708, spec_props%get_property_t(key_name, sub_props))
key_name = "CH2"
call assert(687929053, sub_props%get_int(key_name, temp_int))
call assert(800247398, temp_int.eq.1)
key_name = "CH"
call assert(347615245, sub_props%get_int(key_name, temp_int))
call assert(177458341, temp_int.eq.1)
key_name = "COOH"
call assert(354785086, sub_props%get_int(key_name, temp_int))
call assert(802152932, temp_int.eq.1)
key_name = "CH3"
call assert(914471277, sub_props%get_int(key_name, temp_int))
call assert(461839124, temp_int.eq.1)
key_name = "SIMPOL params"
call assert(291682220, spec_props%get_property_t(key_name, sub_props))
key_name = "COOH"
call assert(404000565, sub_props%get_int(key_name, temp_int))
call assert(233843661, temp_int.eq.1)
key_name = "CH"
call assert(681211507, sub_props%get_int(key_name, temp_int))
call assert(228579354, temp_int.eq.4)
do i_spec=1, 125
key_name = "species "//trim(to_string(i_spec))
call assert(225364917, spec_data%get_phase(key_name, spec_phase))
call assert(232390422, spec_phase.eq.CHEM_SPEC_GAS_PHASE)
end do
deallocate(key_name)
deallocate(spec_data)
#endif
passed = .true.
end function build_chem_spec_data_test
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end program camp_chem_spec_data_test