make `Redistribute()` and other ParticleContainer functions virtual?
Opened this issue · 5 comments
We would like to have a container all of ParticleContainers in our simulation, e.g. std::map<std::string, amrex::ParticleContainerBase*>
.
Then we want to be able iterate over this container and invoke base_ptr->Redistribute()
. Currently, this is not possible because Redistribute()
is not virtual. We have to explicitly do, e.g., dynamic_cast<AmrParticleContainer*>(base_ptr)->Redistribute()
. Since we have to know what derived ParticleContainer to cast it to, we need to duplicate a lot of code to do the casts for all possible cases.
The functions of interest are:
Redistribute()
WritePlotFile()
Checkpoint()
Are those the only functions you call? That cannot be the case, right? So how do you plan to call other functions. It might be too much to turn the union of all particle containers' functions virtual.
Are those the only functions you call? That cannot be the case, right? So how do you plan to call other functions. It might be too much to turn the union of all particle containers' functions virtual.
No, we call other functions. But those are the only functions we call for all particle containers. For other functions, there is at least one particle container for which it does not make sense to call it. So for those cases, we need to do something special anyway. These are just the ones that would eliminate boilerplate code if they were virtual.
I am not saying it does not make sense to make those functions virtual. I am just saying it can be worked around. I assume you do have a way to get the derived type of a base pointer. Maybe you use the string to obtain the derived type. Whatever you do, in principle, you could do that for Redistribute too.
I am not saying it does not make sense to make those functions virtual. I am just saying it can be worked around. I assume you do have a way to get the derived type of a base pointer. Maybe you use the string to obtain the derived type. Whatever you do, in principle, you could do that for Redistribute too.
Yes, we can do that for now.
We do implicitly depend on the member functions called by amrex::ParticleToMesh
as well, since we pass a pointer to the particle container to that. But we can dynamic_cast that pointer before passing it as an argument for now.