Coverage for pySDC/projects/Monodomain/transfer_classes/Transfer_DCT_Vector.py: 100%
24 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
1import scipy.fft as fft
3from pySDC.core.space_transfer import SpaceTransfer
4from pySDC.implementations.datatype_classes.mesh import mesh
7class DCT_to_DCT(SpaceTransfer):
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.
12 Arguments:
13 ----------
14 fine_prob: fine problem
15 coarse_prob: coarse problem
16 params: parameters for the transfer operators
17 """
19 def __init__(self, fine_prob, coarse_prob, params):
21 # invoke super initialization
22 super(DCT_to_DCT, self).__init__(fine_prob, coarse_prob, params)
24 self.norm = "forward"
26 self.fine_shape = self.fine_prob.parabolic.shape
27 self.coarse_shape = self.coarse_prob.parabolic.shape
29 if self.fine_shape == self.coarse_shape:
30 self.same_grid = True
31 else:
32 self.same_grid = False
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 """
41 G = mesh(self.coarse_prob.parabolic.init)
43 if self.same_grid:
44 G[:] = F
45 else:
47 G[:] = fft.idctn(
48 fft.dctn(F.reshape(self.fine_shape), norm=self.norm), s=self.coarse_shape, norm=self.norm
49 ).ravel()
51 return G
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 """
60 F = mesh(self.fine_prob.parabolic.init)
62 if self.same_grid:
63 F[:] = G
64 else:
66 F[:] = fft.idctn(
67 fft.dctn(G.reshape(self.coarse_shape), norm=self.norm), s=self.fine_shape, norm=self.norm
68 ).ravel()
70 return F