Coverage for pySDC/projects/Monodomain/transfer_classes/Transfer_DCT_Vector.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-29 09:02 +0000

1import scipy.fft as fft 

2 

3from pySDC.core.SpaceTransfer import space_transfer 

4from pySDC.implementations.datatype_classes.mesh import mesh 

5 

6 

7class DCT_to_DCT(space_transfer): 

8 """ 

9 Class to transfer data between two meshes using DCT. 

10 Restriction is performed by zeroing out high frequency modes, while prolongation is done by zero-padding. 

11 

12 Arguments: 

13 ---------- 

14 fine_prob: fine problem 

15 coarse_prob: coarse problem 

16 params: parameters for the transfer operators 

17 """ 

18 

19 def __init__(self, fine_prob, coarse_prob, params): 

20 

21 # invoke super initialization 

22 super(DCT_to_DCT, self).__init__(fine_prob, coarse_prob, params) 

23 

24 self.norm = "forward" 

25 

26 self.fine_shape = self.fine_prob.parabolic.shape 

27 self.coarse_shape = self.coarse_prob.parabolic.shape 

28 

29 if self.fine_shape == self.coarse_shape: 

30 self.same_grid = True 

31 else: 

32 self.same_grid = False 

33 

34 def restrict(self, F): 

35 """ 

36 Restriction opeartor 

37 Args: 

38 F: the fine level data (easier to access than via the fine attribute) 

39 """ 

40 

41 G = mesh(self.coarse_prob.parabolic.init) 

42 

43 if self.same_grid: 

44 G[:] = F 

45 else: 

46 

47 G[:] = fft.idctn( 

48 fft.dctn(F.reshape(self.fine_shape), norm=self.norm), s=self.coarse_shape, norm=self.norm 

49 ).ravel() 

50 

51 return G 

52 

53 def prolong(self, G): 

54 """ 

55 Prolongation opeartor 

56 Args: 

57 G: the coarse level data (easier to access than via the coarse attribute) 

58 """ 

59 

60 F = mesh(self.fine_prob.parabolic.init) 

61 

62 if self.same_grid: 

63 F[:] = G 

64 else: 

65 

66 F[:] = fft.idctn( 

67 fft.dctn(G.reshape(self.coarse_shape), norm=self.norm), s=self.fine_shape, norm=self.norm 

68 ).ravel() 

69 

70 return F