Repository navigation
Conversation
…entation
Port the system of equations, time stepping, and options of xmhd to
xmhd_lag, keeping the vector Lagrange magnetic field with the k_db
divergence cleaning term (periodic divergence cleaning is not needed).
- nu_visc fluid viscosity (kin/iso), Braginskii parallel viscosity
(nu_par), and gyroviscosity (nu_gyro); visc_type='ani' removed and
nu_perp accepted as a deprecated alias for nu_visc
- Separate ion/electron conduction coefficients (kappa_par(2),
kappa_perp(2)), chi_perp_e_min, shaping functions
- bbc ('bc','ic'), vbc 'norm'/'tang'/'xml', nbc/tbc 'x' per surface BCs
- Rotationally periodic (revolved) domains for B and V
- Linear runs: xmhd_lin_bdf2, Euler start, level-down restart
- dt_max, gmres_maxits/gmres_ninner, nl_update, per-level xmhd_nparts,
profile_only, row/column equation scaling as in xmhd
- Fix geometric multigrid levels (active level mesh, per-region solid
flags) and several bugs in the previous Lagrange implementation
- Hyper-resistivity (eta_hyper) kept but not verified
Tests and examples:
- New Lagrange viscosity, gyroviscosity, Hall, and revolved-domain tests
- Backward Euler linear Alfven tests for the Lagrange module
- Lagrange variant of the gyroviscous gravitational instability example
- Docs describe the differences between the two implementations
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NKQvs6SxkkHtwxEMXESsSK
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NKQvs6SxkkHtwxEMXESsSK
…mple Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NKQvs6SxkkHtwxEMXESsSK
Native dot products subtract shared/periodic duplicate entries from the full local sum. When the Krylov residual nearly vanishes (eg. an exact LU preconditioner inside an MG smoother) the next Arnoldi vector amplifies round-off mismatches between duplicate entries, and w.w can evaluate to a small negative number, giving NaN from SQRT. Clamp w.w and r.r to zero so this is treated as a (lucky) breakdown. Fixes serial MUG MG failures when SuperLU is the LU package. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Apply the same non-negative clamp used for the GMRES Arnoldi step to the other places that take SQRT of a vector self-dot product, which can be slightly negative due to shared/periodic duplicate entries: CG residual norms, GMRES initial/re-orthogonalization/inner-convergence norms (real and complex), Newton residual norms, ML residual reporting, native vector 2-norms, and the finite-difference Jacobian step size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Native dot products and sums previously added all local entries and then subtracted non-owned (shared/periodic) duplicates. When duplicates dominate the sum this suffers catastrophic cancellation, and self dot-products could evaluate to small negative values (eg. GMRES Arnoldi step after an exact preconditioner), producing NaN norms. Instead, build a per-entry 0/1 ownership weight on first use and accumulate only owned entries in a single streaming loop. An integer weight multiply is used rather than a logical mask, as GCC does not vectorize the masked selection; with the weight the real-valued loops vectorize and are 4-8x faster than the previous two-loop form in a standalone benchmark (gfortran 16, Apple M-series). With flang it ranges from ~10% slower (few boundary entries) to ~4x faster (many boundary entries). Seams without boundary entries keep the plain unmasked loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xmhd_set_level did not update the module mesh pointer, so coarse-level Jacobians and BC flags were built using the finest mesh. Set the mesh from the level's FE representation, and replace the fine-mesh per-cell solid flag with a per-region flag that is valid on all levels. On this branch only xmhd.F90 changes: the Lagrange parity rewrite of xmhd_lag.F90 already contains the equivalent fix (reg_solid and the level mesh pointer in xmhd_set_level). Add geometric MG regression tests (serial and MPI, nonlinear and linear) to test_alfven.py and test_alfven_lag.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Primary changes
src/physics/xmhd_lag.F90(all fields, including B, on Lagrange elements) now supports the same system of equations, time stepping, boundary conditions, and options assrc/physics/xmhd.F90. It keeps its vector-Lagrange magnetic field with thek_db ∇∇·Bdivergence-cleaning term, so the periodic divergence cleaning used byxmhdis not needed (ncleanis ignored).The module was rebuilt from
xmhd.F90, keeping only the magnetic-field-specific parts from the old Lagrange code. The field ordering (B, V, n, T), and therefore the restart layout, is unchanged. Newly supported inxmhd_lag:nu_viscfluid viscosity (kin/iso), Braginskii parallel viscosity (nu_par), and gyroviscosity (nu_gyro).kappa_par(2),kappa_perp(2)),chi_perp_e_min, and theres/diff/visc/cond_shapingfunctions.bbc='bc'/'ic'(applied to the nodal B as fixed normal/tangential components),vbc='norm'/'tang'/'xml', and per-surfacenbc/tbc='x'.xmhd_lin_bdf2, the backward-Euler start, and restart from one level down.dt_max,gmres_maxits/gmres_ninner,nl_update, per-levelxmhd_nparts,profile_only, and the same row/column equation scaling asxmhd.Hyper-resistivity (
eta_hyper>0) is carried over from the old Lagrange implementation unchanged. It is not verified, and is deferred to future work.Tests and examples:
test_MUG_visc_lag,test_MUG_gyro_lag,test_MUG_hall_lag: compared with linear theory. They share their drivers and theory with the H(Curl) tests; the viscosity deviations matchxmhdto about 6 digits.test_MUG_revolved_lag: a Z-pinch equilibrium on a revolved wedge, with several boundary-condition combinations, multigrid, and MPI. It holds equilibrium to about 1e-8, and a negative control with the periodic rotation disabled makes it fail.nu_visc(same physics as before).MUG_gyro_grav_lag: a Lagrange variant of the gyroviscous gravitational-instability example, with its own doc page.doc_mug_main.mdanddoc_mug_xmhd_eqns.mddescribe the remaining differences between the two implementations (a newdoc_mug_xmhd_eqns_lagsection).Secondary changes
base/oft_stitching.F90).xmhd.F90geometric multigrid fix: the same fix as inxmhd_lag: set the level mesh inxmhd_set_leveland use per-region solid flags. Geometric MG levels previously segfaulted inxmhd. Matching geometric-MG tests were added totest_alfven.py.test_MUG_visc.pyandtest_MUG_gyro.pytake anexeargument so the Lagrange drivers can reuse them.API changes
Input-file changes for
xmhd_lag(now the same asxmhd):nu_viscmust now be set (use 0 for none).nu_perpis still accepted as a deprecated alias.nu_parnow means Braginskii parallel viscosity, added tonu_visc. It previously meant the isotropic fluid viscosity.visc_type='ani'was removed.kappa_par/kappa_perpare now 2-element (ion, electron) arrays.k_db(kept),bbc,dt_max,gmres_maxits,gmres_ninner,nl_update,xmhd_lin_bdf2.xmhd_npartsis now a per-level total.xmhd_minlevnow defaults to the finest level, as inxmhd(it was 3).Fortran API:
xmhd_rungains an optionalprofile_onlyargument. Public shaping procedure pointers andxmhd_B_epswere added. There are no API changes toxmhd.Testing
baseandlin_alg, on the default (non-slow) selection: all pass except the two known environment-dependenttest_native_bjacobiILU iteration-count cases (77/76 vs 73/70).test_nl_r1_p3and all new geometric-MG tests pass with the merged round-off fixes.Follow-up before merging (in progress)
test_pinch_mgto the faster block-Jacobi/LU multigrid input now that the NaN fix is in.eps=1e-8) hides the growth phase at β ≥ 1e-3. The example's seed/docs andrun_scan.py's growth-rate fit need fixing.FindOFT_PETScchanges needed to configure PETSc builds with UMFPACK.Generated by Claude Code