Skip to content

Commit

Permalink
Merge pull request #232 from mitchute/replace-coolprop
Browse files Browse the repository at this point in the history
Replace CoolProp
  • Loading branch information
MassimoCimmino authored Oct 30, 2022
2 parents c2e82f7 + 18690b3 commit 5465044
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ['3.7', '3.8']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
fail-fast: false

steps:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Current version

### Enhancements

* [Issue 204](https://github.com/MassimoCimmino/pygfunction/issues/204) - Added support for Python 3.9 and 3.10. [CoolProp](https://www.coolprop.org/) is removed from the dependencies and replace with [SecondaryCoolantProps](https://github.com/mitchute/SecondaryCoolantProps).

## Version 2.2.1 (2022-08-12)

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ matplotlib >= 3.5.1
numpydoc >= 1.2.0
recommonmark >= 0.6.0
sphinx >= 4.4.0
CoolProp >= 6.4.1
secondarycoolantprops >= 1.1.0
65 changes: 33 additions & 32 deletions pygfunction/media.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from CoolProp.CoolProp import PropsSI
import warnings
from scp.ethyl_alcohol import EthylAlcohol
from scp.ethylene_glycol import EthyleneGlycol
from scp.methyl_alcohol import MethylAlcohol
from scp.propylene_glycol import PropyleneGlycol
from scp.water import Water


class Fluid:
Expand All @@ -9,7 +12,7 @@ class Fluid:
Parameters
----------
mixer: str
fluid_str: str
The mixer for this application should be one of:
- 'Water' - Complete water solution
- 'MEG' - Ethylene glycol mixed with water
Expand All @@ -22,63 +25,61 @@ class Fluid:
T: float, optional
The temperature of the fluid (in Celcius).
Default is 20 degC.
P: float, optional
The pressure of the fluid (in Pa).
Default is 101325 Pa.
Examples
--------
>>> import pygfunction as gt
>>> T_f = 20. # Temp at 20 C
>>> gage_P = 20 # PsiG
>>> atm_P = 14.69595
>>> P = (gage_P + atm_P) * 6894.75728 # Pressure in Pa
>>> # complete water solution
>>> mix = 'Water'
>>> percent = 0
>>> fluid = gt.media.Fluid(mix, percent, T=T_f, P=P)
>>> fluid = gt.media.Fluid(mix, percent, T=T_f)
>>> print(fluid)
>>> # 20 % propylene glycol mixed with water
>>> mix = 'MPG'
>>> percent = 20
>>> fluid = gt.media.Fluid(mix, percent, T=T_f, P=P)
>>> fluid = gt.media.Fluid(mix, percent, T=T_f)
>>> # 60% ethylene glycol mixed with water
>>> mix = 'MEG'
>>> percent = 60
>>> fluid = gt.media.Fluid(mix, percent, T=T_f, P=P)
>>> fluid = gt.media.Fluid(mix, percent, T=T_f)
>>> print(fluid)
>>> # 5% methanol mixed with water water
>>> # 5% methanol mixed with water
>>> mix = 'MMA'
>>> percent = 5
>>> fluid = gt.media.Fluid(mix, percent, T=T_f, P=P)
>>> fluid = gt.media.Fluid(mix, percent, T=T_f)
>>> print(fluid)
>>> # ethanol / water
>>> mix = 'MEA'
>>> percent = 10
>>> fluid = gt.media.Fluid(mix, percent, T=T_f, P=P)
>>> fluid = gt.media.Fluid(mix, percent, T=T_f)
>>> print(fluid)
"""
def __init__(self, mixer: str, percent: float,
T: float = 20., P: float = 101325.):
if mixer == 'Water':
self.fluid_mix = mixer
elif mixer in ['MEG', 'MPG', 'MMA', 'MEA']: # Expected brines
self.fluid_mix = f'INCOMP::{mixer}-{str(percent)}%'
def __init__(self, fluid_str: str, percent: float, T: float = 20.):
# concentration fraction
x_frac = percent / 100

if fluid_str.upper() == 'WATER':
self.fluid = Water()
elif fluid_str.upper() in ['PROPYLENEGLYCOL', 'MPG']:
self.fluid = PropyleneGlycol(x_frac)
elif fluid_str.upper() in ['ETHYLENEGLYCOL', 'MEG']:
self.fluid = EthyleneGlycol(x_frac)
elif fluid_str.upper() in ['METHYLALCOHOL', 'MMA']:
self.fluid = MethylAlcohol(x_frac)
elif fluid_str.upper() in ['ETHYLALCOHOL', 'MEA']:
self.fluid = EthylAlcohol(x_frac)
else:
warnings.warn('It is unknown whether or not cool props has the '
'mixing fluid requested, proceed with caution.')
raise ValueError(f'Unsupported fluid mixture: "{fluid_str}".')

# Initialize all fluid properties
# Temperature of the fluid (in Celsius)
self.T_C = T
# Temperature of the fluid (in Kelvin)
self.T_K = T + 273.15
# Pressure of the fluid (in Pa)
self.P = P
# Density (in kg/m3)
self.rho = self.density()
# Dynamic viscosity (in Pa.s, or N.s/m2)
Expand Down Expand Up @@ -117,7 +118,7 @@ def density(self):
Density (in kg/m3).
"""
return PropsSI('D', 'T', self.T_K, 'P', self.P, self.fluid_mix)
return self.fluid.density(self.T_C)

def dynamic_viscosity(self):
"""
Expand All @@ -129,7 +130,7 @@ def dynamic_viscosity(self):
Dynamic viscosity (in Pa.s, or N.s/m2).
"""
return PropsSI('V', 'T', self.T_K, 'P', self.P, self.fluid_mix)
return self.fluid.viscosity(self.T_C)

def kinematic_viscosity(self):
"""
Expand All @@ -153,7 +154,7 @@ def specific_heat_capacity(self):
Specific isobaric heat capacity (J/kg.K).
"""
return PropsSI('C', 'T', self.T_K, 'P', self.P, self.fluid_mix)
return self.fluid.specific_heat(self.T_C)

def volumetric_heat_capacity(self):
"""
Expand All @@ -177,7 +178,7 @@ def thermal_conductivity(self):
Thermal conductivity (in W/m.K).
"""
return PropsSI('L', 'T', self.T_K, 'P', self.P, self.fluid_mix)
return self.fluid.conductivity(self.T_C)

def Prandlt_number(self):
"""
Expand All @@ -189,4 +190,4 @@ def Prandlt_number(self):
Prandlt number.
"""
return PropsSI('PRANDTL', 'T', self.T_K, 'P', self.P, self.fluid_mix)
return self.fluid.prandtl(self.T_C)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy
scipy
matplotlib
CoolProp
SecondaryCoolantProps
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ classifiers =
[options]
packages = pygfunction
install_requires =
coolprop >= 6.4.1
matplotlib >= 3.5.1
numpy >= 1.21.5
scipy >= 1.7.3
secondarycoolantprops >= 1.1
python_requires = >=3.7

[options.extras_require]
Expand Down
Loading

0 comments on commit 5465044

Please sign in to comment.