Skip to content

Commit 9564bbb

Browse files
author
Daniel Ruprecht
committed
adds a function to parareal to return the maximum singular value of the error propagatin matrix
1 parent b750af2 commit 9564bbb

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

scripts/plot_dispersion.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def normalise(R, T, target):
5252

5353
phase = np.zeros((6,Nsamples))
5454
amp_factor = np.zeros((6,Nsamples))
55+
svds = np.zeros((3,Nsamples))
5556
u0_val = np.array([[1.0]], dtype='complex')
5657
targets = np.zeros((3,Nsamples))
5758

@@ -89,13 +90,13 @@ def normalise(R, T, target):
8990
amp_factor[2,i] = np.exp(sol_coarse.imag)
9091

9192
# Compute Parareal phase velocity and amplification factor
92-
93+
svds[0,i] = para.get_max_svd(ucoarse=ucoarse)
9394
for jj in range(0,3):
9495
stab_para = para.get_parareal_stab_function(k=niter_v[jj], ucoarse=ucoarse)
9596

9697
if i==0:
9798
targets[jj,0] = np.angle(stab_ex)
98-
99+
99100
stab_para_norm = normalise(stab_para[0,0], Tend, targets[jj,i])
100101
# Make sure that stab_norm*dt = stab
101102
err = abs(stab_para_norm**Tend - stab_para)
@@ -112,7 +113,6 @@ def normalise(R, T, target):
112113
phase[3+jj,i] = sol_para.real/k_vec[i]
113114
amp_factor[3+jj,i] = np.exp(sol_para.imag)
114115

115-
116116
###
117117
rcParams['figure.figsize'] = 2.5, 2.5
118118
fs = 8
@@ -155,3 +155,17 @@ def normalise(R, T, target):
155155
plt.gcf().savefig(filename, bbox_inches='tight')
156156
call(["pdfcrop", filename, filename])
157157

158+
fig = plt.figure()
159+
plt.plot(k_vec, svds[0,:], '-s', color='r', linewidth=1.5, markevery=(1,6), mew=1.0, markersize=fs/2)
160+
plt.xlabel('Wave number', fontsize=fs, labelpad=0.25)
161+
plt.ylabel('Maximal singular value', fontsize=fs, labelpad=0.5)
162+
fig.gca().tick_params(axis='both', labelsize=fs)
163+
plt.xlim([k_vec[0], k_vec[-1:]])
164+
plt.ylim([0, 2.0])
165+
# plt.legend(loc='lower left', fontsize=fs, prop={'size':fs-2})
166+
plt.gca().set_ylim([0.0, 2.0])
167+
plt.xticks([0, 1, 2, 3], fontsize=fs)
168+
#plt.show()
169+
filename = 'parareal-dispersion-svd.pdf'
170+
plt.gcf().savefig(filename, bbox_inches='tight')
171+
call(["pdfcrop", filename, filename])

src/parareal.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ def get_parareal_stab_function(self, k, ucoarse=None):
9696
Mat[:,i] = R.dot(M).flatten()
9797
return Mat
9898

99+
# Returns the largest singular value of the error propagation matrix
100+
def get_max_svd(self, ucoarse=None):
101+
Pmat, Bmat = self.get_parareal_matrix(ucoarse)
102+
svds = linalg.svds(Pmat, k=1, return_singular_vectors=False)
103+
return svds[0]
104+
99105
# Returns array containing all intermediate solutions
100106
def get_parareal_vector(self):
101107
b = np.zeros((self.u0.ndof*(self.timemesh.nslices+1),1))

0 commit comments

Comments
 (0)