Skip to content

Conversation

rogeriojorge
Copy link
Collaborator

  • 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.
@rogeriojorge rogeriojorge requested a review from Copilot October 14, 2025 22:05
Copy link

@Copilot 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 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.

Comment on lines 5 to 7
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)
Copy link

Copilot AI Oct 14, 2025

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.

# (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)
Copy link

Copilot AI Oct 14, 2025

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).

Suggested change
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.

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
Copy link

Copilot AI Oct 14, 2025

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.

Suggested change
# 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.

Copy link

codecov bot commented Oct 14, 2025

Codecov Report

❌ Patch coverage is 86.36364% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
jaxincell/_algorithms.py 53.84% 6 Missing ⚠️
Files with missing lines Coverage Δ
jaxincell/_filters.py 100.00% <100.00%> (ø)
jaxincell/_simulation.py 88.40% <ø> (ø)
jaxincell/_sources.py 100.00% <100.00%> (ø)
jaxincell/_algorithms.py 37.61% <53.84%> (+2.26%) ⬆️

- 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
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