@@ -122,5 +122,49 @@ def test_liquid_takeoff(inlet_fluid, outlet_fluid) -> None:
122122 assert math .isclose (outlet_fluid .pressure_bara , fluid_after_liquid_takeoff .pressure_bara , rel_tol = 0.01 )
123123 assert math .isclose (outlet_fluid .molar_mass , fluid_after_liquid_takeoff .molar_mass , rel_tol = 0.01 )
124124 assert math .isclose (
125- outlet_fluid .enthalpy_joule_per_kg , fluid_after_liquid_takeoff .enthalpy_joule_per_kg , rel_tol = 0.5
125+ outlet_fluid .enthalpy_joule_per_kg , fluid_after_liquid_takeoff .enthalpy_joule_per_kg , rel_tol = 0.02
126126 )
127+
128+
129+ # Propane-rich composition that is ~97% liquid at the probe (P, T) below.
130+ DENSE_LIQUID_COMPOSITION = FluidComposition (
131+ water = 0.003 ,
132+ nitrogen = 2.447 ,
133+ CO2 = 0.64 ,
134+ methane = 41.91 ,
135+ ethane = 19.9 ,
136+ propane = 24.29 ,
137+ i_butane = 3.64 ,
138+ n_butane = 5.40 ,
139+ i_pentane = 0.83 ,
140+ n_pentane = 0.68 ,
141+ n_hexane = 0.26 ,
142+ ).normalized ()
143+
144+
145+ def test_clone_gas_phase_returns_initialized_properties () -> None :
146+ """clone_gas_phase() on a two-phase fluid must return properties matching a clean PT-flash of the gas-only composition."""
147+ two_phase = NeqsimFluid .create_thermo_system (
148+ composition = DENSE_LIQUID_COMPOSITION ,
149+ temperature_kelvin = 301.45 ,
150+ pressure_bara = 91.476 ,
151+ )
152+ assert two_phase .vapor_fraction_molar < 0.1 , (
153+ f"Test precondition: expected mostly-liquid state, got vap={ two_phase .vapor_fraction_molar } "
154+ )
155+
156+ gas_only = two_phase .clone_gas_phase ()
157+
158+ assert math .isclose (gas_only .vapor_fraction_molar , 1.0 , rel_tol = 1e-3 )
159+ # Uninitialized systems return the sentinel kappa==1.0.
160+ assert gas_only .kappa > 1.02 , f"Suspicious kappa (uninitialized?): { gas_only .kappa } "
161+
162+ reference = NeqsimFluid .create_thermo_system (
163+ composition = gas_only .composition ,
164+ temperature_kelvin = gas_only .temperature_kelvin ,
165+ pressure_bara = gas_only .pressure_bara ,
166+ )
167+ assert math .isclose (gas_only .kappa , reference .kappa , rel_tol = 1e-3 )
168+ assert math .isclose (gas_only .z , reference .z , rel_tol = 1e-3 )
169+ assert math .isclose (gas_only .density , reference .density , rel_tol = 1e-3 )
170+ assert math .isclose (gas_only .enthalpy_joule_per_kg , reference .enthalpy_joule_per_kg , rel_tol = 1e-3 )
0 commit comments