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

38 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-29 09:02 +0000

1from pathlib import Path 

2 

3from pySDC.core.Step import step 

4 

5from pySDC.implementations.problem_classes.HeatEquation_ND_FD import heatNd_unforced 

6from pySDC.implementations.sweeper_classes.generic_implicit import generic_implicit 

7from pySDC.tutorial.step_1.A_spatial_problem_setup import run_accuracy_check 

8 

9 

10def main(): 

11 """ 

12 A simple test program to setup a full step instance 

13 """ 

14 

15 # initialize level parameters 

16 level_params = dict() 

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

18 level_params['dt'] = 0.1 

19 

20 # initialize sweeper parameters 

21 sweeper_params = dict() 

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

23 sweeper_params['num_nodes'] = 3 

24 sweeper_params['QI'] = 'LU' 

25 

26 # initialize problem parameters 

27 problem_params = dict() 

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

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

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

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

32 

33 # initialize step parameters 

34 step_params = dict() 

35 step_params['maxiter'] = 20 

36 

37 # fill description dictionary for easy step instantiation 

38 description = dict() 

39 description['problem_class'] = heatNd_unforced 

40 description['problem_params'] = problem_params 

41 description['sweeper_class'] = generic_implicit 

42 description['sweeper_params'] = sweeper_params 

43 description['level_params'] = level_params 

44 description['step_params'] = step_params 

45 

46 # now the description contains more or less everything we need to create a step 

47 S = step(description=description) 

48 

49 # we only have a single level, make a shortcut 

50 L = S.levels[0] 

51 

52 # one of the integral parts of each level is the problem class, make a shortcut 

53 P = L.prob 

54 

55 # now we can do e.g. what we did before with the problem 

56 err = run_accuracy_check(P) 

57 

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

59 f = open('data/step_2_A_out.txt', 'w') 

60 out = 'Error of the spatial accuracy test: %8.6e' % err 

61 f.write(out) 

62 print(out) 

63 f.close() 

64 

65 assert err <= 2e-04, "ERROR: the spatial accuracy is higher than expected, got %s" % err 

66 

67 

68if __name__ == "__main__": 

69 main()