Coverage for pySDC/projects/Hamiltonian/stop_at_error_hook.py: 0%

12 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 stop_at_error_hook(Hooks): 

5 def post_sweep(self, step, level_number): 

6 """ 

7 Overwrite standard post iteration hook 

8 

9 Args: 

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

11 level_number (int): the current level number 

12 """ 

13 super(stop_at_error_hook, self).post_sweep(step, level_number) 

14 

15 # some abbreviations 

16 L = step.levels[0] 

17 P = L.prob 

18 

19 L.sweep.compute_end_point() 

20 

21 uex = P.u_exact(L.time + L.dt) 

22 # print(abs(uex - L.uend)) 

23 

24 if abs(uex - L.uend) < 1e-02: 

25 print('Stop iterating at %s' % step.status.iter) 

26 step.status.force_done = True 

27 

28 return None