Coverage for pySDC/projects/Hamiltonian/hamiltonian_output.py: 100%
24 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
1from pySDC.core.hooks import Hooks
4class hamiltonian_output(Hooks):
5 def __init__(self):
6 """
7 Initialization of particles output
8 """
9 super(hamiltonian_output, self).__init__()
10 self.ham_init = None
12 def pre_run(self, step, level_number):
13 # some abbreviations
14 L = step.levels[0]
15 P = L.prob
16 super(hamiltonian_output, self).pre_run(step, level_number)
17 self.ham_init = P.eval_hamiltonian(L.u[0])
19 def post_iteration(self, step, level_number):
20 """
21 Overwrite standard post iteration hook
23 Args:
24 step (pySDC.Step.step): the current step
25 level_number (int): the current level number
26 """
27 super(hamiltonian_output, self).post_iteration(step, level_number)
29 # some abbreviations
30 L = step.levels[0]
31 P = L.prob
33 L.sweep.compute_end_point()
34 H = P.eval_hamiltonian(L.uend)
36 self.add_to_stats(
37 process=step.status.slot,
38 time=L.time,
39 level=-1,
40 iter=step.status.iter,
41 sweep=L.status.sweep,
42 type='hamiltonian',
43 value=H,
44 )
46 self.add_to_stats(
47 process=step.status.slot,
48 time=L.time,
49 level=-1,
50 iter=step.status.iter,
51 sweep=L.status.sweep,
52 type='err_hamiltonian',
53 value=abs(self.ham_init - H),
54 )
56 return None
58 def post_step(self, step, level_number):
59 """
60 Overwrite standard post iteration hook
62 Args:
63 step (pySDC.Step.step): the current step
64 level_number (int): the current level number
65 """
66 super(hamiltonian_output, self).post_step(step, level_number)
68 # some abbreviations
69 L = step.levels[0]
71 self.add_to_stats(
72 process=step.status.slot,
73 time=L.time,
74 level=-1,
75 iter=step.status.iter,
76 sweep=L.status.sweep,
77 type='position',
78 value=L.uend.pos,
79 )
81 return None