firedrakeproject / firedrake

Firedrake is an automated system for the portable solution of partial differential equations using the finite element method (FEM)
https://firedrakeproject.org
Other
498 stars 157 forks source link

Projection to finer mesh in 1D #1500

Open NBoulle opened 5 years ago

NBoulle commented 5 years ago

I'm trying to project a function defined on a coarse mesh into a finer mesh but the following code fails.

from firedrake import *

# Coarse function
N = 100
mesh = IntervalMesh(N, 0, 1)
V = FunctionSpace(mesh, "CG", 1)
x = SpatialCoordinate(mesh)
f = interpolate(sin(x[0]),V)

# Fine function
N = 1000
mesh = IntervalMesh(N, 0, 1)
V = FunctionSpace(mesh, "CG", 1)

# Project f
f_proj = Function(V)
f_proj = project(f, V)
wence- commented 4 years ago

Apologies for the slow response. This problem occurs because for non-matching meshes like this, we use libsupermesh to find the intersection of cells. However, libsupermesh doesn't support this for interval meshes. On the other hand, it should be quite easy to write the code ourselves that computes the intersection in 1D.

I think one could write this extra code, if you would like to give it a go we can provide some guidance.

Another option, if you can get to your fine mesh by regularly refining the coarse one then you can make a MeshHierarchy and then prolong from one to the other.