Coverage for pySDC/projects/DAE/misc/hooksDAE.py: 100%

19 statements  

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

1from pySDC.core.hooks import Hooks 

2 

3 

4class LogGlobalErrorPostStepDifferentialVariable(Hooks): 

5 """ 

6 Hook class to log the error to the output generated by the sweeper after 

7 each time step. 

8 """ 

9 

10 def post_step(self, step, level_number): 

11 r""" 

12 Default routine called after each step. 

13 

14 Parameters 

15 ---------- 

16 step : pySDC.core.step.Step 

17 Current step. 

18 level_number : pySDC.core.level.Level 

19 Current level number. 

20 """ 

21 

22 super().post_step(step, level_number) 

23 

24 # some abbreviations 

25 L = step.levels[level_number] 

26 P = L.prob 

27 

28 # TODO: is it really necessary to recompute the end point? Hasn't this been done already? 

29 L.sweep.compute_end_point() 

30 

31 # compute and save errors 

32 # Note that the component from which the error is measured is specified here 

33 upde = P.u_exact(step.time + step.dt) 

34 e_global_differential = abs(upde.diff - L.uend.diff) 

35 

36 self.add_to_stats( 

37 process=step.status.slot, 

38 time=L.time + L.dt, 

39 level=L.level_index, 

40 iter=step.status.iter, 

41 sweep=L.status.sweep, 

42 type='e_global_differential_post_step', 

43 value=e_global_differential, 

44 ) 

45 

46 

47class LogGlobalErrorPostStepAlgebraicVariable(Hooks): 

48 """ 

49 Logs the global error in the algebraic variable after each step. 

50 """ 

51 

52 def post_step(self, step, level_number): 

53 r""" 

54 Default routine called after each step. 

55 

56 Parameters 

57 ---------- 

58 step : pySDC.core.step.Step 

59 Current step. 

60 level_number : pySDC.core.level.Level 

61 Current level number. 

62 """ 

63 

64 super().post_step(step, level_number) 

65 

66 L = step.levels[level_number] 

67 P = L.prob 

68 

69 L.sweep.compute_end_point() 

70 

71 upde = P.u_exact(step.time + step.dt) 

72 e_global_algebraic = abs(upde.alg - L.uend.alg) 

73 

74 self.add_to_stats( 

75 process=step.status.slot, 

76 time=L.time + L.dt, 

77 level=L.level_index, 

78 iter=step.status.iter, 

79 sweep=L.status.sweep, 

80 type='e_global_algebraic_post_step', 

81 value=e_global_algebraic, 

82 )