-
Notifications
You must be signed in to change notification settings - Fork 13
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
add MultiFabRegister / ParticleContainerRegister classes #748
Comments
This will allow us to split |
Also, this will allow us to split the |
For reference, this is the WarpX PR for its equivalent |
Just following up on our call, my idea is that a particle type is defined by something like the following class:
Then we have |
This makes sense to me.
So my preferred version of this object is:
Then, the |
Note that function calls to neither virtual functions nor |
Agreed: the idea is that these functions would themselves contain the on-GPU loops, rather than being called from within them. The general API should probably provide access to the full state vector. We may also need to think a bit about how to generalize this with respect to time stepping. I was thinking that these functions would be called in the Strang split stage, but for some things -- particularly tracer particles -- you might want to call them during the hydro update itself and have access to intermediate quantities like the outputs of the Riemann solvers. Not sure there is a really general way to do that. |
Tracer particles could actually be handled in a split way. For second order accuracy, they only need to be advected with the Riemann solver velocity averaged over the hydro step. Currently, this is handled within the hydro update itself, because we don't average the Riemann solver velocity over multiple timesteps when the retry mechanism is triggered. If we propertly average the face-centered velocities over time (including retry substeps), then we can advect the tracer particles in a separate function. Strictly speaking, we need to do that anyway in order to provide the correct boundary conditions for the tracer particle velocities on refined AMR levels (since the coarser levels could have had retries triggered). Edit: I think the tracer velocity boundary conditions are not correct currently when we are doing AMR subcycling in time. This is a somewhat tricky issue to fix. |
I think all of the particle interactions can be handled in a split way. |
Great, then no problem at will the design. We can just put a loop in the |
I finished a first version of this design: #820 . It's working great for CICParticles and RadParticles. I did this before even reading your comments on Dec 12, so I haven't thought about time stepping yet. |
I'm using |
Both of you talked about NeighborParticleContainer; do you mean |
This is the class we mean: https://amrex-codes.github.io/amrex/doxygen/classamrex_1_1NeighborParticleContainer.html. |
OK, I found it. Turns out it's because my vscode is ignore amrex in earch: |
Can't use Neighbor Particles right now because we need |
No, this is bad. Void pointers are unsafe and should never be used. You should use a std::unique_ptr to the base class. Casting to/from the derived to base class pointer type with dynamic_cast is safe. |
Spoken like a modern-day C++ object-oriented coward! When I learned programming it was in C, and we didn't bother with "safety". We just accessed raw memory like Real Men! ;-) |
The C++ Core Guidelines are worth reading. They are written by real C++ experts (many of whom wrote the C++ standard), not an LLM. Guideline C.146 says:
See https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c146-use-dynamic_cast-where-class-hierarchy-navigation-is-unavoidable for more details. |
Describe the proposal
We often need to do the same set of operations over all
MultiFab
s andParticleContainer
s, but C++ doesn't provide a capability to iterate over all of the member variables in a class, so we have to hard code them. However, can instead dynamically allocate MultiFabs and keep track of a list of all of the MultiFabs ourselves.WarpX does this with its
MultiFabRegister
. This creates an object that behaves like a dictionary (e.g., in Python), where we can access (or create) the MultiFabs with a string, and also loop over all of them with an iterator.We also need to do this with particle containers, since we may have many particle containers, and we don't want to hard code everywhere we need to redistribute particles, write them to disk, etc., for each particle container individually.
If we need to use the MultiFabs inside a
amrex::ParallelFor
kernel, we just get a reference to the MultiFab from the MultiFabManager while outside the ParallelFor, and from then on, use it as we normally would.Describe alternatives you've considered
Keep as-is. If we need to loop over all MultiFabs or ParticleContainers, we do it manually.
Additional context
https://github.com/ECP-WarpX/WarpX/blob/fb9e7dd1a2946c1f293cd25f2061d78cf5d1d71f/Source/ablastr/fields/MultiFabRegister.H#L156
The text was updated successfully, but these errors were encountered: