Coverage for pySDC/implementations/hooks/default_hook.py: 100%
19 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
1import time
2from pySDC.core.hooks import Hooks
5class DefaultHooks(Hooks):
6 """
7 Hook class to contain the functions called during the controller runs (e.g. for calling user-routines)
8 """
10 def post_sweep(self, step, level_number):
11 """
12 Default routine called after each sweep
14 Args:
15 step (pySDC.Step.step): the current step
16 level_number (int): the current level number
17 """
18 super().post_sweep(step, level_number)
20 L = step.levels[level_number]
22 self.logger.info(
23 'Process %2i on time %8.6f at stage %15s: Level: %s -- Iteration: %2i -- Sweep: %2i -- ' 'residual: %12.8e',
24 step.status.slot,
25 L.time,
26 step.status.stage,
27 L.level_index,
28 step.status.iter,
29 L.status.sweep,
30 L.status.residual,
31 )
33 self.add_to_stats(
34 process=step.status.slot,
35 process_sweeper=L.sweep.rank,
36 time=L.time,
37 level=L.level_index,
38 iter=step.status.iter,
39 sweep=L.status.sweep,
40 type='residual_post_sweep',
41 value=L.status.residual,
42 )
44 def post_iteration(self, step, level_number):
45 """
46 Default routine called after each iteration
48 Args:
49 step (pySDC.Step.step): the current step
50 level_number (int): the current level number
51 """
52 super().post_iteration(step, level_number)
54 L = step.levels[level_number]
56 self.add_to_stats(
57 process=step.status.slot,
58 process_sweeper=L.sweep.rank,
59 time=L.time,
60 level=-1,
61 iter=step.status.iter,
62 sweep=L.status.sweep,
63 type='residual_post_iteration',
64 value=L.status.residual,
65 )
67 def post_step(self, step, level_number):
68 """
69 Default routine called after each step or block
71 Args:
72 step (pySDC.Step.step): the current step
73 level_number (int): the current level number
74 """
75 super().post_step(step, level_number)
77 L = step.levels[level_number]
79 self.add_to_stats(
80 process=step.status.slot,
81 process_sweeper=L.sweep.rank,
82 time=L.time,
83 level=-1,
84 iter=step.status.iter,
85 sweep=L.status.sweep,
86 type='niter',
87 value=step.status.iter,
88 )
89 self.add_to_stats(
90 process=step.status.slot,
91 process_sweeper=L.sweep.rank,
92 time=L.time,
93 level=L.level_index,
94 iter=-1,
95 sweep=L.status.sweep,
96 type='residual_post_step',
97 value=L.status.residual,
98 )
100 # record the recomputed quantities at weird positions to make sure there is only one value for each step
101 for t in [L.time, L.time + L.dt]:
102 self.add_to_stats(
103 process=-1,
104 time=t,
105 level=-1,
106 iter=-1,
107 sweep=-1,
108 type='_recomputed',
109 value=step.status.get('restart'),
110 process_sweeper=-1,
111 )