AMReX-Astro / AMReX-Astro/Microphysics
Screening temperature derivatives do not differentiate the returned value
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 43
- Forks
- 46
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
Summary
The automatic derivative of fast_atan(x) is defined as 1/(1+x*x),
which differentiates exact atan(x). Its value is instead evaluated
using a piecewise polynomial approximation. Consequently, the Chabrier
and Chugunov 2009 screening temperature derivatives disagree with finite
differences even away from approximation branch boundaries.
Suggested priority: medium. Reaction Jacobians receive an inconsistent
screening contribution. Solver convergence failures were not established.
Affected code
util/microphysics_autodiff.H:398-402:FastAtanOpderivative rule.util/approx_math/approx_math.H:20-94: actual approximated value.screening/screen.H:461,553: affected free-energy expressions.screening/screen.H:663-672,697-706: derivative output interfaces.
Reviewed commit: e4b401b7637894a3db5ffa1e4b401509a332a1d6.
The derivative rule is attributed to commit bbe8723a1, PR #1593.
Reproduction
Run the harness described in README.md. Use pure hydrogen,
rho = 100 g/cm^3, a proton-proton screening pair, and
T = 13408146.05173284 K. Disable Debye-Huckel skipping and the optional
Chabrier quantum correction.
Seed the temperature of plasma_state_t<autodiff::dual>, then compare
actual_log_screen's derivative with a centered finite difference of the
real-valued routine, using delta_T = 1.e-5 * T.
Method Automatic dh/dT Finite-difference dh/dT
chabrier1998 -4.246705441041109e-9 -4.280877898758545e-9
chugunov2009 -3.490568036519522e-9 -3.519126114425965e-9
The relative disagreements are approximately 0.798% and 0.812%,
respectively. These samples are away from the 0.378 branch transition.
The same inconsistency propagates through actual_screen via exp(h).
Expected behavior
Automatic differentiation should differentiate the screening function
actually returned to callers. If an approximate Jacobian is intentional,
its accuracy and purpose should be explicitly documented and validated.
Proposed fix
Replace both screening uses of admath::fast_atan with admath::atan.
This also removes the value discontinuity documented separately in
02-free-energy-discontinuity.md.
Alternatively, differentiate each implemented polynomial exactly. For
the small-argument branch the derivative is 1 - x^2 + x^4; for the
other polynomial it is 5*A*x^4 + 3*B*x^2 + C. Apply the chain rule for
the reciprocal branches and handle the constant large-argument branch.
That change alone does not remove the branch discontinuities.
Validation
Compare automatic derivatives with finite differences across both
screening methods, multiple ion pairs, and a range of thermodynamic
states. Vary the finite-difference step to distinguish truncation error
from a persistent derivative mismatch. Test branch continuity separately.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with util/microphysics_autodiff.H:398-402 and util/approx_math/approx_math.H:20-94 to compare the derivative rule with the implemented value, then inspect the affected expressions and derivative interfaces in screening/screen.H. Run the README.md harness using the stated hydrogen screening case, and validate both screening methods across ion pairs and thermodynamic states. Done means automatic derivatives agree with finite differences and branch continuity is tested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100