Skip to content

Brunt B from eos partials #823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Brunt B from eos partials #823

wants to merge 11 commits into from

Conversation

Debraheem
Copy link
Member

@Debraheem Debraheem commented May 22, 2025

This pr adds an option to directly compute the Brunt B term from eos partials.

The “B” term appears in the Brunt-Vaisala frequency and the Ledoux criterion (see section 3.3 of Paxton+2013, aka MESA II). Currently, we evaluate B on cell faces using finite difference directional derivative between the compositions of neighboring cells (equations 7 & 8 of MESA II).

This pr attempts to compute the "B" term directly using its formal definition following equation 6.

B = −1/χTi=1N−1 (∂ ln P / ∂ ln Xi)ρ,T,Xj≠i · (d ln Xi / d ln P).

In practice, I actually sum over all the isotopes, and don't enforce the (\sum_{i=1}^N X_i = 1) condition, but that might be necessary if this is eventually turned into an implicit formulation.

I am still left wondering if it is worth computing this term using a compensator or quad precision (optionally?), as this term involves a summation over all terms that appear in the network, and hence is prone to loss of precision from consecutive subtraction/addition of large and small numbers.

Tagging asteroseismology folks who probablt know better than me for a review... I'm curious what if any effect this will have...

(still missing a changelog entry, but we will get there if this even works.)

@Debraheem Debraheem self-assigned this May 22, 2025
@Debraheem Debraheem added the enhancement New feature or request label May 22, 2025
@Debraheem
Copy link
Member Author

At the moment, the eos partials from skye, PC, and ideal eos are 0. MESA gets around this using finite differences for these terms in the hydro solver, so i'm considering employing that approach here, while there is no alternative.

At the moment, this just sets the brunt B term to 0 when using these three EOS'.

If gfortan had good support for derived types for arrays, then this would become a non-issue for Skye as it could then return the eos partials using the current machinery and a dynamic array size set by the number of isotopes in the network. Still waiting for a day when this becomes a reality, but looking at the latest gfort 15.1, this compiler support issue still persists.

@rhdtownsend
Copy link
Contributor

rhdtownsend commented May 22, 2025 via email

@Debraheem
Copy link
Member Author

Debraheem commented May 22, 2025

Sorry i think it is called a parameterized derived type? I probably explained that incorrectly, and I'm a compiler newb. You might already be familiar with this.

Instead of having fixed typing for example:
auto_diff_real_star_order1 (which is fixed to 33 star variables) is set with a fixed size.

 type :: auto_diff_real_star_order1
     real(dp) :: val
     real(dp) :: d1Array(33)
  end type auto_diff_real_star_order1

In theory you could have an auto_diff type that can handle an arbitrary sized array of variables and the compiler would handle it at run time, something like:

type(auto_diff_real_star_order1(nVar))

In SKYE, Adam has
auto_diff_real_2var_order3 (fixed to 2 variables for rho-T, what SKYE uses)

and he sets all the eos derivatives to 0, but if you could do auto_diff_real_order3(2+num_isos), then SKYE would compute these partials for your for free-ish?

from https://ui.adsabs.harvard.edu/abs/2021ApJ...913...72J/abstract

Screen Shot 2025-05-22 at 12 01 48 PM
(accidentally shared the wrong png)

As far as I'm aware, this is still an issue. But there could be a way to hack around it...

@rhdtownsend
Copy link
Contributor

rhdtownsend commented May 22, 2025 via email

@warrickball
Copy link
Contributor

IIRC this GCC bug report is the relevant one.

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