Coverage for pySDC/projects/parallelSDC_reloaded/scripts/fig02_stab.py: 100%

40 statements  

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

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3""" 

4Created on Wed Jan 10 12:02:55 2024 

5 

6Stability plots (on Dahlquist) for the article 

7""" 

8import os 

9import numpy as np 

10 

11from pySDC.projects.parallelSDC_reloaded.utils import getParamsSDC, solutionSDC, plotStabContour, plt 

12from pySDC.helpers.testing import DataChecker 

13 

14data = DataChecker(__file__) 

15 

16PATH = '/' + os.path.join(*__file__.split('/')[:-1]) 

17SCRIPT = __file__.split('/')[-1].split('.')[0] 

18 

19# Script parameters 

20zoom = 2 

21reLims = -4.5 * zoom, 0.5 * zoom 

22imLims = -3.5 * zoom, 3.5 * zoom 

23nVals = 251 

24 

25# Collocation parameters 

26nNodes = 4 

27nodeType = "LEGENDRE" 

28quadType = "RADAU-RIGHT" 

29 

30# Configuration 

31# (qDeltaType) 

32config = [ 

33 "PIC", 

34 "MIN-SR-NS", 

35 "MIN-SR-S", 

36 "MIN-SR-FLEX", 

37 "LU", 

38 "VDHS", 

39] 

40 

41 

42# ----------------------------------------------------------------------------- 

43# Script execution 

44# ----------------------------------------------------------------------------- 

45 

46# Problem instanciation 

47reVals = np.linspace(*reLims, num=nVals) 

48imVals = np.linspace(*imLims, num=nVals) 

49lambdas = reVals[None, :] + 1j * imVals[:, None] 

50 

51# Scheme instanciation 

52for qDeltaType in config: 

53 if qDeltaType == "MIN-SR-S": 

54 fac = 5 

55 reVals *= fac 

56 imVals *= fac 

57 lambdas *= fac 

58 

59 for nSweeps in [1, 2, 3, 4]: 

60 params = getParamsSDC(quadType, nNodes, qDeltaType, nSweeps, nodeType) 

61 

62 uNum, counters, parallel = solutionSDC(1, 1, params, 'DAHLQUIST', lambdas=lambdas.ravel()) 

63 

64 uEnd = uNum[-1, :].reshape(lambdas.shape) 

65 stab = np.abs(uEnd) 

66 

67 figName = f"{qDeltaType}_K{nSweeps}" 

68 plt.figure(figName) 

69 

70 plotStabContour(reVals, imVals, stab) 

71 data.storeAndCheck(f"{SCRIPT}_{figName}", stab[::5, -50]) 

72 

73 plt.xticks(fontsize=8) 

74 plt.yticks(fontsize=8) 

75 plt.title(f"$K={nSweeps}$", fontsize=10) 

76 plt.gcf().set_size_inches(2.5, 2.5) 

77 plt.tight_layout() 

78 plt.savefig(f"{PATH}/{SCRIPT}_{figName}.pdf") 

79 

80data.writeToJSON()