|
| 1 | +# pyXSteam |
| 2 | + |
| 3 | +pyXSteam is a Python library designed for calculating thermodynamic properties of water and steam based on the [IAPWS](http://www.iapws.org) (International Association for the Properties of Water and Steam) formulations. |
| 4 | + |
| 5 | +This library was ported from the original Matlab released by Magnus Holmgren. The original can be founbd at [Sourceforge](http://xsteam.sourceforge.net) and/or <http://www.x-eng.com>. |
| 6 | + |
| 7 | +A .NET implementation is available thanks to the work of rogerlew here: [XSteamNET](https://github.com/rogerlew/XSteamNET). |
| 8 | + |
| 9 | +XSteam provides (mostly) accurate steam and water properties from 0 - |
| 10 | +1000 bar and from 0 - 2000 °C according to the [IAPWS release IF-97](http://www.iapws.org/relguide/IF97-Rev.pdf). For |
| 11 | +accuracy of the functions in different regions see IF-97 Page 4 |
| 12 | + |
| 13 | +Also included are functions for thermal conductivity and viscosity which are not part of R7-97(2012). |
| 14 | + |
| 15 | + - [IAPWS R15-11: Thermal Conductivity of Ordinary Water Substance](http://www.iapws.org/relguide/ThCond.pdf) |
| 16 | + - [IAPWS R12-08: Viscosity of Ordinary Water Substance](http://www.iapws.org/relguide/visc.pdf) |
| 17 | + - [IAPWS R1-76(2014): Surface Tension of Ordinary Water Substance](https://www.iapws.org/relguide/Surf-H2O-2014.pdf) |
| 18 | + |
| 19 | +Some effort has been made to include the refined function of more recent releases and also functions for calculations on heavy water. This implementation is still in progress, these function should not be used. This includes: |
| 20 | + |
| 21 | + - IAPWS R4 (deprecated) |
| 22 | + - IAPWS R5-85(1994) |
| 23 | + - IAPWS R14 |
| 24 | + |
| 25 | + |
| 26 | +## Contributors to pyXSteam |
| 27 | +In chronological order: |
| 28 | +- IAPWS |
| 29 | +- Magnus Holmgren |
| 30 | +- drunsinn |
| 31 | +- mohit0749 |
| 32 | +- gonmolina |
| 33 | +- xjtu-blacksmith |
| 34 | +- sebastiantuinstra |
| 35 | + |
| 36 | +## Documentation |
| 37 | + |
| 38 | +Check out [pyXSteam at readthedocs](https://pyxsteam.readthedocs.io) |
| 39 | + |
| 40 | +## Requirements |
| 41 | + |
| 42 | +There are no requirements for installing pyXSteam with Python 3.8 and up. The demos require `numpy` and `matplotlib`. |
| 43 | + |
| 44 | +### Tests |
| 45 | + |
| 46 | +Tests require `pytest` and `numpy` |
| 47 | + |
| 48 | +## Install |
| 49 | + |
| 50 | +run `pip install pyXSteam` |
| 51 | + |
| 52 | +To run unittests you need two additional packages: `pytest` and `numpy`. After installing both, just run pytest in the base directory. The tests use some fixed values from the documentation to make sure that every coefficient and formula works as intended. |
| 53 | + |
| 54 | +To test if setup was successful, run `pyXSteamDemo`. This will require numpy and matplotlib to be installed. |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +Simple Example: |
| 59 | + |
| 60 | +``` |
| 61 | + from pyXSteam.XSteam import XSteam |
| 62 | + steamTable = XSteam(XSteam.UNIT_SYSTEM_MKS) |
| 63 | + print(steamTable.hL_p(220.0)) |
| 64 | +``` |
| 65 | + |
| 66 | +By using the unitSystem Parameter, you can tell XSteam witch Unit System you are using. |
| 67 | + |
| 68 | +``` |
| 69 | + steamTable = XSteam(XSteam.UNIT_SYSTEM_MKS) # m/kg/sec/°C/bar/W |
| 70 | + steamTable = XSteam(XSteam.UNIT_SYSTEM_FLS) # ft/lb/sec/°F/psi/btu |
| 71 | + steamTable = XSteam(XSteam.UNIT_SYSTEM_BARE) # m/kg/sec/K/MPa/W |
| 72 | +``` |
| 73 | + |
| 74 | +To enable logging, add the following lines to your code: |
| 75 | + |
| 76 | +``` |
| 77 | + import logging |
| 78 | + logging.basicConfig(level=logging.INFO) |
| 79 | +``` |
| 80 | + |
| 81 | +or alternatively |
| 82 | + |
| 83 | +``` |
| 84 | + import logging |
| 85 | + logger = logging.getLogger('pyXSteam') |
| 86 | + logger.setLevel(logging.DEBUG) |
| 87 | + sh = logging.StreamHandler() |
| 88 | + sh.setFormatter(logging.Formatter('%(name)s - %(levelname)s - %(message)s')) |
| 89 | + logger.addHandler(sh) |
| 90 | +``` |
| 91 | + |
| 92 | +## Related projects |
| 93 | + |
| 94 | +Implementations of the IAPWS releases are also available for other programming languages: |
| 95 | + |
| 96 | +- Matlab and Excel: [xsteam](http://xsteam.sourceforge.net) |
| 97 | +- Matlab: [xsteam](https://github.com/stu314159/xsteam) |
| 98 | +- .NET: [XSteamNET](https://github.com/rogerlew/XSteamNET) |
| 99 | + |
| 100 | + |
| 101 | +## Notes |
| 102 | + |
| 103 | +### Density (rho) |
| 104 | + |
| 105 | +Density is calculated as 1/v. See section for Specific volume |
| 106 | + |
| 107 | +### Viscosity |
| 108 | + |
| 109 | +Viscosity is not part of IAPWS Steam IF97. Equations from "Revised Release on the IAPWS Formulation 1985 for the Viscosity of Ordinary Water Substance", 2003 are used. Viscosity in the mixed region (4) is interpolated according to the density. This is not true since it will be two phases. |
| 110 | + |
| 111 | +### Thermal conductivity |
| 112 | + |
| 113 | +Revised release on the IAPS Formulation 1985 for the Thermal Conductivity of ordinary water substance (IAPWS 1998) |
| 114 | + |
| 115 | +## Nomenclature |
| 116 | + |
| 117 | +All Functions follow the same naming schema: First the wanted property, then a underscore `_`, then the wanted input properties Example: `t_ph` is temperature as a function of pressure and enthalpy. For a list of valid functions se below: |
| 118 | + |
| 119 | +| Property | Description | |
| 120 | +|----------|--------------------------------------------------------------| |
| 121 | +| t | Temperature (°C or °F) | |
| 122 | +| p | Pressure (bar or psi) | |
| 123 | +| h | Enthalpy (kJ/kg or btu/lb) | |
| 124 | +| v | Specific volume (m3/kg or ft\^3/lb) | |
| 125 | +| rho | Density (kg/m3 or lb/ft\^3) | |
| 126 | +| s | Specific entropy (kJ/(kg °C) or btu/(lb °F)) | |
| 127 | +| u | Specific internal energy (kJ/kg or btu/lb) | |
| 128 | +| Cp | Specific isobaric heat capacity (kJ/(kg °C) or btu/(lb °F)) | |
| 129 | +| Cv | Specific isochoric heat capacity (kJ/(kg °C) or btu/(lb °F)) | |
| 130 | +| w | Speed of sound (m/s or ft/s) | |
| 131 | +| my | Viscosity (N s/m\^2 or lbm/ft/hr) | |
| 132 | +| tc | Thermal Conductivity (W/(m °C) or btu/(h ft °F)) | |
| 133 | +| st | Surface Tension (N/m or lb/ft) | |
| 134 | +| x | Vapor fraction | |
| 135 | +| vx | Vapor Volume Fraction | |
| 136 | + |
| 137 | + |
| 138 | +## Available Functions |
| 139 | + |
| 140 | +### Temperature |
| 141 | +| Function | Description | |
| 142 | +|----------|----------------------------------------------------| |
| 143 | +| tsat_p | Saturation temperature | |
| 144 | +| t_ph | Temperature as a function of pressure and enthalpy | |
| 145 | +| t_ps | Temperature as a function of pressure and entropy | |
| 146 | +| t_hs | Temperature as a function of enthalpy and entropy | |
| 147 | + |
| 148 | +### Pressure |
| 149 | +| Function | Description | |
| 150 | +|----------|----------------------------------------------------------------------------------------------------------------| |
| 151 | +| psat_t | Saturation pressure | |
| 152 | +| p_hs | Pressure as a function of h and s. | |
| 153 | +| p_hrho | Pressure as a function of h and rho. Very inaccurate for solid water region since it's almost incompressible! | |
| 154 | +| pmelt_t | Pressure as a function of temperature along the melting curve. Optional parameter to select ice region | |
| 155 | +| psubl_t | Pressure as a function of temperature along the sublimation curve. | |
| 156 | + |
| 157 | + |
| 158 | +### Enthalpy |
| 159 | +| Function | Description | |
| 160 | +|----------|---------------------------------------------------------------------------------------------------------------------| |
| 161 | +| hV_p | Saturated vapor enthalpy | |
| 162 | +| hL_p | Saturated liquid enthalpy | |
| 163 | +| hV_t | Saturated vapor enthalpy | |
| 164 | +| hL_t | Saturated liquid enthalpy | |
| 165 | +| h_pt | Enthalpy as a function of pressure and temperature | |
| 166 | +| h_ps | Enthalpy as a function of pressure and entropy | |
| 167 | +| h_px | Enthalpy as a function of pressure and vapor fraction | |
| 168 | +| h_prho | Enthalpy as a function of pressure and density. Observe for low temperatures (liquid) this equation has 2 solutions | |
| 169 | +| h_tx | Enthalpy as a function of temperature and vapor fraction | |
| 170 | + |
| 171 | +### Specific volume |
| 172 | +| Function | Description | |
| 173 | +|----------|-----------------------------------------------------------| |
| 174 | +| vV_p | Saturated vapor volume | |
| 175 | +| vL_p | Saturated liquid volume | |
| 176 | +| vV_t | Saturated vapor volume | |
| 177 | +| vL_t | Saturated liquid volume | |
| 178 | +| v_pt | Specific volume as a function of pressure and temperature | |
| 179 | +| v_ph | Specific volume as a function of pressure and enthalpy | |
| 180 | +| v_ps | Specific volume as a function of pressure and entropy | |
| 181 | + |
| 182 | +### Density |
| 183 | +| Function | Description | |
| 184 | +|----------|---------------------------------------------------| |
| 185 | +| rhoV_p | Saturated vapor density | |
| 186 | +| rhoL_p | Saturated liquid density | |
| 187 | +| rhoV_t | Saturated vapor density | |
| 188 | +| rhoL_t | Saturated liquid density | |
| 189 | +| rho_pt | Density as a function of pressure and temperature | |
| 190 | +| rho_ph | Density as a function of pressure and enthalpy | |
| 191 | +| rho_ps | Density as a function of pressure and entropy | |
| 192 | + |
| 193 | +### Specific entropy |
| 194 | +| Function | Description | |
| 195 | +|----------|----------------------------------------------------------------------------------------------------------| |
| 196 | +| sV_p | Saturated vapor entropy | |
| 197 | +| sL_p | Saturated liquid entropy | |
| 198 | +| sV_t | Saturated vapor entropy | |
| 199 | +| sL_t | Saturated liquid entropy | |
| 200 | +| s_pt | Specific entropy as a function of pressure and temperature (Returns saturated vapor enthalpy if mixture) | |
| 201 | +| s_ph | Specific entropy as a function of pressure and enthalpy | |
| 202 | + |
| 203 | +### Specific internal energy |
| 204 | +| Function | Description | |
| 205 | +|----------|--------------------------------------------------------------------| |
| 206 | +| uV_p | Saturated vapor internal energy | |
| 207 | +| uL_p | Saturated liquid internal energy | |
| 208 | +| uV_t | Saturated vapor internal energy | |
| 209 | +| uL_t | Saturated liquid internal energy | |
| 210 | +| u_pt | Specific internal energy as a function of pressure and temperature | |
| 211 | +| u_ph | Specific internal energy as a function of pressure and enthalpy | |
| 212 | +| u_ps | Specific internal energy as a function of pressure and entropy | |
| 213 | + |
| 214 | +### Specific isobaric heat capacity |
| 215 | +| Function | Description | |
| 216 | +|----------|---------------------------------------------------------------------------| |
| 217 | +| CpV_p | Saturated vapor heat capacity | |
| 218 | +| CpL_p | Saturated liquid heat capacity | |
| 219 | +| CpV_t | Saturated vapor heat capacity | |
| 220 | +| CpL_t | Saturated liquid heat capacity | |
| 221 | +| Cp_pt | Specific isobaric heat capacity as a function of pressure and temperature | |
| 222 | +| Cp_ph | Specific isobaric heat capacity as a function of pressure and enthalpy | |
| 223 | +| Cp_ps | Specific isobaric heat capacity as a function of pressure and entropy | |
| 224 | + |
| 225 | +### Specific isochoric heat capacity |
| 226 | +| Function | Description | |
| 227 | +|----------|----------------------------------------------------------------------------| |
| 228 | +| CvV_p | Saturated vapor isochoric heat capacity | |
| 229 | +| CvL_p | Saturated liquid isochoric heat capacity | |
| 230 | +| CvV_t | Saturated vapor isochoric heat capacity | |
| 231 | +| CvL_t | Saturated liquid isochoric heat capacity | |
| 232 | +| Cv_pt | Specific isochoric heat capacity as a function of pressure and temperature | |
| 233 | +| Cv_ph | Specific isochoric heat capacity as a function of pressure and enthalpy | |
| 234 | +| Cv_ps | Specific isochoric heat capacity as a function of pressure and entropy | |
| 235 | + |
| 236 | +### Speed of sound |
| 237 | +| Function | Description | |
| 238 | +|----------|----------------------------------------------------------| |
| 239 | +| wV_p | Saturated vapor speed of sound | |
| 240 | +| wL_p | Saturated liquid speed of sound | |
| 241 | +| wV_t | Saturated vapor speed of sound | |
| 242 | +| wL_t | Saturated liquid speed of sound | |
| 243 | +| w_pt | Speed of sound as a function of pressure and temperature | |
| 244 | +| w_ph | Speed of sound as a function of pressure and enthalpy | |
| 245 | +| w_ps | Speed of sound as a function of pressure and entropy | |
| 246 | + |
| 247 | +### Viscosity |
| 248 | +| Function | Description | |
| 249 | +|----------|-----------------------------------------------------| |
| 250 | +| my_pt | Viscosity as a function of pressure and temperature | |
| 251 | +| my_ph | Viscosity as a function of pressure and enthalpy | |
| 252 | +| my_ps | Viscosity as a function of pressure and entropy | |
| 253 | + |
| 254 | +### Thermal Conductivity |
| 255 | +| Function | Description | |
| 256 | +|----------|----------------------------------------------------------------| |
| 257 | +| tcL_p | Saturated vapor thermal conductivity | |
| 258 | +| tcV_p | Saturated liquid thermal conductivity | |
| 259 | +| tcL_t | Saturated vapor thermal conductivity | |
| 260 | +| tcV_t | Saturated liquid thermal conductivity | |
| 261 | +| tc_pt | Thermal conductivity as a function of pressure and temperature | |
| 262 | +| tc_ph | Thermal conductivity as a function of pressure and enthalpy | |
| 263 | +| tc_hs | Thermal conductivity as a function of enthalpy and entropy | |
| 264 | + |
| 265 | +### Surface tension |
| 266 | +| Function | Description | |
| 267 | +|----------|--------------------------------------------------------------| |
| 268 | +| st_t | Surface tension for two phase water/steam as a function of T | |
| 269 | +| st_p | Surface tension for two phase water/steam as a function of p | |
| 270 | + |
| 271 | +### vapor fraction |
| 272 | +| Function | Description | |
| 273 | +|----------|-------------------------------------------------------| |
| 274 | +| x_ph | vapor fraction as a function of pressure and enthalpy | |
| 275 | +| x_ps | vapor fraction as a function of pressure and entropy | |
| 276 | + |
| 277 | +### vapor volume fraction |
| 278 | +| Function | Description | |
| 279 | +|----------|--------------------------------------------------------------| |
| 280 | +| vx_ph | vapor volume fraction as a function of pressure and enthalpy | |
| 281 | +| vx_ps | vapor volume fraction as a function of pressure and entropy | |
| 282 | + |
| 283 | +### Pressure along the Melting and Sublimation Curves |
| 284 | +| Function | Description | |
| 285 | +|----------|--------------------------------------------------------------------| |
| 286 | +| pmelt_t | Pressure along the melting curve as a function of temperature | |
| 287 | +| psubl_t | Pressure along the sublimation curve as a function of temperature | |
| 288 | + |
| 289 | +## Development |
| 290 | +- pull requests are always wellcome! |
| 291 | +- code style is enforced by black |
0 commit comments