Coverage for pySDC/implementations/hooks/log_embedded_error_estimate.py: 100%

20 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 LogEmbeddedErrorEstimate(Hooks): 

5 """ 

6 Store the embedded error estimate at the end of each step as "error_embedded_estimate". 

7 """ 

8 

9 def log_error(self, step, level_number, appendix=''): 

10 L = step.levels[level_number] 

11 

12 for flavour in ['', '_collocation']: 

13 if L.status.get(f'error_embedded_estimate{flavour}'): 

14 if flavour == '_collocation': 

15 iter, value = L.status.error_embedded_estimate_collocation 

16 else: 

17 iter = step.status.iter 

18 value = L.status.error_embedded_estimate 

19 self.add_to_stats( 

20 process=step.status.slot, 

21 process_sweeper=L.sweep.rank, 

22 time=L.time + L.dt, 

23 level=L.level_index, 

24 iter=iter, 

25 sweep=L.status.sweep, 

26 type=f'error_embedded_estimate{flavour}{appendix}', 

27 value=value, 

28 ) 

29 

30 def post_step(self, step, level_number, appendix=''): 

31 """ 

32 Record embedded error estimate 

33 

34 Args: 

35 step (pySDC.Step.step): the current step 

36 level_number (int): the current level number 

37 

38 Returns: 

39 None 

40 """ 

41 super().post_step(step, level_number) 

42 self.log_error(step, level_number, appendix) 

43 

44 

45class LogEmbeddedErrorEstimatePostIter(LogEmbeddedErrorEstimate): 

46 """ 

47 Store the embedded error estimate after each iteration as "error_embedded_estimate_post_iteration". 

48 

49 Because the error estimate is computed after the hook is called, we record the value belonging to the last 

50 iteration, which is also why we need to record something after the step, which belongs to the final iteration. 

51 """ 

52 

53 def post_iteration(self, step, level_number): 

54 """ 

55 Record embedded error estimate 

56 

57 Args: 

58 step (pySDC.Step.step): the current step 

59 level_number (int): the current level number 

60 

61 Returns: 

62 None 

63 """ 

64 super().post_iteration(step, level_number) 

65 self.log_error(step, level_number, '_post_iteration') 

66 

67 def post_step(self, step, level_number): 

68 super().post_step(step, level_number, appendix='_post_iteration')