-
Notifications
You must be signed in to change notification settings - Fork 229
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
API: Support harmonic averaging for parameter Function #2456
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2456 +/- ##
==========================================
- Coverage 87.08% 87.06% -0.03%
==========================================
Files 238 238
Lines 45118 45171 +53
Branches 8408 8417 +9
==========================================
+ Hits 39291 39326 +35
- Misses 5094 5112 +18
Partials 733 733 ☔ View full report in Codecov by Sentry. |
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
devito/types/basic.py
Outdated
@@ -983,6 +983,11 @@ def __init_finalize__(self, *args, **kwargs): | |||
# certain optimizations, such as avoiding memory copies | |||
self._is_transient = kwargs.get('is_transient', False) | |||
|
|||
# Averaging mode for off the grid evaluation | |||
self._avg_mode = kwargs.get('avg_mode', 'arithmetic') | |||
assert self._avg_mode in ['arithmetic', 'harmonic'], "Accepted avg_mode " \ |
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.
this shouldn't be an assert, but rather a raise ValueError
devito/types/basic.py
Outdated
# Apply interpolation from inner most dim | ||
for d, i in self._grid_map.items(): | ||
retval = retval.diff(d, 0, fd_order=2, x0={d: i}) | ||
retval = retval.diff(d, deriv_order=0, fd_order=2, x0={d: i}).evaluate |
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.
Always a bit wary of these premature evaluations
# Evaluate. Since we used `self.function` it will be on the grid when evaluate | ||
# is called again within FD | ||
return retval.evaluate | ||
return retval.evaluate.expand() |
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.
why the need to expand ?
also, not that we're calling .evaluate
multiple times here -- above in the for d, i in self._grid_map
loop at each iteration, and then again here.
THere's something weird about this
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.
Without exapnd you get horrible stuff like 05*(0.5*(0.5 ... instead of 0.125.
This is a trivial square/cube averaging that should be a plain expression anything else is just messing up with the compiler for no reason
import pytest | ||
try: | ||
import pytest | ||
except: |
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.
nitpicking: All these imports should be except ImportError
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.
I thought we needed exactly the opposite?..e.g. pass
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.
???
devito/types/basic.py
Outdated
@@ -1147,13 +1152,16 @@ def _evaluate(self, **kwargs): | |||
return self | |||
|
|||
# Base function | |||
retval = self.function | |||
retval = 1 / self.function if self._avg_mode == 'harmonic' else self.function |
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.
nitpicking: for homogeneity with the rest of the codebase, it should be
if cond:
<then part>
else:
<else part>
even if it's a trivial code fragment. But again, nitpicking...
retval = retval.diff(d, deriv_order=0, fd_order=2, x0={d: i}).evaluate | ||
if self._avg_mode == 'harmonic': | ||
retval = 1 / retval | ||
|
||
# Evaluate. Since we used `self.function` it will be on the grid when evaluate |
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.
does this comment still apply?
e599547
to
1f13559
Compare
Needed for accurate elastic simulations
On top of #2455