Coverage for pySDC/projects/parallelSDC_reloaded/protheroRobinson_setup.py: 100%
30 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 Thu Dec 7 13:12:40 2023
6Setup script for the ProtheroRobinson (linear and non-linear) problem
7"""
8import numpy as np
9import matplotlib.pyplot as plt
11from pySDC.projects.parallelSDC_reloaded.utils import solutionExact, getParamsRK, solutionSDC
13script = __file__.split('/')[-1].split('.')[0]
15tEnd = 2 * np.pi
16nSteps = 2
17epsilon = np.inf
18rkScheme = "ESDIRK43"
20tVals = np.linspace(0, tEnd, nSteps + 1)
21tValsFine = np.linspace(0, tEnd, nSteps * 10 + 1)
23for pType in ["linear", "nonlinear"]:
24 probName = "PROTHERO-ROBINSON"
25 if pType == "nonlinear":
26 probName += "-NL"
28 print(f"Computing {pType} ODE solution")
29 uExact = solutionExact(tEnd, nSteps, "PROTHERO-ROBINSON", epsilon=epsilon)
31 params = getParamsRK(rkScheme)
32 uNum, counters, parallel = solutionSDC(tEnd, nSteps, params, probName, epsilon=epsilon)
33 uNumFine, counters, parallel = solutionSDC(tEnd, nSteps * 10, params, probName, epsilon=epsilon)
35 figName = f"{script}_{pType}"
36 plt.figure(figName)
37 plt.plot(tVals, uExact[:, 0], '-', label="Exact")
38 plt.plot(tVals, uNum[:, 0], '--', label="Numerical")
39 plt.plot(tValsFine, uNumFine[:, 0], '-.', label="Numerical (fine)")
42for figName in [f"{script}_linear", f"{script}_nonlinear"]:
43 plt.figure(figName)
44 plt.legend()
45 plt.xlabel("time")
46 plt.ylabel("solution")
47 plt.tight_layout()