Coverage for pySDC/projects/FastWaveSlowWave/HookClass_acoustic.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-16 14:51 +0000

1import numpy as np 

2 

3from pySDC.core.hooks import Hooks 

4 

5 

6class dump_energy(Hooks): 

7 def __init__(self): 

8 """ 

9 Initialization of output 

10 """ 

11 super(dump_energy, self).__init__() 

12 

13 self.file = open('data/energy-sdc.txt', 'w') 

14 

15 def post_step(self, step, level_number): 

16 """ 

17 Default routine called after each iteration, compute and dump energy 

18 

19 Args: 

20 step: the current step 

21 level_number: the current level number 

22 """ 

23 

24 super(dump_energy, self).post_step(step, level_number) 

25 

26 # some abbreviations 

27 L = step.levels[level_number] 

28 

29 xx = L.uend 

30 E = np.sum(np.square(xx[0, :]) + np.square(xx[1, :])) 

31 self.file.write('%30.20f\n' % E)