From 5f4bc51e2b88d1800fb0eb12621742fe3084986d Mon Sep 17 00:00:00 2001 From: mloubout Date: Sat, 9 Mar 2024 21:46:32 -0500 Subject: [PATCH] api: fix symbolic indices with stagger --- devito/finite_differences/tools.py | 6 +++++- examples/seismic/elastic/elastic_example.py | 2 +- examples/seismic/viscoelastic/viscoelastic_example.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/devito/finite_differences/tools.py b/devito/finite_differences/tools.py index be5b94d51f2..14910aee90d 100644 --- a/devito/finite_differences/tools.py +++ b/devito/finite_differences/tools.py @@ -374,7 +374,10 @@ def generate_indices_staggered(expr, dim, order, side=None, x0=None): indices = [start, start - diff] indices = IndexSet(dim, indices) else: - if start is dim: + if x0 is None or order % 2 == 0: + o_min = -order//2 + o_max = order//2 + elif start is dim: o_min = -order//2 + 1 o_max = order//2 start = dim + diff/2 @@ -382,6 +385,7 @@ def generate_indices_staggered(expr, dim, order, side=None, x0=None): o_min = -order//2 o_max = order//2 - 1 start = dim + d = make_stencil_dimension(expr, o_min, o_max) iexpr = ind0 + d * diff indices = IndexSet(dim, expr=iexpr) diff --git a/examples/seismic/elastic/elastic_example.py b/examples/seismic/elastic/elastic_example.py index bc2d56af9af..f025c36d722 100644 --- a/examples/seismic/elastic/elastic_example.py +++ b/examples/seismic/elastic/elastic_example.py @@ -37,7 +37,7 @@ def run(shape=(50, 50), spacing=(20.0, 20.0), tn=1000.0, def test_elastic(dtype): _, _, _, [rec1, rec2, v, tau] = run(dtype=dtype) assert np.isclose(norm(rec1), 19.25636, atol=1e-3, rtol=0) - assert np.isclose(norm(rec2), 0.644412, atol=1e-3, rtol=0) + assert np.isclose(norm(rec2), 0.6276, atol=1e-3, rtol=0) @pytest.mark.parametrize('shape', [(51, 51), (16, 16, 16)]) diff --git a/examples/seismic/viscoelastic/viscoelastic_example.py b/examples/seismic/viscoelastic/viscoelastic_example.py index 045aef18000..05e39ac4882 100644 --- a/examples/seismic/viscoelastic/viscoelastic_example.py +++ b/examples/seismic/viscoelastic/viscoelastic_example.py @@ -39,7 +39,7 @@ def run(shape=(50, 50), spacing=(20.0, 20.0), tn=1000.0, def test_viscoelastic(dtype): _, _, _, [rec1, rec2, v, tau] = run(dtype=dtype) assert np.isclose(norm(rec1), 12.28040, atol=1e-3, rtol=0) - assert np.isclose(norm(rec2), 0.320738, atol=1e-3, rtol=0) + assert np.isclose(norm(rec2), 0.312462, atol=1e-3, rtol=0) @pytest.mark.parametrize('shape', [(51, 51), (16, 16, 16)])