-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfasst_libpfasst.py
326 lines (315 loc) · 21.5 KB
/
pfasst_libpfasst.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
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
from pfasst import Pfasst
class PfasstLibpfasst(Pfasst):
def __init__(self, *args, **kwargs):
"""
Constructor
"""
super().__init__(*args, **kwargs)
if self.iterations == 0:
raise Exception('not implemented')
def pfasst(self, k):
"""
k'th PFASST iteration
:param k: iteration
"""
for level in range(0, self.L - 1):
for i in range(1, self.nt):
if k == 1 or level > 0:
self.f_eval_single(
op_in=['u', self.cr_dict(iteration=k - 1, level=level, time_point=i, colloc_node='first')],
op_out=['f', self.cr_dict(iteration=k - 1, level=level, time_point=i, colloc_node='first')],
level=level,
i=i)
if self.sweep_level_0_start_iteration or level > 0:
for j in range(self.nsweeps[level]):
if j == 0:
op_in_1 = ['u', self.cr_dict(iteration=k - 1, level=level, time_point=i, colloc_node='all')]
op_in_2 = ['f', self.cr_dict(iteration=k - 1, level=level, time_point=i, colloc_node='all')]
else:
op_in_1 = ['tmp_fr_u' + str(j - 1),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
op_in_2 = ['tmp_fr_f' + str(j - 1),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
if j == self.nsweeps[level] - 1:
op_out_1 = ['u', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
op_out_2 = ['f', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
else:
op_out_1 = ['tmp_fr_u' + str(j),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
op_out_2 = ['tmp_fr_f' + str(j),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
self.sdc_sweep(op_in_1=op_in_1,
op_in_2=op_in_2,
op_in_3=None if level == 0 else ['tau',
self.cr_dict(iteration=k, level=level,
time_point=i, colloc_node='all')],
op_out_1=op_out_1,
op_out_2=op_out_2,
level=level,
i=i)
else:
self.copy(op_in=['u', self.cr_dict(iteration=k - 1, level=level, time_point=i, colloc_node='all')],
op_out=['u', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
level=level,
i=i)
self.copy(op_in=['f', self.cr_dict(iteration=k - 1, level=level, time_point=i, colloc_node='all')],
op_out=['f', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
level=level,
i=i)
self.restrict_all(op_in=['u', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
op_out=['u', self.cr_dict(iteration=k - 1, level=level + 1, time_point=i,
colloc_node='all')],
level=level,
i=i)
self.f_eval_all(
op_in=['u', self.cr_dict(iteration=k - 1, level=level + 1, time_point=i, colloc_node='all')],
op_out=['f', self.cr_dict(iteration=k - 1, level=level + 1, time_point=i, colloc_node='all')],
level=level,
i=i,
cost=self.cost_f_eval_all[level + 1])
self.fas(op_in_1=['f', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
op_in_2=['f', self.cr_dict(iteration=k - 1, level=level + 1, time_point=i, colloc_node='all')],
op_in_3=None if level == 0 else ['tau', self.cr_dict(iteration=k, level=level, time_point=i,
colloc_node='all')],
op_out=['tau', self.cr_dict(iteration=k, level=level + 1, time_point=i, colloc_node='all')],
level=level,
i=i)
if self.placing_conv_crit == 1:
self.update_cc(k=k)
self.convergence_criterion(poins_with_dependencies=self.cc)
# Coarsest level
for i in range(1, self.nt):
if i > 1:
self.copy_and_f_eval_single(
op_in=['u', self.cr_dict(iteration=k, level=self.L - 1, time_point=i - 1, colloc_node='last')],
op_out_1=['u', self.cr_dict(iteration=k - 1, level=self.L - 1, time_point=i, colloc_node='first')],
op_out_2=['f', self.cr_dict(iteration=k - 1, level=self.L - 1, time_point=i, colloc_node='first')],
level=self.L - 1,
i=i)
for j in range(self.nsweeps[self.L - 1]):
if j == 0:
op_in_1 = ['u', self.cr_dict(iteration=k - 1, level=self.L - 1, time_point=i, colloc_node='all')]
op_in_2 = ['f', self.cr_dict(iteration=k - 1, level=self.L - 1, time_point=i, colloc_node='all')]
else:
op_in_1 = ['tmp_cl_u' + str(j - 1),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
op_in_2 = ['tmp_cl_f' + str(j - 1),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
if j == self.nsweeps[self.L - 1] - 1:
op_out_1 = ['u', self.cr_dict(iteration=k, level=self.L - 1, time_point=i, colloc_node='all')]
op_out_2 = ['f', self.cr_dict(iteration=k, level=self.L - 1, time_point=i, colloc_node='all')]
else:
op_out_1 = ['tmp_cl_u' + str(j),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
op_out_2 = ['tmp_cl_f' + str(j),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
self.sdc_sweep(op_in_1=op_in_1,
op_in_2=op_in_2,
op_in_3=None if level == 0 else ['tau',
self.cr_dict(iteration=k, level=self.L - 1,
time_point=i, colloc_node='all')],
op_out_1=op_out_1,
op_out_2=op_out_2,
level=self.L - 1,
i=i)
for level in range(self.L - 2, -1, -1):
for i in range(1, self.nt):
self.interpolate_and_correct_all(
op_in_1=['u', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
op_in_2=['u', self.cr_dict(iteration=k, level=level + 1, time_point=i, colloc_node='all')],
op_in_3=['u', self.cr_dict(iteration=k - 1, level=level + 1, time_point=i, colloc_node='all')],
op_out=['v', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
level=level,
i=i, )
self.f_eval_all(op_in=['v', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
op_out=['f', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
level=level,
i=i,
cost=self.cost_f_eval_all[level] if self.pfasst_style == 'classic' else
self.cost_f_eval_all[level] - self.cost_f_eval_single[level])
if i > 1:
self.copy_and_error_correction(
op_in_1=['u', self.cr_dict(iteration=k, level=level, time_point=i - 1, colloc_node='last')],
op_in_2=['u', self.cr_dict(iteration=k, level=level + 1, time_point=i, colloc_node='first')],
op_out_1=['v', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='first')],
op_out_2=['f', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='first')],
level=level,
i=i)
for i in range(1, self.nt):
if level > 0 or self.sweep_level_0_end_iteration:
for j in range(self.nsweeps[level]):
if j == 0:
op_in_1 = ['v', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
op_in_2 = ['f', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
else:
op_in_1 = ['tmp_ba_u' + str(j - 1),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
op_in_2 = ['tmp_ba_f' + str(j - 1),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
if j == self.nsweeps[level] - 1:
op_out_1 = ['u', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
op_out_2 = ['f', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
else:
op_out_1 = ['tmp_ba_u' + str(j),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
op_out_2 = ['tmp_ba_f' + str(j),
self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')]
self.sdc_sweep(op_in_1=op_in_1,
op_in_2=op_in_2,
op_in_3=None if level == 0 else ['tau',
self.cr_dict(iteration=k, level=level,
time_point=i, colloc_node='all')],
op_out_1=op_out_1,
op_out_2=op_out_2,
level=level,
i=i)
else:
self.copy(op_in=['v', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
op_out=['u', self.cr_dict(iteration=k, level=level, time_point=i, colloc_node='all')],
level=level,
i=i)
if k == self.iterations:
for i in range(1, self.nt):
if self.iterations == 0:
self.f_eval_single(op_in=['u', self.cr_dict(iteration=self.iterations, level=0, time_point=i,
colloc_node='first')],
op_out=['f', self.cr_dict(iteration=self.iterations, level=0, time_point=i,
colloc_node='first')],
level=0,
i=i)
self.sdc_sweep(
op_in_1=['u', self.cr_dict(iteration=self.iterations, level=0, time_point=i, colloc_node='all')],
op_in_2=['f', self.cr_dict(iteration=self.iterations, level=0, time_point=i, colloc_node='all')],
op_in_3=None,
op_out_1=['u', self.cr_dict(iteration=self.iterations, level=0, time_point=i, colloc_node='all')],
op_out_2=['v', self.cr_dict(iteration=self.iterations, level=0, time_point=i, colloc_node='all')],
level=0,
i=i)
def predict(self):
"""
Predictor
"""
for i in range(1, self.nt):
self.add_node(name="c0|",
predecessors=['u_0'],
set_values=self.create_node_name(var_name='u',
var_dict=self.cr_dict(iteration=0, level=0, time_point=i,
colloc_node='first')),
cost=self.cost_copy[0],
point=i,
description='Set first point of every time step to initial value')
self.add_node(name="C0|",
predecessors=['0'],
set_values=self.create_node_name(var_name='u',
var_dict=self.cr_dict(iteration=0, level=0, time_point=i,
colloc_node='last')),
cost=self.cost_copy[0],
point=i,
description='Set last point of every time step to 0')
self.add_node(name="C0|",
predecessors=['0'],
set_values=self.create_node_name(var_name='f',
var_dict=self.cr_dict(iteration=0, level=0, time_point=i,
colloc_node='all')),
cost=self.cost_copy[0],
point=i,
description='Set f to 0')
if self.predict_type == 'libpfasst_true':
for i in range(1, self.nt):
self.f_eval_single(op_in=['u', self.cr_dict(iteration=0, level=0, time_point=i, colloc_node='first')],
op_out=['f', self.cr_dict(iteration=0, level=0, time_point=i, colloc_node='first')],
level=0,
i=i)
for level in range(0, self.L - 1):
for i in range(1, self.nt):
self.restrict_single(
op_in=['u', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='first')],
op_out=['u', self.cr_dict(iteration=0, level=level + 1, time_point=i, colloc_node='first')],
level=level,
i=i)
self.restrict_all(
op_in=['u', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_out=['u', self.cr_dict(iteration=0, level=level + 1, time_point=i, colloc_node='all')],
level=level,
i=i)
self.f_eval_all(
op_in=['u', self.cr_dict(iteration=0, level=level + 1, time_point=i, colloc_node='all')],
op_out=['f', self.cr_dict(iteration=0, level=level + 1, time_point=i, colloc_node='all')],
level=level,
i=i,
cost=self.cost_f_eval_all[level + 1])
self.fas(op_in_1=['f', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_in_2=['f', self.cr_dict(iteration=0, level=level + 1, time_point=i, colloc_node='all')],
op_in_3=None if level == 0 else ['tau',
self.cr_dict(iteration=0, level=level, time_point=i,
colloc_node='all')],
op_out=['tau',
self.cr_dict(iteration=0, level=level + 1, time_point=i, colloc_node='all')],
level=level,
i=i)
level = self.L - 1
# burnin
for j in range(2, self.nt):
for i in range(self.nt - 1, j - 1, -1):
self.copy_and_f_eval_single(
op_in=['u', self.cr_dict(iteration=0, level=self.L - 1, time_point=i, colloc_node='last')],
op_out_1=['u', self.cr_dict(iteration=0, level=self.L - 1, time_point=i, colloc_node='first')],
op_out_2=['f', self.cr_dict(iteration=0, level=self.L - 1, time_point=i, colloc_node='first')],
level=self.L - 1,
i=i)
self.sdc_sweep(
op_in_1=['u', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_in_2=['f', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_in_3=['tau', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_out_1=['u', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_out_2=['f', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
level=level,
i=i)
# sweep
for i in range(1, self.nt):
self.copy_and_f_eval_single(
op_in=['u', self.cr_dict(iteration=0, level=self.L - 1, time_point=i, colloc_node='last')],
op_out_1=['u', self.cr_dict(iteration=0, level=self.L - 1, time_point=i, colloc_node='first')],
op_out_2=['f', self.cr_dict(iteration=0, level=self.L - 1, time_point=i, colloc_node='first')],
level=self.L - 1,
i=i)
self.sdc_sweep(op_in_1=['u', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_in_2=['f', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_in_3=['tau', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_out_1=['u', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_out_2=['f', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
level=level,
i=i)
for level in range(self.L - 2, -1, -1):
for i in range(1, self.nt):
self.interpolate_and_correct_all(
op_in_1=['u', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_in_2=['u', self.cr_dict(iteration=0, level=level + 1, time_point=i, colloc_node='all')],
op_in_3=['u', self.cr_dict(iteration=0, level=level + 1, time_point=i, colloc_node='all')],
op_out=['v', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
level=level,
i=i)
self.f_eval_all(
op_in=['v', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_out=['f', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
level=level,
i=i,
cost=self.cost_f_eval_all[level])
if i > 1:
self.copy_and_error_correction(
op_in_1=['u', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='last')],
op_in_2=['u',
self.cr_dict(iteration=0, level=level + 1, time_point=i, colloc_node='first')],
op_out_1=['v', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='first')],
op_out_2=['f', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='first')],
level=level,
i=i)
self.sdc_sweep(
op_in_1=['v', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_in_2=['f', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_in_3=None if level == 0 else ['tau', self.cr_dict(iteration=0, level=level, time_point=i,
colloc_node='all')],
op_out_1=['u', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
op_out_2=['f', self.cr_dict(iteration=0, level=level, time_point=i, colloc_node='all')],
level=level,
i=i)