Interpolation of a Function from a 1D mesh to a 2D mesh

Hello everyone,

I need to interpolate some 1D data from snippet_dataset.txt on the left boundary of a RectangleMesh(). First, I read data from file and I define an IntervalMesh() with the same number of elements as the number of values in the file, in order to have one value per element. Then I define a function on this 1D mesh and I attribute a value from the data file to each element. Now I want to project this function on the left boundary of a 2D mesh called mesh_2D. I tried with the project() function but it doesn’t work. I also tried some solutions proposed in Is it possible to interpolate a function from 1d mesh to 2d mesh… Here is the snippet of the code:

from dolfin import *
import numpy as np
import matplotlib.pyplot as plt

parameters["reorder_dofs_serial"] = False #dofs in the same order than coordinates

# Define mesh
nx = 100
ny = 50

lx = 0.002
ly = 0.001

mesh_2D = RectangleMesh(Point(0., 0.), Point(lx,ly), nx, ny, "crossed") #2D Fenics mesh

p = np.loadtxt('snippet_dataset.txt', usecols=0, unpack='True')

n_dataset = len(p)-1

mesh_1D = IntervalMesh(n_dataset,0.,ly) #1D mesh corresponding to the data set

V = FunctionSpace(mesh_2D, "CG", 1)
W = FunctionSpace(mesh_1D, "CG", 1)

pf = Function(W)
pf_proj = Function(V) 

pf.vector()[:] = p

LagrangeInterpolator.interpolate(V, pf)

plot(pf)
plt.show()

pf_proj = project(pf,V) #doesn't work

The snippet_dataset.txt file is organised as follows (as an example):

0
1
2
3
4
5
4
3
2
1
0

Thank you in advance,

Lucas Ménez