Skip to content

Commit fa29b61

Browse files
committed
changed Q-transfer to work without u0
1 parent d0dda36 commit fa29b61

File tree

4 files changed

+43
-58
lines changed

4 files changed

+43
-58
lines changed

pySDC/core/BaseTransfer.py

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
from pySDC.helpers.pysdc_helper import FrozenClass
5+
from scipy import interpolate
56
import pySDC.helpers.transfer_helper as th
67
from pySDC.core.Errors import UnlockError
78

@@ -49,33 +50,11 @@ def __init__(self, pars):
4950
self.fine = fine_level
5051
self.coarse = coarse_level
5152

52-
# for Q-based transfer, check if we need to add 0 to the list of nodes
53-
if not self.fine.sweep.coll.left_is_node:
54-
fine_grid = np.concatenate(([0], self.fine.sweep.coll.nodes))
55-
coarse_grid = np.concatenate(([0], self.coarse.sweep.coll.nodes))
56-
else:
57-
fine_grid = self.fine.sweep.coll.nodes
58-
coarse_grid = self.coarse.sweep.coll.nodes
59-
60-
if self.params.coll_iorder > len(coarse_grid):
61-
self.logger.warning('requested order of Q-interpolation is not valid, resetting to %s' % len(coarse_grid))
62-
self.params.coll_iorder = len(coarse_grid)
63-
if self.params.coll_rorder != 1:
64-
self.logger.warning('requested order of Q-restriction is != 1, can lead to weird behavior!')
65-
66-
# set up preliminary transfer matrices for Q-based coarsening
67-
Pcoll = th.interpolation_matrix_1d(fine_grid, coarse_grid, k=self.params.coll_iorder, pad=0).toarray()
68-
Rcoll = th.restriction_matrix_1d(fine_grid, coarse_grid, k=self.params.coll_rorder, pad=0).toarray()
69-
70-
# pad transfer matrices if necessary
71-
if self.fine.sweep.coll.left_is_node:
72-
self.Pcoll = np.zeros((self.fine.sweep.coll.num_nodes + 1, self.coarse.sweep.coll.num_nodes + 1))
73-
self.Rcoll = np.zeros((self.coarse.sweep.coll.num_nodes + 1, self.fine.sweep.coll.num_nodes + 1))
74-
self.Pcoll[1:, 1:] = Pcoll
75-
self.Rcoll[1:, 1:] = Rcoll
76-
else:
77-
self.Pcoll = Pcoll
78-
self.Rcoll = Rcoll
53+
fine_grid = self.fine.sweep.coll.nodes
54+
coarse_grid = self.coarse.sweep.coll.nodes
55+
56+
self.Pcoll = th.interpolation_matrix_1d(fine_grid, coarse_grid, k=self.params.coll_iorder, pad=0).toarray()
57+
self.Rcoll = th.restriction_matrix_1d(fine_grid, coarse_grid, k=self.params.coll_rorder, pad=0).toarray()
7958

8059
# set up spatial transfer
8160
self.space_transfer = space_transfer_class(fine_prob=self.fine.prob, coarse_prob=self.coarse.prob,
@@ -105,16 +84,16 @@ def restrict(self):
10584
raise UnlockError('fine level is still locked, cannot use data from there')
10685

10786
# restrict fine values in space
108-
tmp_u = [self.space_transfer.restrict(F.u[0])]
87+
tmp_u = []
10988
for m in range(1, SF.coll.num_nodes + 1):
11089
tmp_u.append(self.space_transfer.restrict(F.u[m]))
11190

11291
# restrict collocation values
113-
G.u[0] = tmp_u[0]
92+
G.u[0] = self.space_transfer.restrict(F.u[0])
11493
for n in range(1, SG.coll.num_nodes + 1):
115-
G.u[n] = self.Rcoll[n, 0] * tmp_u[0]
116-
for m in range(1, SF.coll.num_nodes + 1):
117-
G.u[n] += self.Rcoll[n, m] * tmp_u[m]
94+
G.u[n] = self.Rcoll[n - 1, 0] * tmp_u[0]
95+
for m in range(1, SF.coll.num_nodes):
96+
G.u[n] += self.Rcoll[n - 1, m] * tmp_u[m]
11897

11998
# re-evaluate f on coarse level
12099
G.f[0] = PG.eval_f(G.u[0], G.time)
@@ -129,15 +108,15 @@ def restrict(self):
129108

130109
# restrict fine level tau correction part in space
131110
tmp_tau = []
132-
for m in range(0, SF.coll.num_nodes):
111+
for m in range(SF.coll.num_nodes):
133112
tmp_tau.append(self.space_transfer.restrict(tauF[m]))
134113

135114
# restrict fine level tau correction part in collocation
136115
tauFG = []
137116
for n in range(1, SG.coll.num_nodes + 1):
138-
tauFG.append(self.Rcoll[n, 1] * tmp_tau[0])
117+
tauFG.append(self.Rcoll[n - 1, 0] * tmp_tau[0])
139118
for m in range(1, SF.coll.num_nodes):
140-
tauFG[-1] += self.Rcoll[n, m + 1] * tmp_tau[m]
119+
tauFG[-1] += self.Rcoll[n - 1, m] * tmp_tau[m]
141120

142121
# build tau correction
143122
for m in range(SG.coll.num_nodes):
@@ -146,14 +125,13 @@ def restrict(self):
146125
if F.tau is not None:
147126
# restrict possible tau correction from fine in space
148127
tmp_tau = []
149-
for m in range(0, SF.coll.num_nodes):
128+
for m in range(SF.coll.num_nodes):
150129
tmp_tau.append(self.space_transfer.restrict(F.tau[m]))
151130

152131
# restrict possible tau correction from fine in collocation
153-
for n in range(1, SG.coll.num_nodes + 1):
154-
G.tau[n - 1] += self.Rcoll[n, 1] * tmp_tau[0]
155-
for m in range(1, SF.coll.num_nodes):
156-
G.tau[n - 1] += self.Rcoll[n, m + 1] * tmp_tau[m]
132+
for n in range(SG.coll.num_nodes):
133+
for m in range(SF.coll.num_nodes):
134+
G.tau[n] += self.Rcoll[n, m] * tmp_tau[m]
157135
else:
158136
pass
159137

@@ -203,8 +181,8 @@ def prolong(self):
203181
# interpolate values in collocation
204182
F.u[0] += tmp_u[0]
205183
for n in range(1, SF.coll.num_nodes + 1):
206-
for m in range(0, SG.coll.num_nodes + 1):
207-
F.u[n] += self.Pcoll[n, m] * tmp_u[m]
184+
for m in range(1, SG.coll.num_nodes + 1):
185+
F.u[n] += self.Pcoll[n - 1, m - 1] * tmp_u[m]
208186

209187
# re-evaluate f on fine level
210188
F.f[0] = PF.eval_f(F.u[0], F.time)
@@ -250,8 +228,8 @@ def prolong_f(self):
250228
F.u[0] += tmp_u[0]
251229
F.f[0] += tmp_f[0]
252230
for n in range(1, SF.coll.num_nodes + 1):
253-
for m in range(0, SG.coll.num_nodes + 1):
254-
F.u[n] += self.Pcoll[n, m] * tmp_u[m]
255-
F.f[n] += self.Pcoll[n, m] * tmp_f[m]
231+
for m in range(1, SG.coll.num_nodes + 1):
232+
F.u[n] += self.Pcoll[n - 1, m - 1] * tmp_u[m]
233+
F.f[n] += self.Pcoll[n - 1, m - 1] * tmp_f[m]
256234

257235
return None

pySDC/implementations/controller_classes/allinclusive_multigrid_nonMPI.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,21 @@ def pfasst(self, MS):
455455
# prolong values
456456
S.transfer(source=S.levels[l], target=S.levels[l - 1])
457457

458+
# send updated values forward
459+
if self.params.fine_comm and not S.status.last:
460+
self.logger.debug('Process %2i provides data on level %2i with tag %s'
461+
% (S.status.slot, l - 1, S.status.iter))
462+
self.send(S.levels[l - 1], tag=(l - 1, S.status.iter, S.status.slot))
463+
464+
# # receive values
465+
if self.params.fine_comm and not S.status.first:
466+
self.logger.debug('Process %2i receives from %2i on level %2i with tag %s' %
467+
(S.status.slot, S.prev.status.slot, l - 1, S.status.iter))
468+
self.recv(S.levels[l - 1], S.prev.levels[l - 1], tag=(l - 1, S.status.iter,
469+
S.prev.status.slot))
470+
471+
S.levels[l - 1].sweep.compute_residual()
472+
458473
# on middle levels: do communication and sweep as usual
459474
if l - 1 > 0:
460475

pySDC/projects/matrixPFASST/compare_to_propagator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def compare_controllers(type=None, par=0.0, f=None):
268268

269269
def main():
270270

271-
f = open('comparison_matrix_vs_propagator_detail.txt', 'a')
271+
f = open('comparison_matrix_vs_propagator_detail.txt', 'w')
272272
# compare_controllers(type='diffusion', par=1E-00, f=f)
273273
# compare_controllers(type='advection', par=1E-00, f=f)
274274
compare_controllers(type='testequation', par=0.0, f=f)

pySDC/tests/test_Q_transfer.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ def check_Q_transfer(collclass):
3737

3838
assert coll_fine.left_is_node == coll_coarse.left_is_node, 'ERROR: should be using the same class for coarse and fine Q'
3939

40-
if not coll_fine.left_is_node:
41-
fine_grid = np.concatenate(([0], coll_fine.nodes))
42-
coarse_grid = np.concatenate(([0], coll_coarse.nodes))
43-
else:
44-
fine_grid = coll_fine.nodes
45-
coarse_grid = coll_coarse.nodes
40+
fine_grid = coll_fine.nodes
41+
coarse_grid = coll_coarse.nodes
4642

4743
for order in range(2,coll_coarse.num_nodes+1):
4844

@@ -88,12 +84,8 @@ def check_Q_transfer_minimal(collclass):
8884

8985
assert coll_fine.left_is_node == coll_coarse.left_is_node, 'ERROR: should be using the same class for coarse and fine Q'
9086

91-
if not coll_fine.left_is_node:
92-
fine_grid = np.concatenate(([0], coll_fine.nodes))
93-
coarse_grid = np.concatenate(([0], coll_coarse.nodes))
94-
else:
95-
fine_grid = coll_fine.nodes
96-
coarse_grid = coll_coarse.nodes
87+
fine_grid = coll_fine.nodes
88+
coarse_grid = coll_coarse.nodes
9789

9890
Pcoll = th.interpolation_matrix_1d(fine_grid, coarse_grid, k=2, pad=0)
9991
Rcoll = th.restriction_matrix_1d(fine_grid, coarse_grid, k=2, pad=0)

0 commit comments

Comments
 (0)