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

31 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-29 09:02 +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 

7""" 

8import numpy as np 

9import matplotlib.pyplot as plt 

10 

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

12 

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

14 

15tEnd = 2 * np.pi 

16nSteps = 2 

17epsilon = np.inf 

18rkScheme = "ESDIRK43" 

19 

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

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

22 

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

24 probName = "PROTHERO-ROBINSON" 

25 if pType == "nonlinear": 

26 probName += "-NL" 

27 

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

29 uExact = solutionExact(tEnd, nSteps, "PROTHERO-ROBINSON", epsilon=epsilon) 

30 

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) 

34 

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)") 

40 

41 

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()