Skip to content

Adjust lnR and lnd reconstruction - #1136

Closed
Debraheem wants to merge 7 commits into
mainfrom
EbF/feature/improve_lnd_lnR_reconstruction
Closed

Debraheem wants to merge 7 commits into
mainfrom
EbF/feature/improve_lnd_lnR_reconstruction

Conversation

@Debraheem

@Debraheem Debraheem commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

This is a draft. In hb_2M, rebuilding density from rounded radii in a thin shell made the pressure interval in the Brunt term 83 times smaller and stalled the solve. I remap shell volumes directly, use the same lnR and lnd mapping in the solver and on restart, and keep the start-of-step density check for changes beyond roundoff. The TZO hook and fixed-radius u_flag mass scaling now update density where they change the mass.

The helium-flash replay reaches stable core helium burning with the relative mass equation enabled. The short tests of both mass edits match with the check on and off and after a photo restart. I’d still like TestHub to cover the full TZO and AMR cases and check energy across remeshing and mass edits. One-page note (PDF)

Keep radius and density derived from the stored logarithms throughout the solve. Use log1p of the shell-to-inner volume ratio to evaluate the mass residual without subtracting two absolute log radii.
Check shell mass closure before remeshing on the shared evolution path. Keep the RSP exclusion, use the same guarded check for both velocity formulations, and preserve the saved mesh during photo loading.
Scale density with envelope mass in the TZO core-growth hook and include cell-centered velocity models in fixed-radius mass relaxation. Both edits retain the existing temperature and composition.
@Debraheem
Debraheem force-pushed the EbF/feature/improve_lnd_lnR_reconstruction branch from f3080b9 to 3ae80bf Compare November 26, 2026 20:16
@Debraheem Debraheem added the enhancement New feature or request label Nov 26, 2026
Debraheem added a commit that referenced this pull request Nov 26, 2026
Set set_rho_to_dm_div_dV to false during the helium flash and
regenerate the TAMS and ZACHeB fixtures. The test reaches HB_limit
and passes the subsequent core helium burning check.

See #1136 for the reconstruction work.
@AstroBarker

AstroBarker commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

I haven't looked into your solution in much detail yet, but if the issue is really precision in the difference, I wonder if some precision might be recovered by a more clever differencing? For example, let $$a = \mathrm{ln}(r_1)$$ and $$b = \mathrm{ln}(r_2)$$ with $$a$$ > $$b$$. We want to evaluate

$$\mathrm{exp}(a)^3 - \mathrm{exp}(b)^3 = \mathrm{exp}(3a) - \mathrm{exp}(3b)$$.

Rewrite this as

$$\mathrm{exp}(3a) [ 1 - \mathrm{exp}(3(b-a)) ]$$

This shows some improvement for me with the radii you shared.

Note

The difference $$\mathrm{exp}(x) - 1$$ can often be computed to higher accuracy with standard library builtins which would further save precision by fully eliminating the subtraction, but today I learned that apparently fortran does not support this..

@zingale

zingale commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

I've always done $a^3 - b^3 = (a - b) (a^2 + ab + b^2)$, which can also greatly reduce roundoff.

@Debraheem

Copy link
Copy Markdown
Member Author

thanks both, I actually tried both and the answer didn't seem to change much, but is marginally better.

i think the main problem is really in the precision that is already missing from lnR, and it doesn't matter how you rewrite the expression, you won't recover digits that are already not included.

The deeper issue here is mesa already making lnR consistent with dm and rho in edit_lnR, so there is in fact no purpose to doing set_rho_to_dm_div_dv = .true. outside of loading mod files, it just runs the chance of reducing precision in the reconstructed density that was already consistent with the cell volume.

I do think both of your expressions are useful for refactoring the radius residual in the radius equation though. Something Mike already brought to me privately. Will address in a follow up pr.


I think the main source of the issues i was seeing in the hb_2m test case were coming directly from remeshing artifacts. I failed to check for this during my first investigation. These same issues are popping up across the test suite when i look closer, including in Brandon's neu bugfix pr.

For now this branch was really just an overboard LLM hack fest to see low i could bring the residuals, and by doing things in quad inside the solver. Maybe these ideas are useful later in the future, but for now, I think it was a bit of an uncessary refactor. It could be useful to do this accumulation of specific volumes in the future, but it's unnecessary right now i think. I will close this draft for now.

@Debraheem Debraheem closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants