-
Notifications
You must be signed in to change notification settings - Fork 5
Add filtering parameters and functions for charge density calculations #12
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
base: main
Are you sure you want to change the base?
Conversation
rogeriojorge
commented
Oct 14, 2025
- Introduced filter_passes, filter_alpha, and filter_strides in input parameters.
- Implemented filtering in charge density calculations and Boris step functions.
- Added filter functions for scalar and vector fields in a new filters module.
- Introduced filter_passes, filter_alpha, and filter_strides in input parameters. - Implemented filtering in charge density calculations and Boris step functions. - Added filter functions for scalar and vector fields in a new filters module.
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 PR adds filtering capabilities to charge density and current density calculations in the jaxincell simulation package. The filtering is implemented using binomial filters with configurable parameters to smooth field values.
- Added three new input parameters: filter_passes, filter_alpha, and filter_strides for controlling filtering behavior
- Implemented filtering functions for scalar and vector fields using binomial smoothing algorithms
- Integrated filtering into charge density and current density calculations throughout the simulation pipeline
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
jaxincell/_filters.py | New module containing binomial filter implementations for scalar and vector fields |
jaxincell/_sources.py | Added filtering to charge density calculations with new filter parameters |
jaxincell/_simulation.py | Added default filter parameter values to simulation configuration |
jaxincell/_algorithms.py | Integrated filtering into Boris and CN step functions for current and charge density |
examples/input.toml | Added filter configuration parameters and reduced total simulation steps |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
jaxincell/_filters.py
Outdated
def binomial1(x, alpha=0.5, stride=1): | ||
# 3-point: x^f_j = α x_j + (1-α)(x_{j-1}+x_{j+1})/2 | ||
# periodic ends assumed at call site (we’ll pad/roll in callers) |
Copilot
AI
Oct 14, 2025
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.
The function name 'binomial1' is not descriptive. Consider renaming to 'binomial_filter_3point' or similar to better indicate its purpose as a 3-point binomial filter.
Copilot uses AI. Check for mistakes.
jaxincell/_filters.py
Outdated
# (passes-1) regular passes | ||
def body(_, val): | ||
return binomial1(val, alpha, stride=stride) | ||
y = lax.fori_loop(0, jnp.maximum(passes - 1, 0), lambda i, v: body(i, v), y) |
Copilot
AI
Oct 14, 2025
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.
The lambda function lambda i, v: body(i, v)
is redundant since it's equivalent to just body
. This can be simplified to lax.fori_loop(0, jnp.maximum(passes - 1, 0), body, y)
.
y = lax.fori_loop(0, jnp.maximum(passes - 1, 0), lambda i, v: body(i, v), y) | |
y = lax.fori_loop(0, jnp.maximum(passes - 1, 0), body, y) |
Copilot uses AI. Check for mistakes.
jaxincell/_filters.py
Outdated
def body(_, val): | ||
return binomial1(val, alpha, stride=stride) | ||
y = lax.fori_loop(0, jnp.maximum(passes - 1, 0), lambda i, v: body(i, v), y) | ||
# compensation pass |
Copilot
AI
Oct 14, 2025
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.
The compensation alpha calculation lacks explanation. Add a comment explaining why this specific formula is used for the compensation pass.
# compensation pass | |
# compensation pass | |
# The compensation alpha is chosen so that the overall filter preserves the DC (mean) component. | |
# After (passes-1) regular passes with alpha, the final pass uses: | |
# comp_alpha = passes - alpha * (passes - 1) | |
# This ensures that the total weight sums to 1, avoiding attenuation of the mean. |
Copilot uses AI. Check for mistakes.
Codecov Report❌ Patch coverage is
|
… and update references
- Implemented `initialize_simulation_parameters` to set up simulation parameters with user-defined and default values. - Created `load_parameters` function to read simulation parameters from a TOML file. - Developed `initialize_particles_fields` to generate initial particle positions, velocities, charges, and electromagnetic fields. - Included detailed documentation for all functions and parameters. - Added filtering options for charge density calculations in `_sources.py`.
…icle velocities and momenta - Implemented `sample_maxwell_boltzmann` for nonrelativistic velocity sampling with thermal speeds and drifts. - Added `sample_maxwell_juttner_p` for isotropic momentum sampling using rejection sampling based on the Maxwell-Jüttner distribution. - Introduced `sample_boosted_maxwell_juttner_p` to Lorentz-boost momenta to the lab frame. - Created helper functions for unit vector sampling and normalization. - Developed `_relativistic_distribution` and `_nonrelativistic_distribution` for initializing particle velocities and momenta based on simulation parameters. - Added visualization functions in `_movies.py` for wave spectrum and phase-space movies, including particle trails and electric field overlays. - Enhanced the particle box movie function to include electric field visualization and improved aesthetics.
…lgorithm and enhance kinetic energy calculations