Coverage for pySDC / projects / parallelSDC_reloaded / protheroRobinson_accuracy.py: 100%
58 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-27 07:06 +0000
« 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
6Script to investigate diagonal SDC on the ProtheroRobinson
7(linear and non-linear) problem :
9- error VS time-step
10- error VS computation cost
12Note : implementation in progress ...
13"""
15import numpy as np
16import matplotlib.pyplot as plt
18from pySDC.projects.parallelSDC_reloaded.utils import getParamsSDC, getParamsRK, solutionSDC, solutionExact
20# Problem parameters
21tEnd = 2 * np.pi
22nonLinear = False
23epsilon = 1e-3
24collUpdate = False
25initSweep = "copy"
27pName = "PROTHERO-ROBINSON" + (nonLinear) * "-NL"
30def getError(uNum, uRef):
31 if uNum is None:
32 return np.inf
33 return np.linalg.norm(uRef[:, 0] - uNum[:, 0], np.inf)
36def getCost(counters):
37 nNewton, nRHS, tComp = counters
38 return nNewton + nRHS
41# Base variable parameters
42nNodes = 4
43quadType = 'RADAU-RIGHT'
44nodeType = 'LEGENDRE'
45parEfficiency = 0.8
47qDeltaList = [
48 'MIN-SR-NS',
49 'MIN-SR-S',
50 'MIN-SR-FLEX',
51 "ESDIRK43",
52 'LU',
53 'VDHS',
54 # 'IE', 'LU', 'IEpar', 'PIC',
55 # "MIN3",
56]
57nStepsList = np.array([2, 5, 10, 20, 50, 100, 200])
58# nSweepList = [1, 2, 3, 4]
60# qDeltaList = ['ESDIRK43', 'ESDIRK53', 'VDHS']
61nSweepList = [6]
64symList = ['o', '^', 's', '>', '*', '<', 'p', '>'] * 10
65fig, axs = plt.subplots(1, 2)
67dtVals = tEnd / nStepsList
69i = 0
70for qDelta in qDeltaList:
71 for nSweeps in nSweepList:
72 sym = symList[i]
73 i += 1
75 name = f"{qDelta}({nSweeps})"
76 try:
77 params = getParamsRK(qDelta)
78 name = name.split('(')[0]
79 if nSweeps != nSweepList[0]: # pragma: no cover
80 continue
82 except KeyError:
83 params = getParamsSDC(
84 quadType=quadType,
85 numNodes=nNodes,
86 nodeType=nodeType,
87 qDeltaI=qDelta,
88 nSweeps=nSweeps,
89 collUpdate=collUpdate,
90 initType=initSweep,
91 )
92 print(f'computing for {name} ...')
94 errors = []
95 costs = []
97 for nSteps in nStepsList:
98 print(f' -- nSteps={nSteps} ...')
100 uRef = solutionExact(tEnd, nSteps, pName, epsilon=epsilon)
102 uSDC, counters, parallel = solutionSDC(tEnd, nSteps, params, pName, epsilon=epsilon)
104 err = getError(uSDC, uRef)
105 errors.append(err)
107 cost = getCost(counters)
108 if parallel:
109 cost /= nNodes * parEfficiency
110 costs.append(cost)
112 # error VS dt
113 axs[0].loglog(dtVals, errors, sym + '-', label=name)
114 # error VS cost
115 axs[1].loglog(costs, errors, sym + '-', label=name)
117for i in range(2):
118 axs[i].set(
119 xlabel=r"$\Delta{t}$" if i == 0 else "cost",
120 ylabel=r"$L_\infty$ error",
121 ylim=(1e-12, 1e3),
122 )
123 axs[i].legend()
124 axs[i].grid()
126fig.set_size_inches(12, 5)
127fig.tight_layout()