-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeated call to interpolate_nonmatching_mesh_any seems not to work #31
Comments
Hi Søren, I haven't really touched this function in quite a few years so it's a bit difficult for me to say what's wrong. Are you saying it works if you apply |
Yes, when I call it twice in a row on the same functions but with modified values, it simply spits out the values from the first time it was called. It does that also when using two different function spaces (u0 \in V1 and i0 \in V2), but I just kept the code above as simple as possible. In test_Interpolation.py it seems also to be called only once pr. dimension pr. function-type (1 time for an expression and 1 time for a function), so maybe this is not really tested? If I change 'test_functional2D' to use the function twice on two different expressions, i.e.
then I get an assertion error when running 'test_Interpolation.py': |
Ok, so then it's highly likely a bug. Thanks for reporting and feel free to dig deeper:-) I'd be happy to accept a PR that fixes the issue:-) |
It seems to me that the fault is due to the map coords_to_values is being declared as static, and the next time the method is called it already contains all the old values from the first call. Adding coords_to_values.clear(); near the end of interpolate_any1 (in interpolation.cpp) seems to fix the problem: coords_to_values.clear(); Thanks again for this great functionality. It should IMO be included directly in fenics :) |
Maybe there should also be a coords.clear(); at the same place, since coords is also declared static. |
Great work, will you submit a PR? |
Yes, just did. Let me know if it works. |
Hi!
The code below should produce two arrays of all 0s and two arrays of all 1s, but I get
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
The code is
from dolfin import *
from fenicstools import interpolate_nonmatching_mesh_any
import numpy
mesh = UnitSquareMesh(2, 2)
V = FunctionSpace(mesh, "Nedelec 1st kind H(curl)", 1)
u0=Function(V)
u0.vector().set_local( u0.vector().get_local()*0.0 )
u0.vector().apply('insert')
print(u0.vector().get_local()) # Should be all 0
i0 = interpolate_nonmatching_mesh_any(u0, V)
print(i0.vector().get_local()) # Should be all 0
u1=Function(V)
u1.vector().set_local( u1.vector().get_local()*0.0+1.0 )
u1.vector().apply('insert')
print(u1.vector().get_local()) # Should be all 1
i1 = interpolate_nonmatching_mesh_any(u1, V)
print(i1.vector().get_local()) # Should be all 1
Is this a bug or am I doing something wrong?
Best Regards,
Søren
PS This function is a really nice and useful addition to fenics. Thanks for sharing it!
The text was updated successfully, but these errors were encountered: