Skip to content

Fill ptil so probe output stops writing undefined ptilde and ptot - #1742

Merged
sbryngelson merged 1 commit into
masterfrom
fix/ptilde-probe-output
Aug 20, 2026
Merged

Fill ptil so probe output stops writing undefined ptilde and ptot#1742
sbryngelson merged 1 commit into
masterfrom
fix/ptilde-probe-output

Conversation

@sbryngelson

Copy link
Copy Markdown
Member

Description

ptil is allocated in m_global_parameters.fpp:929 and pushed to the device, but nothing in the codebase ever assigns it. The probe path reads it anyway:

  • m_data_output.fpp:1300 ptilde = ptil(j - 2, k, l)
  • m_data_output.fpp:1301 ptot = pres - ptilde
  • m_data_output.fpp:1471 both are passed through s_mpi_allreduce_sum
  • m_data_output.fpp:1509 both are written to the probe file

So 1D Euler-Euler bubble runs with probe_wrt = T and num_fluids = 3 have been writing undefined values in the ptilde and ptot columns. Because the values are MPI-reduced first, they are not reproducible across runs or rank counts. Fixes #1741.

Changes

s_compute_ptilde in m_bubbles_EE.fpp evaluates the correction at cell centers, mirroring what the HLLC solver applies to reconstructed face states in m_riemann_solver_hllc.fpp:736-746:

ptil = alpha (p_l - <R^3 p_bw>/<R^3> - rho <R^3 Rdot^2>/<R^3>)

which is Eq. (2.5) of Ando (Caltech thesis, 2010). The small_alf degenerate branch and the QBMM moment path (mom_sp 1, 3, 4) are both mirrored so the diagnostic cannot drift from the solver.

It is called from s_compute_rhs rather than from s_compute_bubble_EE_source. The latter is guarded by (.not. adap_dt) .and. (.not. qbmm) at m_rhs.fpp:839, so hanging the fix off it would have left ptil unfilled in exactly the QBMM and adaptive-timestep cases.

m_start_up.fpp also gains a GPU_UPDATE(host='[ptil]') next to the existing q_cons sync in the probe_wrt block. Without it the array stayed device-resident and the host-side probe read would still have been invalid on GPU builds.

Type of change

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

Scope

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

Testing

Built simulation locally and ran examples/1D_bubblescreen (bubbles_euler, probe_wrt) with temporary instrumentation on ptil. Values are finite and evolve smoothly. The magnitudes check out against the case setup: the background patch has alpha = 1e-12, below small_alf = 1e-11, so it takes the degenerate branch and gives ptil = alpha * p of about 1e-12, which matches the observed maximum. The bubble screen at vf0 = 4e-5 contributes near zero because the bubbles start in equilibrium, so p_l - p_bw and Rdot both vanish. The instrumentation was removed before commit.

./mfc.sh precheck passes.

ptil is diagnostic only and never feeds back into the solution, and the new computation is gated on probe_wrt, so no golden values move.

Note on coverage

No example or test case combines 1D, bubbles_euler, probe_wrt, and num_fluids = 3, which is why this went unnoticed. Adding one would be a reasonable follow-up.

ptil was allocated in m_global_parameters and pushed to the device, but nothing
ever assigned it. The probe path read it at m_data_output.fpp:1300, reduced the
result across ranks, and wrote it as the ptilde and ptot columns, so 1D
Euler-Euler bubble runs with probe_wrt and num_fluids = 3 emitted undefined
values in those two columns.

Add s_compute_ptilde, which evaluates the pressure correction at cell centers
the same way the HLLC solver applies it to reconstructed face states, including
the small_alf degenerate branch and the qbmm moment path. Call it from
s_compute_rhs rather than from s_compute_bubble_EE_source, since the latter is
skipped when qbmm or adap_dt is on and would leave ptil unfilled in exactly
those cases. Copy ptil back to the host alongside q_cons before probes are
written, which was also missing.

ptil is diagnostic only and never feeds the solution, so no golden values move.
The computation runs only when probe_wrt is set.
Copilot AI lite review requested due to automatic review settings August 19, 2026 21:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Fixes undefined ptilde/ptot probe outputs in Euler–Euler bubble runs by computing and syncing the ptil diagnostic field before probe writes.

Changes:

  • Compute ptil in the RHS path (gated on bubbles_euler + probe_wrt) via new s_compute_ptilde.
  • Add GPU host sync for ptil in the probe-related startup sync block.
  • Implement cell-centered ptil evaluation mirroring the HLLC solver’s pressure-correction logic (including QBMM and degenerate branches).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/simulation/m_start_up.fpp Adds host synchronization of ptil for GPU builds when probes are enabled.
src/simulation/m_rhs.fpp Calls s_compute_ptilde during RHS evaluation when probe output is enabled.
src/simulation/m_bubbles_EE.fpp Introduces s_compute_ptilde to fill the probe diagnostic ptil consistently with solver logic.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

!> Evaluate the Euler-Euler pressure correction at cell centers and store it in ptil. This mirrors the modified mixture pressure
!! that the HLLC solver applies to the reconstructed face states in m_riemann_solver_hllc.fpp, following Ando (2010), Eq. (2.5).
!! It is a diagnostic: ptil is read only by the probe output path and never feeds back into the solution.
impure subroutine s_compute_ptilde(q_cons_vf, q_prim_vf)
Comment on lines +370 to +372
R3bar = R3bar + weight(q)*(myR**3._wp)
R3V2bar = R3V2bar + weight(q)*(myR**3._wp)*(myV**2._wp)
PbwR3bar = PbwR3bar + weight(q)*f_cpbw_KM(R0(q), myR, myV, myPb)*(myR**3._wp)
Comment on lines +624 to +626
if (bubbles_euler) then
$:GPU_UPDATE(host='[ptil]')
end if
@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 962130b

Files changed:

  • 3
  • src/simulation/m_bubbles_EE.fpp
  • src/simulation/m_rhs.fpp
  • src/simulation/m_start_up.fpp

Findings:

  • ptil is only ever populated by s_compute_ptilde, which m_rhs.fpp gates on bubbles_euler .and. probe_wrt (src/simulation/m_rhs.fpp:848), but the corresponding GPU_UPDATE(host='[ptil]') added in m_start_up.fpp is gated on bubbles_euler alone, with no probe_wrt check (src/simulation/m_start_up.fpp:624). This host sync runs during startup, before the time-stepping loop (and hence before s_compute_ptilde has ever executed), so if bubbles_euler is on the device-side ptil buffer — which Fortran does not zero-initialize on allocation — gets pulled to host and is available to be written into the initial (t_step 0) probe output even when it was never computed, or before it was computed. The two guards should match (bubbles_euler .and. probe_wrt) to avoid surfacing uninitialized data as a diagnostic value.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.07407% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.61%. Comparing base (d4ffa29) to head (962130b).

Files with missing lines Patch % Lines
src/simulation/m_bubbles_EE.fpp 72.00% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1742      +/-   ##
==========================================
+ Coverage   61.59%   61.61%   +0.01%     
==========================================
  Files          84       84              
  Lines       21493    21520      +27     
  Branches     3176     3180       +4     
==========================================
+ Hits        13239    13259      +20     
- Misses       6078     6082       +4     
- Partials     2176     2179       +3     

☔ View full report in Codecov by Harness.
📢 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.

@sbryngelson
sbryngelson merged commit 10201f3 into master Aug 20, 2026
92 of 93 checks passed
@sbryngelson
sbryngelson deleted the fix/ptilde-probe-output branch August 20, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Probe output writes uninitialized ptilde and ptot for Euler-Euler bubble cases

2 participants