Skip to content
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

make Redistribute() and other ParticleContainer functions virtual? #4275

Open
BenWibking opened this issue Dec 20, 2024 · 5 comments
Open

make Redistribute() and other ParticleContainer functions virtual? #4275

BenWibking opened this issue Dec 20, 2024 · 5 comments
Assignees

Comments

@BenWibking
Copy link
Contributor

BenWibking commented Dec 20, 2024

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()
@WeiqunZhang
Copy link
Member

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.

@BenWibking
Copy link
Contributor Author

BenWibking commented Dec 20, 2024

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.

@WeiqunZhang
Copy link
Member

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.

@BenWibking
Copy link
Contributor Author

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.

@BenWibking
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants