Coverage for pySDC/projects/parallelSDC_reloaded/lorenz_accuracy.py: 100%
57 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
« 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 Tue Dec 5 11:02:39 2023
6Script to investigate diagonal SDC on Lorenz system
8- error VS time-step
9- error VS computation cost
11Note : implementation in progress ...
12"""
13import numpy as np
14import matplotlib.pyplot as plt
16from pySDC.projects.parallelSDC_reloaded.utils import getParamsSDC, getParamsRK, solutionSDC, solutionExact
18tEnd = 1.24
21def getError(uNum, uRef):
22 if uNum is None: # pragma: no cover
23 return np.inf
24 return np.linalg.norm(np.linalg.norm(uRef - uNum, np.inf, axis=-1), np.inf)
27def getCost(counters):
28 nNewton, nRHS, tComp = counters
29 return nNewton + nRHS
32# Base variable parameters
33nNodes = 4
34quadType = 'RADAU-RIGHT'
35nodeType = 'LEGENDRE'
36parEfficiency = 0.8 # 1/nNodes
38qDeltaList = [
39 'RK4',
40 'ESDIRK53',
41 'VDHS',
42 'MIN',
43 # 'IE', 'LU', 'IEpar', 'PIC',
44 'MIN-SR-NS',
45 'MIN-SR-S',
46 'MIN-SR-FLEX',
47 "PIC",
48 # "MIN3",
49]
50nStepsList = np.array([2, 5, 10, 20, 50, 100, 200])
51nSweepList = [1, 2, 3, 4]
54symList = ['o', '^', 's', '>', '*', '<', 'p', '>'] * 10
56qDeltaList = ['MIN-SR-S', 'RK4']
57# nSweepList = [4]
59fig, axs = plt.subplots(1, 2)
62dtVals = tEnd / nStepsList
64i = 0
65for qDelta in qDeltaList:
66 for nSweeps in nSweepList:
67 sym = symList[i]
68 i += 1
70 name = f"{qDelta}({nSweeps})"
71 try:
72 params = getParamsRK(qDelta)
73 name = name[:-3]
74 if nSweeps != nSweepList[0]:
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} ...')
82 errors = []
83 costs = []
85 for nSteps in nStepsList:
86 print(f' -- nSteps={nSteps} ...')
88 uRef = solutionExact(tEnd, nSteps, "LORENZ", u0=(5, -5, 20))
90 uSDC, counters, parallel = solutionSDC(tEnd, nSteps, params, "LORENZ", u0=(5, -5, 20))
92 err = getError(uSDC, uRef)
93 errors.append(err)
95 cost = getCost(counters)
96 if parallel:
97 cost /= nNodes * parEfficiency
98 costs.append(cost)
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)
105x = dtVals[4:]
106for k in [1, 2, 3, 4, 5]:
107 axs[0].loglog(x, 1e4 * x**k, "--", color="gray", linewidth=0.8)
109for i in range(2):
110 axs[i].set(
111 xlabel=r"$\Delta{t}$" if i == 0 else "cost",
112 ylabel=r"$L_\infty$ error",
113 ylim=(8.530627786509715e-12, 372.2781393394293),
114 )
115 axs[i].legend(loc="lower right" if i == 0 else "lower left")
116 axs[i].grid()
118fig.set_size_inches(12, 5)
119fig.tight_layout()