Skip to main content

REFPROP connector

REFPROP connector is a tool developed by the SERG research group of the University of Florence for launching REFPROP calculations and retrieving results from Python.

To use the code, you must have both REFPROP and the REFPROP wrappers for Python installed and properly working.

The purpose of this library is to make the usage of the refprop wrappers simpler.

Download and installation

The beta version can be downloaded using PIP:

pip install REFPROP_connector

First Steps

Once the installation is complete, you can import the tool and initialize the connector itself.

from REFPROPConnector import ThermodynamicPoint

tp = ThermodynamicPoint(["air"], [1.])

Important aspects to keep in mind for initialization:

  • A file-dialog may appear the first time the connector is imported asking the user to select the REFPROP installation folder (usually "C:\Program Files (x86)\REFPROP"). Once the executable path has been selected, the program will keep it in memory to avoid a new appearance of the file-dialog. The stored executable can be modified by calling the following function:
from REFPROPConnector import retreive_RP_exec

retreive_RP_exec()

If you have multiple or conflicting REFPROP installations, you can force the program not to use the default executable path by using the option:

from REFPROPConnector import retreive_RP_exec

retreive_RP_exec(ignore_default=True)

Alternatively, you can explicitly provide the installation folder path using

from REFPROPConnector import retreive_RP_exec

retreive_RP_exec(file_path="<your path to RP installation>")

IMPORTANT: Each time you run "retreive_RP_exec" open the program that is executing your python code (such as the Terminal, PyCharm or Spider) in administrator mode otherwise the call may not have any effect.

Basic Usage

Each ThermodynamicPoint class instance represents a thermodynamic state, so you must provide at least two independent state variables to calculate the others.

from REFPROPConnector import ThermodynamicPoint

tp = ThermodynamicPoint(["water"], [1.])

tp.set_variable("P", 0.101325)     # P in MPa (ambient pressure)
tp.set_variable("Q", 0.5)          # vapour quality for multiphase condition

T_sat = tp.get_variable("T")       # saturation temperature in Celsius (100 °C)

Abstract Class

AbstractThermodynamicPoint is a class that can be overwritten to perform some calculation once both independent state variables have been set. It can be useful, for example, for the evaluation of the Reynolds number for a fluid flowing in a pipe.

from REFPROPConnector import AbstractThermodynamicPoint, RefPropHandler, init_handler
import numpy as np


class TubeSection(AbstractThermodynamicPoint):

    def __init__(self, diam, flow_rate):
        
        self.diam = diam
        self.area = np.pi * np.power(diam / 2, 2)
        self.flow_rate = flow_rate
        self.Re = 0.
        
        refprop = init_handler(

            chosen_subclass=RefPropHandler,
            fluids=["air"], composition=[1]
            
        )

        super().__init__(refprop)

    def other_calculation(self):
        
        mu = self.get_variable("mu") / (10 ** 6)  # conversion uPa*s -> Pa*s
        self.Re = self.flow_rate * self.diam / (self.area * mu)

if __name__ == "__main__":

    section = TubeSection(0.5, 1)
    
    """
    
        The following line will return 0. as the function "other_calculation" 
        is called only when 2 independent state variables are provided 
        
    """
    print(section.get_variable("Re"))   
    
    section.set_variable("P", 0.5)
    section.set_variable("T", 20)
    
    """
    
        The following line will return the actual Reynolds number
        
    """
    print(section.get_variable("Re"))

Unit system and state variable list

Variables that can be calculated can be listed using the list_properties method from both ThermodynamicPoint and AbstractThermodynamicPoint (the name is not case-sensitive). Finally, the user can also select the unit system to be used in the calculation; a list of possible unit systems can be retrieved by calling the method list_unit_systems() (current unit_system will be highlighted):

from REFPROPConnector import ThermodynamicPoint

tp = ThermodynamicPoint(["water"], [1.], unit_system="MASS BASE SI")
tp.list_properties()
tp.list_unit_systems()

Default unit system is SI with C

Metastable Calculation

You can force the state to represent a metastable condition as follows:

from REFPROPConnector import ThermodynamicPoint

tp = ThermodynamicPoint(["water"], [1.], unit_system="MASS BASE SI")
tp.metastability = "liq" # or "vap" for vapour metastable condition

Acceptable keywords for metastability are ["liquid", "liq", "l", ">"] for the liquid metastable state, or ["vap", "vapour", "vapor", "v", "<"] for the vapour state (keywords are not case-sensitive).

Static and Stagnation condition evaluation

You can evaluate either the static point given the total condition and the speed or the stagnation condition given the static ones by using the following commands:

from REFPROPConnector import ThermodynamicPoint

tp = ThermodynamicPoint(["water"], [1.], unit_system="MASS BASE SI")
speed = 300     # m/s
static_point = tp.get_static_point(speed=speed)
total_point = tp.get_stagnation_point(speed=speed)

The speed value must be given in m/s!

Diagram Plotter

The DiagramPlotter class can be used to plot a specific state diagram that can then be used to describe state transformations. The diagram can be customized using the DiagramPlotterOptions class. The following is an example of how to use the class.

from REFPROPConnector import (
    
    ThermodynamicPoint, 
    DiagramPlotter, 
    DiagramPlotterOptions

)

tp = ThermodynamicPoint(["Carbon Dioxide"], [1])
options = DiagramPlotterOptions(

    x_variable="T",
    x_var_range = (0, 150), x_var_log=False,
    y_var_range = (4, 15),
    isoline_ranges={

        "rho": (50, 1000, 25),
        "H": (200, 550, 25)

    }

)
plotter = DiagramPlotter(tp, options=options)
plotter.calculate()

fig, (ax_1) = plt.subplots(1, 1, dpi=200)
fig.set_size_inches(10, 5)
plotter.plot(ax_1)
plt.show()

Uncertainty Calculation

The connector allows you to manage and calculate the uncertainty of thermodynamic variables through error propagation.
You can set the relative uncertainty (as a fraction, e.g. 0.01 for 1%) on input variables and calculate the uncertainty on derived variables.

Setting the uncertainty

from REFPROPConnector import ThermodynamicPoint

tp = ThermodynamicPoint(["water"], [1.])
tp.set_variable("P", 0.101325)
tp.set_variable("T", 100)

# Set relative uncertainty on pressure and temperature
tp.set_relative_uncertainty("P", 0.01)  # 1% on pressure
tp.set_relative_uncertainty("T", 0.005) # 0.5% on temperature

Calculating uncertainty on a derived variable

Uncertainty is calculated by error propagation considering the partial derivatives with respect to the inputs:

# Calculate absolute uncertainty on density
rho_unc = tp.get_absolute_uncertainty("rho")
print("Uncertainty on density:", rho_unc)

You can also convert the uncertainty to another unit system:

rho_unc_SI = tp.get_absolute_uncertainty("rho", other_unit_system="SI BASE")

The get_uncertainty method uses error propagation considering the uncertainties set on the input variables (typically the first two independent variables defined).

-------------------------- !!! THIS IS A BETA VERSION !!! --------------------------

please report any bug or problems in the installation to pietro.ungar@unifi.it

Release files for REFPROP-connector 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for REFPROP-connector 0.4.1
File Size Uploaded
REFPROP_connector-0.4.1.tar.gz 5.3 MB Details

Release files / REFPROP_connector-0.4.1.tar.gz

Download URL REFPROP_connector-0.4.1.tar.gz
Size 5.3 MB
Tags Source
SHA-256 checksum
How to use checksums
bd1d21cc50b8831807a08cffeb8ad47ed767872946ca7d684ca555327e1f0e0e
BLAKE2b-256 checksum
How to use checksums
761c3df20d39b649d1886cc91a1d560f3d075180055871720c6c123c57a8c589
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.4.1 This release

1 release file

0.3.14

1 release file

0.3.13

1 release file

0.3.12

1 release file

0.3.11

1 release file

0.3.10

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page