Coverage for pySDC/projects/parallelSDC/minimization.py: 0%

48 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-16 14:51 +0000

1import matplotlib 

2import matplotlib.pylab as plt 

3import numpy as np 

4import scipy.optimize as opt 

5 

6from pySDC.core.collocation import CollBase 

7 

8 

9def main(): 

10 def rho(x): 

11 return max(abs(np.linalg.eigvals(np.eye(M) - np.diag([x[i] for i in range(M)]).dot(coll.Qmat[1:, 1:])))) 

12 

13 M = 2 

14 

15 coll = CollBase(M, 0, 1, quad_type='RADAU-RIGHT') 

16 

17 x0 = np.ones(M) 

18 d = opt.minimize(rho, x0, method='Nelder-Mead') 

19 print(d) 

20 

21 numsteps = 800 

22 xdim = np.linspace(0, 8, numsteps) 

23 ydim = np.linspace(0, 13, numsteps) 

24 

25 minfield = np.zeros((len(xdim), len(ydim))) 

26 

27 for idx, x in enumerate(xdim): 

28 for idy, y in enumerate(ydim): 

29 minfield[idx, idy] = max(abs(np.linalg.eigvals(np.eye(M) - np.diag([x, y]).dot(coll.Qmat[1:, 1:])))) 

30 

31 # Set up plotting parameters 

32 params = { 

33 'legend.fontsize': 20, 

34 'figure.figsize': (12, 8), 

35 'axes.labelsize': 20, 

36 'axes.titlesize': 20, 

37 'xtick.labelsize': 16, 

38 'ytick.labelsize': 16, 

39 'lines.linewidth': 3, 

40 } 

41 plt.rcParams.update(params) 

42 matplotlib.style.use('classic') 

43 

44 plt.figure() 

45 plt.pcolor(xdim, ydim, minfield.T, cmap='Reds', vmin=0, vmax=1) 

46 plt.text(d.x[0], d.x[1], 'X', horizontalalignment='center', verticalalignment='center') 

47 plt.xlim((min(xdim), max(xdim))) 

48 plt.ylim((min(ydim), max(ydim))) 

49 plt.xlabel('component 1') 

50 plt.ylabel('component 2') 

51 cbar = plt.colorbar() 

52 cbar.set_label('spectral radius') 

53 

54 fname = 'data/parallelSDC_minimizer_full.png' 

55 plt.savefig(fname, bbox_inches='tight') 

56 

57 plt.figure() 

58 xdim_part = xdim[int(0.25 * numsteps) : int(0.75 * numsteps) + 1] 

59 ydim_part = ydim[0 : int(0.25 * numsteps)] 

60 minfield_part = minfield[int(0.25 * numsteps) : int(0.75 * numsteps) + 1, 0 : int(0.25 * numsteps)] 

61 plt.pcolor(xdim_part, ydim_part, minfield_part.T, cmap='Reds', vmin=0, vmax=1) 

62 plt.text(d.x[0], d.x[1], 'X', horizontalalignment='center', verticalalignment='center') 

63 plt.xlim((min(xdim_part), max(xdim_part))) 

64 plt.ylim((min(ydim_part), max(ydim_part))) 

65 plt.xlabel('component 1') 

66 plt.ylabel('component 2') 

67 cbar = plt.colorbar() 

68 cbar.set_label('spectral radius') 

69 

70 fname = 'data/parallelSDC_minimizer_zoom.png' 

71 plt.savefig(fname, bbox_inches='tight') 

72 

73 

74if __name__ == "__main__": 

75 main()