Coverage for pySDC / projects / parallelSDC_reloaded / protheroRobinsonAutonomous_setup.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-03 10:35 +0000

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3""" 

4Created on Thu Dec 7 13:12:40 2023 

5 

6Setup script for the ProtheroRobinson (linear and non-linear) problem, 

7using the autonomous formulation 

8""" 

9 

10import numpy as np 

11import matplotlib.pyplot as plt 

12 

13from pySDC.projects.parallelSDC_reloaded.utils import solutionExact, getParamsRK, solutionSDC 

14 

15script = __file__.split('/')[-1].split('.')[0] 

16 

17tEnd = 2 * np.pi 

18nSteps = 2 

19epsilon = 1e-3 

20rkScheme = "ESDIRK43" 

21 

22tVals = np.linspace(0, tEnd, nSteps + 1) 

23tValsFine = np.linspace(0, tEnd, nSteps * 10 + 1) 

24 

25for pType in ["linear", "nonlinear"]: 

26 probName = "PROTHERO-ROBINSON-A" 

27 if pType == "nonlinear": 

28 probName += "-NL" 

29 

30 print(f"Computing {pType} ODE solution") 

31 uExact = solutionExact(tEnd, nSteps, probName, epsilon=epsilon) 

32 

33 params = getParamsRK(rkScheme) 

34 uNum, counters, parallel = solutionSDC(tEnd, nSteps, params, probName, epsilon=epsilon) 

35 uNumFine, counters, parallel = solutionSDC(tEnd, nSteps * 10, params, probName, epsilon=epsilon) 

36 

37 figName = f"{script}_{pType}" 

38 plt.figure(figName) 

39 plt.plot(tVals, uExact[:, 0], '-', label="Exact") 

40 plt.plot(tVals, uNum[:, 0], '--', label="Numerical") 

41 plt.plot(tValsFine, uNumFine[:, 0], '-.', label="Numerical (fine)") 

42 

43 

44for figName in [f"{script}_linear", f"{script}_nonlinear"]: 

45 plt.figure(figName) 

46 plt.legend() 

47 plt.xlabel("time") 

48 plt.ylabel("solution") 

49 plt.tight_layout()