-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper_simulations.py
207 lines (183 loc) · 5.87 KB
/
paper_simulations.py
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
# paper_simulations.py
"""Source code for the simulations used in the publication."""
import argparse
import itertools
from batch_simulations import BatchSimulator
from simulation_results import SimulationResults
func_dict = {}
def option(func):
"""Add the function to the global list of options"""
func_dict[func.__name__] = func
return func
@option
def probe_order(dirname):
sim = BatchSimulator(dirname, N=512, lambda2=1, overwrite=True)
base_params = {
"alpha": 1,
"mu_scale": 1.8,
"max_t": 60,
"modes": 21,
"timestepper":"rk4"
}
base_params["initial_guess"] = {"lambda2": 2}
ranges = {
"dt": [1e-2, 1e-3, 5e-3, 1e-4, 5e-4],
"order": [1,2,3]
}
sim.run_batch(base_params, ranges=ranges)
@option
def multiparam_combinations(dirname):
sim = BatchSimulator(dirname, N=256, lambda2=1, overwrite=True)
base_params = {
"alpha": 1,
"mu_scale": 1.8,
"max_t": 80,
"modes": 21,
"order": 2,
"dt": 1e-3
}
# lambda4 is the coefficient by the fourth derivative u_xxxx,
# lambda2 is the coefficient by the second derivative term u_xx.
estimate_params = [
"lambda2",
"lambda4",
"nonlinear_coeff",
"lambda1",
"lambda3"
]
initial_guesses = []
for included in itertools.product([False, True], repeat=5):
# Skip the boring case of nothing to estimate.
if not any(included):
continue
initial_guess = {}
for is_included, param_name in zip(included, estimate_params):
if is_included:
initial_guess[param_name] = 2
initial_guesses.append(initial_guess)
sim.run_batch(base_params, ranges={"initial_guess": initial_guesses})
@option
def high_spatial_res(dirname):
sim = BatchSimulator(dirname, N=1024, lambda2=1, overwrite=True)
base_params = {
"alpha": 1,
"mu_scale": 1.8,
"order": 3,
"max_t": 45,
"modes": 21,
"timestepper":"rk4"
}
base_params["initial_guess"] = {"lambda2": 2}
sim.run_batch(base_params, ranges={"dt": [2.5e-4], "modes": [42, 84, 168]})
results = SimulationResults(dirname)
df = results.get_summary()
print(df)
print(df[["dt", "modes", "lambda2_error"]])
@option
def explore_alpha(dirname):
sim = BatchSimulator(dirname, N=512, lambda2=1, overwrite=True)
base_params = {
"alpha": 1,
"mu_scale": 1.8,
"order": 3,
"max_t": 60,
"dt": 1e-3,
"modes": 21,
"timestepper": "rk4"
}
ranges = {
"initial_guess": [
{"lambda2": 2},
{"lambda2": 2, "lambda4": 2, "nonlinear_coeff": 2}
],
"alpha": [.5, 1, 10, 100, None]
}
sim.run_batch(base_params, ranges=ranges)
@option
def mu_alpha_convergence(dirname):
"""Vary mu_scale and alpha - and see how the convergence rate changes.
"""
sim = BatchSimulator(dirname, N=512, lambda2=1, overwrite=True)
base_params = {
"alpha": 1,
"mu_scale": 1.8,
"order": 3,
"max_t": 60,
"dt": 1e-3,
"modes": 21,
"timestepper": "rk4",
"initial_guess": {"lambda2": 2}}
ranges = {
"alpha": [.1, .5, 1, 5, 10, 50, 100],
"mu_scale": [5e-4, .001, .005, .01, .05, .1, .5, 1, 1.4, 1.8]
}
sim.run_batch(base_params, ranges=ranges, grid=False) # No grid search.
@option
def multiparam_mu_alpha_convergence(dirname):
"""Vary mu_scale and alpha - and see how the convergence rate changes.
"""
sim = BatchSimulator(dirname, N=512, lambda2=1, overwrite=True)
base_params = {
"alpha": 1,
"mu_scale": 1.8,
"order": 3,
"max_t": 60,
"dt": 1e-3,
"modes": 21,
"timestepper":"rk4",
"initial_guess": {"lambda2": 2, "lambda4":2, "nonlinear_coeff":2}
}
ranges = {
"alpha": [.1, .5, 1, 5, 10, 50, 100],
"mu_scale": [5e-4, .001, .005, .01, .05, .1, .5, 1, 1.4, 1.8]
}
sim.run_batch(base_params, ranges=ranges, grid=False)
@option
def interpolator_scan(dirname):
"""Do a parameter scan over interpolators.
We vary both the functional form (piecewise-linear, cubic, Fourier modes,
etc) and the dimension.
"""
sim = BatchSimulator(dirname, N=512, lambda2=1, overwrite=True)
# modes = [4, 8, 16, 21, 32, 48, 64, 96, 128]
# interpolators = [None, "cubic", "linear"]
# None stands for the standard Fourier interpolator.
# Use a much smaller mu.
base_params = {
"alpha": 1,
"mu_scale": .01,
"order": 3,
"max_t": 60,
"dt": 1e-3,
"modes": 21,
"timestepper":"rk4",
"initial_guess": {"lambda2": 2}
}
pointwise_modes = list(range(34,48,2))
fourier_modes = list(range(17,22))
# mu_scales = [1e-3, 1e-2, 1e-1]
pointwise_params = sim.get_param_list(base_params, ranges={
"modes": pointwise_modes,
"pointwise_interpolation": ["cubic", "quadratic", "linear"],
"mu_scale": [.01]}
)
fourier_params = sim.get_param_list(base_params, ranges={
"modes":fourier_modes,
"mu_scale": [1.8]}
)
# sim.run_batch(base_params, ranges={
# "modes": modes,
# "pointwise_interpolation": interpolators}
# )
sim.run_simulations_low(pointwise_params + fourier_params)
# =============================================================================
if __name__ == "__main__":
func_names = list(func_dict.keys())
parser = argparse.ArgumentParser()
parser.add_argument("dirname",
help="Directory in which to save simulation results.")
parser.add_argument("--simulation",
choices=func_names, default="probe_order")
args = parser.parse_args()
print(f"Running simulation {args.simulation}")
func_dict[args.simulation](args.dirname)