From 46fee216d0cefe6339101c19c5da34033ddc2600 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 15 Jun 2017 11:21:52 +0100 Subject: [PATCH 1/3] Timestepping: Add forward-backward test with overlapping definitions --- tests/test_timestepping.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_timestepping.py b/tests/test_timestepping.py index 3dadf41919..fd7e996526 100644 --- a/tests/test_timestepping.py +++ b/tests/test_timestepping.py @@ -63,6 +63,7 @@ def test_forward_unroll(a, c, nt=5): def test_forward_backward(a, b, nt=5): + """Test a forward operator followed by a backward marching one""" a.data[0, :] = 1. b.data[0, :] = 1. eqn_a = Eq(a.forward, a + 1.) @@ -74,6 +75,22 @@ def test_forward_backward(a, b, nt=5): assert np.allclose(b.data[i, :], 2. + i, rtol=1.e-12) +def test_forward_backward_overlapping(a, b, nt=5): + """ + Test a forward operator followed by a backward one, but with + overlapping operator definitions. + """ + a.data[0, :] = 1. + b.data[0, :] = 1. + op_fwd = Operator(Eq(a.forward, a + 1.), time_axis=Forward) + op_bwd = Operator(Eq(b, a + 1.), time_axis=Backward) + + op_fwd(time=nt) + op_bwd(time=nt) + for i in range(nt): + assert np.allclose(b.data[i, :], 2. + i, rtol=1.e-12) + + def test_loop_bounds_forward(d): """Test the automatic bound detection for forward time loops""" d.data[:] = 1. From 0c6c6c50b8b6102b299122116e1c9f588a2fd63c Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 15 Jun 2017 11:28:46 +0100 Subject: [PATCH 2/3] Iteration: Store `reverse` flag, since it might change on the dimension This can create a bug where the direction of the `time` direction changes before code generation is invoked on the first operator, thus causing the iteration to use the wrong direction. --- devito/nodes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/devito/nodes.py b/devito/nodes.py index 21038d732b..178c8e987a 100644 --- a/devito/nodes.py +++ b/devito/nodes.py @@ -276,6 +276,9 @@ def __init__(self, nodes, dimension, limits, index=None, offsets=None, self.dim = dimension self.index = index or self.dim.name + # Store direction, as it might change on the dimension + # before we use it during code generation. + self.reverse = self.dim.reverse # Generate loop limits if isinstance(limits, Iterable): @@ -336,7 +339,7 @@ def ccode(self): end = self.limits[1] # For reverse dimensions flip loop bounds - if self.dim.reverse: + if self.reverse: loop_init = c.InlineInitializer(c.Value("int", self.index), ccode('%s - 1' % end)) loop_cond = '%s >= %s' % (self.index, ccode(start)) From 960784ca78fe0c505151a8a7d4af4c8bc7b83b39 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 15 Jun 2017 11:32:30 +0100 Subject: [PATCH 3/3] Timestepping: Drop `dle=None` and `dse=None` restrictions from tests --- tests/test_timestepping.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/test_timestepping.py b/tests/test_timestepping.py index fd7e996526..44b327e185 100644 --- a/tests/test_timestepping.py +++ b/tests/test_timestepping.py @@ -37,16 +37,14 @@ def d(shape=(11, 11)): def test_forward(a): a.data[0, :] = 1. - eqn = Eq(a.forward, a + 1.) - Operator(eqn, dle=None, dse=None)() + Operator(Eq(a.forward, a + 1.))() for i in range(a.shape[0]): assert np.allclose(a.data[i, :], 1. + i, rtol=1.e-12) def test_backward(b): b.data[-1, :] = 7. - eqn = Eq(b.backward, b - 1.) - Operator(eqn, dle=None, dse=None, time_axis=Backward)() + Operator(Eq(b.backward, b - 1.), time_axis=Backward)() for i in range(b.shape[0]): assert np.allclose(b.data[i, :], 2. + i, rtol=1.e-12) @@ -57,7 +55,7 @@ def test_forward_unroll(a, c, nt=5): c.data[0, :] = 1. eqn_c = Eq(c.forward, c + 1.) eqn_a = Eq(a.forward, c.forward) - Operator([eqn_c, eqn_a], dle=None, dse=None)(time=nt) + Operator([eqn_c, eqn_a])(time=nt) for i in range(nt): assert np.allclose(a.data[i, :], 1. + i, rtol=1.e-12) @@ -67,10 +65,10 @@ def test_forward_backward(a, b, nt=5): a.data[0, :] = 1. b.data[0, :] = 1. eqn_a = Eq(a.forward, a + 1.) - Operator(eqn_a, dle=None, dse=None, time_axis=Forward)(time=nt) + Operator(eqn_a, time_axis=Forward)(time=nt) eqn_b = Eq(b, a + 1.) - Operator(eqn_b, dle=None, dse=None, time_axis=Backward)(time=nt) + Operator(eqn_b, time_axis=Backward)(time=nt) for i in range(nt): assert np.allclose(b.data[i, :], 2. + i, rtol=1.e-12)