jaxprop.coolprop.fluid_properties module#
- jaxprop.coolprop.fluid_properties.Fluid#
alias of
FluidCoolProp
- class jaxprop.coolprop.fluid_properties.FluidCoolProp(name, backend='HEOS', exceptions=True, identifier=None)[source]#
Bases:
SourceReferencesMixin,ReadonlyConfigurationMixinRepresents a fluid with various thermodynamic properties computed via CoolProp.
This class provides a convenient interface to CoolProp for various fluid property calculations.
Critical and triple point properties are computed upon initialization and stored internally for convenience.
- Attributes:
- namestr
Name of the fluid.
- backendstr
Backend used for CoolProp, default is ‘HEOS’.
- exceptionsbool
Legacy constructor option. Only True is accepted; select per-call
errors="mask"for numerical failures without exceptions.- converged_flagbool
Legacy last-call diagnostic. Use the returned state’s status for the result of an individual call, especially with concurrent consumers.
- referencesSourceReferences
Immutable source reference records, independent of mutable evaluation handles. Numerical properties belong to the returned FluidState.
- critical_pointFluidState
Properties at the fluid’s critical point.
- triple_point_liquidFluidState
Properties at the fluid’s triple point in the liquid state.
- triple_point_vaporFluidState
Properties at the fluid’s triple point in the vapor state.
Methods
get_state(input_type, prop_1, prop_2):
Set the thermodynamic state of the fluid using specified property inputs.
Examples
Calculating properties with Fluid.get_state()
>>> fluid = bpy.Fluid(name="Water", backend="HEOS") >>> state = fluid.get_state(bpy.PT_INPUTS, 101325, 300) >>> print(f"Water density is {state.rho:0.2f} kg/m3 at p={state.p:0.2f} Pa and T={state.T:0.2f} K") Water density is 996.56 kg/m3 at p=101325.00 Pa and T=300.00 K
>>> fluid = bpy.Fluid(name="Air", backend="HEOS") >>> state = fluid.get_state(bpy.PT_INPUTS, 101325, 300) >>> print(f"Air heat capacity ratio is {state.gamma:0.2f} at p={state.p:0.2f} Pa and T={state.T:0.2f} K") Air heat capacity ratio is 1.40 at p=101325.00 Pa and T=300.00 K
Accessing critical point properties:
>>> fluid.critical_point.p # Retrieves critical pressure >>> fluid.critical_point['T'] # Retrieves critical temperature
Accessing triple point properties:
>>> fluid.triple_point_liquid.h # Retrieves liquid enthalpy at the triple point >>> fluid.triple_point_vapor.s # Retrieves vapor entropy at the triple point
- get_state(input_type, prop_1, prop_2, *, generalize_quality=False, supersaturation=False, errors='raise', **options)[source]#
Set the thermodynamic state of the fluid using the CoolProp low-level interface.
This method updates the thermodynamic state of the fluid in the CoolProp
AbstractStateobject using the specified input properties. It supports both scalar and array inputs forprop_1andprop_2, automatically broadcasting them to a common shape and evaluating the fluid properties element-wise. The resulting thermodynamic properties are returned as arrays matching the broadcasted input dimensions.Depending on the specified inputs and fluid conditions, the calculation may involve either single-phase or two-phase states.
- Parameters:
- input_typeint
The variable pair used to define the thermodynamic state. This should be one of the predefined CoolProp input pairs (e.g.,
PT_INPUTSfor pressure and temperature).- prop_1float or array_like
The first property value corresponding to the input type.
- prop_2float or array_like
The second property value corresponding to the input type.
- generalize_qualitybool, optional
If True, requests the existing generalized reported-quality calculation.
- supersaturationbool, optional
Include available saturation-departure diagnostics. This does not select a metastable branch. Locally undefined fields remain NaN.
- errors{“raise”, “mask”}, optional
Raise a typed error at the first failing row-major element, or preserve successful elements and encode failures in state.status.
- Returns:
- FluidState
Enabled canonical properties with the exact broadcast input shape, immutable identity metadata, status, and property availability.
- Raises:
- JaxPropError
Invalid or unsupported requests are rejected before source evaluation.
- CalculationError
The source calculation fails after valid numerical inputs.
- get_state_blending(prop_1, prop_1_value, prop_2, prop_2_value, rhoT_guess_equilibrium, rhoT_guess_metastable, blending_onset, blending_width, phase_change, blending_variable='quality_mass', supersaturation=True, generalize_quality=True, solver_algorithm='hybr', solver_tolerance=1e-06, solver_max_iterations=100, print_convergence=False, *, errors='raise')[source]#
Calculate fluid properties by blending equilibrium and metastable properties
Return blended, equilibrium and metastable FluidState objects. The blend is a constitutive interpolation, tagged
blended_real_fluidwith its own settings-dependent identity; it need not satisfy source-EOS response identities. Algorithm coordinates and weights are not thermodynamic fields (sigmaretains its surface-tension meaning). Execution is scalar/eager with explicitraiseormasknumerical policies.Note
For a detailed description of input arguments and calculation methods, see the documentation of the function compute_properties.
- get_state_equilibrium(prop_1, prop_1_value, prop_2, prop_2_value, rhoT_guess=None, supersaturation=True, generalize_quality=True, solver_algorithm='hybr', solver_tolerance=1e-06, solver_max_iterations=100, print_convergence=False, *, errors='raise')[source]#
Calculate fluid properties according to thermodynamic equilibrium.
This is an eager scalar phase solver. Density/temperature pairs use a direct source call; other pairs need a density/temperature guess.
errors="mask"returns a failed scalar state for numerical failures. Static settings remain validated and source clipping is unsupported.Note
For a detailed description of input arguments and calculation methods, see the documentation of the function compute_properties.
- get_state_metastable(prop_1, prop_1_value, prop_2, prop_2_value, rhoT_guess=None, supersaturation=True, generalize_quality=True, solver_algorithm='lm', solver_tolerance=1e-06, solver_max_iterations=100, print_convergence=False, *, errors='raise')[source]#
Calculate fluid properties assuming phase metastability
Evaluate the homogeneous Helmholtz branch, including formal unstable states needed by stability studies. Independent density and temperature must be positive and finite; optional singular responses are unavailable. Scalar
raise/maskpolicies use the configured source reference context and protect the complete calculation with its reentrant lock.Note
For a detailed description of input arguments and calculation methods, see the documentation of the function compute_properties.
- get_state_saturation(input_type, prop_1, prop_2, *, errors='raise')[source]#
Evaluate a source saturation request with the ordinary state policy.
- plot_phase_diagram(x_prop='s', y_prop='T', axes=None, N=100, plot_saturation_line=True, plot_critical_point=True, plot_triple_point_liquid=False, plot_triple_point_vapor=False, plot_spinodal_line=False, spinodal_line_color=array([0.5, 0.5, 0.5]), spinodal_line_width=1.25, spinodal_line_method='slsqp', spinodal_line_use_previous=False, plot_quality_isolines=False, plot_two_phase_patch=False, plot_pseudocritical_line=False, quality_levels=array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.]), quality_labels=False, show_in_legend=False, x_scale='linear', y_scale='linear', dT_crit=1.0)[source]#
Draw or update source-EOS phase curves on the selected axes.
Numerical curve caches include their sampling/solver options. Artists belong to each fluid and axes pair: repeated calls update existing lines, and disabling an option hides/removes only that fluid’s artists. Plotting is an eager Matplotlib operation, outside state evaluation.
- jaxprop.coolprop.fluid_properties.build_alias_map()[source]#
Build a mapping from alias names to canonical CoolProp fluid names.
- Returns:
- dict
Dictionary where keys are aliases and values are canonical fluid names.
- jaxprop.coolprop.fluid_properties.compute_property_grid_rhoT(fluid, rho_array, T_array)[source]#
Evaluate homogeneous states on temperature rows and density columns.
The returned FluidState retains identity, optional availability and the exact grid shape. Calls use the configured fluid’s locked/reference-aware public homogeneous path rather than mutating its raw source handle.
- jaxprop.coolprop.fluid_properties.compute_pseudocritical_line(fluid, N_points=100)[source]#
Compute pseudocritical line (approximate, defined here at critical density).
- jaxprop.coolprop.fluid_properties.compute_quality_grid(fluid, num_points, quality_levels, dT_crit=1.0)[source]#
Return a common state on quality/temperature axes, without source bypasses.
HEOS pseudo-pure models implement QT only at bubble/dew endpoints. Interior quality is therefore rejected explicitly here; use ordinary PQ calls when a pressure/quality grid is the intended physical geometry.
- jaxprop.coolprop.fluid_properties.compute_saturation_line(fluid, N=100, dT_crit=0.5)[source]#
Compute the saturation line for a given fluid.
- Parameters:
- fluidobject
The fluid object containing thermodynamic properties and methods.
- Nint, optional
Number of distinct subcritical samples. The critical endpoint is prepended, so each returned branch has N+1 states. Default is 100.
- Returns:
- saturation_liqFluidState
Batched FluidState for the liquid saturation line.
- saturation_vapFluidState
Batched FluidState for the vapor saturation line.
- jaxprop.coolprop.fluid_properties.compute_spinodal_line(fluid, N=50, method='slsqp', use_previous_as_initial_guess=False, supersaturation=False, dT_crit=0.25, tolerance=1e-08)[source]#
Compute the spinodal line for a given fluid.
- Parameters:
- fluidobject
The fluid object containing thermodynamic properties and methods.
- Nint, optional
Number of points to compute along the spinodal line. Default is 50.
- methodstr, optional
The optimization method to solve the spinodal point problem (‘bfgs’ or ‘slsqp’). Default is ‘bfgs’.
- use_previous_as_initial_guessbool, optional
Whether to use the previous point as the initial guess for the next point. Default is False.
- supersaturationbool, optional
Whether to compute supersaturation properties. Default is False.
- Returns:
- spinodal_liqFluidState
Batched FluidState for the liquid spinodal line.
- spinodal_vapFluidState
Batched FluidState for the vapor spinodal line.
- jaxprop.coolprop.fluid_properties.compute_spinodal_point(temperature, fluid, branch, rho_guess=None, N_trial=100, method='slsqp', tolerance=1e-08, supersaturation=False, print_convergence=False)[source]#
Compute the vapor or liquid spinodal point of a fluid at a given temperature.
- Parameters:
- temperaturefloat
Temperature of the fluid (K).
- fluidbarotropy.Fluid
The fluid for which the spinodal point is to be calculated.
- branchstr
Branch of the spinodal line used to determine the density initial guess. Options: ‘liquid’ or ‘vapor’.
- rho_guessfloat, optional
Initial guess for the density. If provided, this value will be used directly. If not provided, the density initial guess will be generated based on a number of trial points.
- N_trialint, optional
Number of trial points to generate the density initial guess. Default is 50.
- methodstr, optional
The optimization method to solve the problem (‘bfgs’ or ‘slsqp’).
- tolerancefloat, optional
Tolerance for the solver termination. Defaults to 1e-6.
- print_convergencebool, optional
If True, displays the convergence progress. Defaults to False.
- Returns:
- barotropy.State
A State object containing the fluid properties
- Raises:
- ValueError
If the input temperature is higher than the critical temperature or lower than the triple temperature.
Notes
When a single-phase fluid undergoes a thermodynamic process and enters the two-phase region it can exist in a single-phase state that is different from the equilibrium two-phase state. Such states are know as metastable states and they are only possible in the thermodynamic region between the saturation lines and the spinodal lines. If the thermodynamic process continues and crosses the spinodal lines metastable states become unstable and the transition to two-distinct phase occurs rapidly. Therefore, the spinodal line represents the locus of points that separates the region where a mixture is thermodynamically unstable and prone to phase separation from the region where metastable states are physically possible.
In mathematical terms, the spinodal line is defined as the loci of thermodynamic states in which the isothermal bulk modulus of the fluid is zero:
\[K_T = \rho \left( \frac{\partial p}{\partial \rho} \right)_T = 0\]More precisely, a vapor spinodal point is the first local maximum of a isotherm line in a pressure-density diagram as the density increases. Conversely, a liquid spinodal point is the first local minimum of a isotherm line in a pressure-density diagram as the density decreases. The spinodal lines and phase envelope of carbon dioxide according to the HEOS developed by [Span and Wagner, 1996] are illustrated in the figure below
Some equations of state are not well-posed and do not satisfy the condition \(K_T=0\) within the two-phase region. This is exemplified by the nitrogen HEOS developed by [Span et al., 2000].
As seen in the figure, this HEOS is not well-posed because there are isotherms that do not have a local minimum/maximum corresponding to a state with zero isothermal bulk modulus. In such cases, this function returns the inflection point of the isotherms (corresponding to the point closest to zero bulk modulus) as the spinodal point.
- jaxprop.coolprop.fluid_properties.compute_spinodal_point_general(prop_type, prop_value, fluid, branch, rho_guess=None, N_trial=100, method='slsqp', tolerance=1e-08, print_convergence=False, supersaturation=False)[source]#
General function to compute the spinodal point for a given property name and value.
This function uses the underlying compute_spinodal_point function and iterates on temperature until the specified property at the spinodal point matches the given value.
- Parameters:
- prop_typestr
The type of property to match (e.g., ‘rho’, ‘p’).
- prop_valuefloat
The value of the property to match at the spinodal point.
- fluidobject
The fluid object containing thermodynamic properties and methods.
- branchstr
The branch of the spinodal line. Options: ‘liquid’ or ‘vapor’.
- rho_guessfloat, optional
Initial guess for the density. If provided, this value will be used directly. If not provided, the density initial guess will be generated based on a number of trial points.
- N_trialint, optional
Number of trial points to generate the density initial guess. Default is 100.
- methodstr, optional
The optimization method to solve the problem (‘bfgs’ or ‘slsqp’). Default is ‘bfgs’.
- tolerancefloat, optional
Tolerance for the solver termination. Defaults to 1e-6.
- print_convergencebool, optional
If True, displays the convergence progress. Defaults to False.
- Returns:
- barotropy.State
A State object containing the fluid properties
- Raises:
- ValueError
If the scalar root to determine the spinodal point fails to converge.
Notes
This function uses a root-finding algorithm to iterate on temperature until the property specified by prop_type at the spinodal point matches prop_value. The compute_spinodal_point function is called iteratively to evaluate the spinodal properties at different temperatures.
Examples
>>> state = compute_spinodal_point_general( ... prop_type='density', ... prop_value=500, ... T_guess=300, ... fluid=my_fluid, ... branch='liquid', ... rho_guess=10, ... N_trial=150, ... method='slsqp', ... tolerance=1e-7, ... print_convergence=True, ... )
- jaxprop.coolprop.fluid_properties.print_fluid_names()[source]#
Print all canonical fluids and their aliases in a structured format.
- jaxprop.coolprop.fluid_properties.safe_alias_split(raw_string)[source]#
Split a CoolProp alias string safely, preserving multi-part names that include commas (e.g., chemical names like ‘1,2-dichloroethane’).
- Parameters:
- raw_stringstr
Comma-separated alias string from CoolProp.
- Returns:
- list of str
Cleaned list of alias names, with spurious splits recombined.
- jaxprop.coolprop.fluid_properties.try_initialize_fluid(name: str, backend: str = 'HEOS')[source]#
Attempt to initialize a CoolProp AbstractState for the given fluid name. If initialization fails, raise a ValueError with close name suggestions.
- Parameters:
- namestr
Fluid name or alias to initialize.
- backendstr, optional
CoolProp backend to use (default is ‘HEOS’).
- Returns:
- CP.AbstractState
Initialized CoolProp AbstractState object.
- Raises:
- ValueError
If the fluid name is not recognized by CoolProp, with close suggestions.