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

Introduce HandleSpacecharge #842

Merged
merged 2 commits into from
Feb 12, 2025

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Feb 11, 2025

Similar to our HandleWakefield logic for particle tracking, this simplifies the central particle tracking loop by cleanly hiding implementation details in a separate function.

Similar to our `HandleWakefield` logic for particle tracking,
this simplifies the central particle tracking loop by cleanly
hiding implementation details in a separate function.
@ax3l ax3l added the component: space charge Space charge & potential solver label Feb 11, 2025
@ax3l ax3l requested a review from cemitch99 February 11, 2025 01:29
Comment on lines 113 to +115

// Space-charge calculation: turn off if there is only 1 particle
if (space_charge &&
amr_data->track_particles.m_particle_container->TotalNumberOfParticles(true, false)) {

// transform from x',y',t to x,y,z
transformation::CoordinateTransformation(
*amr_data->track_particles.m_particle_container,
CoordSystem::t);

// Note: The following operation assume that
// the particles are in x, y, z coordinates.

// Resize the mesh, based on `m_particle_container` extent
ResizeMesh();

// Redistribute particles in the new mesh in x, y, z
amr_data->track_particles.m_particle_container->Redistribute();

// charge deposition
amr_data->track_particles.m_particle_container->DepositCharge(
amr_data->track_particles.m_rho,
amr_data->refRatio()
);

// poisson solve in x,y,z
spacecharge::PoissonSolve(
*amr_data->track_particles.m_particle_container,
amr_data->track_particles.m_rho,
amr_data->track_particles.m_phi,
amr_data->refRatio()
);

// calculate force in x,y,z
spacecharge::ForceFromSelfFields(
amr_data->track_particles.m_space_charge_field,
amr_data->track_particles.m_phi,
amr_data->Geom()
);

// gather and space-charge push in x,y,z , assuming the space-charge
// field is the same before/after transformation
// TODO: This is currently using linear order.
spacecharge::GatherAndPush(
*amr_data->track_particles.m_particle_container,
amr_data->track_particles.m_space_charge_field,
amr_data->Geom(),
slice_ds
);

// transform from x,y,z to x',y',t
transformation::CoordinateTransformation(
*amr_data->track_particles.m_particle_container,
CoordSystem::s
);
}

// for later: original Impact implementation as an option
// Redistribute particles in x',y',t
// TODO: only needed if we want to gather and push space charge
// in x',y',t
// TODO: change geometry beforehand according to transformation
//m_particle_container->Redistribute();
//
// in original Impact, we gather and space-charge push in x',y',t ,
// assuming that the distribution did not change
// Space-charge calculation
particles::spacecharge::HandleSpacecharge(amr_data, [this](){ this->ResizeMesh(); }, slice_ds);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the location that this PR cleans up :)

Co-authored-by: Chad Mitchell <[email protected]>
@ax3l ax3l requested a review from cemitch99 February 11, 2025 23:10
@ax3l ax3l merged commit 5816acc into ECP-WarpX:development Feb 12, 2025
16 checks passed
@ax3l ax3l deleted the topic-handle-spacecharge branch February 12, 2025 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: space charge Space charge & potential solver
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants