Skip to content

fix(process): scale LiquidRemover mass rate by gas mass fraction#1546

Open
olelod wants to merge 3 commits intomainfrom
fix/liquid-remover-mass-rate
Open

fix(process): scale LiquidRemover mass rate by gas mass fraction#1546
olelod wants to merge 3 commits intomainfrom
fix/liquid-remover-mass-rate

Conversation

@olelod
Copy link
Copy Markdown
Contributor

@olelod olelod commented May 7, 2026

Type of Work

  • Patch: X.Y.Z+1. NEGLIGIBLE visible changes, does not change input or output - OR changes behaviour. Use chore:, refactor: etc
  • Minor: X.Y+1.Z. Minor changes, might ADD new input (YAML), or other backwards-compatible changes. Use feat:, fix:
  • Major: X+1.Y.Z. Major and most likely BREAKING changes, wo. backwards compatibility, or removing temporary backwards compatibility functionality. Use ! or BREAKING:.

See here (internal): https://github.com/equinor/ecalc-internal/discussions/1044

Have you remembered and considered?

  • IF FEAT: I have remembered to update documentation
  • IF FIX OR FEAT: I have remembered to update manual changelog (docs/drafts/next.draft.md)
  • IF BREAKING: I have remembered to update migration guide (docs/docs/migration_guides/)
  • IF BREAKING: I have committed with BREAKING: in footer or ! in header
  • I have added tests (if not, comment why)
  • I have used conventional commits syntax (if you squash, make sure that conventional commit is used)
  • I have included the Github issue nr in the footer!

What is this PR all about?

When LiquidRemover activates on a two-phase inlet, it removes the liquid phase from the composition but previously kept the total mass rate unchanged — so the dropped-out liquid mass was effectively re-injected into the gas stream downstream.

This PR scales the outlet mass rate by the gas mass fraction so the removed liquid is no longer carried by the gas:

gas_mass_fraction = vapor_fraction_molar * outlet_molar_mass / inlet_molar_mass
new_mass_rate     = inlet.mass_rate * gas_mass_fraction

Pure-vapor inlets are unchanged.

What else did you consider?

Also exposing the removed liquid as a separate outlet stream (e.g. for routing to an oil pump or emissions accounting). Left as a docstring note — it would change propagate_stream's contract and there is no consumer for it yet.

Between the lines?

Resolves equinor/ecalc-internal#1767

@olelod olelod marked this pull request as ready for review May 7, 2026 13:17
@olelod olelod requested a review from a team as a code owner May 7, 2026 13:17
Copy link
Copy Markdown
Contributor

@tj098895 tj098895 left a comment

Choose a reason for hiding this comment

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

looks good. leaves it for @kjbrak to reverify

Comment on lines +37 to +40
if inlet_molar_mass > 0.0:
gas_mass_fraction = inlet_stream.vapor_fraction_molar * new_fluid.molar_mass / inlet_molar_mass
else:
gas_mass_fraction = 1.0
Copy link
Copy Markdown
Contributor

@kjbrak kjbrak May 8, 2026

Choose a reason for hiding this comment

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

Consider failing explicitly when inlet_molar_mass <= 0.0 rather than preserving the full inlet mass rate. A non-positive molar mass is non-physical, and gas_mass_fraction = 1.0 would hide the invalid thermodynamic state while carrying all removed-liquid mass downstream again for that edge case.

If using InvalidStreamException, the matching import also needs to be added.

Suggested change
if inlet_molar_mass > 0.0:
gas_mass_fraction = inlet_stream.vapor_fraction_molar * new_fluid.molar_mass / inlet_molar_mass
else:
gas_mass_fraction = 1.0
if inlet_molar_mass <= 0.0:
raise InvalidStreamException(
f"Cannot remove liquid from stream with non-positive molar mass: {inlet_molar_mass}"
)
gas_mass_fraction = inlet_stream.vapor_fraction_molar * new_fluid.molar_mass / inlet_molar_mass

kjbrak
kjbrak approved these changes May 8, 2026
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.

3 participants