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

58 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-13 09:00 +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 Allen-Cahn 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 = 50 

21pName = "ALLEN-CAHN" 

22periodic = False 

23pParams = { 

24 "periodic": periodic, 

25 "nvars": 2**11 - (not periodic), 

26 "epsilon": 0.04, 

27} 

28 

29 

30def getError(uNum, uRef): 

31 if uNum is None: 

32 return np.inf 

33 return np.linalg.norm(uRef[-1, :] - uNum[-1, :], ord=2) 

34 

35 

36def getCost(counters): 

37 nNewton, nRHS, tComp = counters 

38 return 2 * nNewton + nRHS 

39 

40 

41# Base variable parameters 

42nNodes = 4 

43quadType = 'RADAU-RIGHT' 

44nodeType = 'LEGENDRE' 

45parEfficiency = 1 / nNodes 

46 

47qDeltaList = [ 

48 'RK4', 

49 'ESDIRK53', 

50 'VDHS', 

51 'MIN', 

52 # 'IE', 'LU', 'IEpar', 'PIC', 

53 'MIN-SR-NS', 

54 'MIN-SR-S', 

55 'MIN-SR-FLEX', 

56 "PIC", 

57 # "MIN3", 

58] 

59nStepsList = np.array([1, 2, 5, 10, 20, 50, 100, 200]) 

60nSweepList = [1, 2, 3, 4, 5, 6] 

61 

62qDeltaList = ['ESDIRK43', 'MIN-SR-FLEX'] 

63nSweepList = [4] 

64 

65 

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

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

68 

69dtVals = tEnd / nStepsList 

70 

71i = 0 

72for qDelta in qDeltaList: 

73 for nSweeps in nSweepList: 

74 sym = symList[i] 

75 i += 1 

76 

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

78 try: 

79 params = getParamsRK(qDelta) 

80 name = name[:-3] 

81 except KeyError: 

82 params = getParamsSDC( 

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

84 ) 

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

86 

87 errors = [] 

88 costs = [] 

89 

90 for nSteps in nStepsList: 

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

92 

93 uRef = solutionExact(tEnd, nSteps, pName, **pParams) 

94 

95 uSDC, counters, parallel = solutionSDC(tEnd, nSteps, params, pName, **pParams) 

96 

97 err = getError(uSDC, uRef) 

98 errors.append(err) 

99 

100 cost = getCost(counters) 

101 if parallel: 

102 cost /= nNodes * parEfficiency 

103 costs.append(cost) 

104 

105 # error VS dt 

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

107 # error VS cost 

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

109 

110for i in range(2): 

111 axs[i].set( 

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

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

114 ylim=(1e-5, 1e1), 

115 ) 

116 axs[i].legend() 

117 axs[i].grid() 

118 

119fig.set_size_inches(12, 5) 

120fig.tight_layout()