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

Output the potential phi on the macroparticles #4599

Merged
merged 30 commits into from
Apr 8, 2024

Conversation

RemiLehe
Copy link
Member

@RemiLehe RemiLehe commented Jan 10, 2024

This adds the option for the user to output the field phi on the macroparticles.

The fields are gathered after particles have been filtered for output. As a consequence, the particles are in pinned memory, when the gather kernel is called, which could be slow if this diagnostic is done frequently and/or on a large number of particles.

The automated test looks at the case of an electrostatic sphere exploding under its own space charge (Coulomb explosition). In this process, electrostatic potential energy (space charge) is converted into kinetic energy (explosion velocity). The test uses phi on the particles to compute the potential energy.

TODO in follow-up PRs:

  • Generalize to any field (on a staggered grid)
  • Implement arbitrary shape factors

@@ -548,48 +548,6 @@ for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) {
pinned_pc->make_alike<amrex::PinnedArenaAllocator>() :
pc->make_alike<amrex::PinnedArenaAllocator>();

// names of amrex::Real and int particle attributes in SoA data
Copy link
Member Author

@RemiLehe RemiLehe Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move this code further down, so that it comes after tmp.AddRealComp("phi");

(This is because the code below reads tmp.getParticleRuntimeComps(); and sets the output flags accordingly.)

@RemiLehe RemiLehe changed the title [WIP] Output the potential phi on the macroparticles Output the potential phi on the macroparticles Apr 8, 2024
Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - just a small separation of the functional block added into a function maybe? :)

"Output of the electrostatic potential (phi) on the particles was requested, "
"but this is only available with `diag_type = Full`.");
tmp.AddRealComp("phi");
tmp.defineAllParticleTiles();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should not be needed anymore as of AMReX 24.04 :)

Comment on lines +592 to +594
// Gather the electrostatic potential (phi) on the macroparticles
if ( particle_diags[i].m_plot_phi ) {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
Copy link
Member

@ax3l ax3l Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this if block a function call please so it does separate out nicely and does not make this sub-function longer? I would call it add_phi_component or so and also declare it in ParticleIO.H?

Source/Particles/ParticleIO.H Outdated Show resolved Hide resolved
@ax3l ax3l added component: openPMD openPMD I/O component: diagnostics all types of outputs labels Apr 8, 2024
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
for (int lev=0; lev<=warpx.finestLevel(); lev++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (int lev=0; lev<=warpx.finestLevel(); lev++) {
for (int lev=0; lev<=tmp.finestLevel(); lev++) {

const amrex::Geometry& geom = warpx.Geom(lev);
auto plo = geom.ProbLoArray();
auto dxi = geom.InvCellSizeArray();
amrex::MultiFab const& phi = warpx.getField( FieldType::phi_fp, lev, 0 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For less overhead, we should add a helper that returns an mf on all levels. -> follow-up pr

@ax3l ax3l enabled auto-merge (squash) April 8, 2024 22:19
@ax3l ax3l self-assigned this Apr 8, 2024
@ax3l ax3l merged commit b4ed706 into ECP-WarpX:development Apr 8, 2024
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: diagnostics all types of outputs component: openPMD openPMD I/O
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants