thermopt.components.basic_components module#

thermopt.components.basic_components.compression_process(fluid, h_in, p_in, p_out, efficiency=None, efficiency_type='isentropic', mass_flow=None, data_in={}, num_steps=10)[source]#

Calculate properties along a compression process defined by a isentropic or polytropic efficiency

Parameters:
fluidFluid

The fluid object used to evaluate thermodynamic properties

h_infloat

Enthalpy at the start of the compression process.

p_infloat

Pressure at the start of the compression process.

p_outfloat

Pressure at the end of the compression process.

efficiencyfloat

The efficiency of the compression process.

efficiency_typestr, optional

The type of efficiency to be used in the process (‘isentropic’ or ‘polytropic’). Default is ‘isentropic’.

num_stepsint, optional

The number of steps for the polytropic process calculation. Default is 50.

Returns:
tuple

Tuple containing (state_out, states) where states is a list with all intermediate states

Raises:
ValueError

If an invalid ‘efficiency_type’ is provided.

thermopt.components.basic_components.compute_component_energy_flows(components)[source]#

Compute power and heat flows for a set of components in a thermodynamic cycle.

For heat exchangers, the function calculates local and total heat transfer on both hot and cold sides, assuming precomputed enthalpy profiles. For turbomachinery (compressors or expanders), it evaluates the mechanical power based on mass flow and specific work. The results are stored in-place in the components dictionary.

Parameters:
componentsdict

Dictionary of components, each with a ‘type’ field and required properties such as mass flow, enthalpy states, and specific work.

Returns:
None

The function modifies the components dictionary in place, adding: - ‘power’ [W] - ‘heat_flow’ and ‘heat_flow_bis’ [W] - ‘heat_balance’ [W] for heat exchangers

thermopt.components.basic_components.expansion_process(fluid, h_in, p_in, p_out, efficiency=None, efficiency_type='isentropic', mass_flow=None, data_in={}, num_steps=50)[source]#

Calculate properties along a compression process defined by a isentropic or polytropic efficiency

Parameters:
fluidFluid

The fluid object used to evaluate thermodynamic properties

h_infloat

Enthalpy at the start of the compression process.

p_infloat

Pressure at the start of the compression process.

p_outfloat

Pressure at the end of the compression process.

efficiencyfloat

The efficiency of the compression process.

efficiency_typestr, optional

The type of efficiency to be used in the process (‘isentropic’ or ‘polytropic’). Default is ‘isentropic’.

num_stepsint, optional

The number of steps for the polytropic process calculation. Default is 50.

Returns:
tuple

Tuple containing (state_out, states) where states is a list with all intermediate states

Raises:
ValueError

If an invalid ‘efficiency_type’ is provided.

thermopt.components.basic_components.heat_exchanger(fluid_hot, h_in_hot, h_out_hot, p_in_hot, p_out_hot, fluid_cold, h_in_cold, h_out_cold, p_in_cold, p_out_cold, num_steps=50, counter_current=True)[source]#

Simulate a counter-current or co-current heat exchanger using discretized enthalpy and pressure profiles.

The heat exchange is discretized along both streams. Thermodynamic states are evaluated at linearly spaced enthalpy and pressure points. The resulting states are ordered in the direction of increasing temperature. For counter-current flow, the hot-side state array is flipped to enable element-wise temperature difference computation.

Parameters:
fluid_hotCoolProp.AbstractState

Fluid object for the hot side.

h_in_hotfloat

Inlet specific enthalpy [J/kg] of the hot fluid.

h_out_hotfloat

Outlet specific enthalpy [J/kg] of the hot fluid.

p_in_hotfloat

Inlet pressure [Pa] of the hot fluid.

p_out_hotfloat

Outlet pressure [Pa] of the hot fluid.

fluid_coldCoolProp.AbstractState

Fluid object for the cold side.

h_in_coldfloat

Inlet specific enthalpy [J/kg] of the cold fluid.

h_out_coldfloat

Outlet specific enthalpy [J/kg] of the cold fluid.

p_in_coldfloat

Inlet pressure [Pa] of the cold fluid.

p_out_coldfloat

Outlet pressure [Pa] of the cold fluid.

num_stepsint, optional

Number of discretization steps (default is 50).

counter_currentbool, optional

If True, assumes counter-current flow and flips hot-side state arrays (default is True).

Returns:
dict

Dictionary containing: - ‘type’: str, component type - ‘hot_side’: dict, state and property arrays for the hot stream - ‘cold_side’: dict, state and property arrays for the cold stream - ‘q_hot_side’: float, specific enthalpy drop [J/kg] on the hot side - ‘q_cold_side’: float, specific enthalpy gain [J/kg] on the cold side - ‘temperature_hot_side’: ndarray, temperatures [K] for the hot side (ordered by increasing T) - ‘temperature_cold_side’: ndarray, temperatures [K] for the cold side - ‘temperature_difference’: ndarray, element-wise temperature difference [K] - ‘mass_flow_ratio’: float, ratio of cold-side to hot-side mass flow required for heat balance

thermopt.components.basic_components.heat_transfer_process(fluid, h_1, p_1, h_2, p_2, num_steps=25)[source]#

Compute a discretized heat transfer process by idiscretizing enthalpy and pressure between inlet and outlet.

This function generates a sequence of thermodynamic states along a heat transfer path by linearly spacing enthalpy and pressure between inlet and outlet values. The resulting states are organized in the direction of increasing enthalpy, which for sensible heating/cooling corresponds to increasing temperature.

Parameters:
fluidCoolProp.AbstractState

CoolProp fluid object used for property evaluation.

h_1float

Inlet specific enthalpy [J/kg].

p_1float

Inlet pressure [Pa].

h_2float

Outlet specific enthalpy [J/kg].

p_2float

Outlet pressure [Pa].

num_stepsint, optional

Number of discretization steps (default is 25).

Returns:
dict

Dictionary containing: - ‘states’: dict of arrays with thermodynamic properties along the process - ‘fluid_name’: str, name of the fluid - ‘state_in’: CoolProp state object at the inlet - ‘state_out’: CoolProp state object at the outlet - ‘mass_flow’: float, set to NaN (to be populated externally) - ‘heat_flow’: float, set to NaN (to be populated externally) - ‘color’: str, set to ‘black’ (optional use for plotting)

thermopt.components.basic_components.isenthalpic_valve(state_in, p_out, fluid, N=50)[source]#

Simulate an isenthalpic throttling process across a valve.

The enthalpy remains constant across the valve, and pressure is reduced from inlet to outlet. The function returns a list of thermodynamic states along the expansion

This function will yield similar results as an expansion process with a polytropic/isentropic efficiency of 0 %.

Parameters:
state_inCoolProp.AbstractState

Inlet thermodynamic state.

p_outfloat

Outlet pressure [Pa].

fluidCoolProp.AbstractState

Fluid object for property evaluation.

Nint, optional

Number of pressure steps between inlet and outlet (default is 50).

Returns:
list of CoolProp.AbstractState

List of thermodynamic states along the isenthalpic path.

thermopt.components.basic_components.postprocess_ode(t, y, ode_handle)[source]#

Reconstruct thermodynamic states from ODE solution vectors.

This function applies a user-defined ODE handle to each time step to extract the corresponding thermodynamic state based on the integrated solution. It is useful for evaluating additional fluid properties not stored in the raw y vector.

Parameters:
tndarray

Time array [s].

yndarray

Solution array of shape (n_states, n_time_steps).

ode_handlecallable

Function that takes (t_i, y_i) and returns a tuple (_, state), where state is a CoolProp.AbstractState or similar object.

Returns:
list

List of thermodynamic states reconstructed from the ODE trajectory.