-
Notifications
You must be signed in to change notification settings - Fork 197
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
Function to get particle cell index. #5118
Function to get particle cell index. #5118
Conversation
Thanks for the PR, @archermarx! |
yes, done! |
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.
That looks splendid, thank you so much for this!
Double checking, I had to cast a few parameters to |
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.
Thanks for this cleanup! Just a couple small comments.
Co-authored-by: Roelof Groenewald <[email protected]>
Ok, I added an overload for the function when called on a |
CI is fixed for good now. Once adding the update from @roelof-groenewald , please rebase once more @archermarx . |
Co-authored-by: Roelof Groenewald <[email protected]>
Ok, made the requested changes and rebased |
Source/Utils/ParticleUtils.cpp
Outdated
static_cast<int>((p.pos(0)-plo[0])*dxi[0] - lo.x), | ||
static_cast<int>((p.pos(1)-plo[1])*dxi[1] - lo.y), | ||
static_cast<int>((p.pos(2)-plo[2])*dxi[2] - lo.z))}; | ||
return getParticleCell(p, plo, dxi, cbx); |
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 see most (maybe all) of the examples that involve sorting the particles per cell are still failing. Looking closer, I see that the current development
function here calculates the cell indices with
ii = (p.pos(0) - plo[0]) * dxi[0] - lo.x
whereas the AMReX function uses
ii = (p.pos(0) - plo[0]) * dxi[0] + cbx.smallend[0]
So the difference is that the development
version calculates a cell index starting from 0 for each tile whereas the AMReX function calculates a global cell index for the entire domain. It's not clear to me why this breaks the code though since the binning should only care about which particles have the same cell index, not about what the value of the indices are.
I'll look more into the current reason for the test failures but I also wanted to point out that the new utility function can be used in https://github.com/ECP-WarpX/WarpX/blob/development/Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp in a similar way as in the temperature diagnostic. |
OK, I can add it in there too |
Great! Those tests have been problematic for a while now (see #5132). After that PR is merged you can rebase and they should pass. |
Oh great, that's good to know! |
I would be okay to merge this since it already cleans up the code quite a bit, but we should be able to replace
with something like
where EDIT: On second thought, I like that second option. I'll go ahead and submit a PR to AMReX. |
That sounds good, and would let us eliminate a lot of code. For the version that takes positions instead of a particle type, is there a way we can delegate to |
I just pushed a version that uses your overload of |
## Summary In WarpX we have a few routines that requires the local cell index of particles (i.e. the cell number in the current box). The AMReX function `getParticleCell` currently only has logic to return the global cell index (relative to the domain low end). This PR adds a new overload for that function which does not shift the cell index based on the global box index. ## Additional background See ECP-WarpX/WarpX#5118 for WarpX context. ## Checklist The proposed changes: - [ ] fix a bug or incorrect behavior in AMReX - [x] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate
Ok, looks like that got merged into AMReX. Once we update AMReX for the week, this should work, I think |
@archermarx would you mind rebasing on development now that the AMReX version has been updated? |
Yes, will do in a moment
…On Tue, Aug 20, 2024, 5:22 PM Roelof Groenewald ***@***.***> wrote:
@archermarx <https://github.com/archermarx> would you mind rebasing on
development now that the AMReX version has been updated?
—
Reply to this email directly, view it on GitHub
<#5118 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOP3QGXQETHMM6DHSAVWLHDZSOXQ7AVCNFSM6AAAAABMFCQT66VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJZG44DQNRSGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
To fix some further redundancy, I have eliminated the new function entirely and just call the new overload of |
CI should pass now. I tried replacing the particle cell finding in |
Co-authored-by: Roelof Groenewald <[email protected]>
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.
Thanks for this PR! I think PRs that remove this many lines of code without altering functionality (or obscuring it) are really great!
const amrex::Real lz = (z - plo[2]) * dxi[2]; | ||
kk = static_cast<int>(amrex::Math::floor(lz)); | ||
#endif | ||
const auto [ii, jj, kk] = amrex::getParticleCell(p, plo, dxi).dim3(); |
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.
Ah, there is another branch, m_do_average
, below that can use the same functionality.
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.
Follow-up in #5557
Close #4977
This PR adds a function to get a particle's cell index to
ParticleUtils.H
, and uses it in bothParticleUtils.cpp
andTemperatureFunctor.cpp
.