Coverage for pySDC/implementations/hooks/log_embedded_error_estimate.py: 100%
20 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-02 12:30 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-02 12:30 +0000
1from pySDC.core.hooks import Hooks
4class LogEmbeddedErrorEstimate(Hooks):
5 """
6 Store the embedded error estimate at the end of each step as "error_embedded_estimate".
7 """
9 def log_error(self, step, level_number, appendix=''):
10 """
11 Add the embedded error estimate as ``error_embedded_estimate<appendix>`` and, if the level carries one, the
12 estimate of the collocation error as ``error_embedded_estimate_collocation<appendix>`` to the stats. The latter
13 is recorded with the iteration number stored alongside it in the level status.
15 Args:
16 step (pySDC.Step.step): the current step
17 level_number (int): the current level number
18 appendix (str): suffix appended to the type of the recorded statistics
20 Returns:
21 None
22 """
23 L = step.levels[level_number]
25 for flavour in ['', '_collocation']:
26 if L.status.get(f'error_embedded_estimate{flavour}'):
27 if flavour == '_collocation':
28 iter, value = L.status.error_embedded_estimate_collocation
29 else:
30 iter = step.status.iter
31 value = L.status.error_embedded_estimate
32 self.add_to_stats(
33 process=step.status.slot,
34 process_sweeper=L.sweep.rank,
35 time=L.time + L.dt,
36 level=L.level_index,
37 iter=iter,
38 sweep=L.status.sweep,
39 type=f'error_embedded_estimate{flavour}{appendix}',
40 value=value,
41 )
43 def post_step(self, step, level_number, appendix=''):
44 """
45 Record embedded error estimate
47 Args:
48 step (pySDC.Step.step): the current step
49 level_number (int): the current level number
50 appendix (str): suffix appended to the type of the recorded statistics
52 Returns:
53 None
54 """
55 super().post_step(step, level_number)
56 self.log_error(step, level_number, appendix)
59class LogEmbeddedErrorEstimatePostIter(LogEmbeddedErrorEstimate):
60 """
61 Store the embedded error estimate after each iteration as "error_embedded_estimate_post_iteration".
63 Because the error estimate is computed after the hook is called, we record the value belonging to the last
64 iteration, which is also why we need to record something after the step, which belongs to the final iteration.
65 """
67 def post_iteration(self, step, level_number):
68 """
69 Record embedded error estimate
71 Args:
72 step (pySDC.Step.step): the current step
73 level_number (int): the current level number
75 Returns:
76 None
77 """
78 super().post_iteration(step, level_number)
79 self.log_error(step, level_number, '_post_iteration')
81 def post_step(self, step, level_number):
82 """
83 Record the embedded error estimate of the final iteration as ``error_embedded_estimate_post_iteration``.
85 Args:
86 step (pySDC.Step.step): the current step
87 level_number (int): the current level number
89 Returns:
90 None
91 """
92 super().post_step(step, level_number, appendix='_post_iteration')