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

26 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 Allen-Cahn problem 

7""" 

8import numpy as np 

9import matplotlib.pyplot as plt 

10 

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

12 

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

14 

15tEnd = 50 

16nSteps = 50 

17 

18useRK = True 

19if useRK: 

20 rkScheme = "ESDIRK53" 

21 params = getParamsRK(rkScheme) 

22else: # pragma: no cover 

23 nNodes = 4 

24 nSweeps = 5 

25 quadType = 'RADAU-RIGHT' 

26 nodeType = 'LEGENDRE' 

27 qDelta = "MIN-SR-S" 

28 params = getParamsSDC(quadType, nNodes, qDelta, nSweeps, nodeType) 

29 

30pName = "ALLEN-CAHN" 

31periodic = False 

32pParams = { 

33 "periodic": periodic, 

34 "nvars": 2**11 - (not periodic), 

35 "epsilon": 0.04, 

36} 

37 

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

39 

40print("Computing ODE solution") 

41uExact = solutionExact(tEnd, nSteps, pName, **pParams) 

42 

43 

44uNum, counters, _ = solutionSDC(tEnd, nSteps, params, pName, **pParams) 

45 

46figName = f"{script}_solution" 

47plt.figure(figName) 

48plt.plot(uExact[0, :], '-', label="$u(0)$") 

49plt.plot(uExact[-1, :], '-', label="$u_{exact}(T)$") 

50plt.plot(uNum[-1, :], '--', label="$u_{num}(T)$") 

51 

52 

53plt.legend() 

54plt.xlabel("X") 

55plt.ylabel("solution") 

56plt.tight_layout()