This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Meaning of output from interpolate()

0 votes

Hello,

This is a trivial question from an engineer's perspective and novice to fem and applied math.

I understand interpolation in numerical methods, but am not able to visualize it exactly in a function space format. I understand that it constructs a finite element function whose degrees of freedom (or values at the nodes) are calculated from the expression. I am not able to see that properly in the output. It would be very kind if someone could try explaining what's happening here.

So, when I run the following:

mesh = UnitSquareMesh(8,8)
v = Expression("sin(pi*x[0])")
V = FunctionSpace(mesh, "Lagrange", 1)
Iv = interpolate(v, V)
print Iv.vector().array()

I get the following output:

[  0.00000000e+00   0.00000000e+00   3.82683432e-01   0.00000000e+00
   3.82683432e-01   7.07106781e-01   0.00000000e+00   3.82683432e-01
   7.07106781e-01   9.23879533e-01   0.00000000e+00   3.82683432e-01
   7.07106781e-01   9.23879533e-01   1.00000000e+00   0.00000000e+00
   3.82683432e-01   7.07106781e-01   9.23879533e-01   1.00000000e+00
   9.23879533e-01   0.00000000e+00   3.82683432e-01   7.07106781e-01
   9.23879533e-01   1.00000000e+00   9.23879533e-01   7.07106781e-01
   0.00000000e+00   3.82683432e-01   7.07106781e-01   9.23879533e-01
   1.00000000e+00   9.23879533e-01   7.07106781e-01   3.82683432e-01
   0.00000000e+00   3.82683432e-01   7.07106781e-01   9.23879533e-01
   1.00000000e+00   9.23879533e-01   7.07106781e-01   3.82683432e-01
   1.22464680e-16   3.82683432e-01   7.07106781e-01   9.23879533e-01
   1.00000000e+00   9.23879533e-01   7.07106781e-01   3.82683432e-01
   1.22464680e-16   7.07106781e-01   9.23879533e-01   1.00000000e+00
   9.23879533e-01   7.07106781e-01   3.82683432e-01   1.22464680e-16
   9.23879533e-01   1.00000000e+00   9.23879533e-01   7.07106781e-01
   3.82683432e-01   1.22464680e-16   1.00000000e+00   9.23879533e-01
   7.07106781e-01   3.82683432e-01   1.22464680e-16   9.23879533e-01
   7.07106781e-01   3.82683432e-01   1.22464680e-16   7.07106781e-01
   3.82683432e-01   1.22464680e-16   3.82683432e-01   1.22464680e-16
   1.22464680e-16]
asked Oct 1, 2015 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)
edited Oct 5, 2015 by Chaitanya_Raj_Goyal

1 Answer

+2 votes
 
Best answer

The output is the value of v at each dof of V. Perhaps it is easier to appreciate doing this:

mesh = UnitSquareMesh(8,8)
v = Expression("sin(pi*x[0])")
V = FunctionSpace(mesh, "Lagrange", 1)
Iv = interpolate(v, V)

print ("DOFS: "), dof_to_vertex_map(V)
print Iv.vector().array()

plot(Iv, interactive = True)

and looking the plot of Iv activating the options (on the plot window): point view, mesh overlay and vertex indices (press "h" on the plot windows for help).

answered Oct 2, 2015 by hernan_mella FEniCS Expert (19,460 points)
selected Oct 2, 2015 by Chaitanya_Raj_Goyal

That was perfect. I get it now. Initially, I didn't get it because I didn't realise that the output is not in increasing order of DOF....like vertice 1, 2, 3, ......80. The output is all mixed up and doesn't make sense without seeing Vertices side by side.

Thanks Hernan_mella!

...