Assembling a vector on a fine mesh using a function on a coarser mesh


192
views
0
5 months ago by
Hi

I have a function which appears as part of the linear functional in a variational formulation. I want to avoid interpolating the function because I use CR elements, which are discontinuous. The problem arises when I want to use the gradient, as illustrated in the MWE below.

from dolfin import *

mesh = UnitSquareMesh(5,5)
mesh1= refine(mesh)

CR = VectorElement("CR", mesh.ufl_cell(), 1)
L1 = VectorElement("Lagrange", mesh.ufl_cell(), 1)
W  = FunctionSpace(mesh, CR)
W1 = FunctionSpace(mesh1, CR)

F = Expression(('sin(pi*x[0])*cos(2*pi*x[1])','sin(pi*x[0])'),element=L1) # just a dummy function. 
u = project(F, W) # a solution of a PDE on W.
v = TestFunction(W1)
b1 = assemble(inner(u,v)*dx(mesh1)) # does work
b2 = assemble(inner(grad(u),grad(v))*dx(mesh1)) # doesn't work​

What can I do in order to assemble b2?

Thank you
Community: FEniCS Project

2 Answers


4
5 months ago by
So I will answer my own question.

My supervisor came up with the workaround of manually projecting the gradient of u onto the tensor space DG0:
from dolfin import *

mesh = UnitSquareMesh(5,5)
mesh1= refine(mesh)

CR = VectorElement("CR", mesh.ufl_cell(), 1)
L1 = VectorElement("Lagrange", mesh.ufl_cell(), 1)
W  = FunctionSpace(mesh, CR)
W1 = FunctionSpace(mesh1, CR)

W0 = TensorFunctionSpace(W.mesh(), "DG", 0)

F = Expression(('sin(pi*x[0])*cos(2*pi*x[1])','sin(pi*x[0])'),element=L1)
u = project(F, W)
v = TestFunction(W1)
b1 = assemble(inner(u,v)*dx(mesh1))

grad_u = project(grad(u),W0)
b2 = assemble(inner(grad_u,grad(v))*dx(mesh1))
​


I'm not really sure why this projection should be necessary in the first place. And more interestingly my initial script appears to work in FEniCS 2016.2.

0
5 months ago by
I'm not sure if it is not intentional, but you have u and v from different function spaces (distinct meshes). This should solve it:
u = project(F, W1)​
Thanks for your reply. It is indeed intentional that u belongs to W and not W1. I will edit the mwe to make it more clear that F is just a dummy function, and that u is actually a solution of another pde solved on the coarse mesh. The point is that I want to use the old quadrature points etc when assembling the right hand side of a system I will later solve on the fine mesh.
written 5 months ago by petterjf  
Ok, then my answer isn't clearly much of a help :-)
written 5 months ago by Adam Janecka  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »