Skip to content

Conversation

@JRChreim
Copy link
Contributor

@JRChreim JRChreim commented Nov 22, 2025

User description

User description

Description

This PR is to expand the SG EoS to its general form.

Such a change is needed for the PC model to work on both 5- and 6-equation models. The major difference is to include the 'q' parameter from the thermal SG EoS

p = (gamma - 1) * rho *(e - q) - gamma * ps_inf

which is also needed to calculate the speed of sound for the 5-equation model

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Scope

  • This PR comprises a set of related changes with a common goal

If you cannot check the above box, please split your PR into multiple PRs that each have a common goal.

How Has This Been Tested?

  • Expansion tube with the 5-equation model and pT-relaxation activated, one single fluid (water liquid), velocity discontinuity in the center (v = +-2 m/s).

Comparison between the pressure behaviour without (black) and with (red) the addition of 'q' into the calculation of the speed of sound.

ExpansionTubeWith5Eqn
  • note that this pT(g)-relaxation in the 5-equation model is only available on my local branch, so I am breaking the PRs into multiple, and this is a necessary predecessor.

Test Configuration:

  • What computers and compilers did you use to test this:
  • only my local computer, as this is a small bug fix

Checklist

They run to completion and demonstrate "interesting physics"

  • I ran ./mfc.sh format before committing my code
  • This PR does not introduce any repeated code (it follows the DRY principle)
  • I cannot think of a way to condense this code and reduce any introduced additional line count

If your code changes any code source files (anything in src/simulation)

To make sure the code is performing as expected on GPU devices, I have:

  • Checked that the code compiles using NVHPC compilers
  • Checked that the code compiles using CRAY compilers
  • Ran the code on either V100, A100, or H100 GPUs and ensured the new feature performed as expected (the GPU results match the CPU results)
  • Ran the code on MI200+ GPUs and ensure the new features performed as expected (the GPU results match the CPU results)
  • Enclosed the new feature via nvtx ranges so that they can be identified in profiles
  • Ran a Nsight Systems profile using ./mfc.sh run XXXX --gpu -t simulation --nsys, and have attached the output file (.nsys-rep) and plain text results to this PR
  • Ran a Rocprof Systems profile using ./mfc.sh run XXXX --gpu -t simulation --rsys --hip-trace, and have attached the output file and plain text results to this PR.
  • Ran my code using various numbers of different GPUs (1, 2, and 8, for example) in parallel and made sure that the results scale similarly to what happens if you run without the new code/feature

PR Type

Bug fix, Enhancement

Description

  • Expand Stiffened Gas (SG) equation of state to general form

    • Include qv parameter (internal energy reference value) in speed of sound calculations
    • Support both 5- and 6-equation models for PC model compatibility
  • Simplify 3-equation model speed of sound calculation

    • Replace loop-based computation with vectorized sum operation
  • Update all speed of sound function calls across codebase

    • Add qv parameter to s_compute_speed_of_sound subroutine signature
    • Propagate qv through enthalpy and data output modules

Diagram Walkthrough

flowchart LR
  A["SG EoS General Form"] -->|"Add qv parameter"| B["s_compute_speed_of_sound"]
  B -->|"Update calls"| C["Riemann Solvers"]
  B -->|"Update calls"| D["Data Output"]
  B -->|"Update calls"| E["CBC Module"]
  B -->|"Update calls"| F["Time Steppers"]
  A -->|"Simplify 3-eq model"| G["Vectorized Computation"]
Loading

File Walkthrough

Relevant files
Enhancement
m_variables_conversion.fpp
Add qv parameter and simplify speed of sound                         

src/common/m_variables_conversion.fpp

  • Add qv parameter to s_compute_speed_of_sound subroutine signature
  • Simplify 3-equation model speed of sound calculation from loop to
    vectorized sum
  • Update 5-equation model to include qv/rho term in speed of sound
    formula
  • Maintain backward compatibility for other model equations
+4/-10   
m_data_output.fpp
Include qv in energy data output calculations                       

src/post_process/m_data_output.fpp

  • Add qv variable declaration and initialization
  • Compute qv as weighted sum of fluid reference energies
  • Update enthalpy calculation to include qv term
  • Pass qv to s_compute_speed_of_sound function call
+5/-3     
m_start_up.fpp
Update speed of sound call with qv field                                 

src/post_process/m_start_up.fpp

  • Pass qv_sf field to s_compute_speed_of_sound function call
  • Ensure speed of sound computation uses spatial qv values
+1/-1     
m_cbc.fpp
Add qv to CBC speed of sound calculation                                 

src/simulation/m_cbc.fpp

  • Pass qv parameter to s_compute_speed_of_sound function call
  • Update characteristic boundary condition speed of sound computation
+1/-1     
m_data_output.fpp
Propagate qv through stability criteria computation           

src/simulation/m_data_output.fpp

  • Add qv variable to private list in GPU parallel loop
  • Update s_compute_enthalpy call to compute and return qv
  • Pass qv to all s_compute_speed_of_sound function calls
  • Ensure stability criteria computation includes qv parameter
+7/-6     
m_riemann_solvers.fpp
Add qv to all Riemann solver speed of sound calls               

src/simulation/m_riemann_solvers.fpp

  • Add qv_avg variable declaration for average state computation
  • Update all s_compute_speed_of_sound calls to include qv parameters
  • Pass qv_L, qv_R, and qv_avg to speed of sound calculations
  • Apply changes across multiple Riemann solver implementations
+21/-19 
m_sim_helpers.fpp
Make qv output parameter in enthalpy computation                 

src/simulation/m_sim_helpers.fpp

  • Add qv as output parameter to s_compute_enthalpy subroutine
  • Change qv from local variable to subroutine output
  • Enable qv value to be returned to calling routines
+3/-2     
m_time_steppers.fpp
Include qv in time stepper CFL computation                             

src/simulation/m_time_steppers.fpp

  • Add qv variable declaration with documentation
  • Add qv to private list in GPU parallel loop
  • Update s_compute_enthalpy calls to compute qv
  • Pass qv to s_compute_speed_of_sound function call
+5/-4     

CodeAnt-AI Description

Account for SG q reference in sound speed and diagnostics

What Changed

  • Sound speed and enthalpy calculations across startup, timestep, Riemann solvers, and boundary routines now pass the SG q reference so the generalized equation of state returns the correct speed of sound for both 5- and 6-equation models.
  • Diagnostic routines (runtime info, energy output, post-processing probes) now accumulate qv when building enthalpy and q averages, keeping reported Mach numbers, energies, and stability criteria consistent with the new sound-speed values.
  • The acoustic averages used in Riemann solvers now include qv so interface fluxes and relaxation steps match the updated EoS form.

Impact

✅ Correct sound speed for SG 5/6-equation waves
✅ Accurate energy and Mach diagnostics with SG q reference
✅ Stable timestep decisions based on q-aware enthalpy

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • New Features

    • Energy outputs and run-time diagnostics now include an additional reference energy term for richer energy reporting.
  • Bug Fixes

    • Speed-of-sound and total-energy calculations consistently account for the reference energy across simulation, solvers, and post-processing.
  • Refactor

    • Enthalpy, sound-speed, stability checks, solver average-state logic, time-steppers, and parallel loops updated to thread the reference energy through relevant computations.

✏️ Tip: You can customize this high-level summary in your review settings.

This PR is to expand the SG EoS to its general form.

Such a change is needed for the PC model to work on both 5 and 6 equation models
@JRChreim JRChreim requested a review from a team November 22, 2025 03:58
@codeant-ai
Copy link

codeant-ai bot commented Nov 22, 2025

CodeAnt AI is reviewing your PR.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 22, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR introduces a new internal-energy reference variable qv, makes s_compute_enthalpy return qv, extends s_compute_speed_of_sound to accept qv, and threads qv through Riemann solvers, time-steppers, post-processing, startup, CBC, data-output, and inline averages; the non-bubble speed-of-sound formula now subtracts qv/rho.

Changes

Cohort / File(s) Change Summary
Speed-of-sound computation
src/common/m_variables_conversion.fpp
s_compute_speed_of_sound signature extended to accept qv (real(wp) intent(in)); non-bubble/non-chemistry branch updated to compute c = (H - 0.5*vel_sum - qv/rho)/gamma; minor comment fix.
Enthalpy computation
src/simulation/m_sim_helpers.fpp
s_compute_enthalpy signature changed to add qv as an output argument (removed local qv); callers must now receive qv.
Post-processing: energy & startup
src/post_process/m_data_output.fpp, src/post_process/m_start_up.fpp
qv declared/initialized/accumulated in energy routines; H updated to include qv; calls to s_compute_speed_of_sound extended to pass qv (startup passes qv_sf(i,j,k)).
Simulation: data output & CBC
src/simulation/m_data_output.fpp, src/simulation/m_cbc.fpp
Local qv introduced and added to GPU private lists; qv passed to s_compute_enthalpy and s_compute_speed_of_sound; CBC call sites updated to pass qv.
Riemann solvers
src/simulation/m_riemann_solvers.fpp
New qv_avg/qv_L/qv_R introduced; average-state computations extended to compute/propagate qv_avg; all relevant calls to s_compute_speed_of_sound now include qv; GPU loop private/copyin lists updated.
Inline averages
src/simulation/include/inline_riemann.fpp
Added qv_avg to arithmetic_avg and roe_avg (density-weighted/mean forms).
Time steppers & runtime info
src/simulation/m_time_steppers.fpp, src/simulation/m_data_output.fpp
qv added to GPU/private clauses and threaded through enthalpy and speed-of-sound call sites; runtime info and stability criteria updated to use qv.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Enthalpy as s_compute_enthalpy
    participant SpeedSound as s_compute_speed_of_sound

    Caller->>Enthalpy: compute H (pres,rho,gamma,pi_inf,vel,...) 
    Note right of Enthalpy `#DDEEFF`: returns H and qv (qv now an output)
    Enthalpy-->>Caller: H, qv

    Caller->>SpeedSound: compute c (pres,rho,gamma,pi_inf,H,adv,vel_sum, ..., qv)
    Note right of SpeedSound `#F6E7D7`: non-bubble path uses qv: c = (H - 0.5*vel_sum - qv/rho)/gamma
    SpeedSound-->>Caller: c
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Focus review on src/simulation/m_riemann_solvers.fpp (many call-site and averaging logic changes).
  • Verify all call sites for s_compute_enthalpy and s_compute_speed_of_sound match updated signatures.
  • Inspect GPU/OpenACC private/copyin lists where qv was added for potential race conditions.
  • Review physical/formula change in src/common/m_variables_conversion.fpp for consistency across model branches.

Suggested labels

Review effort 4/5, size:XXL

Suggested reviewers

  • wilfonba

Poem

🐰 A tiny qv hopped into the code,

It warmed up H on every road,
From enthalpy's pocket to solver's call,
It threaded through modules, short and tall,
Sound speeds now hum — a rabbit's ode.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Complete form of the SG EoS' directly aligns with the PR's main objective to expand the Stiffened Gas equation of state to its general form.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description is comprehensive and follows the template structure with most required sections completed.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-merge-pro
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

In the 5-equation branch, the new formula uses c = (H - 0.5*vel_sum - qv/rho)/gamma. Ensure this matches the intended SG EoS derivation for speed of sound (units and dependence) and that H provided already includes/excludes qv consistently to avoid double-counting qv.

    c = (H - 5.e-1*vel_sum - qv/rho)/gamma
end if

if (mixture_err .and. c < 0._wp) then
    c = 100._wp*sgm_eps
Logic Consistency

H is modified to include qv: H = ((gamma + 1)*pres + pi_inf + qv)/rho, and qv is also passed separately to s_compute_speed_of_sound. Verify that downstream usage expects H with qv included; otherwise the qv/rho subtraction inside s_compute_speed_of_sound could cancel incorrectly.

H = ((gamma + 1._wp)*pres + pi_inf + qv)/rho

call s_compute_speed_of_sound(pres, rho, &
                              gamma, pi_inf, &
                              H, adv, 0._wp, 0._wp, c, qv)
API Change

s_compute_speed_of_sound gained a new qv argument; confirm all call sites were updated (including less-traveled code paths and preprocess-disabled sections) to prevent mismatched interface at compile time, especially for alternative models or conditional branches.

subroutine s_compute_speed_of_sound(pres, rho, gamma, pi_inf, H, adv, vel_sum, c_c, c, qv)
    $:GPU_ROUTINE(function_name='s_compute_speed_of_sound', &
        & parallelism='[seq]', cray_inline=True)

    real(wp), intent(in) :: pres
    real(wp), intent(in) :: rho, gamma, pi_inf, qv
    real(wp), intent(in) :: H
    real(wp), dimension(num_fluids), intent(in) :: adv
    real(wp), intent(in) :: vel_sum
    real(wp), intent(in) :: c_c

@codeant-ai codeant-ai bot added the size:M This PR changes 30-99 lines, ignoring generated files label Nov 22, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 8 files

@codeant-ai
Copy link

codeant-ai bot commented Nov 22, 2025

CodeAnt AI finished reviewing your PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/simulation/m_riemann_solvers.fpp (1)

361-375: Make qv_avg private inside every GPU loop

qv_avg is newly introduced for the averaged stiffened-gas offset but it isn’t added to the private set of the GPU loops (e.g., this @:GPU_PARALLEL_LOOP and the analogous HLLC loop around Line 2003). On accelerators that share loop variables by default, this leaves qv_avg as a race-prone shared scalar, so different cell evaluations stomp on each other’s value and the averaged speed of sound becomes numerically garbage. Please add qv_avg to the private lists for all of these kernels.

- $:GPU_PARALLEL_LOOP(... private='[..., qv_L, qv_R, c_L, c_R, G_L, G_R, rho_avg, H_avg, c_avg, gamma_avg, ...]')
+ $:GPU_PARALLEL_LOOP(... private='[..., qv_L, qv_R, qv_avg, c_L, c_R, G_L, G_R, rho_avg, H_avg, c_avg, gamma_avg, ...]')

…and repeat for every other @:GPU_PARALLEL_LOOP that uses qv_avg.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22af239 and 62d430e.

📒 Files selected for processing (8)
  • src/common/m_variables_conversion.fpp (3 hunks)
  • src/post_process/m_data_output.fpp (3 hunks)
  • src/post_process/m_start_up.fpp (1 hunks)
  • src/simulation/m_cbc.fpp (1 hunks)
  • src/simulation/m_data_output.fpp (4 hunks)
  • src/simulation/m_riemann_solvers.fpp (9 hunks)
  • src/simulation/m_sim_helpers.fpp (1 hunks)
  • src/simulation/m_time_steppers.fpp (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Spell Check
  • GitHub Check: Detect File Changes
  • GitHub Check: Detect File Changes
  • GitHub Check: Detect File Changes
  • GitHub Check: Build & Publish
  • GitHub Check: PMD
  • GitHub Check: Detect File Changes
  • GitHub Check: Detect File Changes
  • GitHub Check: Lint Source
  • GitHub Check: Detect File Changes
  • GitHub Check: Formatting
  • GitHub Check: Lint Toolchain
  • GitHub Check: cubic · AI code reviewer
🔇 Additional comments (19)
src/simulation/m_cbc.fpp (1)

857-857: LGTM! Signature update is consistent.

The call to s_compute_speed_of_sound correctly includes qv as the new final parameter, and qv is properly obtained from the mixture variable conversion at lines 817-819.

src/post_process/m_start_up.fpp (1)

703-703: LGTM! Post-processing signature updated correctly.

The call to s_compute_speed_of_sound now includes qv_sf(i, j, k) as the final parameter, consistent with the PR's goal of incorporating the thermal SG EoS parameter.

src/simulation/m_time_steppers.fpp (1)

712-740: LGTM! Proper threading of qv through time-stepping.

The changes correctly:

  1. Declare qv as a local variable (line 712)
  2. Include it in the GPU private list (line 729)
  3. Obtain it as an output from s_compute_enthalpy (lines 734, 736)
  4. Pass it to s_compute_speed_of_sound (line 740)

The implementation maintains the correct data flow for the new thermal SG EoS parameter.

src/simulation/m_data_output.fpp (2)

276-289: LGTM! Consistent threading through run-time information.

The changes in s_write_run_time_information properly:

  1. Declare qv as a local variable
  2. Add it to the GPU private list
  3. Obtain it from s_compute_enthalpy
  4. Pass it to s_compute_speed_of_sound

1296-1296: Code verified as correct—no changes needed.

The inline enthalpy formula ((gamma + 1._wp)*pres + pi_inf)/rho is correct for the stiffened gas EoS. The s_compute_speed_of_sound function properly accounts for qv by subtracting qv/rho from the enthalpy (line 1656 of src/common/m_variables_conversion.fpp). This design—computing/passing enthalpy without qv and handling the reference energy separately inside the function—is consistent throughout the codebase (e.g., m_cbc.fpp line 854, m_riemann_solvers.fpp multiple locations). The physics is accurate.

src/post_process/m_data_output.fpp (4)

1585-1585: Variable declaration looks correct.

The addition of qv to the variable declaration list is appropriate and follows the existing code style.


1629-1629: Accumulation formula is correct (assuming the initialization bug is fixed).

The formula qv = qv + adv(l)*q_prim_vf(l)%sf(i,j,k)*fluid_pp(l)%qv correctly computes the volume-fraction-weighted internal energy reference. The units are dimensionally consistent: volume fraction × partial density × specific energy reference = energy per volume (pressure units), which matches the usage in the enthalpy formula at line 1632.


1632-1632: Enthalpy formula correctly implements the general SG EoS.

The addition of qv to the enthalpy calculation implements the thermal SG EoS parameter as described in the PR objectives. The formula H = ((gamma + 1._wp)*pres + pi_inf + qv)/rho is dimensionally consistent and correctly incorporates the internal energy reference term.


1634-1636: Speed of sound call correctly includes qv parameter.

The addition of qv as the final parameter to s_compute_speed_of_sound is consistent with the PR objective to compute speed of sound correctly for the 5-equation model. The parameter is passed after computing both H (which includes qv) and the accumulated qv value itself.

src/common/m_variables_conversion.fpp (10)

426-433: LGTM: Density-weighted qv accumulation is physically sound.

The density-weighted accumulation qv = qv + alpha_rho_K(i)*qvs(i) correctly computes the mixture's energy reference by summing partial density contributions from each fluid. This pattern is consistently applied across the codebase (lines 300, 313, 514, 573, 580).


143-149: LGTM: qv correctly integrated into pressure calculations.

The qv term is consistently subtracted from the energy before computing pressure across all branches (MHD, standard, bubbles_euler). This correctly implements the Stiffened Gas EoS form: p = (gamma - 1) * rho * (e - q) - gamma * pi_inf, which matches the PR objectives.


626-650: LGTM: Proper initialization of qvs and qvps arrays.

The qv-related arrays are correctly allocated and initialized from the fluid_pp structure for all fluids, with proper GPU memory management. The pattern follows the existing initialization of gammas, pi_infs, etc.


1586-1595: LGTM: Complete deallocation of qv-related arrays.

All qv-related memory (qv_sf, qvs, qvps) is properly deallocated, preventing memory leaks.


826-826: LGTM: qv properly threaded through conservative-to-primitive conversion.

The qv_K variable is correctly declared, computed from mixture variables, and passed to s_compute_pressure, ensuring the qv term participates in the pressure calculation as intended.

Also applies to: 884-891, 1038-1041


1303-1310: LGTM: qv correctly added to energy in primitive-to-conservative conversion.

The qv term is properly added to the conservative energy variable (lines 1305, 1310), which is the inverse operation of subtracting it during pressure computation. This maintains consistency with the Stiffened Gas EoS.


1524-1526: LGTM: qv included in flux energy computation.

The qv_K term is correctly included in the energy calculation for flux variables, maintaining consistency with the conservative energy formulation.


1651-1651: Manually verify H computation and qv consistency in speed of sound formula.

The verification encountered limitations due to code generation and preprocessing in the file. The subroutine s_compute_speed_of_sound at line 1604 takes H and qv as separate input parameters, and line 1651 subtracts both (H - 5.e-1*vel_sum - qv/rho)/gamma.

However:

  • No call sites to s_compute_speed_of_sound were found in the codebase
  • No references to s_convert_primitive_to_flux_variables were found
  • The file uses preprocessor directives (#ifndef MFC_PRE_PROCESS) suggesting build-time code generation

Please manually verify:

  1. Where H is computed before being passed to s_compute_speed_of_sound
  2. Whether H already includes the qv term in its upstream calculation
  3. Whether the subtraction of qv/rho on line 1651 is correct (not a double-subtraction)
  4. Build/generation scripts to understand how this subroutine is actually called

221-221: Hardcoded qv = 0._wp at line 221 is flagged as incomplete work and needs clarification.

Line 221 explicitly includes a TODO-like comment ("keep this value nill for now. For future adjustment"), indicating this is known incomplete implementation for the gamma/pi_inf model (model_eqns==1). However, qv is used downstream in pressure, energy, and speed of sound calculations, so hardcoding it to zero may produce incorrect results.

The suggested fix in the original comment (using fluid_pp(1)%qv) references a different function's pattern and may not be the intended approach here. Clarify:

  • Should model_eqns==1 extract qv from a field variable (would require adding qv_idx, similar to gamma_idx/pi_inf_idx)?
  • Or should it use fluid_pp(1)%qv despite the current pattern of extracting from fields?
  • If qv=0 is intentional for this model, the downstream calculations using qv need review.

1636-1638: The code is correct—model_eqns == 3 is the 6-equation model, not 5-equation, and uses a different speed of sound formulation.

The verification confirms that line 1637 is correct as-is. The speed of sound formula c = sum(adv*gs_min*(pres + ps_inf))/rho is the appropriate formulation for the 6-equation model (Saurel et al., 2009), which uses mixture-based computation via volume fractions and stiffness terms. The qv parameter is only utilized in the else branch (model_eqns == 1, the Gamma/Pi_inf model) at line 1651, which is the intended design: different equation systems use different physical formulations. The qv parameter is necessary in the function signature because all call sites provide it for model_eqns == 1 cases. No changes required.

@JRChreim JRChreim changed the title Sg eo s Complete form of the SG EoS Nov 22, 2025
@codecov
Copy link

codecov bot commented Nov 22, 2025

Codecov Report

❌ Patch coverage is 60.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.35%. Comparing base (22af239) to head (7e030b8).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
src/post_process/m_data_output.fpp 0.00% 4 Missing ⚠️
src/simulation/m_riemann_solvers.fpp 71.42% 4 Missing ⚠️
src/simulation/m_data_output.fpp 60.00% 2 Missing ⚠️
src/common/m_variables_conversion.fpp 50.00% 1 Missing ⚠️
src/simulation/m_time_steppers.fpp 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1057      +/-   ##
==========================================
+ Coverage   44.34%   44.35%   +0.01%     
==========================================
  Files          71       71              
  Lines       20578    20589      +11     
  Branches     1990     1990              
==========================================
+ Hits         9125     9133       +8     
- Misses      10308    10311       +3     
  Partials     1145     1145              

☔ 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.

@codeant-ai
Copy link

codeant-ai bot commented Nov 23, 2025

CodeAnt AI is running Incremental review

@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Nov 23, 2025
@codeant-ai
Copy link

codeant-ai bot commented Nov 23, 2025

CodeAnt AI Incremental review completed.

Copy link
Contributor Author

@JRChreim JRChreim left a comment

Choose a reason for hiding this comment

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

All suggestions have been reviewed, and the revert requested by @wilfonba was also done

@wilfonba
Copy link
Contributor

@JRChreim Any idea why the tests are failing with minor tolerance violations? As far as I can tell from the changes, the answers shouldn't change as long as qv is zero.

@codeant-ai
Copy link

codeant-ai bot commented Nov 23, 2025

CodeAnt AI is running Incremental review

@wilfonba
Copy link
Contributor

Never mind. I think I fixed it.

@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Nov 23, 2025
@codeant-ai
Copy link

codeant-ai bot commented Nov 23, 2025

CodeAnt AI Incremental review completed.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files (reviewed changes from recent commits).

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="src/simulation/include/inline_riemann.fpp">

<violation number="1" location="src/simulation/include/inline_riemann.fpp:36">
Roe-averaged `qv` is computed with enthalpy values and `sqrt(qv)` weights, so the reference energy passed to the SG EOS is wrong; weight it with `sqrt(rho)` and average the actual `qv` values.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/simulation/m_riemann_solvers.fpp (1)

1938-1943: Ensure flux_ene_e is private in the 5‑equation HLLC GPU loop when elasticity is enabled

In the 5‑equation HLLC branch’s GPU_PARALLEL_LOOP (starting around Line 3095), the private list does not include flux_ene_e, yet:

  • flux_ene_e is a subroutine-local scalar (declared near Line 1970).
  • It is used and reassigned inside the loop when elasticity is true:
if (elasticity) then
    flux_ene_e = 0._wp
    ...
    flux_ene_e = flux_ene_e - ...
    ...
    flux_rs${XYZ}$_vf(j, k, l, E_idx) = flux_rs${XYZ}$_vf(j, k, l, E_idx) + flux_ene_e
end if

If elasticity can ever be active for this branch, sharing flux_ene_e across iterations/threads on the device would introduce a data race and corrupt the energy flux.

I suggest adding flux_ene_e to the private clause of this loop for safety:

- $:GPU_PARALLEL_LOOP(collapse=3, private='[Re_max, i, q, T_L, T_R, idx1, idxi, vel_L_rms, ...
-                                           Yi_avg,Phi_avg, h_iL, h_iR, h_avg_2, G_L, G_R]', copyin='[is1, is2, is3]')
+ $:GPU_PARALLEL_LOOP(collapse=3, private='[Re_max, i, q, T_L, T_R, idx1, idxi, vel_L_rms, ...
+                                           Yi_avg,Phi_avg, h_iL, h_iR, h_avg_2, flux_ene_e, G_L, G_R]', copyin='[is1, is2, is3]')

If by construction elasticity is guaranteed to be false for model_eqns corresponding to this branch, it would still be clearer and more robust to treat flux_ene_e as private here.

Also applies to: 3095-3310, 3435-3451

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec8834a and d7fd48f.

📒 Files selected for processing (1)
  • src/simulation/m_riemann_solvers.fpp (14 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: Code Cleanliness Check
  • GitHub Check: Github (macos, mpi, debug, false)
  • GitHub Check: Github (ubuntu, no-mpi, single, no-debug, false)
  • GitHub Check: Github (macos, mpi, no-debug, false)
  • GitHub Check: Github (ubuntu, mpi, no-debug, false)
  • GitHub Check: Self Hosted (cpu, none, frontier)
  • GitHub Check: Github (ubuntu, mpi, no-debug, true)
  • GitHub Check: Github (ubuntu, mpi, debug, true)
  • GitHub Check: Github (ubuntu, mpi, debug, false)
  • GitHub Check: Self Hosted (cpu, none, gt)
  • GitHub Check: Self Hosted (gpu, acc, gt)
  • GitHub Check: Self Hosted (gpu, omp, gt)
  • GitHub Check: Self Hosted (gpu, omp, frontier)
  • GitHub Check: Self Hosted (gpu, acc, frontier)
  • GitHub Check: Coverage Test on CodeCov
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Build & Publish
🔇 Additional comments (5)
src/simulation/m_riemann_solvers.fpp (5)

320-323: HLL solver: qv handling and speed-of-sound calls look consistent

  • qv_L/qv_R are accumulated using alpha_rho_* * qvs(i) and included in energy E_* in the same way as gamma_* and pi_inf_*, which keeps the SG energetics consistent.
  • qv_avg is declared and treated as a private scalar in the GPU loop, and then passed into s_compute_speed_of_sound along with the updated signature (…, vel_*_rms, ..., c_*, qv_*).

This block is internally consistent with the SG+qv formulation and with how the other Riemann solvers are updated.

Also applies to: 361-452, 632-643


1129-1219: LF solver: qv propagation into sound-speed is correct

  • qv_L/qv_R are initialized, built from alpha_rho_* * qvs(i), and then added to E_* in non‑chemistry branches in the same way as in HLL/HLLC.
  • The GPU loop’s private list now includes qv_L and qv_R, avoiding shared-state issues on accelerators.
  • Both left and right calls to s_compute_speed_of_sound use the new trailing qv argument in the expected position: (..., vel_*_rms, 0._wp, c_*, qv_*).

Looks correct and symmetric between left and right states.

Also applies to: 1359-1364


1938-1943: HLLC 6‑equation (model_eqns == 3): qv integration is coherent

  • qv_L/qv_R are reset to zero, accumulated with qL/R_prim * qvs(i), and included in E_L/E_R prior to computing H_L/H_R, keeping energy consistent with the extended SG EOS.
  • qv_avg is declared, made private in the GPU loop, and passed into the average-state s_compute_speed_of_sound call alongside rho_avg, H_avg, and gamma_avg.
  • Left/right and average sound-speed calls all pass qv_* as the final argument, preserving the previous argument ordering.

This branch’s treatment of qv matches the intended SG generalization.

Also applies to: 2000-2013, 2028-2078, 2098-2176


1938-1943: HLLC 4‑equation (model_eqns == 4): qv usage is consistent with other branches

  • qv_L/qv_R are built from alpha_rho_* * qvs(i) and included in E_L/E_R and thus in H_L/H_R, same pattern as in the 6‑equation branch.
  • The GPU private list is updated to include qv_L, qv_R, and qv_avg.
  • All three s_compute_speed_of_sound calls use the new trailing qv parameter correctly.

No correctness or threading red flags here.

Also applies to: 2414-2423, 2452-2487


3650-3753: HLLD solver: qv threading into the MHD SG EOS is clean

  • The new riemann_states :: qv member is accumulated alongside rho, gamma, and pi_inf from alpha_rho_* and alpha_*.
  • E%L/E%R and H_no_mag%L/H_no_mag%R include qv%L/qv%R consistently with the extended SG equation of state.
  • Left and right calls to s_compute_speed_of_sound use qv%L and qv%R as the final argument, then feed c into the fast magnetosonic speed calculation.

No issues spotted in this integration; the HLLD path stays self-consistent.

JRChreim

This comment was marked as duplicate.

@JRChreim
Copy link
Contributor Author

Never mind. I think I fixed it.

Thank you. I missed that

Including a suggestion from coderabbitai, effectively initializing qv_avg to input parameter on 's_compute_speed_of_sound'
@codeant-ai
Copy link

codeant-ai bot commented Nov 23, 2025

CodeAnt AI is running Incremental review

@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Nov 23, 2025
@codeant-ai
Copy link

codeant-ai bot commented Nov 23, 2025

CodeAnt AI Incremental review completed.

@codeant-ai
Copy link

codeant-ai bot commented Nov 24, 2025

CodeAnt AI is running Incremental review

@codeant-ai codeant-ai bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Nov 24, 2025
@codeant-ai
Copy link

codeant-ai bot commented Nov 24, 2025

CodeAnt AI Incremental review completed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/simulation/m_riemann_solvers.fpp (1)

2757-2855: Fix from past review: qv_avg now initialized in bubbles-euler avg_state==2

This addresses the prior critical issue:

  • When avg_state == 2, you now compute
    • rho_avg, H_avg, gamma_avg as simple arithmetic means, and
    • qv_avg = 0.5*(qv_L + qv_R) (Line 2853).

This ensures qv_avg is always defined before the subsequent call to s_compute_speed_of_sound that uses it, eliminating the uninitialized‑variable bug in this region (and matching the pattern used for other averages).

🧹 Nitpick comments (2)
src/simulation/m_riemann_solvers.fpp (2)

318-323: Add qv_avg with consistent initialization in HLL solver

qv_avg is declared and added to the GPU private list, and is passed to s_compute_speed_of_sound for c_avg. This is correct assuming @:compute_average_state() fills qv_avg for the models using an average state.

Please double‑check that @:compute_average_state() indeed assigns qv_avg for every configuration where avg_state leads to the average-speed computation; otherwise, add an explicit qv_avg initialization alongside rho_avg, H_avg, and gamma_avg.


2665-2721: bubbles_euler ME2: qv_L/qv_R initialized robustly across num_fluids cases

In this branch:

  • qv_L/qv_R are zeroed and then consistently filled either in the full loop (num_fluids > 2 with or without mpp_lim) or via direct single‑fluid assignments (num_fluids == 1).
  • This covers all num_fluids conditions used in this block; qv_* cannot remain uninitialized on any path.

The remaining E/H formulas (currently omitting + qv from E_*) are unchanged from prior behavior except for qv usage in the EOS via c_*; this looks intentional, but you may want to confirm consistency with the SG definition for this reduced model.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98ce554 and 7e030b8.

📒 Files selected for processing (1)
  • src/simulation/m_riemann_solvers.fpp (15 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: Self Hosted (cpu, none, gt)
  • GitHub Check: Self Hosted (gpu, omp, frontier)
  • GitHub Check: Self Hosted (cpu, none, frontier)
  • GitHub Check: Github (ubuntu, no-mpi, single, no-debug, false)
  • GitHub Check: Self Hosted (gpu, omp, gt)
  • GitHub Check: Self Hosted (gpu, acc, gt)
  • GitHub Check: Self Hosted (gpu, acc, frontier)
  • GitHub Check: Github (ubuntu, mpi, no-debug, false)
  • GitHub Check: Github (macos, mpi, no-debug, false)
  • GitHub Check: Github (macos, mpi, debug, false)
  • GitHub Check: Github (ubuntu, mpi, no-debug, true)
  • GitHub Check: Github (ubuntu, mpi, debug, false)
  • GitHub Check: Github (ubuntu, mpi, debug, true)
  • GitHub Check: Coverage Test on CodeCov
  • GitHub Check: Code Cleanliness Check
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Build & Publish
🔇 Additional comments (17)
src/simulation/m_riemann_solvers.fpp (17)

361-363: GPU private list correctly extended to include qv variables

The HLL solver’s GPU loop private list now includes qv_L, qv_R, and qv_avg, matching their use inside the loop and preventing race conditions on GPUs. No further changes needed here.


632-643: Speed-of-sound calls in HLL solver now consistently pass qv

All three calls to s_compute_speed_of_sound in HLL (left, right, and average states) now pass the appropriate qv_* value. This keeps the SG EOS consistent for both one‑sided and averaged states, provided qv_avg is initialized as noted earlier.


1128-1130: LF solver GPU private list includes new qv state

In the Lax–Friedrichs solver, qv_L and qv_R are added to the GPU private list and are used later in the sound‑speed and energy expressions. This matches their use; no qv_avg is needed since only side speeds are computed here. Looks good.


1359-1364: LF solver speed-of-sound calls correctly extended with qv

The LF solver now passes qv_L and qv_R into s_compute_speed_of_sound. This is consistent with how E and H are constructed and should preserve behavior when qvs are zero while enabling non‑zero qv support.


1940-1942: qv_avg added to HLLC average-state variables

Declaring qv_avg alongside rho_avg, H_avg, and gamma_avg in HLLC matches its role as a reference-energy average for the EOS. This is the right place to store it for average sound‑speed computations.


2003-2004: ME3 (model_eqns == 3) GPU private list includes qv_avg

In the ME3 branch, the GPU private list now carries qv_L, qv_R, and qv_avg, which are used in the energy and sound‑speed computations. This prevents unintended sharing of these scalars across threads and is consistent with their usage.


2010-2077: ME3: qv_L/qv_R computed consistently with density and EOS

For the 6‑equation ME3 branch:

  • qv_L/qv_R are initialized to zero and then accumulated as sum(alpha_rho * qvs) inside the same loop that forms rho, gamma, and pi_inf.
  • E and H include qv_* via E_* = gamma_* p + pi_inf_* + 0.5 ρ v² + qv_*, which is consistent with the stiffened‑gas form used elsewhere.

Assuming @:compute_average_state() takes care of qv_avg, these changes look physically and numerically consistent.


2160-2170: ME3 average-state speed-of-sound uses qv_avg

The left/right sound speeds now use qv_L/qv_R, and c_avg uses qv_avg. This aligns the average-state wave‑speed estimate with the updated SG EOS. Just ensure @:compute_average_state() sets qv_avg before this call for all ME3 cases.


2416-2417: ME4 GPU private list updated with qv and averages

In the ME4 branch, the GPU private list now contains qv_L, qv_R, and qv_avg alongside rho_avg, H_avg, gamma_avg, etc. This matches subsequent use in E/H and speed-of-sound and is necessary for thread safety on GPU.


2452-2463: ME4: qv_L/qv_R computed analogously to other mixture properties

Here qv_L/qv_R are computed as mixture‑weighted sums sum(alpha_rho * qvs) in the same loops that compute rho, gamma, and pi_inf. This is consistent and should keep qv proportional to partial mass contributions.


2477-2487: ME4 sound-speed calls correctly pass qv for all states

In ME4:

  • Left/right calls to s_compute_speed_of_sound pass qv_L and qv_R.
  • The average‑state call passes qv_avg.

This ensures wave speeds respect the reference-energy offset for both side and averaged states. As with other branches, correctness depends on qv_avg being initialized by the average‑state macro.


2659-2661: bubbles_euler (model_eqns == 2) GPU private list now includes qv and averages

For the 2‑equation bubbles‑euler branch, the private list now carries qv_L, qv_R, qv_avg, and c_avg. This matches their usage in speed‑of‑sound and average‑state computations and avoids shared‑state issues in the GPU loop.


2863-2873: bubbles_euler ME2: average sound speed now properly includes qv_avg

Left/right sound speeds use qv_L/qv_R, and the average call now uses qv_avg. With the new initialization of qv_avg, average‑state wave speeds are now consistent with the stiffened‑gas EOS for this bubbles‑euler branch.


3096-3097: 5-equation HLLC branch GPU private list updated with qv_avg

For the 5‑equation model, the GPU private list now includes qv_L, qv_R, and qv_avg among the other state and average variables. This matches later usage in E/H and sound‑speed computations.


3231-3237: 5-equation HLLC: non-chemistry energy uses qv_L/qv_R consistently

In the non‑chemistry case, E is formed as:

  • E_L = gamma_L*pres_L + pi_inf_L + 0.5*rho_L*vel_L_rms + qv_L
  • E_R = gamma_R*pres_R + pi_inf_R + 0.5*rho_R*vel_R_rms + qv_R

and then H is (E + p)/rho. This matches the intended SG EOS with reference energy and ensures enthalpy and sound speed see the same offset.


3300-3310: 5-equation HLLC: all speed-of-sound calls extended with qv

For the 5‑equation branch:

  • Left/right calls pass qv_L and qv_R.
  • The average call uses qv_avg along with rho_avg, gamma_avg, and H_avg.

Given qv_avg is part of the average‑state data, this keeps the characteristic speeds consistent with the updated SG EOS.


3755-3757: HLLD MHD: sound speed now uses qv%L/qv%R

In the HLLD solver, sound speeds for the MHD fast‑wave calculation now pass qv%L and qv%R into s_compute_speed_of_sound. Since qv is built alongside rho, gamma, and pi_inf, this change correctly threads the reference energy into the MHD wave‑speed estimate as well.

Copy link
Contributor

@wilfonba wilfonba left a comment

Choose a reason for hiding this comment

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

Benchmark

@JRChreim JRChreim merged commit 76d6a5c into MFlowCode:master Nov 24, 2025
36 of 39 checks passed
@JRChreim JRChreim deleted the SGEoS branch November 24, 2025 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 3/5 size:M This PR changes 30-99 lines, ignoring generated files

Development

Successfully merging this pull request may close these issues.

2 participants