Coverage for pySDC / projects / parallelSDC_reloaded / jacobiElliptic_accuracy.py: 100%

52 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-27 07:06 +0000

1#!/usr/bin/env python3 

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

3""" 

4Created on Tue Dec 5 11:02:39 2023 

5 

6Script to investigate diagonal SDC on the JacobianElliptic problem 

7 

8- error VS time-step 

9- error VS computation cost 

10 

11Note : implementation in progress ... 

12""" 

13 

14import numpy as np 

15import matplotlib.pyplot as plt 

16 

17from pySDC.projects.parallelSDC_reloaded.utils import getParamsSDC, getParamsRK, solutionSDC, solutionExact 

18 

19# Problem parameters 

20tEnd = 10 

21pName = "JACELL" 

22 

23 

24def getError(uNum, uRef): 

25 if uNum is None: # pragma: no cover 

26 return np.inf 

27 return np.linalg.norm(uRef[-1] - uNum[-1], np.inf) 

28 

29 

30def getCost(counters): 

31 nNewton, nRHS, tComp = counters 

32 return nNewton + nRHS 

33 

34 

35# Base variable parameters 

36nNodes = 4 

37quadType = 'RADAU-RIGHT' 

38nodeType = 'LEGENDRE' 

39parEfficiency = 1 / nNodes 

40 

41qDeltaList = [ 

42 'RK4', 

43 'ESDIRK53', 

44 'ESDIRK43', 

45 'PIC', 

46 # 'IE', 'LU', 'IEpar', 'PIC', 

47 'MIN-SR-NS', 

48 'MIN-SR-S', 

49 'MIN-SR-FLEX', 

50 # "MIN3", 

51] 

52nStepsList = np.array([10, 20, 50, 100, 200]) 

53# nSweepList = [1, 2, 3, 4] 

54 

55# qDeltaList = ['RK4', 'ESDIRK43', 'MIN-SR-S'] 

56nSweepList = [4] 

57 

58 

59symList = ['o', '^', 's', '>', '*', '<', 'p', '>'] * 10 

60fig, axs = plt.subplots(1, 2) 

61 

62dtVals = tEnd / nStepsList 

63 

64i = 0 

65for qDelta in qDeltaList: 

66 for nSweeps in nSweepList: 

67 sym = symList[i] 

68 i += 1 

69 

70 name = f"{qDelta}({nSweeps})" 

71 try: 

72 params = getParamsRK(qDelta) 

73 name = name[:-3] 

74 if nSweeps != nSweepList[0]: # pragma: no cover 

75 continue 

76 except KeyError: 

77 params = getParamsSDC( 

78 quadType=quadType, numNodes=nNodes, nodeType=nodeType, qDeltaI=qDelta, nSweeps=nSweeps 

79 ) 

80 print(f'computing for {name} ...') 

81 

82 errors = [] 

83 costs = [] 

84 

85 for nSteps in nStepsList: 

86 print(f' -- nSteps={nSteps} ...') 

87 

88 uRef = solutionExact(tEnd, nSteps, pName) 

89 

90 uSDC, counters, parallel = solutionSDC(tEnd, nSteps, params, pName) 

91 

92 err = getError(uSDC, uRef) 

93 errors.append(err) 

94 

95 cost = getCost(counters) 

96 if parallel: 

97 cost /= nNodes * parEfficiency 

98 costs.append(cost) 

99 

100 # error VS dt 

101 axs[0].loglog(dtVals, errors, sym + '-', label=name) 

102 # error VS cost 

103 axs[1].loglog(costs, errors, sym + '-', label=name) 

104 

105for i in range(2): 

106 axs[i].set( 

107 xlabel=r"$\Delta{t}$" if i == 0 else "cost", 

108 ylabel=r"$L_\infty$ error", 

109 # ylim=(1e-9, 1e0), 

110 ) 

111 axs[i].legend(loc="lower right" if i == 0 else "lower left") 

112 axs[i].grid() 

113 

114fig.set_size_inches(12, 5) 

115fig.tight_layout()