Hydraulic gas_pressure omits the reference-density offset, breaking roundtrips and the pressure join · Issue #518 · SciML/ModelingToolkitStandardLibrary.jl · GitHub
Skip to content

Hydraulic gas_pressure omits the reference-density offset, breaking roundtrips and the pressure join #518

Open

Description

@EthanJamesLew

Describe the bug 🐞

The gas-density interpolation and pressure inverse do not invert one another. The density relation is ρ = ρ0 + p(ρ0−ρgas)/(−pgas), but the inverse uses ρ(−pgas)/(ρ0−ρgas) without subtracting ρ0.

For ρ0=1000, ρgas=1, pgas=−1000 and p=−500, the roundtrip returns 500500/999 (approximately +501 Pa) instead of −500 Pa. The combined pressure function also returns 1000 at density 999 and zero at density 1000: pressure decreases across the join as density increases.

This function is used by the public FixedVolume component. Direct substitution into that component's pressure equation reproduces the same error.

Expected behavior

On the interpolation branch, pressure and density should roundtrip consistently and match the two specified endpoints. The affine inverse is p = (ρ−ρ0)(−pgas)/(ρ0−ρgas). The gas and liquid pressure branches should join at (ρ0, 0). This asks for consistency of the library's own interpolation, not an ideal-gas law or a different cavitation model.

Minimal Reproducible Example 👇

The helper functions are called through their module because they are not exported. A named tuple supplies exactly the material fields they read. Rational inputs make the counterexample exact.

import ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible as H

# Rational inputs make this an exact arithmetic reproduction.
fluid = (ρ=1000//1, β=1000//1, n=1, let_gas=1,
         ρ_gas=1//1, p_gas=-1000//1)
p = -500//1
rho = H.gas_density(fluid, p)
println("input pressure = ", p)
println("density = ", rho)
println("roundtrip pressure = ", H.gas_pressure(fluid, rho))
println("full pressure at density 999 = ", H.full_pressure(fluid, 999//1))
println("full pressure at density 1000 = ", H.full_pressure(fluid, 1000//1))

Error & Stacktrace ⚠️

No exception or stacktrace occurs. The observed output is:

input pressure = -500//1
density = 1001//2
roundtrip pressure = 500500//999
full pressure at density 999 = 1000//1
full pressure at density 1000 = 0//1

Environment (please complete the following information):

Julia 1.11.9. Relevant installed-package entries, captured with using Pkg; Pkg.status(["ModelingToolkit", "ModelingToolkitStandardLibrary", "Symbolics"]):

⌃ [961ee093] ModelingToolkit v11.20.0
⌅ [16a59e39] ModelingToolkitStandardLibrary v2.29.4
⌃ [0c5d862f] Symbolics v7.18.1

The version markers indicate that newer releases are available; they do not indicate that those releases were executed in this reproduction.

Additional context

This was found using our physics prover model checker.

Activity

  1. ChrisRackauckas-Claude commented on Oct 9, 2026

    @ChrisRackauckas-Claude
    Member

    Thanks for the report. A fix by @jitendravjh is open in #520, which makes gas_pressure the exact inverse of gas_density. It is now in review.

    🤖 Posted by an AI agent (Claude Code, model claude-opus-5-5[1m]) on behalf of Chris Rackauckas: https://claude.ai/code/session_01H4fXBChQshAwfpLMCpEvAX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions