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

Remove particles that are initialized in the EB #4585

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

RemiLehe
Copy link
Member

@RemiLehe RemiLehe commented Jan 6, 2024

The current version of WarpX allows particles to be created in the EB. (In that case, these particles only get removed at the end of the first timestep, which may be confusing to some users. For instance, these particles will appear in the diagnostics associated with t=0, and will deposit charge/current which can be seen in the diagnostic of rho/J.

This PR modifies the particle injection so that these particles can marked (with negative IDs) when they are created, and are removed by the next ReDistribute, which should in general occur before the beginning of the first timestep.

@RemiLehe RemiLehe changed the title [WIP] Remove particles that are initialized in the EB Remove particles that are initialized in the EB Jan 6, 2024
@@ -291,6 +294,12 @@ WarpXParticleContainer::AddNParticles (int /*lev*/, long n,
);
}

// Remove particles that are inside the embedded boundaries
Copy link
Member

Choose a reason for hiding this comment

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

This will work but will result in extra work setting up the particles that will be then removed.

Looking at what scrapeParticles is doing, the check for whether a particle is in the EB is a small bit of code and could easily be added in the loop adding the particles so any particles in the EB are immediately rejected. Would this be better?

                int ieb, jeb, keb;
                amrex::Real Web[AMREX_SPACEDIM][2];
                ablastr::particles::compute_weights_nodal(ppos.x, ppos.y, ppos.z, plo, dxi, ieb, jeb, keb, Web);
                amrex::Real phi_value = ablastr::particles::interp_field_nodal(ieb, jeb, keb, Web, phi);
                if (phi_value < 0.0) {
                    p.id() = -1;
                    continue;
                }

Though I realize that it wouldn't save much since it would have to happen after the UpdatePosition anyway.

Copy link
Member

@roelof-groenewald roelof-groenewald Jan 8, 2024

Choose a reason for hiding this comment

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

Your comment about removing particles after the UpdatePosition call makes me think there is actually a bug in the code presently (besides giving confusing diagnostics on the first step). If I initialize a thermal plasma everywhere in the domain (including over the EB), but we don't remove those immediately, some particles (inside the EB) with velocities directed across the boundary will make it into the valid domain on the first push. Those particles will therefore lead to an undesired preferential velocity (away from the EB) along the edge of the boundary. I guess all this is to say that particles should be removed before the initial push (and also before UpdatePosition, right?).

Copy link
Member

Choose a reason for hiding this comment

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

My comment about UpdatePosition only applies to the flux injection, where particles are loaded onto a plane and UpdatePosition is used to advance the particles a fraction of a time step off of the plane. But your comment would still apply, so it would be better to do the check before the position update, which means doing the check as I suggested. This would also mean that any particles that started from a valid location but then crossed into an EB on its initial particle step would be included in the lost particle diagnostic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good points ; we could create a small device function isInsideEB to do this.

@ax3l ax3l added bug Something isn't working bug: affects latest release Bug also exists in latest release version component: boundary PML, embedded boundaries, et al. labels Jan 6, 2024
@RemiLehe RemiLehe enabled auto-merge (squash) January 29, 2024 19:32
@RemiLehe
Copy link
Member Author

From the above discussion, we could implement the following changes in a second PR:

Copy link
Member

@roelof-groenewald roelof-groenewald left a comment

Choose a reason for hiding this comment

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

As discussed on Slack, we will merge this now so other PRs can move forward and the issues pointed out here will be fixed in subsequent PRs.

@RemiLehe RemiLehe merged commit 67c9aa2 into BLAST-WarpX:development Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: affects latest release Bug also exists in latest release version bug Something isn't working component: boundary PML, embedded boundaries, et al.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants