@@ -1167,12 +1167,16 @@ def _evaluate(self, **kwargs):
11671167 # Apply interpolation from inner most dim
11681168 for d , i in self ._grid_map .items ():
11691169 retval = retval .diff (d , deriv_order = 0 , fd_order = 2 , x0 = {d : i })
1170- if self ._avg_mode == 'harmonic' :
1171- retval = 1 / retval
11721170
11731171 # Evaluate. Since we used `self.function` it will be on the grid when evaluate
11741172 # is called again within FD
1175- return retval .evaluate .expand ()
1173+ if self ._avg_mode == 'harmonic' :
1174+ from devito .finite_differences .differentiable import SafeInv
1175+ retval = SafeInv (retval .evaluate , self .function )
1176+ else :
1177+ retval = retval .evaluate
1178+
1179+ return retval
11761180
11771181 @property
11781182 def shape (self ):
@@ -1450,12 +1454,19 @@ def indexify(self, indices=None, subs=None):
14501454 # Indices after substitutions
14511455 indices = []
14521456 for a , d , o , s in zip (self .args , self .dimensions , self .origin , subs ):
1453- if d in a .free_symbols :
1457+ if a .is_Function and len (a .args ) == 1 :
1458+ # E.g. Abs(expr)
1459+ arg = a .args [0 ]
1460+ func = a .func
1461+ else :
1462+ arg = a
1463+ func = lambda x : x
1464+ if d in arg .free_symbols :
14541465 # Shift by origin d -> d - o.
1455- indices .append (sympy .sympify (a .subs (d , d - o ).xreplace (s )))
1466+ indices .append (func ( sympy .sympify (arg .subs (d , d - o ).xreplace (s ) )))
14561467 else :
14571468 # Dimension has been removed, e.g. u[10], plain shift by origin
1458- indices .append (sympy .sympify (a - o ).xreplace (s ))
1469+ indices .append (func ( sympy .sympify (arg - o ).xreplace (s ) ))
14591470
14601471 indices = [i .xreplace ({k : sympy .Integer (k ) for k in i .atoms (sympy .Float )})
14611472 for i in indices ]
0 commit comments