Project matrix from one function space to another function space

I’m not quite sure what you mean, but it sounds like maybe you’re looking for something like the PETScDMCollection functionality. Take a look at the following example:

from dolfin import *

# Two different meshes and function spaces:
mesh1 = UnitIntervalMesh(7)
mesh2 = UnitIntervalMesh(100)
V1 = FunctionSpace(mesh1,"Lagrange",1)
V2 = FunctionSpace(mesh2,"Lagrange",1)

# Create some function in V1:
f1 = Function(V1)
f1.interpolate(Expression("x[0]*x[0]",degree=2))

# Create a transfer matrix from V1 to V2, and use it to interpolate f1 in V2:
A = PETScDMCollection.create_transfer_matrix(V1,V2)
f2 = Function(V2)
f2.vector()[:] = A*f1.vector()

# Plot results:
import matplotlib.pyplot as plt
plot(f2)
plt.show()
3 Likes