Skip to content

Commit

Permalink
Fix to get the uniform loading working
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgrote committed Jun 19, 2024
1 parent 234a5ce commit a334f4e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
5 changes: 3 additions & 2 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,9 @@ Particle initialization
Maximum plasma density. The density at each point is the minimum between the value given in the profile, and `density_max`.

* ``<species_name>.radially_weighted`` (`bool`) optional (default `true`)
Whether particle's weight is varied with their radius. This only applies to cylindrical geometry.
The only valid value is true.
Whether particle weights are proportional to their initial radius.
When `false`, the particles will be uniformly weighted.
This only applies to cylindrical geometry.

* ``<species_name>.momentum_distribution_type`` (`string`)
Distribution of the normalized momentum (`u=p/mc`) for this species. The options are:
Expand Down
4 changes: 4 additions & 0 deletions Python/pywarpx/picmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class Species(picmistandard.PICMI_Species):
warpx_do_not_gather: bool, default=False
Whether or not to gather the fields from grids for this species
warpx_radially_weighted: bool, default=True
When true, particle weights are proportional to their initial radii.
When false, the particles are uniformly weighted.
warpx_random_theta: bool, default=True
Whether or not to add random angle to the particles in theta
when in RZ mode.
Expand Down
31 changes: 21 additions & 10 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,15 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int
Real yb = pos.y;

#ifdef WARPX_DIM_RZ
if (!radially_weighted) {
// With uniformly weighted particles, the sqrt stretches
// the positions to produce a uniform density.
// Note that the tile_realbox.contains check above ensures
// that the "logical" space is uniformly filled. The sqrt
// converts to physical space.
xb = std::sqrt(xb/rmax)*rmax;
}

// Replace the x and y, setting an angle theta.
// These x and y are used to get the momentum and density
// With only 1 mode, the angle doesn't matter so
Expand Down Expand Up @@ -1445,10 +1454,7 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int
if (radially_weighted) {
weight *= 2._rt*MathConst::pi*xb;
} else {
// This is not correct since it might shift the particle
// out of the local grid
xb = std::sqrt(xb*rmax);
weight *= MathConst::pi * rmax;
weight *= MathConst::pi*rmax;
}
#endif
pa[PIdx::w ][ip] = weight;
Expand Down Expand Up @@ -1865,6 +1871,16 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector,
}

#ifdef WARPX_DIM_RZ
amrex::Real radial_position = ppos.x;
if (!radially_weighted) {
// With uniformly weighted particles, the sqrt stretches
// the positions to produce a uniform density.
// Note that the containsInclusive check above ensures
// that the "logical" space is uniformly filled. The sqrt
// converts to physical space.
radial_position = std::sqrt(radial_position/rmax)*rmax;
}

// Conversion from cylindrical to Cartesian coordinates
// Replace the x and y, setting an angle theta.
// These x and y are used to get the momentum and flux
Expand All @@ -1876,7 +1892,6 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector,
Real const cos_theta = std::cos(theta);
Real const sin_theta = std::sin(theta);
// Rotate the position
const amrex::Real radial_position = ppos.x;
ppos.x = radial_position*cos_theta;
ppos.y = radial_position*sin_theta;
if (loc_flux_normal_axis != 2) {
Expand Down Expand Up @@ -1932,11 +1947,7 @@ PhysicalParticleContainer::AddPlasmaFlux (PlasmaInjector const& plasma_injector,
if (radially_weighted) {
t_weight *= 2._rt*MathConst::pi*radial_position;
} else {
// This is not correct since it might shift the particle
// out of the local grid
ppos.x *= std::sqrt(radial_position/rmax);
ppos.y *= std::sqrt(radial_position/rmax);
t_weight *= dx[0];
t_weight *= MathConst::pi*rmax;
}
}
const Real weight = t_weight;
Expand Down

0 comments on commit a334f4e

Please sign in to comment.