Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: Fix custom fd for staggered #2323

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions devito/finite_differences/coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def index(self):
The dimension to which the coefficients will be applied plus the offset
in that dimension if the function is staggered.
"""
return self._function.indices_ref[self._dimension]
return self._dimension

@property
def weights(self):
Expand Down Expand Up @@ -268,7 +268,6 @@ def generate_subs(deriv_order, function, index):
return subs

# Determine which 'rules' are missing

sym = get_sym(functions)
terms = obj.find(sym)
for i in obj.find(Weights):
Expand Down Expand Up @@ -304,10 +303,12 @@ def generate_subs(deriv_order, function, index):
try:
for k, v in subs.rules.items():
ofs, do, f, d = k.args
if deriv_order == do and dim is d and f in expr._functions:
mapper[k.func(ofs, do, expr, d)] = v
is_dim = dim == expr.indices_ref[d]
if deriv_order == do and is_dim and f in expr._functions:
mapper[k.func(ofs, do, expr, expr.indices_ref[d])] = v
except AttributeError:
assert subs is None
# assert subs is None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover, but gonna merge for now

pass

if mapper:
rules.update(mapper)
Expand Down
22 changes: 21 additions & 1 deletion tests/test_symbolic_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ def test_staggered_array(self, order):
eq_f = Eq(f, f.dx2, coefficients=Substitutions(coeffs_f))
eq_g = Eq(g, g.dx2, coefficients=Substitutions(coeffs_g))

Operator([eq_f, eq_g])()
op = Operator([eq_f, eq_g])
op()

assert np.allclose(f.data, g.data, atol=1e-7)

Expand Down Expand Up @@ -303,6 +304,25 @@ def test_staggered_function(self, order):

assert np.allclose(f.data, g.data, atol=1e-7)

def test_staggered_function_evalat(self):
grid = Grid(shape=(11,), extent=(10.,))
x = grid.dimensions[0]

f = Function(name='f', grid=grid, space_order=2,
coefficients='symbolic')
g = Function(name='g', grid=grid, space_order=2,
coefficients='symbolic', staggered=x)

w = Function(name='w', space_order=0, shape=(3,),
dimensions=(Dimension("p"),))
coeffs_g = Coefficient(2, g, x, w)

eq_fg = Eq(f, g.dx2, coefficients=Substitutions(coeffs_g))

expected = 'Eq(f(x), g(x - h_x/2)*w[0] + g(x + h_x/2)*w[1])'

assert str(eq_fg.evaluate) == expected

def test_staggered_equation(self):
"""
Check that expressions with substitutions are consistent with
Expand Down
Loading