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

26 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-13 09:00 +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""" 

8 

9import numpy as np 

10import matplotlib.pyplot as plt 

11 

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

13 

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

15 

16tEnd = 50 

17nSteps = 50 

18 

19useRK = True 

20if useRK: 

21 rkScheme = "ESDIRK53" 

22 params = getParamsRK(rkScheme) 

23else: # pragma: no cover 

24 nNodes = 4 

25 nSweeps = 5 

26 quadType = 'RADAU-RIGHT' 

27 nodeType = 'LEGENDRE' 

28 qDelta = "MIN-SR-S" 

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

30 

31pName = "ALLEN-CAHN" 

32periodic = False 

33pParams = { 

34 "periodic": periodic, 

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

36 "epsilon": 0.04, 

37} 

38 

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

40 

41print("Computing ODE solution") 

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

43 

44 

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

46 

47figName = f"{script}_solution" 

48plt.figure(figName) 

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

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

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

52 

53 

54plt.legend() 

55plt.xlabel("X") 

56plt.ylabel("solution") 

57plt.tight_layout()