Skip to content

Fix H_bias time levels in MacroscopicEvolveHM_2nd - #168

Merged
ajnonaka merged 1 commit into
AMReX-Microelectronics:developmentfrom
ajnonaka:new_mh_2nd_fixes
Nov 24, 2026
Merged

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

Conversation

@ajnonaka

Copy link
Copy Markdown
Contributor

Summary

Replaces #96 (which is being closed). It keeps #96's renaming in the 2nd-order LLG static loop and adds the time-varying H_bias support that #96 intended but didn't actually implement.

Motivation

In MacroscopicEvolveHM_2nd, the "static" part of the update should use quantities at the old time and the iterative part should use quantities at the new time. For H_bias this wasn't the case:

  • The H_bias excitation was applied after MacroscopicEvolveHM_2nd returned, with the parser evaluated at t_new (= t^n during the step) for both half steps.
  • So both loops saw the same H_bias: the FirstHalf used H_bias(t^{n-1}) and the SecondHalf used H_bias(t^n). That lags by up to a full step and is not second-order accurate for a time-dependent bias.

#96 added an internal H_biasfield_old copy, but H_biasfield isn't modified inside the function, so the copy always equaled H_biasfield and the result was unchanged.

Changes

  • Renaming (from Fix mh 2nd #96): the static loop now uses M_*face_old, H*_bias_old, H*_eff_old and M_magnitude_old to make it clear these are old-time quantities. The H_bias comments in both loops now name the time level.
  • Old/new H_bias: FiniteDifferenceSolver::MacroscopicEvolveHM_2nd (and the Cartesian template) now take H_biasfield_old and H_biasfield. The static loop uses the old one and the iterative loop the new one.
  • H_bias advanced inside the wrapper: WarpX::MacroscopicEvolveHM_2nd saves H_bias at the start of each half step, then applies the H_bias excitation at the end of the half step: t^n + dt/2 for FirstHalf, t^{n+1} for SecondHalf. If no H_bias excitation is defined, old and new are the same MultiFab, so there's no extra memory or copying.
  • Excitation time offset: the per-MultiFab ApplyExternalFieldExcitationOnGrid has a new optional a_time_offset argument (default 0, so existing callers are unchanged). Parsers are evaluated at gett_new(lev) + a_time_offset.
  • Evolve loop: in OneStep_nosub, the H_bias excitation after the M update now runs only for mag_time_scheme_order == 1. For the 2nd-order scheme it has moved into the wrapper, so soft sources are still applied the same number of times per step.

Expected impact

  • mag_time_scheme_order = 1: no change.
  • mag_time_scheme_order = 2 with constant or no H_bias excitation: should be bit-for-bit identical.
  • mag_time_scheme_order = 2 with time-dependent H_bias: results change, as expected. H_bias in plotfiles is now at t^{n+1}, consistent with the other fields, instead of t^n.

Testing

  • Existing LLG regression tests pass (2nd-order cases unchanged)
  • Magnetically tunable filter case from Fix mh 2nd #96 (time-varying H_bias)
  • Optional: dt-refinement study showing 2nd-order convergence with a time-dependent H_bias

Not in scope

The 1st-order scheme, and the E/B/H soft-source excitations, still evaluate at t_new = t^n for both half steps. That can be handled separately if we want consistent time levels across all excitations.

…MReX-Microelectronics#96's renaming in the 2nd-order LLG static loop and adds the time-varying `H_bias` support that AMReX-Microelectronics#96 intended but didn't actually implement.

In `MacroscopicEvolveHM_2nd`, the "static" part of the update should use quantities at the old time and the iterative part should use quantities at the new time. For `H_bias` this wasn't the case:

- The `H_bias` excitation was applied *after* `MacroscopicEvolveHM_2nd` returned, with the parser evaluated at `t_new` (= t^n during the step) for both half steps.
- So both loops saw the same `H_bias`: the FirstHalf used `H_bias(t^{n-1})` and the SecondHalf used `H_bias(t^n)`. That lags by up to a full step and is not second-order accurate for a time-dependent bias.

- **Renaming (from AMReX-Microelectronics#96):** the static loop now uses `M_*face_old`, `H*_bias_old`, `H*_eff_old` and `M_magnitude_old` to make it clear these are old-time quantities. The H_bias comments in both loops now name the time level.
- **Old/new H_bias:** `FiniteDifferenceSolver::MacroscopicEvolveHM_2nd` (and the Cartesian template) now take `H_biasfield_old` and `H_biasfield`. The static loop uses the old one and the iterative loop the new one.
- **H_bias advanced inside the wrapper:** `WarpX::MacroscopicEvolveHM_2nd` saves `H_bias` at the start of each half step, then applies the H_bias excitation at the end of the half step: t^n + dt/2 for FirstHalf, t^{n+1} for SecondHalf. If no H_bias excitation is defined, old and new are the same MultiFab, so there's no extra memory or copying.
- **Excitation time offset:** the per-MultiFab `ApplyExternalFieldExcitationOnGrid` has a new optional `a_time_offset` argument (default 0, so existing callers are unchanged). Parsers are evaluated at `gett_new(lev) + a_time_offset`.
- **Evolve loop:** in `OneStep_nosub`, the H_bias excitation after the M update now runs only for `mag_time_scheme_order == 1`. For the 2nd-order scheme it has moved into the wrapper, so soft sources are still applied the same number of times per step.

- `mag_time_scheme_order = 1`: no change.
- `mag_time_scheme_order = 2` with constant or no `H_bias` excitation: should be bit-for-bit identical.
- `mag_time_scheme_order = 2` with time-dependent `H_bias`: results change, as expected. `H_bias` in plotfiles is now at t^{n+1}, consistent with the other fields, instead of t^n.

- [ ] Existing LLG regression tests pass (2nd-order cases unchanged)
- [ ] Magnetically tunable filter case from AMReX-Microelectronics#96 (time-varying `H_bias`)
- [ ] Optional: dt-refinement study showing 2nd-order convergence with a time-dependent `H_bias`

The 1st-order scheme, and the E/B/H soft-source excitations, still evaluate at `t_new` = t^n for both half steps. That can be handled separately if we want consistent time levels across all excitations.
@ajnonaka
ajnonaka merged commit ebe83be into AMReX-Microelectronics:development Nov 24, 2026
9 of 15 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