Coverage for pySDC/tutorial/step_2/C_using_pySDCs_frontend.py: 100%

43 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-16 14:51 +0000

1from pathlib import Path 

2 

3 

4from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI 

5from pySDC.implementations.problem_classes.HeatEquation_ND_FD import heatNd_forced 

6from pySDC.implementations.sweeper_classes.imex_1st_order import imex_1st_order 

7 

8 

9def main(): 

10 """ 

11 A simple test program to run IMEX SDC for a single time step 

12 """ 

13 # initialize level parameters 

14 level_params = dict() 

15 level_params['restol'] = 1e-10 

16 level_params['dt'] = 0.1 

17 

18 # initialize sweeper parameters 

19 sweeper_params = dict() 

20 sweeper_params['quad_type'] = 'RADAU-RIGHT' 

21 sweeper_params['num_nodes'] = 3 

22 

23 # initialize problem parameters 

24 problem_params = dict() 

25 problem_params['nu'] = 0.1 # diffusion coefficient 

26 problem_params['freq'] = 4 # frequency for the test value 

27 problem_params['nvars'] = 1023 # number of degrees of freedom 

28 problem_params['bc'] = 'dirichlet-zero' # boundary conditions 

29 

30 # initialize step parameters 

31 step_params = dict() 

32 step_params['maxiter'] = 20 

33 

34 # initialize controller parameters 

35 controller_params = dict() 

36 controller_params['log_to_file'] = True 

37 controller_params['fname'] = 'data/step_2_C_out.txt' 

38 

39 # Fill description dictionary for easy hierarchy creation 

40 description = dict() 

41 description['problem_class'] = heatNd_forced 

42 description['problem_params'] = problem_params 

43 description['sweeper_class'] = imex_1st_order 

44 description['sweeper_params'] = sweeper_params 

45 description['level_params'] = level_params 

46 description['step_params'] = step_params 

47 

48 Path("data").mkdir(parents=True, exist_ok=True) 

49 

50 # instantiate the controller 

51 controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description) 

52 

53 # set time parameters 

54 t0 = 0.1 

55 Tend = 0.3 # note that we are requesting 2 time steps here (dt is 0.1) 

56 

57 # get initial values on finest level 

58 P = controller.MS[0].levels[0].prob 

59 uinit = P.u_exact(t0) 

60 

61 # call main function to get things done... 

62 uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend) 

63 

64 # compute exact solution and compare 

65 uex = P.u_exact(Tend) 

66 err = abs(uex - uend) 

67 

68 f = open('data/step_2_C_out.txt', 'a') 

69 out = 'Error after SDC iterations: %8.6e' % err 

70 f.write(out) 

71 print(out) 

72 f.close() 

73 

74 assert err <= 2e-5, "ERROR: controller doing IMEX SDC iteration did not reduce the error enough, got %s" % err 

75 

76 

77if __name__ == "__main__": 

78 main()