Skip to content

lumped element cleanup - #171

Merged
ajnonaka merged 1 commit into
AMReX-Microelectronics:developmentfrom
ajnonaka:lumped_cleanup
Nov 25, 2026
Merged

ajnonaka merged 1 commit into
AMReX-Microelectronics:developmentfrom
ajnonaka:lumped_cleanup

Conversation

@ajnonaka

@ajnonaka ajnonaka commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Lumped resistor/capacitor: fix non-3D bug, add input validation, move flags to algo.

Summary

This PR fixes an out-of-bounds read in the lumped resistor/capacitor E-field update when built in 2D/1D, adds input checks so a bad or ignored setup fails loudly, and moves the enable flags from warpx. to algo. to match the other circuit-element options (algo.use_lumped_inductor, algo.use_josephson_junction, algo.use_PEC_mask). The physics is unchanged: the 3D update is the same as before.

Changes

Bug fix: non-3D builds (MacroscopicEvolveE.cpp)

  • The resistor and capacitor terms used dx[2], but dx is a GpuArray<Real, AMREX_SPACEDIM>. In XZ/1D builds with the feature on, this read past the end of the array.
  • The geometric factor Δℓ/ΔA for each edge direction is now computed once before the kernels, inside a WARPX_DIM_3D block. Outside 3D it is 0, and the kernels never touch dx[2].

Input validation (WarpX.cpp, MacroscopicProperties.cpp)

  • Abort if use_lumped_resistor or use_lumped_capacitor is on and algo.em_solver_medium != macroscopic. Before, the flags were silently ignored in that case.
  • Abort if either flag is on in a non-3D build.
  • Abort if any resistor or capacitor value is negative. A negative R is a negative conductance and makes the E update unstable. R = 0 or C = 0 still means "no element on this edge".
  • macroscopic.lumped_{resistor,capacitor}_{x,y,z}_function(x,y,z) are now optional per direction and default to "0". Warn if a flag is on but no function is given.

Parameter rename (WarpX.cpp)

  • warpx.use_lumped_resistor → algo.use_lumped_resistor
  • warpx.use_lumped_capacitor → algo.use_lumped_capacitor
  • The old names still work but print a deprecation warning. If both are set, the algo. value wins.

Cleanup

  • Removed the dead scoped lumped_*_stag declarations and a commented-out printf in MacroscopicEvolveE.cpp.
  • lumped_{resistor,capacitor}_{x,y,z}_IndexType were declared but never assigned. They are now set from J's staggering in MacroscopicProperties::InitData.

Review notes

  • I re-derived the update coefficients from (ε + C·Δℓ/ΔA) ∂E/∂t + (σ + Δℓ/(R·ΔA)) E = ∇×H − J. Both the Lax-Wendroff and Backward Euler alpha_compact/beta_compact match.
  • R and C are applied per edge. An element spanning N edges in series and M edges in parallel has total value R·N/M (resistor) or C·M/N (capacitor).

Compatibility

  • No changes to results in 3D.
  • None of the example inputs use the resistor or capacitor flags, so no inputs needed updating. Input decks that use warpx.use_lumped_* keep working, with a warning.

Testing

  • Builds in 3D (with and without USE_LLG)
  • A 3D lumped-resistor case reproduces the previous results
  • warpx.use_lumped_resistor = 1 runs with the deprecation warning
  • A negative R aborts with a clear message
  • A lumped flag with em_solver_medium = vacuum aborts with a clear message

@ajnonaka
ajnonaka marked this pull request as ready for review November 24, 2026 23:06
@ajnonaka
ajnonaka merged commit e263245 into AMReX-Microelectronics:development Nov 25, 2026
3 checks 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