Skip to content

Commit

Permalink
dsl: tweak to staggered indices generation for intuitive mapping of c…
Browse files Browse the repository at this point in the history
…ustom coefficcients onto stencils
  • Loading branch information
EdCaunt committed Mar 23, 2021
1 parent ef19c4a commit 89d28b6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions devito/finite_differences/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,22 @@ def generate_indices_staggered(func, dim, order, side=None, x0=None):
except AttributeError:
ind0 = start
if start != ind0:
ind = [start - diff/2 - i * diff for i in range(0, order//2)][::-1]
ind += [start + diff/2 + i * diff for i in range(0, order//2)]
# Need to extend range by one depending on stagger direction
# This is for symbolic coefficients only to ensure intutitive mapping
# of user-specified coefficients onto stencils
if func.coefficients == 'symbolic':
stagger_dir = np.sign((start-ind0).subs(diff, 1))
# If start - ind0 is negative then need to add one to upper end
if stagger_dir == -1:
ind = [start - diff/2 - i * diff for i in range(0, order//2)][::-1]
ind += [start + diff/2 + i * diff for i in range(0, order//2+1)]
# If start - ind0 is positive then need to add one to lower end
elif stagger_dir == 1:
ind = [start - diff/2 - i * diff for i in range(0, order//2+1)][::-1]
ind += [start + diff/2 + i * diff for i in range(0, order//2)]
else:
ind = [start - diff/2 - i * diff for i in range(0, order//2)][::-1]
ind += [start + diff/2 + i * diff for i in range(0, order//2)]
if order < 2:
ind = [start - diff/2, start + diff/2]
else:
Expand Down

0 comments on commit 89d28b6

Please sign in to comment.