@@ -34,6 +34,29 @@ def wrapper(interp, *args, **kwargs):
3434 return wrapper
3535
3636
37+ def check_coords (func ):
38+ @wraps (func )
39+ def wrapper (interp , * args , ** kwargs ):
40+ inputs = args + as_tuple (kwargs .get ('expr' , ()))
41+ # Subfunction of the SparseFunction use to create the interpolator
42+ sfunc = interp .sfunction
43+ # Subfunctions found in the arguments of the interpolation/injection operation
44+ a_sfuncs = {f for f in retrieve_functions (inputs )
45+ if f .is_SparseFunction } - {sfunc }
46+ if a_sfuncs :
47+ # Check that is uses the same coordinates as the interpolator's SparseFunction
48+ subfuncs = {getattr (sfunc , s , None ) for s in sfunc ._sub_functions }
49+ for f in a_sfuncs :
50+ for s in f ._sub_functions :
51+ if getattr (f , s , None ) not in subfuncs :
52+ raise ValueError (f"Interpolation/injection with { sfunc } "
53+ f"requires { f } "
54+ f"to use the same { s } as { sfunc } " )
55+
56+ return func (interp , * args , ** kwargs )
57+ return wrapper
58+
59+
3760def _extract_subdomain (variables ):
3861 """
3962 Check if any of the variables provided are defined on a SubDomain
@@ -322,6 +345,7 @@ def _interp_idx(self, variables, implicit_dims=None, pos_only=(), subdomain=None
322345 return idx_subs , temps
323346
324347 @check_radius
348+ @check_coords
325349 def interpolate (self , expr , increment = False , self_subs = None , implicit_dims = None ):
326350 """
327351 Generate equations interpolating an arbitrary expression into ``self``.
@@ -342,6 +366,7 @@ def interpolate(self, expr, increment=False, self_subs=None, implicit_dims=None)
342366 return Interpolation (expr , increment , implicit_dims , self_subs , self )
343367
344368 @check_radius
369+ @check_coords
345370 def inject (self , field , expr , implicit_dims = None ):
346371 """
347372 Generate equations injecting an arbitrary expression into a field.
0 commit comments