Skip to content

Commit

Permalink
Merge pull request #28 from devitocodes/1d_nd_notebook
Browse files Browse the repository at this point in the history
examples: Update 1D vs ND comparison to reflect revisions
  • Loading branch information
EdCaunt authored Feb 27, 2024
2 parents b8dee1e + a7c9cd7 commit 3991446
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 80 deletions.
151 changes: 95 additions & 56 deletions examples/7_1D_vs_ND_comparison.ipynb

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions tests/test_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
9 changes: 6 additions & 3 deletions tests/test_boundary_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
42 changes: 21 additions & 21 deletions tests/test_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3991446

Please sign in to comment.