turboflow.properties.fluid_properties module

class turboflow.properties.fluid_properties.Fluid(name, backend='HEOS', exceptions=True, identifier=None)[source]

Bases: object

Represents a fluid with various thermodynamic properties computed via CoolProp.

This class provides a convenient interface to CoolProp for various fluid property calculations.

Properties can be accessed directly as attributes (e.g., fluid.properties[“p”] for pressure) or through dictionary-like access (e.g., fluid.T for temperature).

Critical and triple point properties are computed upon initialization and stored internally for convenience.

Examples

Accessing properties:

  • fluid.T - Retrieves temperature directly as an attribute.

  • fluid.properties[‘p’] - Retrieves pressure through dictionary-like access.

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.

Attributes:
namestr

Name of the fluid.

backendstr

Backend used for CoolProp, default is ‘HEOS’.

exceptionsbool

Determines if exceptions should be raised during state calculations. Default is True.

converged_flagbool

Flag indicating whether properties calculations converged.

propertiesdict

Dictionary of various fluid properties. Accessible directly as attributes (e.g., fluid.p for pressure).

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

set_state(input_type, prop_1, prop_2):

Set the thermodynamic state of the fluid using specified property inputs.

compute_properties_1phase(generalize_quality=True)[source]

Get single-phase properties from CoolProp low level interface

compute_properties_2phase()[source]

Get two-phase properties from mixing rules and single-phase CoolProp properties

compute_properties_meanline(input_type, prop_1, prop_2)[source]

Extract fluid properties for meanline model

static compute_properties_metastable_rhoT(rho, T, AS)[source]

Compute the thermodynamic properties of a fluid using the Helmholtz energy equation of state. All properties thermodynamic properties can be derived as combinations of the Helmholtz energy and its derivatives with respect to density and pressure.

This function can be used to estimate metastable properties using the equation of state beyond the saturation lines.

compute_sonic_state(input_type, prop_1, prop_2)[source]
get_property(propname)[source]

Get the value of a single property

get_props(input_type, prop_1, prop_2, generalize_quality=True)[source]
plot_phase_diagram(x_variable='s', y_variable='T', axes=None, num_points=200, plot_saturation_line=True, plot_critical_point=True, plot_triple_point_liquid=False, plot_triple_point_vapor=False, plot_spinodal_line=False, spinodal_line_method='standard', spinodal_line_color=array([0.5, 0.5, 0.5]), spinodal_line_width=0.75, plot_quality_isolines=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, **kwargs)[source]
set_state(input_type, prop_1, prop_2, generalize_quality=True)[source]

Set the thermodynamic state of the fluid based on input properties.

This method updates the thermodynamic state of the fluid in the CoolProp abstractstate object using the given input properties. It then calculates either single-phase or two-phase properties based on the current phase of the fluid.

If the calculation of properties fails, converged_flag is set to False, indicating an issue with the property calculation. Otherwise, it’s set to True.

Aliases of the properties are also added to the Fluid.properties dictionary for convenience.

Parameters:
input_typestr or int

The variable pair used to define the thermodynamic state. This should be one of the predefined input pairs in CoolProp, such as PT_INPUTS for pressure and temperature.

prop_1float

The first property value corresponding to the input type (e.g., pressure in Pa if the input type is CP.PT_INPUTS).

prop_2float

The second property value corresponding to the input type (e.g., temperature in K if the input type is CP.PT_INPUTS).

Returns:
dict

A dictionary of computed properties for the current state of the fluid. This includes both the raw properties from CoolProp and any additional alias properties.

Raises:
Exception

If throw_exceptions attribute is set to True and an error occurs during property calculation, the original exception is re-raised.

set_state_metastable(prop_1, prop_1_value, prop_2, prop_2_value, rho_guess, T_guess)[source]
set_state_metastable_rhoT(rho, T)[source]
class turboflow.properties.fluid_properties.FluidState(fluid)[source]

Bases: object

A class representing the thermodynamic state of a fluid.

This class is used to store and access the properties of a fluid state. Properties can be accessed directly as attributes (e.g., fluid_state.p for pressure) or through dictionary-like access (e.g., fluid_state[‘T’] for temperature).

Methods

to_dict():

Convert the FluidState properties to a dictionary.

keys():

Return the keys of the FluidState properties.

items():

Return the items (key-value pairs) of the FluidState properties.

items()[source]
keys()[source]
to_dict()[source]
values()[source]
class turboflow.properties.fluid_properties.PropertyRoot(prop_1, prop_1_value, prop_2, prop_2_value, fluid)[source]

Bases: NonlinearSystemProblem

Find the root for thermodynamic state by iterating on the density-temperature native inputs to the helmholtz energy equations of state.

Attributes:
prop_1str

The first property to be compared.

prop_1_valuefloat

The value of the first property.

prop_2str

The second property to be compared.

prop_2_valuefloat

The value of the second property.

fluidobject

An instance of the fluid class which has the helmholtz energy equations of state.

Methods

get_values(x)

Calculates the residuals based on the given input values of density and temperature.

get_values(x)[source]

Compute the residuals for the given density and temperature.

Parameters:
xlist

List containing the values for density and temperature.

Returns:
np.ndarray

Array containing residuals (difference) for the two properties.

turboflow.properties.fluid_properties.calculate_subcooling(state, fluid)[source]

Calculates the degree of subcooling for a given state and adds this information to the state.

Parameters:
statedict

A dictionary representing the thermodynamic state, containing at least pressure (p), temperature (T), and enthalpy (h) of the fluid.

fluidobject

An object representing the fluid with its properties, including methods to set state and critical point data.

Returns:
dict

The input state dictionary with an added field ‘subcooling’ representing the degree of subcooling.

turboflow.properties.fluid_properties.calculate_superheating(state, fluid)[source]

Calculates the degree of superheating for a given state and adds this information to the state.

Parameters:
statedict

A dictionary representing the thermodynamic state, containing at least pressure (p), temperature (T), and enthalpy (h) of the fluid.

fluidobject

An object representing the fluid with its properties, including methods to set state and critical point data.

Returns:
dict

The input state dictionary with an added field ‘superheating’ representing the degree of superheating.

turboflow.properties.fluid_properties.compute_properties_meshgrid(fluid, input_pair, range_1, range_2)[source]

Compute fluid properties over a specified range and store them in a dictionary.

This function creates a meshgrid of property values based on the specified ranges and input pair, computes the properties of the fluid at each point on the grid, and stores the results in a dictionary where each key corresponds to a fluid property.

Parameters:
fluidFluid object

An instance of the Fluid class.

input_pairtuple

The input pair specifying the property type (e.g., PT_INPUTS for pressure-temperature).

range1tuple

The range linspace(min, max, n) for the first property of the input pair.

range2tuple

The range linspace(min, max, n) for the second property of the input pair.

Returns:
properties_dictdict

A dictionary where keys are property names and values are 2D numpy arrays of computed properties.

grid1, grid2numpy.ndarray

The meshgrid arrays for the first and second properties.

turboflow.properties.fluid_properties.compute_pseudocritical_line(fluid, N_points=100)[source]
turboflow.properties.fluid_properties.compute_quality_grid(fluid, num_points, quality_levels)[source]
turboflow.properties.fluid_properties.compute_saturation_line(fluid, N_points=100)[source]
turboflow.properties.fluid_properties.compute_spinodal_line(fluid, N_points=100, method='standard')[source]
turboflow.properties.fluid_properties.states_to_dict(states)[source]

Convert a list of state objects into a dictionary. Each key is a field name of the state objects, and each value is a NumPy array of all the values for that field.

turboflow.properties.fluid_properties.states_to_dict_2d(states_grid)[source]

Convert a 2D list (grid) of state objects into a dictionary. Each key is a field name of the state objects, and each value is a 2D NumPy array of all the values for that field.

Parameters:
states_gridlist of list of objects

A 2D grid where each element is a state object with the same keys.

Returns:
dict

A dictionary where keys are field names and values are 2D arrays of field values.