Coverage for pySDC/projects/parallelSDC/ErrReductionHook.py: 100%
25 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
1import numpy as np
3from pySDC.core.hooks import Hooks
6class err_reduction_hook(Hooks):
7 def pre_iteration(self, step, level_number):
8 """
9 Routine called before iteration starts
11 Args:
12 step (pySDC.Step.step): the current step
13 level_number (int): the current level number
14 """
15 super(err_reduction_hook, self).pre_iteration(step, level_number)
17 L = step.levels[level_number]
18 if step.status.iter == 2 and np.isclose(L.time + L.dt, 0.1):
19 P = L.prob
21 err = []
22 for m in range(L.sweep.coll.num_nodes):
23 uex = P.u_exact(L.time + L.dt * L.sweep.coll.nodes[m])
24 err.append(abs(uex - L.u[m + 1]))
25 err_full = max(err)
26 self.add_to_stats(
27 process=step.status.slot,
28 time=L.time,
29 level=L.level_index,
30 iter=step.status.iter,
31 sweep=L.status.sweep,
32 type='error_pre_iteration',
33 value=err_full,
34 )
35 # print(L.time, step.status.iter, err_full)
37 def post_iteration(self, step, level_number):
38 """
39 Routine called after each iteration
41 Args:
42 step (pySDC.Step.step): the current step
43 level_number (int): the current level number
44 """
45 super(err_reduction_hook, self).post_iteration(step, level_number)
47 L = step.levels[level_number]
49 if step.status.iter == 2 and np.isclose(L.time + L.dt, 0.1):
50 P = L.prob
52 err = []
53 for m in range(L.sweep.coll.num_nodes):
54 uex = P.u_exact(L.time + L.dt * L.sweep.coll.nodes[m])
55 err.append(abs(uex - L.u[m + 1]))
56 err_full = max(err)
57 self.add_to_stats(
58 process=step.status.slot,
59 time=L.time,
60 level=L.level_index,
61 iter=step.status.iter,
62 sweep=L.status.sweep,
63 type='error_post_iteration',
64 value=err_full,
65 )
66 # print(L.time, step.status.iter, err_full)