-
Notifications
You must be signed in to change notification settings - Fork 1
Debugged Current Calculation #64
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
Conversation
There was a problem hiding this 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.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this 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.
Co-authored-by: Copilot <[email protected]>
Identified and fixed the following errors:
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.