Skip to content

Conversation

@cwoolfo1
Copy link
Member

Identified and fixed the following errors:

  • Previously J from rhov using x at t+1 not t+1/2.
  • Previously depositing J at node centers, not in line with E.
  • 2nd order shaped factor was flipped.

Energy errors are now several orders of magnitude smaller and consistent with benchmarks of the two stream instability and weibel instability against WarpX.

Both the j from rhov and Esirkepov current deposition algorithms are now fully operational in 1D.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes critical bugs in the current calculation algorithms for the PyPIC3D particle-in-cell simulation code. The fixes address three main issues: improper time staggering of particle positions when calculating current from charge density and velocity (J from rhov), incorrect deposition of current at grid nodes instead of staggered cell faces, and flipped second-order shape factor weights. These corrections result in significantly improved energy conservation.

Changes:

  • Fixed J_from_rhov to use particle positions at t+1/2 instead of t+1 for proper time staggering
  • Corrected current deposition to use staggered grid (faces) instead of node centers, with separate face/node weights for each current component
  • Fixed swapped second-order shape factor weights (S₁ and S₋₁)
  • Updated energy calculation to use relativistic formulas and simple summation instead of trapezoidal integration
  • Fixed kinetic energy calculation and Debye length weight calculation for anisotropic grids
  • Added configurable filtering (bilinear/digital/none) for current density
  • Added openPMD output support for particle data
  • Relaxed test tolerances where appropriate and tightened where accuracy improved

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
PyPIC3D/J.py Fixed time staggering, staggered grid deposition with face/node weights, second-order weight formula, and added configurable filtering
PyPIC3D/utils.py Added trilinear filter, updated energy calculation to use relativistic formulas and simple summation
PyPIC3D/particle.py Fixed kinetic energy calculation and weight calculation for anisotropic grids
PyPIC3D/evolve.py Changed J deposition grid from vertex to center grid for proper staggering
PyPIC3D/initialization.py Added filter_j parameter with default and import for openPMD function
PyPIC3D/plotting.py Added openPMD export function for initial particle states
tests/particle_test.py Removed outdated test assertions, adjusted continuity test tolerance, added dt to world params
tests/first_order_yee_test.py Tightened test tolerances reflecting improved accuracy
pyproject.toml Added openpmd-api dependency
Comments suppressed due to low confidence (1)

PyPIC3D/J.py:23

  • The new 'filter' parameter is not documented in the function's docstring. The docstring should be updated to describe the filter parameter, its possible values ('bilinear', 'digital', 'none'), and its purpose.
def J_from_rhov(particles, J, constants, world, grid, filter='bilinear'):
    """
    Compute the current density from the charge density and particle velocities.

    Args:
        particles (list): List of particle species, each with methods to get charge, subcell position, resolution, and index.
        rho (ndarray): Charge density array.
        J (tuple): Current density arrays (Jx, Jy, Jz) for the x, y, and z directions respectively.
        constants (dict): Dictionary containing physical constants.

    Returns:
        tuple: Updated current density arrays (Jx, Jy, Jz) for the x, y, and z directions respectively.
    """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

PyPIC3D/J.py:23

  • The docstring for J_from_rhov is outdated. It doesn't document the new 'filter' parameter and still mentions 'rho' parameter which is not actually used in the function. The docstring should be updated to reflect the current signature and parameters.
    """
    Compute the current density from the charge density and particle velocities.

    Args:
        particles (list): List of particle species, each with methods to get charge, subcell position, resolution, and index.
        rho (ndarray): Charge density array.
        J (tuple): Current density arrays (Jx, Jy, Jz) for the x, y, and z directions respectively.
        constants (dict): Dictionary containing physical constants.

    Returns:
        tuple: Updated current density arrays (Jx, Jy, Jz) for the x, y, and z directions respectively.
    """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cwoolfo1 cwoolfo1 merged commit d31784f into uwplasma:main Jan 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant