|
1 | | -import sympy |
2 | 1 | import numpy as np |
3 | 2 | from cached_property import cached_property |
4 | 3 |
|
5 | 4 | from devito.finite_differences import generate_indices |
| 5 | +from devito.finite_differences.tools import numeric_weights, symbolic_weights |
6 | 6 | from devito.tools import filter_ordered, as_tuple |
7 | 7 |
|
8 | 8 | __all__ = ['Coefficient', 'Substitutions', 'default_rules'] |
@@ -245,15 +245,25 @@ def generate_subs(deriv_order, function, index): |
245 | 245 | subs = {} |
246 | 246 |
|
247 | 247 | mapper = {dim: index} |
| 248 | + # Get full range of indices and weights |
| 249 | + indices, x0 = generate_indices(function, dim, |
| 250 | + fd_order, side=None, x0=mapper) |
| 251 | + sweights = symbolic_weights(function, deriv_order, indices, x0) |
| 252 | + |
| 253 | + # Actual FD used indices and weights |
| 254 | + if deriv_order == 1 and fd_order == 2: |
| 255 | + fd_order = 1 |
248 | 256 |
|
249 | 257 | indices, x0 = generate_indices(function, dim, |
250 | 258 | fd_order, side=None, x0=mapper) |
251 | 259 |
|
252 | | - coeffs = sympy.finite_diff_weights(deriv_order, indices, x0)[-1][-1] |
| 260 | + coeffs = numeric_weights(deriv_order, indices, x0) |
| 261 | + |
| 262 | + for (c, i) in zip(coeffs, indices): |
| 263 | + subs.update({function._coeff_symbol(i, deriv_order, function, index): c}) |
253 | 264 |
|
254 | | - for j in range(len(coeffs)): |
255 | | - subs.update({function._coeff_symbol |
256 | | - (indices[j], deriv_order, function, index): coeffs[j]}) |
| 265 | + # Set all unused weights to zero |
| 266 | + subs.update({w: 0 for w in sweights if w not in subs}) |
257 | 267 |
|
258 | 268 | return subs |
259 | 269 |
|
|
0 commit comments