Skip to content

Commit c09415e

Browse files
committed
Add conditional runs; implement 'run_l96'
1 parent 88750b8 commit c09415e

File tree

2 files changed

+69
-50
lines changed

2 files changed

+69
-50
lines changed

examples/L96m/cfg.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
[Runs]
2+
run_conv = true
3+
run_dns = true
4+
run_bal = true
5+
run_reg = true
6+
17
[Integration]
28
SOLVER = Tsit5
39

examples/L96m/main.jl

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ function print_var(var_names::Array{String})
5454
end
5555
end
5656

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+
5768
################################################################################
5869
# config section ###############################################################
5970
################################################################################
@@ -76,6 +87,18 @@ const LPAD_FLOAT = 13
7687
const LPAD_VAR = 29
7788

7889
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+
79102
# integration parameters #######################################################
80103
# T integration time
81104
# T_conv converging integration time
@@ -147,75 +170,65 @@ println(" " ^ (LPAD_INTEGER + 6),
147170
"\t\telapsed:", lpad(elapsed_jit, LPAD_FLOAT))
148171

149172
# 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\telapsed:", lpad(elapsed_conv, LPAD_FLOAT))
180+
z0 = sol_conv[:,end]
159181
end
160-
println("steps:", lpad(length(sol_conv.t), LPAD_INTEGER),
161-
"\t\telapsed:", lpad(elapsed_conv, LPAD_FLOAT))
162-
z0 = sol_conv[:,end]
163182

164183
# 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\telapsed:", lpad(elapsed_dns, LPAD_FLOAT))
174191
end
175-
println("steps:", lpad(length(sol_dns.t), LPAD_INTEGER),
176-
"\t\telapsed:", lpad(elapsed_dns, LPAD_FLOAT))
177192

178193
# 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\telapsed:", lpad(elapsed_bal, LPAD_FLOAT))
188201
end
189-
println("steps:", lpad(length(sol_bal.t), LPAD_INTEGER),
190-
"\t\telapsed:", lpad(elapsed_bal, LPAD_FLOAT))
191202

192203
# 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\telapsed:", lpad(elapsed_reg, LPAD_FLOAT))
202211
end
203-
println("steps:", lpad(length(sol_reg.t), LPAD_INTEGER),
204-
"\t\telapsed:", lpad(elapsed_reg, LPAD_FLOAT))
205212

206213
################################################################################
207214
# plot section #################################################################
208215
################################################################################
209216
# 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
213222

214223
# 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
216227

217228
# 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
219232

220233
plt.legend()
221234
plt.show()

0 commit comments

Comments
 (0)