Add the option for particle RF phase-wrapping#1380
Add the option for particle RF phase-wrapping#1380cemitch99 wants to merge 151 commits intoBLAST-ImpactX:developmentfrom
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
| std::list<std::unordered_map<std::string, amrex::ParticleReal> > m_beam_moments; | ||
|
|
||
| //! the RF bucket length for particles in the particle container | ||
| amrex::ParticleReal m_bucket_length; |
There was a problem hiding this comment.
I would store this as std::optional so it is clear when this is thought to be undefined/None:
| amrex::ParticleReal m_bucket_length; | |
| std::optional<amrex::ParticleReal> m_bucket_length; |
Maybe even store like store_beam_moments as a public member and document that instead.
| amrex::ParmParse pp_algo("algo"); | ||
| std::string particle_bc = "open"; | ||
| pp_algo.queryAdd("particle_bc", particle_bc); | ||
| int particle_bc_int; |
There was a problem hiding this comment.
Good case for an enum, in our case we can use AMREX_ENUM that supports string conversion.
There was a problem hiding this comment.
Yes, thanks; I will revisit here.
| } else if (particle_bc == "reflecting") { | ||
| particle_bc_int = 3; | ||
| } else { | ||
| particle_bc_int = 0; |
There was a problem hiding this comment.
Logic bug: else seems to imply open, but open already returned above.
Usability: we should throw an error if an unknown other BC is set than the ones we know/handle. (This does not prevent handling no input as open by default.)
There was a problem hiding this comment.
Agreed; will replace this line with an error message.
| // Gather particles and apply boundary condition | ||
| amrex::ParallelFor(np, [=] AMREX_GPU_DEVICE (int i) | ||
| { | ||
| // Access SoA Real data | ||
| amrex::ParticleReal & AMREX_RESTRICT t = part_t[i]; | ||
| amrex::ParticleReal & AMREX_RESTRICT pt = part_pt[i]; | ||
|
|
||
| if (particle_bc_int==1) { | ||
|
|
||
| // Periodic particle boundary condition: apply phase wrapping in t (modulo bucket_duration): | ||
| amrex::ParticleReal ttest = std::fmod(t+bucket_half_duration, bucket_duration); | ||
| t = (bucket_duration != 0.0)? std::fmod(ttest+bucket_duration, bucket_duration)-bucket_half_duration : t; |
There was a problem hiding this comment.
Suggestion: we can write the if/switch on the enum particle_bc_int outside the amrex::ParallelFor and create 3 unique, performant ParallelFor kernels; instead of one branching (slow) one.
There was a problem hiding this comment.
Oh, I thought about branching outside the ParallelFor, but it introduces a lot of duplication. It's ok with me to rework things this way if there is an expected performance advantage.
|
|
||
| namespace impactx::particles | ||
| { | ||
| /** Function to apply longitudinal particle boundary (periodic, etc.) |
There was a problem hiding this comment.
Add the AMREX_ENUM on the types of boundaries we have here.
| amrex::ParmParse pp_algo("algo"); | ||
| std::string particle_bc = "open"; |
There was a problem hiding this comment.
This feel like something we could set on beam.[...] was well... (probably need to generalize the section heading here)
But no super strong opinion.
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
| std::list<std::unordered_map<std::string, amrex::ParticleReal> > m_beam_moments; | ||
|
|
||
| //! the RF bucket length for particles in the particle container | ||
| std::optional<amrex::ParticleReal> m_bucket_length; |
There was a problem hiding this comment.
@ax3l Making this optional is introducing build problems that are taking time to fix. Reverting to the previous behavior for now.
There was a problem hiding this comment.
Oh yes, I just drafted the implementation. I can do it when the PR is ready from your end.
Co-authored-by: Chad Mitchell <46825199+cemitch99@users.noreply.github.com>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
| if (particle_bc == "periodic") { | ||
| particle_bc_int = 1; | ||
| } else if (particle_bc == "absorbing") { |
There was a problem hiding this comment.
memo for @ax3l : use AMREX_ENUM (define in ParticleBoundary.H)
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
This PR adds the capability of applying particle boundary conditions, related to the RF bucket (for example, wrapping particles modulo 2pi in RF phase).
Longitudinal particle boundary condition options to target: