Coverage for pySDC/implementations/transfer_classes/TransferPETScDMDA.py: 53%

34 statements  

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

1from pySDC.core.errors import TransferError 

2from pySDC.core.space_transfer import SpaceTransfer 

3from pySDC.implementations.datatype_classes.petsc_vec import petsc_vec, petsc_vec_imex, petsc_vec_comp2 

4 

5 

6class mesh_to_mesh_petsc_dmda(SpaceTransfer): 

7 """ 

8 This implementation can restrict and prolong between PETSc DMDA grids 

9 """ 

10 

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

12 """ 

13 Initialization routine 

14 

15 Args: 

16 fine_prob: fine problem 

17 coarse_prob: coarse problem 

18 params: parameters for the transfer operators 

19 """ 

20 

21 # invoke super initialization 

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

23 

24 # set interpolation type (no effect as far as I can tell) 

25 # self.coarse_prob.init.setInterpolationType(PETSc.DMDA.InterpolationType.Q1) 

26 # define interpolation (only accurate for constant functions) 

27 self.interp, _ = self.coarse_prob.init.createInterpolation(self.fine_prob.init) 

28 # define restriction as injection (tranpose of interpolation does not work) 

29 self.inject = self.coarse_prob.init.createInjection(self.fine_prob.init) 

30 

31 def restrict(self, F): 

32 """ 

33 Restriction implementation 

34 

35 Args: 

36 F: the fine level data 

37 """ 

38 if isinstance(F, petsc_vec): 

39 u_coarse = self.coarse_prob.dtype_u(self.coarse_prob.init) 

40 self.inject.mult(F, u_coarse) 

41 elif isinstance(F, petsc_vec_imex): 

42 u_coarse = self.coarse_prob.dtype_f(self.coarse_prob.init) 

43 self.inject.mult(F.impl, u_coarse.impl) 

44 self.inject.mult(F.expl, u_coarse.expl) 

45 elif isinstance(F, petsc_vec_comp2): 

46 u_coarse = self.coarse_prob.dtype_f(self.coarse_prob.init) 

47 self.inject.mult(F.comp1, u_coarse.comp1) 

48 self.inject.mult(F.comp2, u_coarse.comp2) 

49 else: 

50 raise TransferError('Unknown type of fine data, got %s' % type(F)) 

51 

52 return u_coarse 

53 

54 def prolong(self, G): 

55 """ 

56 Prolongation implementation 

57 

58 Args: 

59 G: the coarse level data 

60 """ 

61 if isinstance(G, petsc_vec): 

62 u_fine = self.fine_prob.dtype_u(self.fine_prob.init) 

63 self.interp.mult(G, u_fine) 

64 elif isinstance(G, petsc_vec_imex): 

65 u_fine = self.fine_prob.dtype_f(self.fine_prob.init) 

66 self.interp.mult(G.impl, u_fine.impl) 

67 self.interp.mult(G.expl, u_fine.expl) 

68 elif isinstance(G, petsc_vec_comp2): 

69 u_fine = self.fine_prob.dtype_f(self.fine_prob.init) 

70 self.interp.mult(G.comp1, u_fine.comp1) 

71 self.interp.mult(G.comp2, u_fine.comp2) 

72 else: 

73 raise TransferError('Unknown type of coarse data, got %s' % type(G)) 

74 

75 return u_fine