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

Access to .interpolate results

0 votes

Hello,

I used the interpolate-function to interploate a function on a given mesh:

from dolfin import *
import numpy as np

i = 10
mesh = UnitSquareMesh(i,i)
F = FunctionSpace(mesh, "Lagrange", 1)

f = Expression("sin(5*x[0])")
inter = Function(F)
inter.interpolate(f)

Now I want to use the result of the interpolation:

if ("inter[xi]" < 0.0):

is it possible to get the values on the meh coordinates?
I need to do it this way. Interpreting the expression at a given point is not an option.

Regards

asked Nov 21, 2016 by MatheMagie FEniCS Novice (250 points)

2 Answers

0 votes

This could give you those values (if I understand your question correctly)
inter.vector().array()

answered Nov 21, 2016 by meron FEniCS User (2,340 points)

I did it like this. The result is:

array([0., 0., ....., -0.9589])

But I cant acces lmbd[1] or something like this

/edit: sorry I found my mistake

0 votes

If inter is to be used in another variational formulation in the manner you describe, consider using a conditional. E.g:

inter_condition = conditional(lt(inter, 0.0), 1.0, 0.0)

If you want to access the values of inter at the nodes of the mesh, you can use vertex_to_dof_map.

answered Nov 21, 2016 by nate FEniCS Expert (17,050 points)
Values in interpolate

I want to do it like this:

for all i in xrange(0,len(dof)):
   xi = dof[i]
   if(inter[xi] - gamma*(...) < 0.0):
       ...

Therefore, I want to go through all points on my mesh.
The values of inter should already be saved in inter.
How do I get access to these values.

what is exactly what you want?

inter.vector().array()

with the code above, it works well.
Thank you for your help :)

...