[Mesa-users] Missing energy generation in MESA output?

Farag, Ebraheem ebraheem.farag at yale.edu
Fri Feb 28 03:14:52 UTC 2025


"When solutions are numerically converged (i.e., have sufficient space/time resolution to give resolution-independent results) and the EOS is thermodynamically consistent and provides correct partial derivatives (see Section 5.3), these two equations should give identical results. Conversely, the solutions may differ when unconverged." - Jermyn et al. 2023<https://ui.adsabs.harvard.edu/abs/2023ApJS..265...15J/abstract> <https://ui.adsabs.harvard.edu/abs/2023ApJS..265...15J/abstract>

-EbF
________________________________
From: Mesa-users <mesa-users-bounces at lists.mesastar.org> on behalf of Farag, Ebraheem via Mesa-users <mesa-users at lists.mesastar.org>
Sent: Thursday, February 27, 2025 9:16 PM
To: Frank Timmes <fxtimmes at gmail.com>; Jason Wright <astrowright at gmail.com>
Cc: mesa-users <mesa-users at lists.mesastar.org>
Subject: Re: [Mesa-users] Missing energy generation in MESA output?

Thanks Frank,

You are right to point us to back to the instrument papers. Section 5 In MESA VI (Jermyn et al. 2023)  weighs in on the discussion of energy conservation and the eps_grav form to highlight the most recent improvements leading to eps_grav "only requiring first derivatives of e with respect to composition in order to form the Jacobian."

-EbF

________________________________
From: Frank Timmes <fxtimmes at gmail.com>
Sent: Thursday, February 27, 2025 8:15 PM
To: Farag, Ebraheem <ebraheem.farag at yale.edu>; Jason Wright <astrowright at gmail.com>
Cc: Frank Timmes <fxtimmes at gmail.com>; mesa-users <mesa-users at lists.mesastar.org>
Subject: Re: [Mesa-users] Missing energy generation in MESA output?

the energy equation and energy conservation have been a recurring and evolving topic within the source code base and mesa instrument papers - section 8 of mesa iii (paxton et al 2018), in the title and section 3 in mesa iv (paxton et al 2019), and once again in the title and section 5 of mesa vi (jermyn et al 2023). the latter being what i believe represents the current implementation. perhaps they can help shed some light on this situation.

fxt




On Feb 27, 2025, at 5:35 PM, Farag, Ebraheem via Mesa-users <mesa-users at lists.mesastar.org> wrote:

Hello Jason,

(cc'ing mesa-users for this)


  *
Well, I think I solved the energy issue, but not the dT/dm issue.
  *
When using T ds/dt, there is a very slight inconsistency with eps_grav.  When I use the eps_grav method, I get practically perfect agreement with the energy equation from the eps_grav profile output.  When I use the dedt method, I have to use T ds/dt, which is the cause of the disparity.
  *
The new puzzle is why dT/dm gets much better agreement with dP/dm Tbar/Pbar gradT when I use dedt than when I use eps_grav?

I believe I have an idea of what caused this disagreement you're seeing. ​This is not the most general form of the eps_grav equation.

"Δl/Δm = ε_nuc - TdS"

rather it should it is:

"Δl/Δm = ε - dq"

, where I have chosen to say "ε" to characterize that we have (enuc + eneu_nuc) + eneu_non_nuc, and Tds is replaced with dq.

For a purely thermal process dq = Tds, but more formally, dq = Tds + sum[​μi​dX],

Where the second term includes the heat associated with composition changes due to mixing/ionization/burning.

In more complete form,  it is not simply dq = Tds, but rather dq = Tds + sum[partial(e)/partial(yi)] dyi , see equation 58 inhttps://ui.adsabs.harvard.edu/abs/2018ApJS..234...34P/abstract (much more details on eps_grav are here.).
----

I believe this explains why you have a disagreement when adopting the energy equation form and not the eps_grav form. The eps_grav form includes the composition effects, where as you have been assuming eps_grav = -TdS, which is an approximation.

In the profile columns, i find this comment that warns users of this:
 "!delta_entropy ! entropy - entropy_start, change during step (does not include effects of diffusion)"


If we look at the docs, where the eps_grav form is discussed : https://docs.mesastar.org/en/latest/reference/controls.html#eps-grav-form

We find "The final term reflects the change in internal energy due to changes in composition (at fixed density and temperature) and is referred to in MESA as eps_grav_composition_term. "

You can actually test turning this term on or off  to see if it restores your agreement with your estimate:
"include_composition_in_eps_grav = .false.", The default is ".true.".


  *
The new puzzle is why dT/dm gets much better agreement with dP/dm Tbar/Pbar gradT when I use dedt than when I use eps_grav?

I'll have to think about this, but if you're plotting the correct quantities then:
Naively, I would think  this comes from the fact that when adopting the eps_grav form you are explicitly using a derived thermodynamic quantity "S = -∂F/∂T " and then computing an additional derivative "TdS/dt" in your energy equation which can be more sensitive toward any "noise" coming from the EOS and it's precision, and this might propagate into the t-gradient equation. On the other hand, when you adopt the conservative form of the energy equation, you only need "U" (the internal energy) and its direct time derivative, which I believe is a primary variable output from the EOS. Mathematically these approaches should be identical, however numerically they are not.

In this way, (like a magnifying glass) using the eps_grav form is a way of testing the numerical robustness and consistency of your EOS and its derivatives when placed front and center. I believe you need second order continuity in the eos for this approach to work well:
 you require discretized form of -eps_grav ~ TdS ~ d(-T1∂F1/∂T1 + T2∂F2/∂T2)/dt  to be not just continuous but smooth, as additional partial derivatives of this quantity are used to construct the Jacobian matrix used by MESA's multi-dimensional newton Raphson scheme. (where i omitted include the eps_grav composition terms here for brevity).

-EbF


Well, I think I solved the energy issue, but not the dT/dm issue.

When using T ds/dt, there is a very slight inconsistency with eps_grav.  When I use the eps_grav method, I get practically perfect agreement with the energy equation from the eps_grav profile output.  When I use the dedt method, I have to use T ds/dt, which is the cause of the disparity.

The new puzzle is why dT/dm gets much better agreement with dP/dm Tbar/Pbar gradT when I use dedt than when I use eps_grav?



________________________________
From: Jason Wright <astrowright at gmail.com<mailto:astrowright at gmail.com>>
Sent: Thursday, February 27, 2025 2:35:18 PM
To: Farag, Ebraheem <ebraheem.farag at yale.edu<mailto:ebraheem.farag at yale.edu>>
Cc: mesa-users <mesa-users at lists.mesastar.org<mailto:mesa-users at lists.mesastar.org>>
Subject: Re: [Mesa-users] Missing energy generation in MESA output?

Interesting!

Implementing eps_grav solved the problem of the energy imbalance in the atmosphere, so that mystery is solved.

Strangely, where before we had excellent solution for the dT/dm equation, going to the eps_grav formulation created an imbalance in that equation.  I'll investigate more why that might be (have to head out now) but I suppose I must have also triggered an alternative formulation for that equation from the one listed in the first instrument paper somehow.

It did not change the results in the core, though, as you suspected.

I switched to eps_nuc_minus_non_nuc_neu but the difference is very small in my case, (millions of times smaller than the issue I'm having).

Thanks for your prompt help!

Jason

On Thu, Feb 27, 2025 at 1:52 PM Farag, Ebraheem <ebraheem.farag at yale.edu<mailto:ebraheem.farag at yale.edu>> wrote:
Hi Jason,

Without thinking too deeply into the information you've shared.


  *
(I do see there is an advertised eps_grav parameter in MESA, but it is set to zero everywhere, which is why I'm using T ds/dt.  Is there a way to get that output to "turn on"?)

 I believe the energy equation in MESA is now -> 'dedt', a conservative form. The older eps_grav form (eq 11 from MESA I) is still an option "eps_grav", see https://docs.mesastar.org/en/latest/reference/controls.html#energy-eqn-option.

This might be wrong, but I think when the conservative form is chosen, you admit entropy errors to allow for energy conservation, where as when the original eps_grav form is adopted, you admit energy errors for better thermodynamic consistency. In a perfect world these would be identical, but numerically solving yields this fork in the road. The eps_grac parameter should be on when using the 'eps_grav' form of the energy equation.


On both problems, I don't just want eps_nuc but rather eps_nuc - non_nuc_neu, where non_nuc_neu are the thermal neutrino losses. This might help with problem 2, unless you already included it.

I'm still thinking on problem 1... It could be due to the fact that we use a T-tau relation for low tau, but that's something to check?

-EbF
________________________________
From: Mesa-users <mesa-users-bounces at lists.mesastar.org<mailto:mesa-users-bounces at lists.mesastar.org>> on behalf of Jason Wright via Mesa-users <mesa-users at lists.mesastar.org<mailto:mesa-users at lists.mesastar.org>>
Sent: Thursday, February 27, 2025 12:27 PM
To: mesa-users <mesa-users at lists.mesastar.org<mailto:mesa-users at lists.mesastar.org>>
Subject: [Mesa-users] Missing energy generation in MESA output?

Hi, all.  Me again teaching stellar structure with MESA.

One set of our assignments is to test the precision of MESA in computing the equations of stellar structure.  This is a good way for the students to practice coding up physics and exploring which physics matters where in the Sun.  We are using a solar-mass ZAMS star of solar metallicity as our example (from Ed Brown's excellent notes).

We find that the 1st 3 equations of stellar structure are obeyed extremely well, but we are struggling with the luminosity equation.

Δl/Δm = ε_nuc - T

(Eq. 11 of the first MESA instrument paper).

Problem 1:

We get reasonably good agreement for most of the star, but in the outermost cells (m/M > 0.999) there is a big divergence between these quantities.  In the atmosphere of the star, Δl/Δm actually goes very slightly negative, but the reported ε_grav (calculated as -T ds/dt) is still positive there.

I'm guessing the answer is that I'm not calculating T ds/dt properly.  I'm using the delta_entropy profile output, and log_dt from the history file for that timestep.  Perhaps these do not correspond exactly, or that is not the quantity used in determining Δl/Δm?

(I do see there is an advertised eps_grav parameter in MESA, but it is set to zero everywhere, which is why I'm using T ds/dt.  Is there a way to get that output to "turn on"?)

Below:  comparison of the finite difference of Δl/Δm (red, dashed line is negative) and energy generation terms reported by MESA.

[Core is on the left, atmosphere on the right.    The logit_10 function "counts nines" near m/M~1 (so 0.9999 is 4) and "counts zeros" near m~0 (so 0.0001 is -4).  ]
["eps" here is "net_energy", which does not have the precision to show values below 1 erg/s/g]


<Screenshot 2025-02-24 at 1.12.43 PM.png>


Problem 2:

Another mismatch is more subtle, but suggests I'm missing physics.

It's hard to see in the above plot, but the discrepancy actually stars at about m/M=0.5 (logit_10(m/M)=0).  If I integrate up (ε_nuc - T ds/dt)dm to compute luminosity and compare it to the actual luminosity, I get about a 0.1% discrepancy with a strange shape.This shape shares some qualities / features of both eps_nuc and eps_grav, but not exactly.

<Screenshot 2025-02-24 at 1.18.56 PM.png>
Any ideas what's going on?  Am I misunderstanding something about neutrino losses?

Happy to share my code if it helps.



--
                                                -
---------------
Jason T Wright
Professor of Astronomy and Astrophysics
Director, Penn State Extraterrestrial Intelligence Center
he/him/his
https://sites.psu.edu/astrowright/
https://bsky.app/profile/astrowright.bsky.social


--
                                                -
---------------
Jason T Wright
Professor of Astronomy and Astrophysics
Director, Penn State Extraterrestrial Intelligence Center
he/him/his
https://sites.psu.edu/astrowright/
https://bsky.app/profile/astrowright.bsky.social


--
                                                -
---------------
Jason T Wright
Professor of Astronomy and Astrophysics
Director, Penn State Extraterrestrial Intelligence Center
he/him/his
https://sites.psu.edu/astrowright/
https://bsky.app/profile/astrowright.bsky.social


--
                                                -
---------------
Jason T Wright
Professor of Astronomy and Astrophysics
Director, Penn State Extraterrestrial Intelligence Center
he/him/his
https://sites.psu.edu/astrowright/
https://bsky.app/profile/astrowright.bsky.social
_______________________________________________
mesa-users at lists.mesastar.org<mailto:mesa-users at lists.mesastar.org>
https://lists.mesastar.org/mailman/listinfo/mesa-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20250228/8f880bfd/attachment.htm>


More information about the Mesa-users mailing list