@@ -66,34 +66,30 @@ def get_parareal_matrix(self, ucoarse=None):
6666 Bmat = sparse .linalg .inv (Gmat )
6767 # this is call is necessary because if Bmat has only 1 entry, it gets converted to a dense array here
6868 Bmat = sparse .csc_matrix (Bmat )
69- Pmat = Bmat .dot (Gmat - Fmat )
70- return Pmat , Bmat
69+ Emat = Bmat .dot (Gmat - Fmat )
70+ return Emat , Bmat
7171
7272 # Returns the stability matrix for Parareal with fixed number of iterations
7373 def get_parareal_stab_function (self , k , ucoarse = None ):
74- e0 = np .zeros ((self .timemesh .nslices + 1 ,1 ))
75- e0 [0 ,:] = 1.0
76- Mat = np .zeros ((self .u0 .ndof ,self .u0 .ndof ), dtype = 'complex' )
77- Pmat , Bmat = self .get_parareal_matrix (ucoarse )
78- Id = sparse .eye (self .u0 .ndof * (self .timemesh .nslices + 1 ), format = "csc" )
74+ e0 = np .zeros ((self .timemesh .nslices + 1 ,1 ))
75+ e0 [0 ,:] = 1.0
76+ # Mat = np.zeros((self.u0.ndof,self.u0.ndof), dtype='complex')
77+ Emat , Bmat = self .get_parareal_matrix (ucoarse )
78+ Id = sparse .eye (self .u0 .ndof * (self .timemesh .nslices + 1 ), format = "csc" )
7979
80- # Selection matrix
80+ # Selection matrices
8181 Zeros = np .zeros ((self .u0 .ndof ,self .u0 .ndof * self .timemesh .nslices ))
8282 Idd = sparse .eye (self .u0 .ndof , format = "csc" )
83- R = sparse .hstack ((Zeros ,Idd ), format = "csc" )
84-
85- # Construct stability matrix from unit vectors
86- for i in range (0 ,self .u0 .ndof ):
87- y0 = np .zeros ((self .u0 .ndof ,1 ))
88- y0 [i ,0 ] = 1.0
89- ee0 = np .kron (e0 , y0 )
90- M = copy .deepcopy (Id )
91- # Compute (sum(j=1,..n) Pmat^j) *Bmat
92- for j in range (1 ,k + 1 ):
93- M += Pmat ** j
94- M = M .dot (Bmat )
95- M = M .dot (ee0 )
96- Mat [:,i ] = R .dot (M ).flatten ()
83+ C1 = sparse .hstack ((Zeros ,Idd ), format = "csc" )
84+ Zeros = np .zeros ((self .u0 .ndof * self .timemesh .nslices , self .u0 .ndof ))
85+ C2 = sparse .vstack ((Idd , Zeros ), format = "csc" )
86+
87+ E_power_k = copy .deepcopy (Id )
88+ # Compute (sum(j=1,..n) Pmat^j) *Bmat
89+ for j in range (1 ,k + 1 ):
90+ E_power_k += Emat ** j
91+
92+ Mat = C1 .dot (E_power_k .dot (Bmat .dot (C2 )))
9793 return Mat
9894
9995 # Returns the largest singular value of the error propagation matrix
0 commit comments