-
Notifications
You must be signed in to change notification settings - Fork 256
Interp enforce coords #2884
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
Interp enforce coords #2884
Changes from all commits
6ded0a0
56d4626
1745806
19abed3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,29 @@ def wrapper(interp, *args, **kwargs): | |
| return wrapper | ||
|
|
||
|
|
||
| def check_coords(func): | ||
| @wraps(func) | ||
| def wrapper(interp, *args, **kwargs): | ||
| inputs = args + as_tuple(kwargs.get('expr', ())) | ||
| # Subfunction of the SparseFunction use to create the interpolator | ||
| sfunc = interp.sfunction | ||
| # Subfunctions found in the arguments of the interpolation/injection operation | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SubFunctions |
||
| a_sfuncs = {f for f in retrieve_functions(inputs) | ||
| if f.is_SparseFunction} - {sfunc} | ||
| if a_sfuncs: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to avoid one nesting level, I suggest to return early and de-indent (ultra-nitpick) |
||
| # Check that is uses the same coordinates as the interpolator's SparseFunction | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
| subfuncs = {getattr(sfunc, s, None) for s in sfunc._sub_functions} | ||
| for f in a_sfuncs: | ||
| for s in f._sub_functions: | ||
| if getattr(f, s, None) not in subfuncs: | ||
| raise ValueError(f"Interpolation/injection with {sfunc}" | ||
| f"requires {f} " | ||
| f"to use the same {s} as {sfunc}") | ||
|
|
||
| return func(interp, *args, **kwargs) | ||
| return wrapper | ||
|
|
||
|
|
||
| def _extract_subdomain(variables): | ||
| """ | ||
| 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 | |
| return idx_subs, temps | ||
|
|
||
| @check_radius | ||
| @check_coords | ||
| def interpolate(self, expr, increment=False, self_subs=None, implicit_dims=None): | ||
| """ | ||
| Generate equations interpolating an arbitrary expression into ``self``. | ||
|
|
@@ -342,6 +366,7 @@ def interpolate(self, expr, increment=False, self_subs=None, implicit_dims=None) | |
| return Interpolation(expr, increment, implicit_dims, self_subs, self) | ||
|
|
||
| @check_radius | ||
| @check_coords | ||
| def inject(self, field, expr, implicit_dims=None): | ||
| """ | ||
| Generate equations injecting an arbitrary expression into a field. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use some blank lines here