Skip to content

Tests: Derive analytical formula for particle_boundary_interaction#6817

Merged
RemiLehe merged 7 commits intoBLAST-WarpX:developmentfrom
RemiLehe:derive_analytical_formula_particle_boundary_interaction
Apr 29, 2026
Merged

Tests: Derive analytical formula for particle_boundary_interaction#6817
RemiLehe merged 7 commits intoBLAST-WarpX:developmentfrom
RemiLehe:derive_analytical_formula_particle_boundary_interaction

Conversation

@RemiLehe
Copy link
Copy Markdown
Member

@RemiLehe RemiLehe commented Apr 28, 2026

Summary

This PR replaces hard-coded reference values in two test analysis scripts with Python expressions that derive them analytically from the input parameters (read via parse_input_file from warpx_used_inputs).

test_rz_particle_boundary_interaction_picmi

  • The analysis script compared the simulated particle position at the end of the run to three hard-coded reference values, which made it unclear what was being tested.
  • The new code derives the expected position analytically: relativistic Lorentz factor, straight-line ray-sphere intersection to find the impact point, mirror reflection of the velocity at that point, and free flight until ts.t[-1].
  • The relative tolerance had to be loosened from 1e-5 to 2 %, because the simulation result differs from the analytical (purely geometric) result by about 1.8 % on z. This error is due to the discretization of the EB (a sphere approximated by AMReX's cut-cell approach). This was confirmed by running with twice the resolution in r and z and half the timestep: the dominant z error dropped from 1.79 % to 0.61 %, consistent with first-order convergence of the EB scraping.

test_rz_secondary_ion_emission_picmi

  • The analysis script compared emitted-electron positions to hard-coded expected values.
  • The new code computes analytically the impact point of each ion on the sphere (same ray-sphere intersection formula as above).
  • Each emitted secondary electron is back-propagated from the final diagnostic time to the analytically computed ion impact time using its velocity (read from the diagnostic; openpmd_viewer returns proper velocities in units of c). This removes the stochastic thermal-kick displacement from the comparison, so the check is sensitive only to the EB discretization error.
  • Each back-propagated electron is then matched to the closest analytical impact point (rather than by index), because the stochastic thermal kick at emission scrambles the correspondence between emitted electrons and parent ions.
  • The tolerance is set to 5 % of the sphere radius R, consistent with the relative-error convention used in the companion test, and comfortably above the observed ~3.6 % maximum.

🤖 Generated with Claude Code

Replace the hard-coded reference values with a Python expression that
derives them from the input parameters: relativistic Lorentz factor,
straight-line ray-sphere intersection for the impact point, mirror
reflection at the impact point, and free flight to ts.t[-1].

Loosened tolerance from 1e-5 to 0.02. The remaining ~1.8% gap between
the simulation and the analytical formula is due to the discretization
of the embedded boundary in WarpX (the buffered scrape position sits
slightly inside the sphere and the cell normal differs from the
geometric one): doubling the resolution in r and z and halving dt
reduces the z error from 1.79% to 0.61%, confirming convergence.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@RemiLehe RemiLehe changed the title Tests: Derive analytical formula for particle_boundary_interaction [WIP] Tests: Derive analytical formula for particle_boundary_interaction Apr 28, 2026
Previously the comment dropped the x0 and vx0 terms (they happen to
vanish for the chosen initial condition x0 = 0). Write the full
quadratic and use it in the code so the derivation reads correctly.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@RemiLehe RemiLehe marked this pull request as draft April 28, 2026 17:35
Comment thread Examples/Tests/particle_boundary_interaction/analysis.py Outdated
@EZoni EZoni mentioned this pull request Apr 28, 2026
1 task
Replace hard-coded electron positions with analytically computed ion
impact points. Each emitted electron is matched to the closest impact
point (rather than by index) to accommodate the stochastic thermal
kick applied at emission. Tolerance is set as an absolute distance
(0.025 m) that bounds the combined effect of the thermal kick and the
EB discretization.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@RemiLehe RemiLehe marked this pull request as ready for review April 28, 2026 18:05
RemiLehe and others added 4 commits April 28, 2026 11:07
Replace hard-coded parameter values (sphere radius, initial particle
positions and velocities) in both analysis scripts with values read
from warpx_used_inputs via parse_input_file, as done in other analysis
scripts. This makes the analytical derivation self-consistent with the
actual simulation inputs.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Read ux/uy/uz from the final diagnostic (OpenPMDTimeSeries returns u/c)
and back-propagate each electron to the analytically computed ion impact
time. This removes the deterministic part of the thermal-kick displacement
from the comparison, so the check captures only the EB discretization
error. The tolerance tightens from 0.025 m to 0.01 m.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Express the tolerance as a fraction of the sphere radius R (5 %) rather
than an absolute distance, consistent with the particle_boundary_interaction
analysis script.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@RemiLehe RemiLehe changed the title [WIP] Tests: Derive analytical formula for particle_boundary_interaction Tests: Derive analytical formula for particle_boundary_interaction Apr 28, 2026
@EZoni EZoni self-assigned this Apr 28, 2026
@EZoni EZoni added component: tests Tests and CI component: boundary PML, embedded boundaries, et al. geometry: RZ axisymmetric 2D and quasi-3D labels Apr 28, 2026
@RemiLehe RemiLehe merged commit e205462 into BLAST-WarpX:development Apr 29, 2026
47 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: boundary PML, embedded boundaries, et al. component: tests Tests and CI geometry: RZ axisymmetric 2D and quasi-3D

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants