Skip to content

Commit 3991446

Browse files
authored
Merge pull request #28 from devitocodes/1d_nd_notebook
examples: Update 1D vs ND comparison to reflect revisions
2 parents b8dee1e + a7c9cd7 commit 3991446

4 files changed

Lines changed: 127 additions & 80 deletions

File tree

examples/7_1D_vs_ND_comparison.ipynb

Lines changed: 95 additions & 56 deletions
Large diffs are not rendered by default.

tests/test_boundary.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from test_geometry import read_sdf
99
from schism import BoundaryConditions, Boundary, BoundaryGeometry
1010
from collections import Counter
11+
from devito.tools.utils import filter_sorted
1112

1213

1314
class TestSubstitutions:
@@ -140,5 +141,9 @@ def test_forward_timestep(self, s_o):
140141
current_weights = dv.symbolics.retrieve_functions(current)
141142
forward_weights = dv.symbolics.retrieve_functions(forward)
142143

144+
# Sort to ensure that weights are in the same order
145+
current_weights = filter_sorted(current_weights)
146+
forward_weights = filter_sorted(forward_weights)
147+
143148
for crt, fwd in zip(current_weights, forward_weights):
144149
assert np.all(np.isclose(crt.data, fwd.data))

tests/test_boundary_conditions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,13 @@ def test_coefficient_replacement(self, bc, funcs):
245245
condition = SingleCondition(bc, funcs=funcs)
246246
# Check that if we substitute the placeholders for their expressions,
247247
# we get our original LHS
248-
check = sp.simplify(condition.lhs
249-
- condition._mod_lhs.subs(condition.expr_map))
250248

251-
assert check == 0
249+
# Force expansion as sympy as need to string check
250+
reconstruction = sp.expand(condition._mod_lhs.subs(condition.expr_map))
251+
expanded_lhs = sp.expand(condition.lhs)
252+
253+
# Matching strings is ugly, but SymPy simplification is unreliable
254+
assert str(reconstruction) == str(expanded_lhs)
252255

253256
@pytest.mark.parametrize('bc, g', [(dv.Eq(f+g), g), (dv.Eq(g*f.dx+g), g),
254257
(dv.Eq(f+g+1), g), (dv.Eq(g*(f+1)), g)])

tests/test_substitution.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -257,27 +257,27 @@ def test_fill_weights_consistency(self):
257257
def test_returned_expr(self):
258258
"""Check that the correct expression is returned"""
259259
subs = weights_test_setup()
260-
ans = 'f(t, x, y)*w_f_f_dy2_0_0(x, y) ' \
261-
+ '+ f(t, x, y - 2*h_y)*w_f_f_dy2_0_m2(x, y) ' \
262-
+ '+ f(t, x, y - h_y)*w_f_f_dy2_0_m1(x, y) ' \
263-
+ '+ f(t, x, y + h_y)*w_f_f_dy2_0_1(x, y) ' \
264-
+ '+ f(t, x, y + 2*h_y)*w_f_f_dy2_0_2(x, y) ' \
265-
+ '+ f(t, x - 2*h_x, y)*w_f_f_dy2_m2_0(x, y) ' \
266-
+ '+ f(t, x - 2*h_x, y - h_y)*w_f_f_dy2_m2_m1(x, y) ' \
267-
+ '+ f(t, x - 2*h_x, y + h_y)*w_f_f_dy2_m2_1(x, y) ' \
268-
+ '+ f(t, x - h_x, y)*w_f_f_dy2_m1_0(x, y) ' \
269-
+ '+ f(t, x - h_x, y - 2*h_y)*w_f_f_dy2_m1_m2(x, y) ' \
270-
+ '+ f(t, x - h_x, y - h_y)*w_f_f_dy2_m1_m1(x, y) ' \
271-
+ '+ f(t, x - h_x, y + h_y)*w_f_f_dy2_m1_1(x, y) ' \
272-
+ '+ f(t, x - h_x, y + 2*h_y)*w_f_f_dy2_m1_2(x, y) ' \
273-
+ '+ f(t, x + h_x, y)*w_f_f_dy2_1_0(x, y) ' \
274-
+ '+ f(t, x + h_x, y - 2*h_y)*w_f_f_dy2_1_m2(x, y) ' \
275-
+ '+ f(t, x + h_x, y - h_y)*w_f_f_dy2_1_m1(x, y) ' \
276-
+ '+ f(t, x + h_x, y + h_y)*w_f_f_dy2_1_1(x, y) ' \
277-
+ '+ f(t, x + h_x, y + 2*h_y)*w_f_f_dy2_1_2(x, y) ' \
278-
+ '+ f(t, x + 2*h_x, y)*w_f_f_dy2_2_0(x, y) ' \
279-
+ '+ f(t, x + 2*h_x, y - h_y)*w_f_f_dy2_2_m1(x, y) ' \
280-
+ '+ f(t, x + 2*h_x, y + h_y)*w_f_f_dy2_2_1(x, y)'
260+
ans = 'w_f_f_dy2_0_0(x, y)*f(t, x, y) ' \
261+
+ '+ w_f_f_dy2_0_1(x, y)*f(t, x, y + h_y) ' \
262+
+ '+ w_f_f_dy2_0_2(x, y)*f(t, x, y + 2*h_y) ' \
263+
+ '+ w_f_f_dy2_0_m1(x, y)*f(t, x, y - h_y) ' \
264+
+ '+ w_f_f_dy2_0_m2(x, y)*f(t, x, y - 2*h_y) ' \
265+
+ '+ w_f_f_dy2_1_0(x, y)*f(t, x + h_x, y) ' \
266+
+ '+ w_f_f_dy2_1_1(x, y)*f(t, x + h_x, y + h_y) ' \
267+
+ '+ w_f_f_dy2_1_2(x, y)*f(t, x + h_x, y + 2*h_y) ' \
268+
+ '+ w_f_f_dy2_1_m1(x, y)*f(t, x + h_x, y - h_y) ' \
269+
+ '+ w_f_f_dy2_1_m2(x, y)*f(t, x + h_x, y - 2*h_y) ' \
270+
+ '+ w_f_f_dy2_2_0(x, y)*f(t, x + 2*h_x, y) ' \
271+
+ '+ w_f_f_dy2_2_1(x, y)*f(t, x + 2*h_x, y + h_y) ' \
272+
+ '+ w_f_f_dy2_2_m1(x, y)*f(t, x + 2*h_x, y - h_y) ' \
273+
+ '+ w_f_f_dy2_m1_0(x, y)*f(t, x - h_x, y) ' \
274+
+ '+ w_f_f_dy2_m1_1(x, y)*f(t, x - h_x, y + h_y) ' \
275+
+ '+ w_f_f_dy2_m1_2(x, y)*f(t, x - h_x, y + 2*h_y) ' \
276+
+ '+ w_f_f_dy2_m1_m1(x, y)*f(t, x - h_x, y - h_y) ' \
277+
+ '+ w_f_f_dy2_m1_m2(x, y)*f(t, x - h_x, y - 2*h_y) ' \
278+
+ '+ w_f_f_dy2_m2_0(x, y)*f(t, x - 2*h_x, y) ' \
279+
+ '+ w_f_f_dy2_m2_1(x, y)*f(t, x - 2*h_x, y + h_y) ' \
280+
+ '+ w_f_f_dy2_m2_m1(x, y)*f(t, x - 2*h_x, y - h_y)'
281281

282282
assert str(subs.expr) == ans
283283

0 commit comments

Comments
 (0)