@@ -54,6 +54,17 @@ function print_var(var_names::Array{String})
54
54
end
55
55
end
56
56
57
+ function run_l96 (rhs, ic, T)
58
+ pb = DE. ODEProblem (rhs, ic, (0.0 , T), l96)
59
+ return DE. solve (
60
+ pb,
61
+ SOLVER,
62
+ reltol = reltol,
63
+ abstol = abstol,
64
+ dtmax = dtmax
65
+ )
66
+ end
67
+
57
68
# ###############################################################################
58
69
# config section ###############################################################
59
70
# ###############################################################################
@@ -76,6 +87,18 @@ const LPAD_FLOAT = 13
76
87
const LPAD_VAR = 29
77
88
78
89
parameters = String[]
90
+ # which runs to perform ########################################################
91
+ # run_conv DNS, converging to attractor run, skipped; full system
92
+ # run_dns DNS, direct numerical simulation; full system
93
+ # run_bal balanced, naive closure; only slow variables
94
+ # run_reg regressed, GPR closure; only slow variables
95
+ push! (parameters, " run_conv" , " run_dns" , " run_bal" , " run_reg" )
96
+
97
+ const run_conv = get_cfg_value (config, " runs" , " run_conv" , true )
98
+ const run_dns = get_cfg_value (config, " runs" , " run_dns" , true )
99
+ const run_bal = get_cfg_value (config, " runs" , " run_bal" , true )
100
+ const run_reg = get_cfg_value (config, " runs" , " run_reg" , true )
101
+
79
102
# integration parameters #######################################################
80
103
# T integration time
81
104
# T_conv converging integration time
@@ -147,75 +170,65 @@ println(" " ^ (LPAD_INTEGER + 6),
147
170
" \t\t elapsed:" , lpad (elapsed_jit, LPAD_FLOAT))
148
171
149
172
# full L96m integration (converging to attractor)
150
- print (rpad (" (full, converging)" , RPAD))
151
- elapsed_conv = @elapsed begin
152
- pb_conv = DE. ODEProblem (full, z00, (0.0 , T_conv), l96)
153
- sol_conv = DE. solve (pb_conv,
154
- SOLVER,
155
- reltol = reltol,
156
- abstol = abstol,
157
- dtmax = dtmax
158
- )
173
+ if run_conv
174
+ print (rpad (" (full, converging)" , RPAD))
175
+ elapsed_conv = @elapsed begin
176
+ sol_conv = run_l96 (full, z00, T_conv)
177
+ end
178
+ println (" steps:" , lpad (length (sol_conv. t), LPAD_INTEGER),
179
+ " \t\t elapsed:" , lpad (elapsed_conv, LPAD_FLOAT))
180
+ z0 = sol_conv[:,end ]
159
181
end
160
- println (" steps:" , lpad (length (sol_conv. t), LPAD_INTEGER),
161
- " \t\t elapsed:" , lpad (elapsed_conv, LPAD_FLOAT))
162
- z0 = sol_conv[:,end ]
163
182
164
183
# full L96m integration
165
- print (rpad (" (full)" , RPAD))
166
- elapsed_dns = @elapsed begin
167
- pb_dns = DE. ODEProblem (full, z0, (0.0 , T), l96)
168
- sol_dns = DE. solve (pb_dns,
169
- SOLVER,
170
- reltol = reltol,
171
- abstol = abstol,
172
- dtmax = dtmax
173
- )
184
+ if run_dns
185
+ print (rpad (" (full)" , RPAD))
186
+ elapsed_dns = @elapsed begin
187
+ sol_dns = run_l96 (full, z0, T)
188
+ end
189
+ println (" steps:" , lpad (length (sol_dns. t), LPAD_INTEGER),
190
+ " \t\t elapsed:" , lpad (elapsed_dns, LPAD_FLOAT))
174
191
end
175
- println (" steps:" , lpad (length (sol_dns. t), LPAD_INTEGER),
176
- " \t\t elapsed:" , lpad (elapsed_dns, LPAD_FLOAT))
177
192
178
193
# balanced L96m integration
179
- print (rpad (" (balanced)" , RPAD))
180
- elapsed_bal = @elapsed begin
181
- pb_bal = DE. ODEProblem (balanced, z0[1 : l96. K], (0.0 , T), l96)
182
- sol_bal = DE. solve (pb_bal,
183
- SOLVER,
184
- reltol = reltol,
185
- abstol = abstol,
186
- dtmax = dtmax
187
- )
194
+ if run_bal
195
+ print (rpad (" (balanced)" , RPAD))
196
+ elapsed_bal = @elapsed begin
197
+ sol_bal = run_l96 (balanced, z0[1 : l96. K], T)
198
+ end
199
+ println (" steps:" , lpad (length (sol_bal. t), LPAD_INTEGER),
200
+ " \t\t elapsed:" , lpad (elapsed_bal, LPAD_FLOAT))
188
201
end
189
- println (" steps:" , lpad (length (sol_bal. t), LPAD_INTEGER),
190
- " \t\t elapsed:" , lpad (elapsed_bal, LPAD_FLOAT))
191
202
192
203
# regressed L96m integration
193
- print (rpad (" (regressed)" , RPAD))
194
- elapsed_reg = @elapsed begin
195
- pb_reg = DE. ODEProblem (regressed, z0[1 : l96. K], (0.0 , T), l96)
196
- sol_reg = DE. solve (pb_reg,
197
- SOLVER,
198
- reltol = reltol,
199
- abstol = abstol,
200
- dtmax = dtmax
201
- )
204
+ if run_reg
205
+ print (rpad (" (regressed)" , RPAD))
206
+ elapsed_reg = @elapsed begin
207
+ sol_reg = run_l96 (regressed, z0[1 : l96. K], T)
208
+ end
209
+ println (" steps:" , lpad (length (sol_reg. t), LPAD_INTEGER),
210
+ " \t\t elapsed:" , lpad (elapsed_reg, LPAD_FLOAT))
202
211
end
203
- println (" steps:" , lpad (length (sol_reg. t), LPAD_INTEGER),
204
- " \t\t elapsed:" , lpad (elapsed_reg, LPAD_FLOAT))
205
212
206
213
# ###############################################################################
207
214
# plot section #################################################################
208
215
# ###############################################################################
209
216
# plot DNS
210
- plt. plot (sol_dns. t, sol_dns[k,:], label = " DNS" )
211
- plt. plot (sol_dns. t, sol_dns[l96. K + (k- 1 )* l96. J + j,:],
212
- lw = 0.6 , alpha = 0.6 , color= " gray" )
217
+ if run_dns
218
+ plt. plot (sol_dns. t, sol_dns[k,:], label = " DNS" )
219
+ plt. plot (sol_dns. t, sol_dns[l96. K + (k- 1 )* l96. J + j,:],
220
+ lw = 0.6 , alpha = 0.6 , color= " gray" )
221
+ end
213
222
214
223
# plot balanced
215
- plt. plot (sol_bal. t, sol_bal[k,:], label = " balanced" )
224
+ if run_bal
225
+ plt. plot (sol_bal. t, sol_bal[k,:], label = " balanced" )
226
+ end
216
227
217
228
# plot regressed
218
- plt. plot (sol_reg. t, sol_reg[k,:], label = " regressed" )
229
+ if run_reg
230
+ plt. plot (sol_reg. t, sol_reg[k,:], label = " regressed" )
231
+ end
219
232
220
233
plt. legend ()
221
234
plt. show ()
0 commit comments