Coverage for pySDC/implementations/transfer_classes/TransferFenicsMesh.py: 65%
31 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 dolfin as df
3from pySDC.core.errors import TransferError
4from pySDC.core.space_transfer import SpaceTransfer
5from pySDC.implementations.datatype_classes.fenics_mesh import fenics_mesh, rhs_fenics_mesh
8class mesh_to_mesh_fenics(SpaceTransfer):
9 """
10 This implementation can restrict and prolong between fenics meshes
11 """
13 def __init__(self, fine_prob, coarse_prob, params):
14 """
15 Initialization routine
17 Args:
18 fine_prob: fine problem
19 coarse_prob: coarse problem
20 params: parameters for the transfer operators
21 """
23 # invoke super initialization
24 super(mesh_to_mesh_fenics, self).__init__(fine_prob, coarse_prob, params)
26 pass
28 def project(self, F):
29 """
30 Restriction implementation via projection
32 Args:
33 F: the fine level data
34 """
35 if isinstance(F, fenics_mesh):
36 u_coarse = fenics_mesh(df.project(F.values, self.coarse_prob.init))
37 elif isinstance(F, rhs_fenics_mesh):
38 u_coarse = rhs_fenics_mesh(self.coarse_prob.init)
39 u_coarse.impl.values = df.project(F.impl.values, self.coarse_prob.init)
40 u_coarse.expl.values = df.project(F.expl.values, self.coarse_prob.init)
41 else:
42 raise TransferError('Unknown type of fine data, got %s' % type(F))
44 return u_coarse
46 def restrict(self, F):
47 """
48 Restriction implementation
50 Args:
51 F: the fine level data
52 """
53 if isinstance(F, fenics_mesh):
54 u_coarse = fenics_mesh(df.interpolate(F.values, self.coarse_prob.init))
55 elif isinstance(F, rhs_fenics_mesh):
56 u_coarse = rhs_fenics_mesh(self.coarse_prob.init)
57 u_coarse.impl.values = df.interpolate(F.impl.values, self.coarse_prob.init)
58 u_coarse.expl.values = df.interpolate(F.expl.values, self.coarse_prob.init)
59 else:
60 raise TransferError('Unknown type of fine data, got %s' % type(F))
62 return u_coarse
64 def prolong(self, G):
65 """
66 Prolongation implementation
68 Args:
69 G: the coarse level data
70 """
71 if isinstance(G, fenics_mesh):
72 u_fine = fenics_mesh(df.interpolate(G.values, self.fine_prob.init))
73 elif isinstance(G, rhs_fenics_mesh):
74 u_fine = rhs_fenics_mesh(self.fine_prob.init)
75 u_fine.impl.values = df.interpolate(G.impl.values, self.fine_prob.init)
76 u_fine.expl.values = df.interpolate(G.expl.values, self.fine_prob.init)
77 else:
78 raise TransferError('Unknown type of coarse data, got %s' % type(G))
80 return u_fine