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

8 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-17 13:41 +0000

1from pySDC.core.hooks import Hooks 

2 

3 

4class LogResidualPostSweep(Hooks): 

5 """ 

6 Compute the residual after every sweep, on every level, and store it as "residual_post_sweep". 

7 

8 The controllers compute the residual only once per iteration, where the convergence check needs it: after the new 

9 initial value has come in. This hook adds the residual after each sweep for those who want to watch the levels 

10 converge, at the cost of one residual per sweep. It is computed with the sweep's stage, so stages listed in the 

11 sweeper's `skip_residual_computation` are still skipped. 

12 """ 

13 

14 def post_sweep(self, step, level_number): 

15 """ 

16 Compute and record the residual 

17 

18 Args: 

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

20 level_number (int): the current level number 

21 

22 Returns: 

23 None 

24 """ 

25 super().post_sweep(step, level_number) 

26 

27 L = step.levels[level_number] 

28 L.sweep.compute_residual(stage=step.status.stage) 

29 

30 self.logger.info( 

31 'Process %2i on time %8.6f at stage %15s: Level: %s -- Iteration: %2i -- Sweep: %2i -- residual: %12.8e', 

32 step.status.slot, 

33 L.time, 

34 step.status.stage, 

35 L.level_index, 

36 step.status.iter, 

37 L.status.sweep, 

38 L.status.residual, 

39 ) 

40 

41 self.add_to_stats( 

42 process=step.status.slot, 

43 process_sweeper=L.sweep.rank, 

44 time=L.time, 

45 level=L.level_index, 

46 iter=step.status.iter, 

47 sweep=L.status.sweep, 

48 type='residual_post_sweep', 

49 value=L.status.residual, 

50 )