-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfullchem_AutoReduceFuncs.F90
346 lines (323 loc) · 11.8 KB
/
fullchem_AutoReduceFuncs.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
!------------------------------------------------------------------------------
! GEOS-Chem Global Chemical Transport Model !
!------------------------------------------------------------------------------
!BOP
!
! !IROUTINE: fullchem_AutoReduceFuncs
!
! !DESCRIPTION: Contains routines to abstract rosenbrock_autoreduce-specific
! code out of fullchem_mod.F90. This will avoid compilation errors when
! building other KPP-generated mechanisms.
!\\
!\\
! !INTERFACE:
!
MODULE fullchem_AutoReduceFuncs
!
! !USES:
!
IMPLICIT NONE
!
! !PUBLIC MEMBER FUNCTIONS:
!
PUBLIC :: fullchem_AR_KeepHalogensActive
PUBLIC :: fullchem_AR_SetKeepActive
PUBLIC :: fullchem_AR_UpdateKppDiags
PUBLIC :: fullchem_AR_SetIntegratorOptions
!
!EOP
!------------------------------------------------------------------------------
!BOC
CONTAINS
!EOC
!------------------------------------------------------------------------------
! GEOS-Chem Global Chemical Transport Model !
!------------------------------------------------------------------------------
!BOP
!
! !IROUTINE: fullchem_AR_KeepHalogensActive
!
! !DESCRIPTION: Sets halogen species to "fast" for the rosenbrock_autoreduce
! integrator.
!\\
!\\
! !INTERFACE:
!
SUBROUTINE fullchem_AR_KeepHalogensActive( doPrint )
!
! !USES:
!
USE gckpp_Precision
USE gckpp_Parameters
USE gckpp_Global, ONLY : keepSpcActive
!
! !INPUT PARAMETERS:
!
LOGICAL, INTENT(IN) :: doPrint ! Print informational message
!EOP
!------------------------------------------------------------------------------
!BOC
! Informational printout
IF ( doPrint ) THEN
WRITE( 6, 100 )
100 FORMAT('Setting halogen species to "fast" for rosenbrock_autoreduce"')
ENDIF
! New halogens auto-reduce list hplin 01/27/22, 03/02/22
! based off Shen et al. 2020 GMD Table 1, lines 10, 11, 12
keepSpcActive(ind_AERI ) = .TRUE. ! Iodine on aerosol
keepSpcActive(ind_Br ) = .TRUE.
keepSpcActive(ind_Br2 ) = .TRUE.
keepSpcActive(ind_BrCl ) = .TRUE.
keepSpcActive(ind_BrNO2 ) = .TRUE.
keepSpcActive(ind_BrNO3 ) = .TRUE.
keepSpcActive(ind_BrO ) = .TRUE.
keepSpcActive(ind_BrSALA) = .TRUE.
keepSpcActive(ind_BrSALC) = .TRUE.
keepSpcActive(ind_HBr ) = .TRUE.
keepSpcActive(ind_HOBr ) = .TRUE.
keepSpcActive(ind_Cl ) = .TRUE.
keepSpcActive(ind_Cl2 ) = .TRUE.
keepSpcActive(ind_Cl2O2 ) = .TRUE.
keepSpcActive(ind_ClNO2 ) = .TRUE.
keepSpcActive(ind_ClNO3 ) = .TRUE.
keepSpcActive(ind_ClO ) = .TRUE.
keepSpcActive(ind_ClOO ) = .TRUE.
keepSpcActive(ind_OClO ) = .TRUE.
keepSpcActive(ind_HCl ) = .TRUE.
keepSpcActive(ind_HOCl ) = .TRUE.
keepSpcActive(ind_I ) = .TRUE.
keepSpcActive(ind_I2 ) = .TRUE.
keepSpcActive(ind_IO ) = .TRUE.
keepSpcActive(ind_I2O2 ) = .TRUE.
keepSpcActive(ind_HI ) = .TRUE.
keepSpcActive(ind_ISALA ) = .TRUE.
keepSpcActive(ind_ISALC ) = .TRUE.
keepSpcActive(ind_I2O4 ) = .TRUE.
keepSpcActive(ind_I2O3 ) = .TRUE.
keepSpcActive(ind_INO ) = .TRUE.
keepSpcActive(ind_IONO ) = .TRUE.
keepSpcActive(ind_IONO2 ) = .TRUE.
keepSpcActive(ind_ICl ) = .TRUE.
keepSpcActive(ind_IBr ) = .TRUE.
keepSpcActive(ind_HOI ) = .TRUE.
keepSpcActive(ind_SALACl) = .TRUE.
keepSpcActive(ind_SALCCl) = .TRUE.
keepSpcActive(ind_SALAAL) = .TRUE.
keepSpcActive(ind_SALCAL) = .TRUE.
END SUBROUTINE fullchem_AR_KeepHalogensActive
!EOC
!------------------------------------------------------------------------------
! GEOS-Chem Global Chemical Transport Model !
!------------------------------------------------------------------------------
!BOP
!
! !IROUTINE: fullchem_AR_SetKeepActive
!
! !DESCRIPTION: Abstracts setting the rosenbrock_autoreduce keepActive flag
! out of fullchem_mod.F90
!\\
!\\
! !INTERFACE:
!
SUBROUTINE fullchem_AR_SetKeepActive( option )
!
! !USES:
!
USE gckpp_Precision
USE gckpp_Global, ONLY : keepActive
!
! !INPUT PARAMETERS:
!
LOGICAL, INTENT(IN) :: option
!EOP
!------------------------------------------------------------------------------
!BOC
keepActive = option
END SUBROUTINE fullchem_AR_SetKeepActive
!EOC
!------------------------------------------------------------------------------
! GEOS-Chem Global Chemical Transport Model !
!------------------------------------------------------------------------------
!BOP
!
! !IROUTINE: fullchem_AR_UpdateKppDiags
!
! !DESCRIPTION: Updates KPP diagnostics for the rosenbrock_autoreduce solver
!\\
!\\
! !INTERFACE:
!
SUBROUTINE fullchem_AR_UpdateKppDiags( I, J, L, RSTATE, State_Diag )
!
! !USES:
!
USE gckpp_Precision
USE gckpp_Global, ONLY : cNONZERO, rNVAR
USE gckpp_Integrator, ONLY : NARthr
USE State_Diag_Mod, ONLY : DgnState
!
! !INPUT PARAMETERS:
!
INTEGER, INTENT(IN) :: I, J, L
REAL(dp), INTENT(IN) :: RSTATE(20)
!
! !INPUT/OUTPUT PARAMETERS:
!
TYPE(DgnState), INTENT(INOUT) :: State_Diag
!EOP
!------------------------------------------------------------------------------
!BOC
! # of species in auto-reduced mechanism
IF ( State_Diag%Archive_KppAutoReducerNVAR ) THEN
State_Diag%KppAutoReducerNVAR(I,J,L) = rNVAR
ENDIF
! Computed threshold
IF ( State_Diag%Archive_KppAutoReduceThres ) THEN
State_Diag%KppAutoReduceThres(I,J,L) = RSTATE(NARthr)
ENDIF
! # of nonzero elements in LU factorization of Jacobian, AR only
IF ( State_Diag%Archive_KppcNONZERO ) THEN
State_Diag%KppcNONZERO(I,J,L) = cNONZERO
ENDIF
END SUBROUTINE fullchem_AR_UpdateKppDiags
!EOC
!------------------------------------------------------------------------------
! GEOS-Chem Global Chemical Transport Model !
!------------------------------------------------------------------------------
!BOP
!
! !IROUTINE: fullchem_AR_SetIntegratorOptions
!
! !DESCRIPTION: Defines the settings for ICNTRL and RCNTRL used for the
! rosenbrock_autoreduce integrator.
!\\
!\\
! !INTERFACE:
!
SUBROUTINE fullchem_AR_SetIntegratorOptions( Input_Opt, State_Chm, &
State_Met, FirstChem, &
I, J, L, &
ICNTRL, RCNTRL )
!
! !USES:
!
USE gckpp_Parameters
USE gckpp_Precision
USE Input_Opt_Mod, ONLY : OptInput
USE State_Chm_Mod, ONLY : ChmState
USE State_Met_Mod, ONLY : MetState
!
! !INPUT PARAMETERS:
!
TYPE(OptInput), INTENT(IN) :: Input_Opt ! Input Options object
TYPE(ChmState), INTENT(IN) :: State_Chm ! Chemistry State object
TYPE(MetState), INTENT(IN) :: State_Met ! Meteorology State object
LOGICAL, INTENT(IN) :: FirstChem ! Is it the 1st chem timestep
INTEGER, INTENT(IN) :: I, J, L ! Grid box indices
!
! !INPUT/OUTPUT PARAMETERS:
!
INTEGER, INTENT(INOUT) :: ICNTRL(20) ! Options for KPP (integer)
REAL(dp), INTENT(INOUT) :: RCNTRL(20) ! Options for KPP (real )
!
! !REMARKS:
! This code was abstracted out of the parallel DO loop in DO_FULLCHEM
! (in module GeosCore/fullchem_mod.F90)
!EOP
!------------------------------------------------------------------------------
!BOC
!=====================================================================
! fullchem_AR_SetIntegratorOptions begins here!
!=====================================================================
! Initialize
ICNTRL = 0
RCNTRL = 0.0_dp
!=====================================================================
! Define settings in the ICNTRL vector
!=====================================================================
! 0 - non-autonomous, 1 - autonomous
ICNTRL(1) = 1
! NOTE: ICNTRL is already zeroed out so we don't need to
! set this to zero again. Uncomment if you change this value.
!! 0 - vector tolerances, 1 - scalars
!ICNTRL(2) = 0
! Select a particular integration method.
! For Rosenbrock, options are:
! = 0 : default method is Rodas3
! = 1 : method is Ros2
! = 2 : method is Ros3
! = 3 : method is Ros4
! = 4 : method is Rodas3
! = 5: method is Rodas4
ICNTRL(3) = 4
! 0 - adjoint, 1 - no adjoint
ICNTRL(7) = 1
! Turn off calling Update_SUN, Update_RCONST, Update_PHOTO from within
! the integrator. Rate updates are done before calling KPP.
ICNTRL(15) = -1
! Specify that a threshold value will be used for auto-reduction.
! The threshold will be specified in RCNTRL(12), see below.
IF ( Input_Opt%USE_AUTOREDUCE .and. .not. FIRSTCHEM ) ICNTRL(12) = 1
! Use the append functionality?
IF ( Input_Opt%AUTOREDUCE_IS_APPEND ) ICNTRL(13) = 1
!=====================================================================
! Define settings in the ICNTRL vector
!=====================================================================
! Initialize Hstart (the starting value of the integration step
! size with the value of Hnew (the last predicted but not yet
! taken timestep) saved to the the restart file.
RCNTRL(3) = State_Chm%KPPHvalue(I,J,L)
!---------------------------------------------------------------------
! Auto-reduce threshold, Method 1: Pressure-dependent
!
! Actual_Threshold =
! Mid-Pressure at Level
! AUTOREDUCE_THRESHOLD (at surface) * --------------------------
! "Mid-Pressure" at Sfc.
!
!---------------------------------------------------------------------
IF ( .not. Input_Opt%AUTOREDUCE_IS_KEY_THRESHOLD ) THEN
IF ( Input_Opt%AUTOREDUCE_IS_PRS_THRESHOLD ) THEN
RCNTRL(12) = Input_Opt%AUTOREDUCE_THRESHOLD &
* State_Met%PMID(I,J,L) &
/ State_Met%PMID(I,J,1)
ENDIF
IF ( .not. Input_Opt%AUTOREDUCE_IS_PRS_THRESHOLD ) THEN
RCNTRL(12) = Input_Opt%AUTOREDUCE_THRESHOLD
ENDIF
ENDIF
!---------------------------------------------------------------------
! Auto-reduce threshold, Method 2: Determine threshold
! dynamically by scaling rates of key species.
!---------------------------------------------------------------------
IF ( Input_Opt%AUTOREDUCE_IS_KEY_THRESHOLD ) THEN
!--------------------------------
! Daytime target species (OH)
!--------------------------------
ICNTRL(14) = ind_OH
RCNTRL(14) = Input_Opt%AUTOREDUCE_TUNING_OH
!--------------------------------
! Nighttime target species (NO2)
!--------------------------------
! COMMENTS BY HAIPENG LIN:
! 1e6 daytime conc...testing shows 5e-5 as an offset here works best.
! Use JNO2 as night determination.
! RXN_NO2: NO2 + hv --> NO + O
! JNO2 ranges from 0 to 0.02 and is order ~ 1e-4 at the terminator.
! We set this threshold to be slightly relaxed so it captures the
! terminator, but this needs some tweaking.
!
! For some reason, RXN_NO2 as a proxy fails to propagate the sunset
! terminator even though all diagnostics seem fine, and after a while
! only the OH scheme applies. Use SUNCOSmid as a proxy to fix this.
! (hplin, 4/20/22)
! IF(ZPJ(L,RXN_NO2,I,J) .eq. 0.0_fp) THEN
!
IF( State_Met%SUNCOSmid(I,J) .le. -0.1391731e+0_dp ) THEN
ICNTRL(14) = ind_NO2
RCNTRL(14) = Input_Opt%AUTOREDUCE_TUNING_NO2
ENDIF
ENDIF
END SUBROUTINE fullchem_AR_SetIntegratorOptions
!EOC
END MODULE fullchem_AutoReduceFuncs