Skip to content

Commit

Permalink
Merge pull request #32 from sma-user/master
Browse files Browse the repository at this point in the history
Add clear static variables near the end of interpolate_any1 and test of multiple calls to interpolate_nonmatching_mesh_any
  • Loading branch information
mikaem authored Feb 17, 2020
2 parents ad1ee5e + 809fcf2 commit 03657ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fenicstools/fem/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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");
Expand Down
16 changes: 16 additions & 0 deletions tests/test_Interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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()

0 comments on commit 03657ff

Please sign in to comment.