wrong interpolation of data in 3D

Asked by Paul Scott

Hi,

I am trying to get an interpolation function f (in3D) at all vertices of cells. I can extract all vertices of cells and then I assign the value to each vertex: If it's in a sphere of radius R, then I assign the value, say 3.91. If it's outside the sphere, then I assign the value 0. I got it running without the error message but then when I calculated the function value at points that are not vertices then it does not give me either 3.91 or 0. Am I doing something wrong here?

Here is a part of my code:

# Extract vertices of all cells, then I export these points and use another software to assign value for each point (say 3.91 for points #inside sphere, 0 for points outside)
coor = mesh.coordinates()
numpy.savetxt('meshforE.txt',coor)

#I get the values at all vertices and then interpolate this to function f
qvalues2 = numpy.loadtxt('qdata.txt')
V = FunctionSpace(mesh, "CG", 1)
f = Function(V)
f.vector()[:] = qvalues2

#then I read points (xp, yp) on z=0 plane and evaluate the funtion at these points
with open('xpdata.txt') as g:
    xp = g.readlines()
print "xp[1]=", xp[1]
with open('ypdata.txt') as h:
    yp = h.readlines()
print "yp[2]=", yp[2]

for i in range(len(xp)):
    g_in[i] = f(xp[i],yp[i],0.0)

#Now when I plot g_i , it does not look like what it should be, i.e. constant(3.91) inside the circle R=50, and 0 outside.
Any help would be appreciated.

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Anders Logg (logg) said :
#1

FEniCS no longer uses Launchapd for Questions & Answers. Please
consult the documentation on the FEniCS web page for where and
how to (re)post your question: http://fenicsproject.org/support/

Revision history for this message
Anders Logg (logg) said :
#2

FEniCS no longer uses Launchapd for Questions & Answers. Please
consult the documentation on the FEniCS web page for where and
how to (re)post your question: http://fenicsproject.org/support/

Revision history for this message
Anders Logg (logg) said :
#3

FEniCS no longer uses Launchapd for Questions & Answers. Please
consult the documentation on the FEniCS web page for where and
how to (re)post your question: http://fenicsproject.org/support/

Can you help with this problem?

Provide an answer of your own, or ask Paul Scott for more information if necessary.

To post a message you must log in.