Coverage for pySDC/projects/parallelSDC_reloaded/vanderpol_accuracy.py: 100%
61 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4Created on Sun Nov 12 22:14:03 2023
6Script to investigate diagonal SDC on Van der Pol with different mu parameters,
7in particular with graphs such as :
9- error VS time-step
10- error VS computation cost
12Note : implementation in progress ...
13"""
14import numpy as np
15import matplotlib.pyplot as plt
17from pySDC.projects.parallelSDC_reloaded.utils import getParamsSDC, getParamsRK, solutionSDC, solutionExact
19muVals = [0.1, 2, 10]
20tEndVals = [6.3, 7.6, 18.9] # tEnd = 1 period for each mu
23def getError(uNum, uRef):
24 if uNum is None:
25 return np.inf
26 return np.linalg.norm(uRef[:, 0] - uNum[:, 0], np.inf)
29def getCost(counters):
30 nNewton, nRHS, tComp = counters
31 return nNewton + nRHS
34# Base variable parameters
35nNodes = 4
36quadType = 'RADAU-RIGHT'
37nodeType = 'LEGENDRE'
38parEfficiency = 1 / nNodes
40qDeltaList = [
41 'RK4',
42 'ESDIRK43',
43 'LU',
44 # 'IE', 'LU', 'IEpar', 'PIC',
45 'MIN-SR-NS',
46 'MIN-SR-S',
47 'MIN-SR-FLEX',
48]
49nStepsList = np.array([2, 5, 10, 20, 50, 100, 200])
50nSweepList = [1, 2, 3, 4, 5, 6]
53symList = ['o', '^', 's', '>', '*', '<', 'p', '>'] * 10
55# qDeltaList = ['LU']
56nSweepList = [4]
58fig, axs = plt.subplots(2, len(muVals))
60for j, (mu, tEnd) in enumerate(zip(muVals, tEndVals)):
61 print("-" * 80)
62 print(f"mu={mu}")
63 print("-" * 80)
65 dtVals = tEnd / nStepsList
67 i = 0
68 for qDelta in qDeltaList:
69 for nSweeps in nSweepList:
70 sym = symList[i]
71 i += 1
73 name = f"{qDelta}({nSweeps})"
74 try:
75 params = getParamsRK(qDelta)
76 name = name[:-3]
77 except KeyError:
78 params = getParamsSDC(
79 quadType=quadType, numNodes=nNodes, nodeType=nodeType, qDeltaI=qDelta, nSweeps=nSweeps
80 )
81 print(f'computing for {name} ...')
83 errors = []
84 costs = []
86 for nSteps in nStepsList:
87 print(f' -- nSteps={nSteps} ...')
89 uRef = solutionExact(tEnd, nSteps, "VANDERPOL", mu=mu)
91 uSDC, counters, parallel = solutionSDC(tEnd, nSteps, params, "VANDERPOL", mu=mu)
93 err = getError(uSDC, uRef)
94 errors.append(err)
96 cost = getCost(counters)
97 if parallel:
98 cost /= nNodes * parEfficiency
99 costs.append(cost)
101 # error VS dt
102 axs[0, j].loglog(dtVals, errors, sym + '-', label=name)
103 # error VS cost
104 axs[1, j].loglog(costs, errors, sym + '-', label=name)
106 for i in range(2):
107 if i == 0:
108 axs[i, j].set_title(f"mu={mu}")
109 axs[i, j].set(
110 xlabel=r"$\Delta{t}$" if i == 0 else "cost",
111 ylabel=r"$L_\infty$ error",
112 ylim=(1e-11, 10),
113 )
114 axs[i, j].legend(loc="lower right" if i == 0 else "lower left")
115 axs[i, j].grid()
117fig.set_size_inches(18.2, 10.4)
118fig.tight_layout()