How to use the thermo.mixture.Mixture function in thermo

To help you get started, we’ve selected a few thermo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CalebBell / thermo / tests / test_mixture.py View on Github external
def test_Mixture_calculated_Vfs():
    # Liquid standard fractions
    S = Mixture(['hexane', 'decane'], zs=[0.25, 0.75])
    Vfls = S.Vfls(298.16, 101326)
    assert_allclose(Vfls, [0.18301434895886864, 0.8169856510411313])
    assert_allclose(S.Vfls(), [0.18301384717011993, 0.8169861528298801])
    assert_allclose(S.Vfls(P=1E6), [0.18292777184777048, 0.8170722281522296])
    assert_allclose(S.Vfls(T=299.15), [0.1830642468206885, 0.8169357531793114])
    
    # gas fractions
    S = Mixture(['hexane', 'decane'], zs=[0.25, 0.75], T=699)
    assert_allclose(S.Vfgs(700, 101326), [0.251236709756207, 0.748763290243793])
    assert_allclose(S.Vfgs(), [0.25124363058052673, 0.7487563694194732])
    assert_allclose(S.Vfgs(P=101326), [0.2512436429605387, 0.7487563570394613])
    assert_allclose(S.Vfgs(T=699), [0.25124363058052673, 0.7487563694194732])
github CalebBell / thermo / tests / test_activity.py View on Github external
def test_bubble_at_P_with_ideal_mixing():
    '''Check to see if the bubble pressure calculated from the temperature
    matches the temperature calculated by the test function'''

    test_mix = Mixture(['ethylene oxide',
                        'tetrahydrofuran',
                        'beta-propiolactone'],
                       ws=[6021, 111569.76, 30711.21, ],
                       T=273.15 + 80,
                       P=101325 + 1.5e5)

    bubble_temp = bubble_at_P(test_mix.Pbubble,
                              test_mix.zs,
                              test_mix.VaporPressures)

    assert_allclose(test_mix.T, bubble_temp)
github CalebBell / thermo / tests / test_mixture.py View on Github external
def test_constant_properties():
    R_specific = Mixture(['N2', 'O2'], zs=[0.79, .21]).R_specific
    assert_allclose(R_specific, 288.1928437986195, rtol=1E-5)
github CalebBell / thermo / tests / test_property_package.py View on Github external
def test_UNIFAC_Dortmund_PP():
    m = Mixture(['ethanol', 'water'], zs=[0.5, 0.5], P=6500, T=298.15)
    vodka = UNIFAC_Dortmund_PP(UNIFAC_groups=m.UNIFAC_Dortmund_groups, VaporPressures=m.VaporPressures, 
                               Tms=m.Tms, Tcs=m.Tcs, Pcs=m.Pcs)
    # Low pressure ethanol-water ideal TP flash
    phase, xs, ys, V_over_F = vodka.flash_TP_zs(m.T, m.P, m.zs)
    V_over_F_expect = 0.721802969194136
    xs_expect = [0.26331608196660095, 0.736683918033399]
    ys_expect = [0.5912226272910779, 0.408777372708922]
    assert phase == 'l/g'
    assert_allclose(xs, xs_expect)
    assert_allclose(ys, ys_expect)
    assert_allclose(V_over_F, V_over_F_expect)
    # Same flash with T-VF spec
    phase, xs, ys, V_over_F, P = vodka.flash_TVF_zs(m.T, V_over_F_expect, m.zs)
    assert phase == 'l/g'
    assert_allclose(xs, xs_expect, rtol=1E-5)
    assert_allclose(ys, ys_expect, rtol=1E-5)
github CalebBell / thermo / tests / test_mixture.py View on Github external
m = Mixture(**{key:d})
        assert_allclose(m.zs, kwargs['zs'], rtol=1E-6)
        assert_allclose(m.zs, m.xs)
        assert_allclose(m.Vfls(), kwargs['Vfls'], rtol=1E-5)
        assert_allclose(m.Vfgs(), kwargs['Vfgs'], rtol=2E-5)
        
    # numpy array inputs
    IDs = ['pentane', 'hexane', 'heptane']
    kwargs = {'ws': np.array([0.4401066297270966, 0.31540115235588945, 0.24449221791701395]), 
              'zs': np.array([.5, .3, .2]),
              'Vfls': np.array([0.45725229530669054, 0.3106973688150756, 0.2320503358782339]),
              'Vfgs': np.array([0.5127892380094016, 0.2979448661739439, 0.18926589581665448])}
    
    for key, val in kwargs.items():
        
        m = Mixture(IDs, **{key:val})
        assert_allclose(m.zs, kwargs['zs'], rtol=1E-6)
        assert_allclose(m.zs, m.xs)
        assert_allclose(m.Vfls(), kwargs['Vfls'], rtol=1E-5)
        assert_allclose(m.Vfgs(), kwargs['Vfgs'], rtol=2E-5)


    with pytest.raises(Exception):
        Mixture(['water', 'ethanol'])
        
    Mixture(['water'], ws=[1], T=300, P=1E5)
    
    Mixture('water', ws=[1], T=365).SGl
github CalebBell / thermo / tests / test_viscosity.py View on Github external
# DIPPR  1983 manual example
    m = Mixture(['carbon tetrachloride', 'isopropanol'], zs=[0.5, 0.5], T=313.2)
    
    ViscosityLiquids = [i.ViscosityLiquid for i in m.Chemicals]

    obj = ViscosityLiquidMixture(ViscosityLiquids=ViscosityLiquids, CASs=m.CASs)
    mu = obj.mixture_property(m.T, m.P, m.zs, m.ws)
    assert_allclose(mu, 0.0009956952502281852)
    
    mu = obj.calculate(m.T, m.P, m.zs, m.ws, MIXING_LOG_MOLAR)
    assert_allclose(mu, 0.0009956952502281852)
    mu = obj.calculate(m.T, m.P, m.zs, m.ws, MIXING_LOG_MASS)
    assert_allclose(mu, 0.0008741268796817256)
    
    # Test Laliberte
    m = Mixture(['water', 'sulfuric acid'], zs=[0.5, 0.5], T=298.15)
    ViscosityLiquids = [i.ViscosityLiquid for i in m.Chemicals]
    obj = ViscosityLiquidMixture(ViscosityLiquids=ViscosityLiquids, CASs=m.CASs)
    mu = obj.mixture_property(m.T, m.P, m.zs, m.ws)
    assert_allclose(mu, 0.024955325569420893)
    assert obj.sorted_valid_methods == [LALIBERTE_MU]
    
    # Unhappy paths
    with pytest.raises(Exception):
        obj.calculate(m.T, m.P, m.zs, m.ws, 'BADMETHOD')
        
    with pytest.raises(Exception):
        obj.test_method_validity(m.T, m.P, m.zs, m.ws, 'BADMETHOD')
github CalebBell / thermo / tests / test_property_package.py View on Github external
def test_IdealPPThermodynamic_TS():
    m = Mixture(['pentane', 'hexane', 'octane'], zs=[.1, .4, .5], T=298.15)
    pkg = IdealPPThermodynamic(VaporPressures=m.VaporPressures, Tms=m.Tms, Tbs=m.Tbs, Tcs=m.Tcs, Pcs=m.Pcs, 
                  HeatCapacityLiquids=m.HeatCapacityLiquids, HeatCapacityGases=m.HeatCapacityGases,
                  EnthalpyVaporizations=m.EnthalpyVaporizations)
    Ts = np.linspace(300, 400, 10)
    VFs = [1E-5, .1, .5, .99, 1]
    
    for T in Ts:
        for VF in VFs:
            T = float(T)
            pkg.flash(T=T, VF=VF, zs=m.zs)
            pkg._post_flash()
            P = pkg.P
            P_calc = pkg.flash_TS_zs_bounded(T=T, Sm=pkg.Sm, zs=m.zs)
            assert_allclose(P_calc, P, rtol=1E-3)
github CalebBell / thermo / tests / test_mixture.py View on Github external
def test_Mixture():
    Mixture(['water', 'ethanol'], ws=[.5, .5], T=320, P=1E5)
    Mixture(['water', 'phosphoric acid'], ws=[.5, .5], T=320, P=1E5)
    Mixture('air', T=320, P=1E5)
    
    Mixture(['ethanol', 'water'], ws=[0.5, 0.5], T=500)
    
    Mixture('water')
    
    s = Mixture(['water', 'ethanol'], P=5200, zs=[0.5, 0.5])
    assert_allclose(s.V_over_F, 0.3061646720256255, rtol=1E-3)
    
    s = Mixture(['water', 'ethanol'], P=5200, zs=[0.5, 0.5])
    assert_allclose(s.quality, 0.34745483870024646, rtol=1E-3)
    
    with pytest.raises(Exception):
        Mixture(['2,2-Dichloro-1,1,1-trifluoroethane'], T=276.15, P=37000, zs=[0.5, 0.5])
    
    m = Mixture(['Na+', 'Cl-', 'water'], ws=[.01, .02, .97]).charge_balance
    assert_allclose(m, -0.0023550338411239182)
github CalebBell / thermo / thermo / stream.py View on Github external
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''

from __future__ import division

__all__ = ['Stream']
 
from collections import OrderedDict
from thermo.utils import property_molar_to_mass, property_mass_to_molar
from thermo.mixture import Mixture

class Stream(Mixture):
    '''Creates a Stream object which is useful for modeling mass and energy 
    balances.
    
    Streams have five variables. The flow rate, composition, and components are
    mandatory; temperature and pressure have defaults of 298.15 K and 101325 Pa.
    
    * The components
    * The composition
    * The flow rate
    * The temperature
    * The pressure

    The composition and flow rate may be specified together or separately. The
    options for specifying them are:
    
    * Mole fractions `zs`
github CalebBell / thermo / thermo / __init__.py View on Github external
__all__.extend(refractivity.__all__)
__all__.extend(safety.__all__)
__all__.extend(solubility.__all__)
__all__.extend(stream.__all__)
__all__.extend(interface.__all__)
__all__.extend(thermal_conductivity.__all__)
__all__.extend(triple.__all__)
__all__.extend(utils.__all__)
__all__.extend(unifac.__all__)
__all__.extend(vapor_pressure.__all__)
__all__.extend(virial.__all__)
__all__.extend(viscosity.__all__)
__all__.extend(volume.__all__)

# backwards compatibility hack to allow thermo.chemical.Mixture to still be importable
chemical.__dict__['Mixture'] = mixture.Mixture
chemical.__dict__['Stream'] = stream.Stream
# However, they cannot go in thermo.chemical's __all__ or they will appear in the
# documentation and Sphinx currently has no wat to exclude them

__version__ = '0.1.39'