-
Notifications
You must be signed in to change notification settings - Fork 199
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
Implement linear interpolation for both cell-centered and nodal data types #3638
Implement linear interpolation for both cell-centered and nodal data types #3638
Conversation
Closing and re-opening to trigger CI. |
Source/Parallelization/WarpXComm_K.H
Outdated
wj = (sj == 0) ? 1.0_rt : (rj - amrex::Math::abs(j - (jc + jj) * rj)) | ||
wj = (sj == 0) ? (rj - amrex::Math::abs(j + 0.5 - (jc + jj + 0.5) * rj)) | ||
/ static_cast<amrex::Real>(rj) | ||
: (rj - amrex::Math::abs(j - (jc + jj) * rj)) | ||
/ static_cast<amrex::Real>(rj); | ||
wk = (sk == 0) ? 1.0_rt : (rk - amrex::Math::abs(k - (kc + kk) * rk)) | ||
wk = (sk == 0) ? (rk - amrex::Math::abs(k + 0.5 - (kc + kk + 0.5) * rk)) | ||
/ static_cast<amrex::Real>(rk) | ||
: (rk - amrex::Math::abs(k - (kc + kk) * rk)) | ||
/ static_cast<amrex::Real>(rk); | ||
wl = (sl == 0) ? 1.0_rt : (rl - amrex::Math::abs(l - (lc + ll) * rl)) | ||
wl = (sl == 0) ? (rl - amrex::Math::abs(l + 0.5 - (lc + ll + 0.5) * rl)) | ||
/ static_cast<amrex::Real>(rl) | ||
: (rl - amrex::Math::abs(l - (lc + ll) * rl)) |
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.
What do you think about aligning the code in the following way? I feel like it'd make it quite more readable (it doesn't matter too much if we go over 100 characters in these few lines):
wj = (sj == 0) ? (rj - amrex::Math::abs(j + 0.5_rt - (jc + jj + 0.5_rt) * rj)) / static_cast<amrex::Real>(rj)
: (rj - amrex::Math::abs(j - (jc + jj ) * rj)) / static_cast<amrex::Real>(rj);
wk = (sk == 0) ? (rk - amrex::Math::abs(k + 0.5_rt - (kc + kk + 0.5_rt) * rk)) / static_cast<amrex::Real>(rk)
: (rk - amrex::Math::abs(k - (kc + kk ) * rk)) / static_cast<amrex::Real>(rk);
wl = (sl == 0) ? (rl - amrex::Math::abs(l + 0.5_rt - (lc + ll + 0.5_rt) * rl)) / static_cast<amrex::Real>(rl)
: (rl - amrex::Math::abs(l - (lc + ll ) * rl)) / static_cast<amrex::Real>(rl);
Please remember to add the _rt
suffix to the real constants, too.
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.
Yes, that looks better. Thanks, @EZoni !
for more information, see https://pre-commit.ci
Co-authored-by: Edoardo Zoni <59625522+EZoni@users.noreply.github.com>
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.
Thank you for this PR, @prkkumar! I reset the CI benchmarks, obviously almost all of those using MR needed to be reset. I also commented one last suggestion on the interpolation function, let me know what you think.
Source/Parallelization/WarpXComm_K.H
Outdated
wj = (sj == 0) ? (rj - amrex::Math::abs(j + 0.5_rt - (jc + jj + 0.5_rt) * rj)) / static_cast<amrex::Real>(rj) | ||
: (rj - amrex::Math::abs(j - (jc + jj ) * rj)) / static_cast<amrex::Real>(rj); | ||
wk = (sk == 0) ? (rk - amrex::Math::abs(k + 0.5_rt - (kc + kk + 0.5_rt) * rk)) / static_cast<amrex::Real>(rk) | ||
: (rk - amrex::Math::abs(k - (kc + kk ) * rk)) / static_cast<amrex::Real>(rk); | ||
wl = (sl == 0) ? (rl - amrex::Math::abs(l + 0.5_rt - (lc + ll + 0.5_rt) * rl)) / static_cast<amrex::Real>(rl) | ||
: (rl - amrex::Math::abs(l - (lc + ll ) * rl)) / static_cast<amrex::Real>(rl); |
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.
At this point, I wonder if it would be slightly better to remove the if
conditions on sj
, sk
and sl
from these nested loops, and have them only once instead, before the loops. sj
, sk
and sl
do not vary depending on jj
, kk
and ll
, so in principle there would be no need to check them within these nested loops.
I think we could do something like the following:
wj = (rj - amrex::Math::abs(j + hj - (jc + jj + hj) * rj)) / static_cast<amrex::Real>(rj);
wk = (rk - amrex::Math::abs(k + hk - (kc + kk + hk) * rk)) / static_cast<amrex::Real>(rk);
wl = (rl - amrex::Math::abs(l + hl - (lc + ll + hl) * rl)) / static_cast<amrex::Real>(rl);
where hj
, hk
and hl
are defined, before the nested loops, as
amrex::Real hj = (sj == 0) ? 0.5_rt : 0._rt;
amrex::Real hk = (sk == 0) ? 0.5_rt : 0._rt;
amrex::Real hl = (sl == 0) ? 0.5_rt : 0._rt;
What do you think?
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.
yes, I like it this way. Thank you! I will make the change and push it. Also, thank you for resetting the CI benchmarks!
This PR implements linear interpolation for both cell-centered and nodal arrays. Before this, we were doing nearest grid point interpolation for cell-centered directions, which was resulting in "stair-casing" in the
aux
field. This effect was particularly intensified with larger mesh refinement ratio (e.g. 4).