Coverage for pySDC/projects/parallelSDC_reloaded/scripts/fig04_protheroRobinson.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 Thu Jan 11 10:21:47 2024
6Figures with experiment on the Prothero-Robinson problem
7"""
8import os
9import numpy as np
11from pySDC.projects.parallelSDC_reloaded.utils import solutionExact, getParamsSDC, solutionSDC, getParamsRK, plt
12from pySDC.helpers.testing import DataChecker
14data = DataChecker(__file__)
16PATH = '/' + os.path.join(*__file__.split('/')[:-1])
17SCRIPT = __file__.split('/')[-1].split('.')[0]
19symList = ['o', '^', 's', '>', '*', '<', 'p', '>'] * 10
21# SDC parameters
22nNodes = 4
23quadType = 'RADAU-RIGHT'
24nodeType = 'LEGENDRE'
25parEfficiency = 0.8 # 1/nNodes
27epsilon = 1e-3
29# -----------------------------------------------------------------------------
30# %% Convergence and error VS cost plots
31# -----------------------------------------------------------------------------
32tEnd = 2 * np.pi
33nStepsList = np.array([2, 5, 10, 20, 50, 100, 200, 500, 1000])
34dtVals = tEnd / nStepsList
37def getError(uNum, uRef):
38 if uNum is None:
39 return np.inf
40 return np.linalg.norm(np.linalg.norm(uRef - uNum, np.inf, axis=-1), np.inf)
43def getCost(counters):
44 nNewton, nRHS, tComp = counters
45 return nNewton + nRHS
48minPrec = ["MIN-SR-NS", "MIN-SR-S", "MIN-SR-FLEX"]
50symList = ['^', '>', '<', 'o', 's', '*', 'p']
51config = [
52 [(*minPrec, "VDHS", "ESDIRK43", "LU"), 4],
53 [(*minPrec, "VDHS", "ESDIRK43", "LU"), 6],
54]
57i = 0
58for qDeltaList, nSweeps in config:
59 figNameConv = f"{SCRIPT}_conv_{i}"
60 figNameCost = f"{SCRIPT}_cost_{i}"
61 i += 1
63 for qDelta, sym in zip(qDeltaList, symList):
64 try:
65 params = getParamsRK(qDelta)
66 except KeyError:
67 params = getParamsSDC(
68 quadType=quadType, numNodes=nNodes, nodeType=nodeType, qDeltaI=qDelta, nSweeps=nSweeps
69 )
71 errors = []
72 costs = []
74 for nSteps in nStepsList:
75 uRef = solutionExact(tEnd, nSteps, "PROTHERO-ROBINSON", epsilon=epsilon)
77 uSDC, counters, parallel = solutionSDC(tEnd, nSteps, params, "PROTHERO-ROBINSON", epsilon=epsilon)
79 err = getError(uSDC, uRef)
80 errors.append(err)
82 cost = getCost(counters)
83 if parallel:
84 cost /= nNodes * parEfficiency
85 costs.append(cost)
87 ls = '-' if qDelta.startswith("MIN-SR-") else "--"
89 plt.figure(figNameConv)
90 plt.loglog(dtVals, errors, sym + ls, label=qDelta)
91 data.storeAndCheck(f"{figNameConv}_{qDelta}", errors)
93 plt.figure(figNameCost)
94 plt.loglog(costs, errors, sym + ls, label=qDelta)
96 for figName in [figNameConv, figNameCost]:
97 plt.figure(figName)
98 plt.gca().set(
99 xlabel="Cost" if "cost" in figName else r"$\Delta {t}$",
100 ylabel=r"$L_\infty$ error",
101 )
102 plt.legend()
103 plt.grid(True)
104 plt.tight_layout()
105 plt.savefig(f"{PATH}/{figName}.pdf")
107data.writeToJSON()