vclibpy.media package

class vclibpy.media.CoolProp(fluid_name, use_high_level_api: bool = False)[source]

Bases: MedProp

Class using the open-source CoolProp package to access the properties.

Args:
use_high_level_api (bool):

True to use the high-level api, which is much slower, but you can use all modes in calc_state. Default is False.

calc_state(mode: str, var1: float, var2: float)[source]

Calculate the thermodynamic state based on the specified mode and state variables.

This function calculates the thermodynamic state based on the chosen mode and provided state variables. The input state variables need to be in SI units.

Notes:
  • PT does not work when the state might fall within the two-phase region.

  • Only functions for density are implemented. In cases where you know the specific volume, use the density functions with the inverse value.

  • Quality (q) may have values outside the ‘physical’ scope:
    • q = -998: Subcooled liquid

    • q = 998: Superheated vapor

    • q = 999: Supercritical state

Possible modes include:
  • “PD”: Pressure, Density

  • “PH”: Pressure, Enthalpy

  • “PQ”: Pressure, Quality

  • “PS”: Pressure, Entropy

  • “PT”: Pressure, Temperature

  • “PU”: Pressure, Internal Energy

  • “TD”: Temperature, Density

  • “TH”: Temperature, Enthalpy

  • “TQ”: Temperature, Quality

  • “TS”: Temperature, Entropy

  • “TU”: Temperature, Internal Energy

  • “DH”: Density, Enthalpy

  • “DS”: Density, Entropy

  • “DU”: Density, Internal Energy

Args:

mode (str): Defines the given input state variables (see possible modes above). var1 (float): Value of the first state variable (as specified in the mode) in SI units. var2 (float): Value of the second state variable (as specified in the mode) in SI units.

Returns:

ThermodynamicState: A ThermodynamicState instance with state variables.

Raises:

AssertionError: If the given mode is not within the available options.

calc_transport_properties(state: ThermodynamicState)[source]

Calculate the transport properties for the given state.

Args:

state (ThermodynamicState): The current thermodynamic state.

Returns:

TransportProperties: An instance of TransportProperties.

get_critical_point()[source]

Retrieve critical point information for the fluid.

Returns:

Tuple[float, float, float]: A tuple containing critical point information (Temperature Tc [K], Pressure pc [Pa], Density dc [kg/m^3]).

get_molar_mass()[source]

Retrieve the molar mass of the current fluid.

Returns:

float: The molar mass M of the current fluid in kg/mol.

class vclibpy.media.MedProp(fluid_name)[source]

Bases: ABC

Base class for all media property interfaces.

This class serves as the base for defining interfaces to access and compute media properties.

Methods:

calc_state: Calculate the thermodynamic state based on mode and state variables. calc_transport_properties: Calculate transport properties for a given state. get_critical_point: Retrieve critical point information. get_molar_mass: Retrieve molar mass information. get_two_phase_limits: Retrieve the two-phase limits for plotting. calc_mean_transport_properties: Calculate the average transport properties for given states.

calc_mean_transport_properties(state_in, state_out)[source]

Calculate the average transport properties for the given states.

Args:

state_in (ThermodynamicState): First state state_out (ThermodynamicState): Second state

Returns:

TransportProperties: Average transport properties

Notes:

The TransportProperties does not contain a state, as an average state is not possible to calculate.

calc_state(mode: str, var1: float, var2: float)[source]

Calculate the thermodynamic state based on the specified mode and state variables.

This function calculates the thermodynamic state based on the chosen mode and provided state variables. The input state variables need to be in SI units.

Notes:
  • PT does not work when the state might fall within the two-phase region.

  • Only functions for density are implemented. In cases where you know the specific volume, use the density functions with the inverse value.

  • Quality (q) may have values outside the ‘physical’ scope:
    • q = -998: Subcooled liquid

    • q = 998: Superheated vapor

    • q = 999: Supercritical state

Possible modes include:
  • “PD”: Pressure, Density

  • “PH”: Pressure, Enthalpy

  • “PQ”: Pressure, Quality

  • “PS”: Pressure, Entropy

  • “PT”: Pressure, Temperature

  • “PU”: Pressure, Internal Energy

  • “TD”: Temperature, Density

  • “TH”: Temperature, Enthalpy

  • “TQ”: Temperature, Quality

  • “TS”: Temperature, Entropy

  • “TU”: Temperature, Internal Energy

  • “DH”: Density, Enthalpy

  • “DS”: Density, Entropy

  • “DU”: Density, Internal Energy

Args:

mode (str): Defines the given input state variables (see possible modes above). var1 (float): Value of the first state variable (as specified in the mode) in SI units. var2 (float): Value of the second state variable (as specified in the mode) in SI units.

Returns:

ThermodynamicState: A ThermodynamicState instance with state variables.

Raises:

AssertionError: If the given mode is not within the available options.

abstract calc_transport_properties(state: ThermodynamicState)[source]

Calculate the transport properties for the given state.

Args:

state (ThermodynamicState): The current thermodynamic state.

Returns:

TransportProperties: An instance of TransportProperties.

abstract get_critical_point()[source]

Retrieve critical point information for the fluid.

Returns:

Tuple[float, float, float]: A tuple containing critical point information (Temperature Tc [K], Pressure pc [Pa], Density dc [kg/m^3]).

abstract get_molar_mass()[source]

Retrieve the molar mass of the current fluid.

Returns:

float: The molar mass M of the current fluid in kg/mol.

get_two_phase_limits(quantity: str, p_min: int = 100000, p_step: int = 5000)[source]

Retrieve the two-phase limits for plotting a specified quantity.

This method returns the two-phase limits for a specified quantity (T, h, s, or p) in an array used for plotting purposes. It calculates the limits within the pressure range from p_min and quality (q) 0 to the critical pressure (pc), and then from the critical pressure to the pressure p_min and quality 1.

Args:

quantity (str): The specified quantity (T, h, s, or p). p_min (int, optional): The minimum pressure value to start iteration. Default is 100000 Pa. p_step (int, optional): The step size for pressure variation. Default is 5000 Pa.

Returns:

numpy.ndarray: An array containing the two-phase limits for the specified quantity.

Raises:

ValueError: If the given quantity is not supported (T, h, s, or p).

terminate()[source]

Terminate the class. Default behaviour does nothing.

class vclibpy.media.RefProp(fluid_name, z=None, dll_path: str | None = None, use_error_check: bool = True, use_warnings: bool = True, ref_prop_path: str | None = None, copy_dll: bool = True, copy_dll_directory: str | None = None)[source]

Bases: MedProp

Class to connect to refProp package.

Args: :param string fluid_name:

Fluid name for RefProp use

Parameters:
  • z (list or None) – Fluid composition. Should only be used, when a self-design mixture shall be used. Further information see notes. When you want to use a self-design mixture to as follows: - Fluid-name needs to contain all component names within mixture: “R32.FLD|R125.FLD” - z needs to be a list with molar fractions: [0.697, 0.303] - Used example would be similar to R410A

  • dll_path (string) – Specifier for the dll path used for RefProp, e.g. dll_path=’C:path_to_dllRefProp64.dll’. If None, the ref_prop_path and function get_dll_path are used to determine the dll path

  • use_error_check (boolean) – Specifier whether errors and warnings shall be checked when calling RefProp or not

  • use_warnings (boolean) – Specifier whether warnings shall be used

  • ref_prop_path (str) – Path to RefProp package. Default is the ENV variable RPPREFIX.

  • copy_dll (bool) – If True (not the default), a copy of the dll is created to enable simultaneous use of multiple fluids in multiprocessing.

  • copy_dll_directory (str) – If copy_dll is True, the DLL is copied to this directory. If None (default), the current working directory is used.

Note:
Functionality:
  • It does not work to have multiple instances simultaneously. When calculating values the last fluid name

    somehow will be used even though instance includes “new” name. Need to be fixed at some point.

How to use RefProp-Wrapper:

1.) Create RefProp instance: rp = RefProp(“R32”) 2.) In case you want to calculate fluid properties (state variables) for a specific state: Use calc_state() function

Multiple inputs can be given (but you need to now two in order to define the values). For further information see function header.

3.) Further get-Functions implemented
  • get_gwp(): Global warming potential

  • get_odp(): Ozone depletion potential

  • get_safety(): Safety class

  • get_mass_fraction(): Mass fractions of pure substances in fluid

  • get_molar_mass(): Molar mass of fluid

  • get_mol_fraction(): Mol fractions of pure substances in fluid

  • get_comp_names(): Pure substances names in fluid

  • get_longname(): Long name of fluid within RefProp

  • get_critical_point(): Crit. Temperature and Pressure

  • get_version(): Version of wrapper and of RefProp dll

Version notes:

0.1.0 (21.04.2020, Christoph Hoeges):
First implementation
  • Contains multiple functions to call RefProp instance

  • Can calculate state, crit, GWP, ODP, Safety class, molar mass etc. of fluid

  • Mixtures might work but it wasn’t fully testet - R455A e.g. still deviates slightly

0.1.1 (25.04.2020, Christoph Hoeges):
Multiple changes, added functionality. Commands are still the same though
  • Self designed mixtures are possible now as well (see instructions in init

  • Added composition input to __init__ function

  • Added modes in calc_state function and removed bug in PH calculation

  • Additional protected functions due to different input

  • Adjusted _call_refprop function (z is not mass frac but mol fraction)

  • Added documentation / instruction

0.1.2 (08.05.2020, Christoph Hoeges):
Multiple adjustments
  • Added function to call ABFLSHdll function in refprop (high level function)

  • Changed function calls in calc_state function to ABFLSH and adjusted conversion

  • Change init-function so user can choose which dll shall be used

  • Add function to get version of this current wrapper as well as RefProp-dll version

0.1.3 (12.05.2020, Christoph Hoeges):
Multiple changes
  • Added function to get all files in MIXTURE and FLUIDS directory to check available fluids

  • Added error function in order to return errors when RefProp-Functions are called.
    NOTE: Not all instances where refprop is called are checked for errors. Currently, it is only used in

    init and calc_state

0.1.4 (19.05.2020, Christoph Hoeges):
Multiple changes:
  • Debugged fluid properties calculation for predefined mixtures

  • Fixed option of self-defined mixtures

0.1.5 (22.05.2020, Christoph Hoeges):

Include transport properties calculation into wrapper

0.1.6 (10.06.2020, Fabian Wuellhorst):

Add option to use a custom dll path. This necessary to use multiple instances with possible different fluids at the same time.

calc_satliq_state(s)[source]

s in kJ/kgK

calc_state(mode: str, var1: float, var2: float, kr=1)[source]

Calculate state. Depending on mode, different function will be chosen. Input state variables need to be in SI units!

Notes:

1.) PT does not work when state might be within the two-phase region! 2.) Only functions for density are implemented. In case you know the specific volume instead use density

functions with inverse value!

3.) Quality can have values outside of ‘physical’ scope:

q = -998: Subcooled liquid q = 998: Superheated vapor q = 999: Supercritical state

Possible modes are currently:
  • “PD”: Pressure, Density

  • “PH”: Pressure, Enthalpy

  • “PQ”: Pressure, Quality

  • “PS”: Pressure, Entropy

  • “PT”: Pressure, Temperature

  • “PU”: Pressure, Internal Energy

  • “TD”: Temperature, Density

  • “TH”: Temperature, Enthalpy

  • “TQ”: Temperature, Quality

  • “TS”: Temperature, Entropy

  • “TU”: Temperature, Internal Energy

  • “DH”: Density, Enthalpy

  • “DS”: Density, Entropy

  • “DU”: Density, Internal Energy

  • “HS”: Enthalpy, Entropy

Parameters:

param string mode:

Defines which input state variables are given (see possible modes above)

param float var1:

Value of state variable 1 (first one in name) - use SI units!

param float var2:

Value of state variable 2 (second one in name) - use SI units!

param int kr:

phase flag (kr=1: lower density, kr=2: higher density) relevant for “TH”, “TS”, “TU”

Return:

return ThermodynamicState state:

Thermodynamic state with state variables

calc_transport_properties(state: ThermodynamicState)[source]

Calculate transport properties of RefProp fluid at given state

Parameters:

param ThermodynamicState state:

Current thermodynamic state

Return:

return TransportProperties props:

Instance of TransportProperties

get_available_substances(mode='all', include_ending=False, save_txt=False)[source]

Get all available RefProp fluids (mixtures and / or pure substances depending on mode)

Parameters:

param string mode:

Mode defining which kind of fluids you want to have: ‘pure’: pure substances, ‘mix’: mixtures, ‘all’: all

param boolean include_ending:

Defines, whether file ending shall be returned as well or not

param boolean save_txt:

Defines, whether a text file with names shall be created in current working directory

Return:

return list names:

String list containing names of available fluids (depending on defined mode)

get_comp_names()[source]

Get name of components within current fluid”

Return:

return list comp_names:

String names of components within current fluid

get_critical_point()[source]

Get T and p of critical point

Return:

return float Tc:

Temperature at critical point in K

return float pc:

Pressure at critical point in Pa

return float dc:

Density at critical point in kg/m^3

get_def_limits()[source]

Get limits of current ref prop fluid Limits contain Tmin, Tmax, Dmax and Pmax (Temperatures, density, pressure)

Return dict limits:

Dictionary with definition limits in RefProp. Contains min/max temperature, max density, max pressure.

static get_dll_path(ref_prop_path: str)[source]

Return the location of the dll

Return: :return: string path_to_dll:

Path of a valid dll

get_fluid_name()[source]

Get fluid name.

Return:

return string fluid_name:

Fluid name

get_gwp()[source]

Get gwp of current fluid from refProp

Return:

return float gwp:

Global warming potential of fluid. In case calculation failed, None will be returned.

get_longname()[source]

Get longname of fluid

Return:

return string longname:

Name of current fluid in refprop - provides mass fractions and components as well (in case of mixture)

get_mass_fraction(use_round=True)[source]

Get mass fractions of pure substances in current fluid

Parameters: :param boolean use_round:

Flag to define, whether the exact values or rounded values (by the fourth number) shall be used

Return:

return list mass_frac:

List of component mass fractions

get_mol_fraction(use_round=True)[source]

Get mol fractions of pure substances in current fluid

Parameters: :param boolean use_round:

Flag to define, whether the exact values or rounded values (by the fourth number) shall be used

Return:

return list frac:

List of component mol fractions

get_molar_composition(state: ThermodynamicState, z_molar=None)[source]

Get composition on molar base. Liquid phase, vapor phase and total.

Parameters:
  • state (ThermodynamicState) – the state whose compositions will be returned

  • z_molar (list) – molar composition of fluid. In case of None, default value _mol_frac is used

Returns:

  • list x:

    composition of liquid phase

  • list y:

    composition of vapor phase

  • list z:

    composition in total

get_molar_mass()[source]

Get molar mass of current fluid

Return:

return float M:

Molar mass of current fluid in kg/mol

get_nbp()[source]

Get normal boiling point (T @ q=0 and 1 bar)

Return:

return float nbp:

Normal boiling point of refrigerant in °C

get_odp()[source]

Calculate ozone depletion potential In case of mixtures: Maximum value of pure substances will be used

Return:

return float odp:

ODP of fluid. In case calculation failed, None will be returned.

get_safety()[source]

Calculate safety class of refrigerant

Return:

return string safety:

Safety class of fluid.

get_sat_vap_pressure(T_sat)[source]

Get pressure of saturated vapor for defined temperature

Note:
  • works for vapor, liquid and solid

  • returns equilibrium pressure at defined line (q=1)

Parameters: :param float T_sat:

Temperature in K

Return: :return float p_sat:

Vapor pressure in Pa

get_triple_point()[source]

Get temperature and pressure at triple point of current fluid

Note: Works fine for pure substances, mixtures might not work properly

Return: :return float T_tpl:

Temperature at triple point in K

Return float p_tpl:

Pressure at triple point in Pa

get_version()[source]

Get version of wrapper and used RefProp dll

Return: :return string wrapper_version:

Refprop wrapper version

Return string refprop_version:

Version of used RefProp dll

is_mixture()[source]

Find out if fluid is mixture or not. In case current fluid is mixture, true is returned. In case current fluid is pure substance, false is returned.

Return:

return boolean _mix_flag:

Boolean for mixture (True), pure substance (False)

set_error_flag(flag)[source]

Set error flag

Parameters: :param boolean flag:

New error flag

Return: :return int err:

Notifier for error code - in case everything went fine, 0 is returned

set_warning_flag(flag)[source]

Set warning flag

Parameters: :param boolean flag:

New warning flag

Return: :return int err:

Notifier for error code - in case everything went fine, 0 is returned

terminate()[source]

Terminate the class. Default behaviour does nothing.

class vclibpy.media.ThermodynamicState(p=None, T=None, u=None, h=None, s=None, v=None, q=None, d=None)[source]

Bases: object

Represents a thermodynamic state within a cycle.

Notes:

Does not necessarily need to have all state variables defined!

Args:

p (float): Pressure at the state in Pa. T (float): Temperature at the state in K. u (float): Inner energy at the state in J/kg. h (float): Enthalpy at the state in J/kg. s (float): Entropy at the state in J/(kg * K). v (float): Specific volume at the state in m^3/kg. q (float): Quality at the state (between 0 and 1). d (float): Density at the state in kg/m^3.

Methods:

__init__: Initializes the state class. __str__: Provides a string representation of the state. get_pretty_print: Formats the state with names, units, and descriptions.

get_pretty_print()[source]

Provides a formatted representation of the state with names, units, and descriptions.

class vclibpy.media.TransportProperties(lam=None, dyn_vis=None, kin_vis=None, pr=None, cp=None, cv=None, beta=None, sur_ten=None, ace_fac=None, state=None)[source]

Bases: object

Represents transport properties at a specific thermodynamic state.

Args:

lam (float): Thermal conductivity in W/(m*K). dyn_vis (float): Dynamic viscosity in Pa*s. kin_vis (float): Kinematic viscosity in m^2/s. Pr (float): Prandtl number. cp (float): Isobaric specific heat capacity in J/(kg*K). cv (float): Isochoric specific heat capacity in J/(kg*K). beta (float): Thermal expansion coefficient in 1/K. sur_ten (float): Surface tension in N/m. ace_fac (float): Acentric factor. state (ThermodynamicState): The state the transport properties belong to.

Methods:

__init__: Initializes the transport properties class. __str__: Provides a string representation of the transport properties. get_pretty_print: Formats the properties with names, units, and descriptions.

get_pretty_print()[source]

Provides a formatted representation of the properties with names, units, and descriptions.

Submodules

vclibpy.media.cool_prop module

Module with cool prop wrapper.

class vclibpy.media.cool_prop.CoolProp(fluid_name, use_high_level_api: bool = False)[source]

Bases: MedProp

Class using the open-source CoolProp package to access the properties.

Args:
use_high_level_api (bool):

True to use the high-level api, which is much slower, but you can use all modes in calc_state. Default is False.

calc_state(mode: str, var1: float, var2: float)[source]

Calculate the thermodynamic state based on the specified mode and state variables.

This function calculates the thermodynamic state based on the chosen mode and provided state variables. The input state variables need to be in SI units.

Notes:
  • PT does not work when the state might fall within the two-phase region.

  • Only functions for density are implemented. In cases where you know the specific volume, use the density functions with the inverse value.

  • Quality (q) may have values outside the ‘physical’ scope:
    • q = -998: Subcooled liquid

    • q = 998: Superheated vapor

    • q = 999: Supercritical state

Possible modes include:
  • “PD”: Pressure, Density

  • “PH”: Pressure, Enthalpy

  • “PQ”: Pressure, Quality

  • “PS”: Pressure, Entropy

  • “PT”: Pressure, Temperature

  • “PU”: Pressure, Internal Energy

  • “TD”: Temperature, Density

  • “TH”: Temperature, Enthalpy

  • “TQ”: Temperature, Quality

  • “TS”: Temperature, Entropy

  • “TU”: Temperature, Internal Energy

  • “DH”: Density, Enthalpy

  • “DS”: Density, Entropy

  • “DU”: Density, Internal Energy

Args:

mode (str): Defines the given input state variables (see possible modes above). var1 (float): Value of the first state variable (as specified in the mode) in SI units. var2 (float): Value of the second state variable (as specified in the mode) in SI units.

Returns:

ThermodynamicState: A ThermodynamicState instance with state variables.

Raises:

AssertionError: If the given mode is not within the available options.

calc_transport_properties(state: ThermodynamicState)[source]

Calculate the transport properties for the given state.

Args:

state (ThermodynamicState): The current thermodynamic state.

Returns:

TransportProperties: An instance of TransportProperties.

get_critical_point()[source]

Retrieve critical point information for the fluid.

Returns:

Tuple[float, float, float]: A tuple containing critical point information (Temperature Tc [K], Pressure pc [Pa], Density dc [kg/m^3]).

get_molar_mass()[source]

Retrieve the molar mass of the current fluid.

Returns:

float: The molar mass M of the current fluid in kg/mol.

vclibpy.media.media module

Module with wrappers to access and handle media property databases.

This module provides interfaces to load media properties using various wrappers and handle calculations related to media properties.

Classes:

MedProp: Base class for all media property interfaces.

Functions:

get_two_phase_limits: Return the states of the boundaries of the two-phase section for a given fluid.

class vclibpy.media.media.MedProp(fluid_name)[source]

Bases: ABC

Base class for all media property interfaces.

This class serves as the base for defining interfaces to access and compute media properties.

Methods:

calc_state: Calculate the thermodynamic state based on mode and state variables. calc_transport_properties: Calculate transport properties for a given state. get_critical_point: Retrieve critical point information. get_molar_mass: Retrieve molar mass information. get_two_phase_limits: Retrieve the two-phase limits for plotting. calc_mean_transport_properties: Calculate the average transport properties for given states.

calc_mean_transport_properties(state_in, state_out)[source]

Calculate the average transport properties for the given states.

Args:

state_in (ThermodynamicState): First state state_out (ThermodynamicState): Second state

Returns:

TransportProperties: Average transport properties

Notes:

The TransportProperties does not contain a state, as an average state is not possible to calculate.

calc_state(mode: str, var1: float, var2: float)[source]

Calculate the thermodynamic state based on the specified mode and state variables.

This function calculates the thermodynamic state based on the chosen mode and provided state variables. The input state variables need to be in SI units.

Notes:
  • PT does not work when the state might fall within the two-phase region.

  • Only functions for density are implemented. In cases where you know the specific volume, use the density functions with the inverse value.

  • Quality (q) may have values outside the ‘physical’ scope:
    • q = -998: Subcooled liquid

    • q = 998: Superheated vapor

    • q = 999: Supercritical state

Possible modes include:
  • “PD”: Pressure, Density

  • “PH”: Pressure, Enthalpy

  • “PQ”: Pressure, Quality

  • “PS”: Pressure, Entropy

  • “PT”: Pressure, Temperature

  • “PU”: Pressure, Internal Energy

  • “TD”: Temperature, Density

  • “TH”: Temperature, Enthalpy

  • “TQ”: Temperature, Quality

  • “TS”: Temperature, Entropy

  • “TU”: Temperature, Internal Energy

  • “DH”: Density, Enthalpy

  • “DS”: Density, Entropy

  • “DU”: Density, Internal Energy

Args:

mode (str): Defines the given input state variables (see possible modes above). var1 (float): Value of the first state variable (as specified in the mode) in SI units. var2 (float): Value of the second state variable (as specified in the mode) in SI units.

Returns:

ThermodynamicState: A ThermodynamicState instance with state variables.

Raises:

AssertionError: If the given mode is not within the available options.

abstract calc_transport_properties(state: ThermodynamicState)[source]

Calculate the transport properties for the given state.

Args:

state (ThermodynamicState): The current thermodynamic state.

Returns:

TransportProperties: An instance of TransportProperties.

abstract get_critical_point()[source]

Retrieve critical point information for the fluid.

Returns:

Tuple[float, float, float]: A tuple containing critical point information (Temperature Tc [K], Pressure pc [Pa], Density dc [kg/m^3]).

abstract get_molar_mass()[source]

Retrieve the molar mass of the current fluid.

Returns:

float: The molar mass M of the current fluid in kg/mol.

get_two_phase_limits(quantity: str, p_min: int = 100000, p_step: int = 5000)[source]

Retrieve the two-phase limits for plotting a specified quantity.

This method returns the two-phase limits for a specified quantity (T, h, s, or p) in an array used for plotting purposes. It calculates the limits within the pressure range from p_min and quality (q) 0 to the critical pressure (pc), and then from the critical pressure to the pressure p_min and quality 1.

Args:

quantity (str): The specified quantity (T, h, s, or p). p_min (int, optional): The minimum pressure value to start iteration. Default is 100000 Pa. p_step (int, optional): The step size for pressure variation. Default is 5000 Pa.

Returns:

numpy.ndarray: An array containing the two-phase limits for the specified quantity.

Raises:

ValueError: If the given quantity is not supported (T, h, s, or p).

terminate()[source]

Terminate the class. Default behaviour does nothing.

vclibpy.media.media.get_two_phase_limits(med_prop: MedProp, p_step: int = 1000, p_min: int = 1000) List[ThermodynamicState][source]

Return the states representing the boundaries of the two-phase section for the given fluid.

This function is primarily used for visualizing the two-phase section and validating the accuracy of calculations.

Args:

med_prop (MedProp): An instance of a valid MedProp-Class. p_step (int): The step size for pressure variation in Pa. Default is 1000 Pa. p_min (int): The minimum pressure in Pa from where to start calculation. Default is 1000 Pa.

Returns:

List[ThermodynamicState]: A list of ThermodynamicState instances representing the two-phase limits.

Notes:

The two-phase limits are computed by iterating over a range of pressures from the minimum pressure up to the critical point pressure (exclusive) with a specified step size. States at quality 0 (saturated liquid) and quality 1 (saturated vapor) are appended to form the two-phase boundary. The list is reversed to maintain the correct order for visualization purposes.

vclibpy.media.ref_prop module

Created on 21.04.2020

@author: Christoph Hoeges, Fabian Wuellhorst, Jona Brach

To test: - Transport properties are not fully tested (Status: 11.06.2020) - Error raising is not implemented at all refprop calls

  • Additional change might be that not all errors and warning are excluded when ‘use_error_check’ is set to false but

    only warnings or errors?

class vclibpy.media.ref_prop.RefProp(fluid_name, z=None, dll_path: str | None = None, use_error_check: bool = True, use_warnings: bool = True, ref_prop_path: str | None = None, copy_dll: bool = True, copy_dll_directory: str | None = None)[source]

Bases: MedProp

Class to connect to refProp package.

Args: :param string fluid_name:

Fluid name for RefProp use

Parameters:
  • z (list or None) – Fluid composition. Should only be used, when a self-design mixture shall be used. Further information see notes. When you want to use a self-design mixture to as follows: - Fluid-name needs to contain all component names within mixture: “R32.FLD|R125.FLD” - z needs to be a list with molar fractions: [0.697, 0.303] - Used example would be similar to R410A

  • dll_path (string) – Specifier for the dll path used for RefProp, e.g. dll_path=’C:path_to_dllRefProp64.dll’. If None, the ref_prop_path and function get_dll_path are used to determine the dll path

  • use_error_check (boolean) – Specifier whether errors and warnings shall be checked when calling RefProp or not

  • use_warnings (boolean) – Specifier whether warnings shall be used

  • ref_prop_path (str) – Path to RefProp package. Default is the ENV variable RPPREFIX.

  • copy_dll (bool) – If True (not the default), a copy of the dll is created to enable simultaneous use of multiple fluids in multiprocessing.

  • copy_dll_directory (str) – If copy_dll is True, the DLL is copied to this directory. If None (default), the current working directory is used.

Note:
Functionality:
  • It does not work to have multiple instances simultaneously. When calculating values the last fluid name

    somehow will be used even though instance includes “new” name. Need to be fixed at some point.

How to use RefProp-Wrapper:

1.) Create RefProp instance: rp = RefProp(“R32”) 2.) In case you want to calculate fluid properties (state variables) for a specific state: Use calc_state() function

Multiple inputs can be given (but you need to now two in order to define the values). For further information see function header.

3.) Further get-Functions implemented
  • get_gwp(): Global warming potential

  • get_odp(): Ozone depletion potential

  • get_safety(): Safety class

  • get_mass_fraction(): Mass fractions of pure substances in fluid

  • get_molar_mass(): Molar mass of fluid

  • get_mol_fraction(): Mol fractions of pure substances in fluid

  • get_comp_names(): Pure substances names in fluid

  • get_longname(): Long name of fluid within RefProp

  • get_critical_point(): Crit. Temperature and Pressure

  • get_version(): Version of wrapper and of RefProp dll

Version notes:

0.1.0 (21.04.2020, Christoph Hoeges):
First implementation
  • Contains multiple functions to call RefProp instance

  • Can calculate state, crit, GWP, ODP, Safety class, molar mass etc. of fluid

  • Mixtures might work but it wasn’t fully testet - R455A e.g. still deviates slightly

0.1.1 (25.04.2020, Christoph Hoeges):
Multiple changes, added functionality. Commands are still the same though
  • Self designed mixtures are possible now as well (see instructions in init

  • Added composition input to __init__ function

  • Added modes in calc_state function and removed bug in PH calculation

  • Additional protected functions due to different input

  • Adjusted _call_refprop function (z is not mass frac but mol fraction)

  • Added documentation / instruction

0.1.2 (08.05.2020, Christoph Hoeges):
Multiple adjustments
  • Added function to call ABFLSHdll function in refprop (high level function)

  • Changed function calls in calc_state function to ABFLSH and adjusted conversion

  • Change init-function so user can choose which dll shall be used

  • Add function to get version of this current wrapper as well as RefProp-dll version

0.1.3 (12.05.2020, Christoph Hoeges):
Multiple changes
  • Added function to get all files in MIXTURE and FLUIDS directory to check available fluids

  • Added error function in order to return errors when RefProp-Functions are called.
    NOTE: Not all instances where refprop is called are checked for errors. Currently, it is only used in

    init and calc_state

0.1.4 (19.05.2020, Christoph Hoeges):
Multiple changes:
  • Debugged fluid properties calculation for predefined mixtures

  • Fixed option of self-defined mixtures

0.1.5 (22.05.2020, Christoph Hoeges):

Include transport properties calculation into wrapper

0.1.6 (10.06.2020, Fabian Wuellhorst):

Add option to use a custom dll path. This necessary to use multiple instances with possible different fluids at the same time.

calc_satliq_state(s)[source]

s in kJ/kgK

calc_state(mode: str, var1: float, var2: float, kr=1)[source]

Calculate state. Depending on mode, different function will be chosen. Input state variables need to be in SI units!

Notes:

1.) PT does not work when state might be within the two-phase region! 2.) Only functions for density are implemented. In case you know the specific volume instead use density

functions with inverse value!

3.) Quality can have values outside of ‘physical’ scope:

q = -998: Subcooled liquid q = 998: Superheated vapor q = 999: Supercritical state

Possible modes are currently:
  • “PD”: Pressure, Density

  • “PH”: Pressure, Enthalpy

  • “PQ”: Pressure, Quality

  • “PS”: Pressure, Entropy

  • “PT”: Pressure, Temperature

  • “PU”: Pressure, Internal Energy

  • “TD”: Temperature, Density

  • “TH”: Temperature, Enthalpy

  • “TQ”: Temperature, Quality

  • “TS”: Temperature, Entropy

  • “TU”: Temperature, Internal Energy

  • “DH”: Density, Enthalpy

  • “DS”: Density, Entropy

  • “DU”: Density, Internal Energy

  • “HS”: Enthalpy, Entropy

Parameters:

param string mode:

Defines which input state variables are given (see possible modes above)

param float var1:

Value of state variable 1 (first one in name) - use SI units!

param float var2:

Value of state variable 2 (second one in name) - use SI units!

param int kr:

phase flag (kr=1: lower density, kr=2: higher density) relevant for “TH”, “TS”, “TU”

Return:

return ThermodynamicState state:

Thermodynamic state with state variables

calc_transport_properties(state: ThermodynamicState)[source]

Calculate transport properties of RefProp fluid at given state

Parameters:

param ThermodynamicState state:

Current thermodynamic state

Return:

return TransportProperties props:

Instance of TransportProperties

get_available_substances(mode='all', include_ending=False, save_txt=False)[source]

Get all available RefProp fluids (mixtures and / or pure substances depending on mode)

Parameters:

param string mode:

Mode defining which kind of fluids you want to have: ‘pure’: pure substances, ‘mix’: mixtures, ‘all’: all

param boolean include_ending:

Defines, whether file ending shall be returned as well or not

param boolean save_txt:

Defines, whether a text file with names shall be created in current working directory

Return:

return list names:

String list containing names of available fluids (depending on defined mode)

get_comp_names()[source]

Get name of components within current fluid”

Return:

return list comp_names:

String names of components within current fluid

get_critical_point()[source]

Get T and p of critical point

Return:

return float Tc:

Temperature at critical point in K

return float pc:

Pressure at critical point in Pa

return float dc:

Density at critical point in kg/m^3

get_def_limits()[source]

Get limits of current ref prop fluid Limits contain Tmin, Tmax, Dmax and Pmax (Temperatures, density, pressure)

Return dict limits:

Dictionary with definition limits in RefProp. Contains min/max temperature, max density, max pressure.

static get_dll_path(ref_prop_path: str)[source]

Return the location of the dll

Return: :return: string path_to_dll:

Path of a valid dll

get_fluid_name()[source]

Get fluid name.

Return:

return string fluid_name:

Fluid name

get_gwp()[source]

Get gwp of current fluid from refProp

Return:

return float gwp:

Global warming potential of fluid. In case calculation failed, None will be returned.

get_longname()[source]

Get longname of fluid

Return:

return string longname:

Name of current fluid in refprop - provides mass fractions and components as well (in case of mixture)

get_mass_fraction(use_round=True)[source]

Get mass fractions of pure substances in current fluid

Parameters: :param boolean use_round:

Flag to define, whether the exact values or rounded values (by the fourth number) shall be used

Return:

return list mass_frac:

List of component mass fractions

get_mol_fraction(use_round=True)[source]

Get mol fractions of pure substances in current fluid

Parameters: :param boolean use_round:

Flag to define, whether the exact values or rounded values (by the fourth number) shall be used

Return:

return list frac:

List of component mol fractions

get_molar_composition(state: ThermodynamicState, z_molar=None)[source]

Get composition on molar base. Liquid phase, vapor phase and total.

Parameters:
  • state (ThermodynamicState) – the state whose compositions will be returned

  • z_molar (list) – molar composition of fluid. In case of None, default value _mol_frac is used

Returns:

  • list x:

    composition of liquid phase

  • list y:

    composition of vapor phase

  • list z:

    composition in total

get_molar_mass()[source]

Get molar mass of current fluid

Return:

return float M:

Molar mass of current fluid in kg/mol

get_nbp()[source]

Get normal boiling point (T @ q=0 and 1 bar)

Return:

return float nbp:

Normal boiling point of refrigerant in °C

get_odp()[source]

Calculate ozone depletion potential In case of mixtures: Maximum value of pure substances will be used

Return:

return float odp:

ODP of fluid. In case calculation failed, None will be returned.

get_safety()[source]

Calculate safety class of refrigerant

Return:

return string safety:

Safety class of fluid.

get_sat_vap_pressure(T_sat)[source]

Get pressure of saturated vapor for defined temperature

Note:
  • works for vapor, liquid and solid

  • returns equilibrium pressure at defined line (q=1)

Parameters: :param float T_sat:

Temperature in K

Return: :return float p_sat:

Vapor pressure in Pa

get_triple_point()[source]

Get temperature and pressure at triple point of current fluid

Note: Works fine for pure substances, mixtures might not work properly

Return: :return float T_tpl:

Temperature at triple point in K

Return float p_tpl:

Pressure at triple point in Pa

get_version()[source]

Get version of wrapper and used RefProp dll

Return: :return string wrapper_version:

Refprop wrapper version

Return string refprop_version:

Version of used RefProp dll

is_mixture()[source]

Find out if fluid is mixture or not. In case current fluid is mixture, true is returned. In case current fluid is pure substance, false is returned.

Return:

return boolean _mix_flag:

Boolean for mixture (True), pure substance (False)

set_error_flag(flag)[source]

Set error flag

Parameters: :param boolean flag:

New error flag

Return: :return int err:

Notifier for error code - in case everything went fine, 0 is returned

set_warning_flag(flag)[source]

Set warning flag

Parameters: :param boolean flag:

New warning flag

Return: :return int err:

Notifier for error code - in case everything went fine, 0 is returned

terminate()[source]

Terminate the class. Default behaviour does nothing.

vclibpy.media.states module

Module containing classes for thermodynamic state and transport properties.

class vclibpy.media.states.ThermodynamicState(p=None, T=None, u=None, h=None, s=None, v=None, q=None, d=None)[source]

Bases: object

Represents a thermodynamic state within a cycle.

Notes:

Does not necessarily need to have all state variables defined!

Args:

p (float): Pressure at the state in Pa. T (float): Temperature at the state in K. u (float): Inner energy at the state in J/kg. h (float): Enthalpy at the state in J/kg. s (float): Entropy at the state in J/(kg * K). v (float): Specific volume at the state in m^3/kg. q (float): Quality at the state (between 0 and 1). d (float): Density at the state in kg/m^3.

Methods:

__init__: Initializes the state class. __str__: Provides a string representation of the state. get_pretty_print: Formats the state with names, units, and descriptions.

get_pretty_print()[source]

Provides a formatted representation of the state with names, units, and descriptions.

class vclibpy.media.states.TransportProperties(lam=None, dyn_vis=None, kin_vis=None, pr=None, cp=None, cv=None, beta=None, sur_ten=None, ace_fac=None, state=None)[source]

Bases: object

Represents transport properties at a specific thermodynamic state.

Args:

lam (float): Thermal conductivity in W/(m*K). dyn_vis (float): Dynamic viscosity in Pa*s. kin_vis (float): Kinematic viscosity in m^2/s. Pr (float): Prandtl number. cp (float): Isobaric specific heat capacity in J/(kg*K). cv (float): Isochoric specific heat capacity in J/(kg*K). beta (float): Thermal expansion coefficient in 1/K. sur_ten (float): Surface tension in N/m. ace_fac (float): Acentric factor. state (ThermodynamicState): The state the transport properties belong to.

Methods:

__init__: Initializes the transport properties class. __str__: Provides a string representation of the transport properties. get_pretty_print: Formats the properties with names, units, and descriptions.

get_pretty_print()[source]

Provides a formatted representation of the properties with names, units, and descriptions.