Evaluating solution along a line #4838
-
|
I am evaluating a 2d solution along a line by sampling some points. v, J, p = w.subfunctions
nl = 1000
line = np.linspace(-1,1,nl)
vz_vs_y = np.empty_like(line)
vz_vs_x = np.empty_like(line)
for i,s in enumerate(line):
vz_vs_x[i] = v((s,0))
vz_vs_y[i] = v((0,s))
np.savetxt("line.txt", np.column_stack((line,vz_vs_x,vz_vs_y)))This is rather slow, taking even more time than the pde solve. I can expect some slowness, since we are evaluating at arbitrary points and the points first need to be located in their element which needs a search. Is there any way I can speed it up ? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
I think calling the point evaluation method in a loop is going to be slow. Doing a single call will speed things up. I was able to get something similar to work like so: zeros = np.zeros_like(line)
vz_vs_x = v(list(np.column_stack((line, zeros))))
vz_vs_y = v(list(np.column_stack((zeros, line))))Can you try and see if that helps? I'm not sure why, but I needed to convert the 2D numpy array to a list first; I got an error message when I just passed the array. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you, this works. |
Beta Was this translation helpful? Give feedback.
-
|
Hi All. Calling the expression is inherently slow. The primary API for point evaluation is the one given here: https://www.firedrakeproject.org/point-evaluation.html#primary-api-interpolation-onto-a-vertex-only-mesh For interpolation onto a line you can also define a 1D mesh immersed in 2D and then interpolate into a function space defined on that line. The Vertex only Mesh solution is likely to be the better option if you want to extract the data for external processing. If you want to do further computations on the line data then the second option gives you the Firedrake Function to do this with. |
Beta Was this translation helpful? Give feedback.
I think calling the point evaluation method in a loop is going to be slow. Doing a single call will speed things up. I was able to get something similar to work like so:
Can you try and see if that helps?
I'm not sure why, but I needed to convert the 2D numpy array to a list first; I got an error message when I just passed the array.