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

24 statements  

« 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 21:22:52 2023 

5 

6Setup script for the Chemical Reaction 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 = 300 

16nSteps = 10 

17rkScheme = "RK4" 

18 

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

20 

21print("Computing ODE solution") 

22uExact = solutionExact(tEnd, nSteps, "CHEMREC") 

23 

24params = getParamsRK(rkScheme) 

25uNum, counters, _ = solutionSDC(tEnd, nSteps, params, 'CHEMREC') 

26 

27figName = f"{script}_solution" 

28plt.figure(figName) 

29plt.plot(tVals, uExact[:, 0], '-', label="c1-exact") 

30plt.plot(tVals, uExact[:, 1], '-', label="c2-exact") 

31plt.plot(tVals, uExact[:, 2], '-', label="c3-exact") 

32plt.plot(tVals, uNum[:, 0], '--', label="c1-num") 

33plt.plot(tVals, uNum[:, 1], '--', label="c2-num") 

34plt.plot(tVals, uNum[:, 2], '--', label="c3-num") 

35 

36plt.legend() 

37plt.xlabel("time") 

38plt.ylabel("solution") 

39plt.tight_layout()