Cannot do L2 projection between functions on different meshes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
DOLFIN |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
I am trying to write a geometric multigrid code and I cannot do L2 projection from a fine mesh to a coarse (the restriction operator).
Here is an simplest code to demostrate this problem:
from dolfin import *
mesh_coarse = UnitSquare(2, 2)
V_coarse = FunctionSpace(
mesh_fine = UnitSquare(4, 4)
V_fine = FunctionSpace(
f = Expression(
f_fine = interpolate(f, V_fine)
u = TrialFunction(
v = TestFunction(
lhs = u*v*dx
A = assemble(lhs)
rhs = f*v*dx
b = assemble(rhs, mesh = mesh_fine) ## This line gives an error because v is an "Argument"
f_coarse = Function(V_coarse)
solve(A, f_coarse.vector(), b)
If I do the assemble without specifying the mesh, f_fine will first be interpolated into V_coarse and then product with v, the end result is just the interpolant but not the L2 projection.
If v=interpolate(f, V_coarse), then assemble(f*v*dx, mesh = V_fine) works and gives the correct answer. However when v is a test function, dolfin complains it cannot be interpolated (which is understandable, because v is not given a concrete value yet).
It seems that the only operation which can go between function spaces defined on different meshes is interpolate so far. It would be nice to implement the above operation which is very valuable in the implementation of geometric multigrids. In terms of coding, it seems to be a matter of passing mesh=mesh_fine into each of the form assembly loops, when v is specified.
Changed in dolfin: | |
status: | New → Invalid |
Changed in dolfin: | |
status: | Invalid → New |
Changed in dolfin: | |
status: | New → Confirmed |
Try:
project(f_fine, V_coarse)
Which essentially does what you describe, but using
b = assemble(rhs)
AFAIK this is the L2 projection of f unto V_coarse.
Also the mesh argument to assemble is only used when the form does not contain any mesh.