22import logging
33
44from pySDC .helpers .pysdc_helper import FrozenClass
5+ from scipy import interpolate
56import pySDC .helpers .transfer_helper as th
67from 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
0 commit comments