Skip to content

Fluid equation of state with density floor#359

Open
bendudson wants to merge 16 commits into
masterfrom
neutral-eos
Open

Fluid equation of state with density floor#359
bendudson wants to merge 16 commits into
masterfrom
neutral-eos

Conversation

@bendudson
Copy link
Copy Markdown
Collaborator

A relatively simple fix that seems to greatly help reduce unphysical behavior near density floors.

Defines the internal energy E as E = Cv * Nlim * T rather than the usual Cv * N * T. This effectively puts a floor on the heat capacity of the fluid. Then solve the pressure equation consistent with this equation of state.

Changes made to pressure equations in evolve_pressure, neutral_mixed and neutral_full_velocity. Unfortunately I ran clang-format on the files so the changes seem numerous. The actual change is quite small: In the pressure advection replace (5/3)P with Nlim * T + (2/3) * P.

This is an example from the midplane of a DIII-D simulation using neutral_full_velocity. The density floor is 1e-5, and previously produced quite unphysical behavior.

image image

bendudson added 3 commits June 8, 2025 20:50
Consistently treat internal energy as Nlim * T, so that
advection of thermal energy takes into account the density floor.

Appears to reduce artefacts where the density falls below the floor.
Improve handling of low density regions by defining the fluid
internal energy as Nlim * T. Modifies the pressure equation.
The internal energy of a fluid is modified to be Nlim * T.  This
changes the pressure equation to be consistent with the application of
a density floor.
@mikekryjak
Copy link
Copy Markdown
Collaborator

@bendudson this is awesome. Looking at evolve_pressure only for now: am I understanding correctly that this in effect makes the density floor in use everywhere consistently, whereas before it was only used where we divided by zero? And P_solver is the pressure without floors that the solver sees, while P is the pressure calculated using floored density?

What about flooring pressure itself? I see that now it's only flooring the density.

I raised an issue to put clang-format in the CI: #360

@bendudson
Copy link
Copy Markdown
Collaborator Author

Hey @mikekryjak . Thanks! The solver now evolves a modified internal energy P_solver = N_lim T, which is divided by N_lim to get temperature, and then the pressure is P = N T. This is why neutral pressure can continue to fall into the core, even when temperature is increasing and the density has hit the floor: the internal energy P_solver is going up into the core, while pressure P is going down.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 65.85366% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.59%. Comparing base (8220ead) to head (440d98f).

Files with missing lines Patch % Lines
src/evolve_pressure.cxx 45.00% 11 Missing ⚠️
src/evolve_momentum.cxx 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #359      +/-   ##
==========================================
+ Coverage   48.54%   48.59%   +0.04%     
==========================================
  Files          96       96              
  Lines        9842     9836       -6     
  Branches     1435     1431       -4     
==========================================
+ Hits         4778     4780       +2     
+ Misses       4574     4566       -8     
  Partials      490      490              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mikekryjak
Copy link
Copy Markdown
Collaborator

@bendudson am I right in thinking that this PR will have no effect if no floor is crossed?

@bendudson
Copy link
Copy Markdown
Collaborator Author

Hey @mikekryjak ! I think that's right, though the softFloor function does change the input above the floor: It's an exponential decay so above 5 or 10 times the floor it will have negligible effect.

Comment thread src/neutral_mixed.cxx Outdated
* Div_a_Grad_perp_flows(DnnPn, logPnlim, ef_adv_perp_xlow, ef_adv_perp_ylow);
ddt(Pn) += (5. / 3)
* Div_a_Grad_perp_flows(Dnn * e_plus_p, logPnlim, ef_adv_perp_xlow,
ef_adv_perp_ylow);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bendudson
Maybe I am misunderstanding something, but isn't the 5/3 already included in basically e_plus_p? That was my understanding why it is not present in the parallel advection anymore.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @totork ! Yes I think you are right: e_plus_p is (5/3) * P so the leading factor should be removed

bendudson added 2 commits May 15, 2026 13:07
Fixing issue noted by @totork. e_plus_p includes the factor of 5/3
because it is p + 2/3 * p.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants