From b305abb43589602fcbd0bb41fef120d4c08909da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Madsen?= Date: Thu, 9 Jan 2020 15:25:27 +0100 Subject: [PATCH 1/2] Add clear static variables near the end of interpolate_any1 --- fenicstools/fem/interpolation.cpp | 8 +++++--- tests/test_Interpolation.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/fenicstools/fem/interpolation.cpp b/fenicstools/fem/interpolation.cpp index 78709e1..f86f9f4 100644 --- a/fenicstools/fem/interpolation.cpp +++ b/fenicstools/fem/interpolation.cpp @@ -541,7 +541,7 @@ void interpolate_any1(const Function& u0, Function& u) // Create vector to hold all local values of u std::vector local_u_vector(u.vector()->local_size()); - + // Get dofmap of u dolfin_assert(V1.dofmap()); const GenericDofMap& dofmap = *V1.dofmap(); @@ -693,7 +693,7 @@ void interpolate_any1(const Function& u0, Function& u) // Store received result in map for (uint i = 0; i < u0.value_size(); i++) values[i] = vals[j*u0.value_size() + i]; - + coords_to_values.insert(std::make_pair(x, values)); } } @@ -751,7 +751,9 @@ void interpolate_any1(const Function& u0, Function& u) local_u_vector[d] = cell_coefficients[i]; } } - + + coords_to_values.clear(); + coords.clear(); // Set and finalize vector u.vector()->set_local(local_u_vector); u.vector()->apply("insert"); diff --git a/tests/test_Interpolation.py b/tests/test_Interpolation.py index 0b092ba..de2a7ec 100644 --- a/tests/test_Interpolation.py +++ b/tests/test_Interpolation.py @@ -44,6 +44,13 @@ def test_functional2D(): u1 = interpolate_nonmatching_mesh_any(u0, V1) assert round(assemble(dot(u0, u0)*dx) - assemble(dot(u1, u1)*dx), 4) == 0 + # Test with another expression + f = Expression(("2*(x[0]*x[0] + x[1]*x[1])", + "2*(x[0]*x[0] + x[1]*x[1] + 1)"), degree=2) + u0 = interpolate_nonmatching_mesh_any(f, V0) + u1 = interpolate_nonmatching_mesh_any(u0, V1) + assert round(assemble(dot(u0, u0)*dx) - assemble(dot(u1, u1)*dx), 4) == 0 + def test_functional3D(): """Test integration of function interpolated in non-matching meshes""" @@ -76,6 +83,15 @@ def test_functional3D(): V1 = FunctionSpace(mesh1, "Nedelec 1st kind H(curl)", 2) u1 = interpolate_nonmatching_mesh_any(u0, V1) assert round(assemble(dot(u0, u0)*dx) - assemble(dot(u1, u1)*dx), 2) == 0 + + # Test with another expression + f = Expression(("2*(x[0]*x[0] + x[1]*x[1])", + "2*(x[0]*x[0] + x[1]*x[1] + 1)", + "2*(x[0]*x[0] + x[1]*x[1] + 2)"), degree=2) + u0 = interpolate(f, V0) + u1 = interpolate_nonmatching_mesh_any(u0, V1) + assert round(assemble(dot(u0, u0)*dx) - assemble(dot(u1, u1)*dx), 1) == 0 if __name__ == '__main__': test_functional2D() + #test_functional3D() From 809fcf2360999c95bc64ba26942359ceb620e0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Madsen?= Date: Thu, 9 Jan 2020 15:31:05 +0100 Subject: [PATCH 2/2] Add clear static variables near the end of interpolate_any1 --- fenicstools/fem/interpolation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fenicstools/fem/interpolation.cpp b/fenicstools/fem/interpolation.cpp index f86f9f4..05dadb7 100644 --- a/fenicstools/fem/interpolation.cpp +++ b/fenicstools/fem/interpolation.cpp @@ -541,7 +541,7 @@ void interpolate_any1(const Function& u0, Function& u) // Create vector to hold all local values of u std::vector local_u_vector(u.vector()->local_size()); - + // Get dofmap of u dolfin_assert(V1.dofmap()); const GenericDofMap& dofmap = *V1.dofmap();