diff --git a/tests/test_boundary.py b/tests/test_boundary.py index 631e488..2554d0a 100644 --- a/tests/test_boundary.py +++ b/tests/test_boundary.py @@ -8,6 +8,7 @@ from test_geometry import read_sdf from schism import BoundaryConditions, Boundary, BoundaryGeometry from collections import Counter +from devito.tools.utils import filter_sorted class TestSubstitutions: @@ -140,5 +141,9 @@ def test_forward_timestep(self, s_o): current_weights = dv.symbolics.retrieve_functions(current) forward_weights = dv.symbolics.retrieve_functions(forward) + # Sort to ensure that weights are in the same order + current_weights = filter_sorted(current_weights) + forward_weights = filter_sorted(forward_weights) + for crt, fwd in zip(current_weights, forward_weights): assert np.all(np.isclose(crt.data, fwd.data)) diff --git a/tests/test_boundary_conditions.py b/tests/test_boundary_conditions.py index 6eea1b9..6576e21 100644 --- a/tests/test_boundary_conditions.py +++ b/tests/test_boundary_conditions.py @@ -245,10 +245,13 @@ def test_coefficient_replacement(self, bc, funcs): condition = SingleCondition(bc, funcs=funcs) # Check that if we substitute the placeholders for their expressions, # we get our original LHS - check = sp.simplify(condition.lhs - - condition._mod_lhs.subs(condition.expr_map)) - assert check == 0 + # Force expansion as sympy as need to string check + reconstruction = sp.expand(condition._mod_lhs.subs(condition.expr_map)) + expanded_lhs = sp.expand(condition.lhs) + + # Matching strings is ugly, but SymPy simplification is unreliable + assert str(reconstruction) == str(expanded_lhs) @pytest.mark.parametrize('bc, g', [(dv.Eq(f+g), g), (dv.Eq(g*f.dx+g), g), (dv.Eq(f+g+1), g), (dv.Eq(g*(f+1)), g)]) diff --git a/tests/test_substitution.py b/tests/test_substitution.py index abbd2a9..4c1e5d0 100644 --- a/tests/test_substitution.py +++ b/tests/test_substitution.py @@ -257,27 +257,27 @@ def test_fill_weights_consistency(self): def test_returned_expr(self): """Check that the correct expression is returned""" subs = weights_test_setup() - ans = 'f(t, x, y)*w_f_f_dy2_0_0(x, y) ' \ - + '+ f(t, x, y - 2*h_y)*w_f_f_dy2_0_m2(x, y) ' \ - + '+ f(t, x, y - h_y)*w_f_f_dy2_0_m1(x, y) ' \ - + '+ f(t, x, y + h_y)*w_f_f_dy2_0_1(x, y) ' \ - + '+ f(t, x, y + 2*h_y)*w_f_f_dy2_0_2(x, y) ' \ - + '+ f(t, x - 2*h_x, y)*w_f_f_dy2_m2_0(x, y) ' \ - + '+ f(t, x - 2*h_x, y - h_y)*w_f_f_dy2_m2_m1(x, y) ' \ - + '+ f(t, x - 2*h_x, y + h_y)*w_f_f_dy2_m2_1(x, y) ' \ - + '+ f(t, x - h_x, y)*w_f_f_dy2_m1_0(x, y) ' \ - + '+ f(t, x - h_x, y - 2*h_y)*w_f_f_dy2_m1_m2(x, y) ' \ - + '+ f(t, x - h_x, y - h_y)*w_f_f_dy2_m1_m1(x, y) ' \ - + '+ f(t, x - h_x, y + h_y)*w_f_f_dy2_m1_1(x, y) ' \ - + '+ f(t, x - h_x, y + 2*h_y)*w_f_f_dy2_m1_2(x, y) ' \ - + '+ f(t, x + h_x, y)*w_f_f_dy2_1_0(x, y) ' \ - + '+ f(t, x + h_x, y - 2*h_y)*w_f_f_dy2_1_m2(x, y) ' \ - + '+ f(t, x + h_x, y - h_y)*w_f_f_dy2_1_m1(x, y) ' \ - + '+ f(t, x + h_x, y + h_y)*w_f_f_dy2_1_1(x, y) ' \ - + '+ f(t, x + h_x, y + 2*h_y)*w_f_f_dy2_1_2(x, y) ' \ - + '+ f(t, x + 2*h_x, y)*w_f_f_dy2_2_0(x, y) ' \ - + '+ f(t, x + 2*h_x, y - h_y)*w_f_f_dy2_2_m1(x, y) ' \ - + '+ f(t, x + 2*h_x, y + h_y)*w_f_f_dy2_2_1(x, y)' + ans = 'w_f_f_dy2_0_0(x, y)*f(t, x, y) ' \ + + '+ w_f_f_dy2_0_1(x, y)*f(t, x, y + h_y) ' \ + + '+ w_f_f_dy2_0_2(x, y)*f(t, x, y + 2*h_y) ' \ + + '+ w_f_f_dy2_0_m1(x, y)*f(t, x, y - h_y) ' \ + + '+ w_f_f_dy2_0_m2(x, y)*f(t, x, y - 2*h_y) ' \ + + '+ w_f_f_dy2_1_0(x, y)*f(t, x + h_x, y) ' \ + + '+ w_f_f_dy2_1_1(x, y)*f(t, x + h_x, y + h_y) ' \ + + '+ w_f_f_dy2_1_2(x, y)*f(t, x + h_x, y + 2*h_y) ' \ + + '+ w_f_f_dy2_1_m1(x, y)*f(t, x + h_x, y - h_y) ' \ + + '+ w_f_f_dy2_1_m2(x, y)*f(t, x + h_x, y - 2*h_y) ' \ + + '+ w_f_f_dy2_2_0(x, y)*f(t, x + 2*h_x, y) ' \ + + '+ w_f_f_dy2_2_1(x, y)*f(t, x + 2*h_x, y + h_y) ' \ + + '+ w_f_f_dy2_2_m1(x, y)*f(t, x + 2*h_x, y - h_y) ' \ + + '+ w_f_f_dy2_m1_0(x, y)*f(t, x - h_x, y) ' \ + + '+ w_f_f_dy2_m1_1(x, y)*f(t, x - h_x, y + h_y) ' \ + + '+ w_f_f_dy2_m1_2(x, y)*f(t, x - h_x, y + 2*h_y) ' \ + + '+ w_f_f_dy2_m1_m1(x, y)*f(t, x - h_x, y - h_y) ' \ + + '+ w_f_f_dy2_m1_m2(x, y)*f(t, x - h_x, y - 2*h_y) ' \ + + '+ w_f_f_dy2_m2_0(x, y)*f(t, x - 2*h_x, y) ' \ + + '+ w_f_f_dy2_m2_1(x, y)*f(t, x - 2*h_x, y + h_y) ' \ + + '+ w_f_f_dy2_m2_m1(x, y)*f(t, x - 2*h_x, y - h_y)' assert str(subs.expr) == ans