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

Open Beginner friendly
#518 1 comment 0 reactions 0 assignees View on GitHub

@jitendravjh is already working on this.

Since Oct 3, 2026.

  • #520 by @jitendravjh — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
julia
Domain
backend

Research direction

Start in src/Hydraulic/IsothermalCompressible/utils.jl at the gas-density, gas-pressure, and full-pressure definitions, then inspect their use in components.jl's FixedVolume component. Run the exact Julia reproduction from the issue; done means the interpolation roundtrips, both pressure branches meet at (ρ0, 0), and the specified endpoint behavior is preserved.

Written by the indexing model from the issue text.

Description

bug

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.

Dominant language
Julia
Stars
171
Forks
51
Avg merge
7d 12h
Merged PRs (30d)
6

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SciML/ModelingToolkitStandardLibrary.jl

All issues in SciML/ModelingToolkitStandardLibrary.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.