@@ -34,6 +34,34 @@ 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+
42+ # SubFunction of the SparseFunction use to create the interpolator
43+ sfunc = interp .sfunction
44+
45+ # SubFunctions found in the arguments of the interpolation/injection operation
46+ a_sfuncs = {f for f in retrieve_functions (inputs )
47+ if f .is_SparseFunction } - {sfunc }
48+ if not a_sfuncs :
49+ # Only uses the the interpolator's SparseFunction, so no need to check
50+ return func (interp , * args , ** kwargs )
51+
52+ # Check that it uses the same coordinates as the interpolator's SparseFunction
53+ subfuncs = {getattr (sfunc , s , None ) for s in sfunc ._sub_functions }
54+ for f in a_sfuncs :
55+ for s in f ._sub_functions :
56+ if getattr (f , s , None ) not in subfuncs :
57+ raise ValueError (f"Interpolation/injection with { sfunc } "
58+ f"requires { f } "
59+ f"to use the same { s } as { sfunc } " )
60+
61+ return func (interp , * args , ** kwargs )
62+ return wrapper
63+
64+
3765def _extract_subdomain (variables ):
3866 """
3967 Check if any of the variables provided are defined on a SubDomain
@@ -322,6 +350,7 @@ def _interp_idx(self, variables, implicit_dims=None, pos_only=(), subdomain=None
322350 return idx_subs , temps
323351
324352 @check_radius
353+ @check_coords
325354 def interpolate (self , expr , increment = False , self_subs = None , implicit_dims = None ):
326355 """
327356 Generate equations interpolating an arbitrary expression into ``self``.
@@ -342,6 +371,7 @@ def interpolate(self, expr, increment=False, self_subs=None, implicit_dims=None)
342371 return Interpolation (expr , increment , implicit_dims , self_subs , self )
343372
344373 @check_radius
374+ @check_coords
345375 def inject (self , field , expr , implicit_dims = None ):
346376 """
347377 Generate equations injecting an arbitrary expression into a field.
0 commit comments