Repository navigation
Fix H_bias time levels in MacroscopicEvolveHM_2nd - #168
Merged
ajnonaka merged 1 commit intoNov 24, 2026
Merged
Conversation
…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
merged commit Nov 24, 2026
ebe83be
into
AMReX-Microelectronics:development
9 of 15 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_biassupport 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. ForH_biasthis wasn't the case:H_biasexcitation was applied afterMacroscopicEvolveHM_2ndreturned, with the parser evaluated att_new(= t^n during the step) for both half steps.H_bias: the FirstHalf usedH_bias(t^{n-1})and the SecondHalf usedH_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_oldcopy, butH_biasfieldisn't modified inside the function, so the copy always equaledH_biasfieldand the result was unchanged.Changes
M_*face_old,H*_bias_old,H*_eff_oldandM_magnitude_oldto make it clear these are old-time quantities. The H_bias comments in both loops now name the time level.FiniteDifferenceSolver::MacroscopicEvolveHM_2nd(and the Cartesian template) now takeH_biasfield_oldandH_biasfield. The static loop uses the old one and the iterative loop the new one.WarpX::MacroscopicEvolveHM_2ndsavesH_biasat 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.ApplyExternalFieldExcitationOnGridhas a new optionala_time_offsetargument (default 0, so existing callers are unchanged). Parsers are evaluated atgett_new(lev) + a_time_offset.OneStep_nosub, the H_bias excitation after the M update now runs only formag_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 = 2with constant or noH_biasexcitation: should be bit-for-bit identical.mag_time_scheme_order = 2with time-dependentH_bias: results change, as expected.H_biasin plotfiles is now at t^{n+1}, consistent with the other fields, instead of t^n.Testing
H_bias)H_biasNot 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.