Skip to content

Refactor Fanno flow calculation and remove short-tube approximation - #8

Merged
test1card merged 2 commits into
mainfrom
claude/fix-fanno-choking-DP2FZ
Feb 28, 2026
Merged

test1card merged 2 commits into
mainfrom
claude/fix-fanno-choking-DP2FZ

Conversation

@test1card

Copy link
Copy Markdown
Owner

Summary

This PR refactors the Fanno flow calculation in the venting module to improve accuracy and consistency. The main changes involve removing the short-tube approximation path for certain pressure ratios and correcting the mass flow rate calculation to use static pressure instead of stagnation pressure.

Key Changes

  • Removed short-tube approximation: Deleted the conditional branch that applied mdot_short_tube_pos() when downstream pressure ratio exceeded 0.6. The Fanno tube model now handles all pressure ratios consistently.

  • Fixed mass flow rate calculation: Changed the mdot calculation to use static pressure p1 instead of stagnation pressure P_up. This corrects the thermodynamic basis of the calculation:

    • Previously: mdot = P_up * m1 * a_eff * sqrt(...)
    • Now: mdot = p1 * m1 * a_eff * sqrt(...)
  • Removed pressure loss factors from outlet pressure: Simplified the outlet_pressure() function by removing the application of K_in and K_out loss coefficients. The function now returns the isentropic pressure p2 directly instead of applying lumped loss corrections.

  • Simplified final mdot calculation: Removed the ad-hoc pressure-ratio-dependent correction that was clamping mdot to 0.99 * md_l for low pressure ratios. The calculation now uses the consistent formula throughout.

  • Code cleanup: Extracted intermediate calculations (t1_final, p1_final) for clarity and to avoid redundant computations.

Test Updates

  • Updated test_fanno_low_mach_matches_lossy_nozzle() to use K_in=0, K_out=0 for the agreement check, with clarifying comments explaining why loss coefficients must be zero for model equivalence.
  • Adjusted test_fanno_with_K_below_lossy() assertion from < 1.0 to < 0.92 to reflect the new calculation's behavior.
  • Relaxed test_fanno_monotonic_with_K() tolerance from 0.98 * prev to prev to account for improved numerical behavior.

Implementation Details

The refactoring moves away from a hybrid approach (short-tube for high pressure ratios, Fanno for low) to a unified Fanno tube model. The use of static pressure in the mass flow calculation is more thermodynamically consistent with compressible flow theory, where mass flow depends on local conditions at the throat/reference section rather than upstream stagnation conditions.

https://claude.ai/code/session_019hMsyJv1g6gSZF3h9SpFrB

…ion, bad mdot formula, and continuity break

Three bugs in the original _fanno_state implementation masked the K-loss effect:

1. outlet_pressure() divided exit pressure by (1+K_out)(1+K_in) a second time
   even though K losses were already encoded in f4ld. This double-counting caused
   the subsonic bisection to return 0 for pressure ratios 0.35–0.59, so _fanno_state
   was silent over most of the subsonic regime.

2. The final mdot formula used P_up (stagnation) with T1 (static temperature),
   overestimating mass flow by the factor (P0/P1) ≈ 1.14 at M=0.44. Using the
   correct static inlet pressure P1 gives mdot_fanno/mdot_lossy ≈ 0.85 at P_dn=0
   (matching the 0.000313 vs 0.000368 kg/s values in the issue).

3. An early fallback at P_dn/P_up >= 0.6 returned the lossy-nozzle result,
   creating a sharp discontinuity (≈8.8% step) at r=0.60 once K losses were
   correctly included in f4ld. Removing this fallback makes _fanno_state compute
   the Fanno solution uniformly across all pressure ratios, restoring monotonicity.

Also removed the 0.99×md_l floor in mdot_fanno_tube that prevented Fanno from
dominating, and restored correct test thresholds (ratio < 0.92, strict prev-1e-12
monotonicity). Updated test_fanno_low_mach_matches_lossy_nozzle to use K=0 where
the two models are designed to agree; with K losses the models correctly diverge
(equivalent-length vs lumped-Cd approximations).

After fix:
  _fanno_state K=0:   mdot=0.000429   (matches issue table 0.000427)
  _fanno_state K=1.5: mdot=0.000314   (matches issue table 0.000313)
  ratio Fanno/lossy = 0.851 < 0.92    (acceptance criterion met)
  Monotonicity: PASS across all pressure ratios
  All 58 tests pass

https://claude.ai/code/session_019hMsyJv1g6gSZF3h9SpFrB
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@test1card
test1card merged commit 315b6d5 into main Feb 28, 2026
6 checks passed
@test1card
test1card deleted the claude/fix-fanno-choking-DP2FZ branch February 28, 2026 01:33
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.

2 participants