Esempio n. 1
0
 def test_water_backends(self):
     w = ct.Water(backend='Reynolds')
     self.assertEqual(w.thermo_model, 'PureFluid')
     w = ct.Water(backend='IAPWS95')
     self.assertEqual(w.thermo_model, 'liquid-water-IAPWS95')
     with self.assertRaisesRegex(KeyError, 'Unknown backend'):
         ct.Water('foobar')
Esempio n. 2
0
    def test_water_iapws(self):
        w = ct.Water(backend='IAPWS95')
        self.assertNear(w.critical_density, 322.)
        self.assertNear(w.critical_temperature, 647.096)
        self.assertNear(w.critical_pressure, 22064000.0)

        # test internal TP setters (setters update temperature at constant
        # density before updating pressure)
        w.TP = 300, ct.one_atm
        dens = w.density
        w.TP = 2000, ct.one_atm  # supercritical
        self.assertEqual(w.phase_of_matter, "supercritical")
        w.TP = 300, ct.one_atm  # state goes from supercritical -> gas -> liquid
        self.assertNear(w.density, dens)
        self.assertEqual(w.phase_of_matter, "liquid")

        # test setters for critical conditions
        w.TP = w.critical_temperature, w.critical_pressure
        self.assertNear(w.density, 322.)
        w.TP = 2000, ct.one_atm  # uses current density as initial guess
        w.TP = 273.16, ct.one_atm  # uses fixed density as initial guess
        self.assertNear(w.density, 999.84376)
        self.assertEqual(w.phase_of_matter, "liquid")
        w.TP = w.T, w.P_sat
        self.assertEqual(w.phase_of_matter, "liquid")
        with self.assertRaisesRegex(ct.CanteraError, "assumes liquid phase"):
            w.TP = 273.1599999, ct.one_atm
        with self.assertRaisesRegex(ct.CanteraError, "assumes liquid phase"):
            w.TP = 500, ct.one_atm
Esempio n. 3
0
    def test_import_no_norm_water(self):
        outfile = self.test_work_path / "solutionarray.h5"
        # In Python >= 3.8, this can be replaced by the missing_ok argument
        if outfile.is_file():
            outfile.unlink()

        w = ct.Water()
        w.TQ = 300, 0.5
        states = ct.SolutionArray(w, 5)
        states.write_hdf(outfile)

        w_new = ct.Water()
        c = ct.SolutionArray(w_new)
        c.read_hdf(outfile, normalize=False)
        self.assertArrayNear(states.T, c.T)
        self.assertArrayNear(states.P, c.P)
        self.assertArrayNear(states.Q, c.Q)
Esempio n. 4
0
 def test_append_no_norm_water(self):
     w = ct.Water()
     states = ct.SolutionArray(w)
     w.TQ = 300, 0.5
     states.append(w.state)
     self.assertEqual(states[0].T, w.T)
     self.assertEqual(states[0].P, w.P)
     self.assertEqual(states[0].Q, w.Q)
Esempio n. 5
0
    def test_purefluid(self):
        water = ct.Water()
        states = ct.SolutionArray(water, 5)
        states.TX = 400, np.linspace(0, 1, 5)

        P = states.P
        for i in range(1, 5):
            self.assertNear(P[0], P[i])

        states.TP = np.linspace(400, 500, 5), 101325
        self.assertArrayNear(states.X.squeeze(), np.ones(5))
Esempio n. 6
0
    def test_saturated_mixture(self):
        self.water.TP = 300, ct.one_atm
        with self.assertRaisesRegex(ct.CanteraError,
                                    'Saturated mixture detected'):
            self.water.TP = 300, self.water.P_sat

        w = ct.Water()

        # Saturated vapor
        self.water.TQ = 373.15, 1.
        self.assertEqual(self.water.phase_of_matter, 'liquid-gas-mix')
        w.TP = self.water.T, .999 * self.water.P_sat
        self.assertNear(self.water.cp, w.cp, 1.e-3)
        self.assertNear(self.water.cv, w.cv, 1.e-3)
        self.assertNear(self.water.thermal_expansion_coeff,
                        w.thermal_expansion_coeff, 1.e-3)
        self.assertNear(self.water.isothermal_compressibility,
                        w.isothermal_compressibility, 1.e-3)

        # Saturated mixture
        self.water.TQ = 373.15, .5
        self.assertEqual(self.water.phase_of_matter, 'liquid-gas-mix')
        self.assertEqual(self.water.cp, np.inf)
        self.assertTrue(np.isnan(self.water.cv))
        self.assertEqual(self.water.isothermal_compressibility, np.inf)
        self.assertEqual(self.water.thermal_expansion_coeff, np.inf)

        # Saturated liquid
        self.water.TQ = 373.15, 0.
        self.assertEqual(self.water.phase_of_matter, 'liquid-gas-mix')
        w.TP = self.water.T, 1.001 * self.water.P_sat
        self.assertNear(self.water.cp, w.cp, 1.e-3)
        self.assertNear(self.water.cv, w.cv, 1.e-3)
        self.assertNear(self.water.thermal_expansion_coeff,
                        w.thermal_expansion_coeff, 1.e-3)
        self.assertNear(self.water.isothermal_compressibility,
                        w.isothermal_compressibility, 1.e-3)
Esempio n. 7
0
 def setUp(self):
     self.fluid = ct.Water()
Esempio n. 8
0
 def setUpClass(cls):
     utilities.CanteraTest.setUpClass()
     cls.water = ct.Water()
# Set reactants state
gas.TPX = 298, 101325, 'CH4:1, O2:2'
h1 = gas.enthalpy_mass
Y_CH4 = gas['CH4'].Y[
    0]  # returns an array, of which we only want the first element

# set state to complete combustion products without changing T or P
gas.TPX = None, None, 'CO2:1, H2O:2'
h2 = gas.enthalpy_mass

print('LHV = {:.3f} MJ/kg'.format(-(h2 - h1) / Y_CH4 / 1e6))  # LHV

# In[2]:

# get the HHV including heat in water vapor
water = ct.Water()
# Set liquid water state, with vapor fraction x = 0
water.TX = 298, 0
h_liquid = water.h
# Set gaseous water state, with vapor fraction x = 1
water.TX = 298, 1
h_gas = water.h

# Calculate higher heating value
Y_H2O = gas['H2O'].Y[0]
print('HHV = {:.3f} MJ/kg'.format(-(h2 - h1 + (h_liquid - h_gas) * Y_H2O) /
                                  Y_CH4 / 1e6))

# ## Generalizing to arbitrary species

# In[4]:
Esempio n. 10
0
 def setUp(self):
     self.water = ct.Water()
Esempio n. 11
0
 def test_invalid_phase_type(self):
     water = ct.Water()
     with self.assertRaises(ct.CanteraError):
         self.mix = ct.Mixture([(self.phase1, 1.0), (water, 2.0)])
Esempio n. 12
0
 def test_invalid_phase_type(self):
     water = ct.Water()
     with self.assertRaisesRegex(ct.CanteraError, 'not compatible'):
         self.mix = ct.Mixture([(self.phase1, 1.0), (water, 2.0)])
Esempio n. 13
0

mr = []
cst = []
ben = []
n_cc = []
prs = []
mdots = []

#Define Fluid States
airCompIn = ct.Nitrogen()
airCompOut = ct.Nitrogen()
airTurbIn = ct.Nitrogen()
airTurbOut = ct.Nitrogen()
airHrsgOut = ct.Nitrogen()
waterPumpIn = ct.Water()
waterPumpOut = ct.Water()
waterTurbIn = ct.Water()
waterTurbOut = ct.Water()

#Define Efficiencies
n_comp = 0.8
n_turb_a = 0.85
n_Hrsg = 0.86
n_pump = 0.9
n_turb_w = 0.9

for pr in range(3, 20):
    cost = 0  #cost per air mass flow rate
    benefit = 0  #benefit per air mass flow rate
Esempio n. 14
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 20:07:38 2020

@author: mohith_sai
"""
"""
Print the critical state properties for the fluids for which Cantera has
built-in liquid/vapor equations of state.
"""

import cantera as ct

fluids = {
    'water': ct.Water(),
    'nitrogen': ct.Nitrogen(),
    'methane': ct.Methane(),
    'hydrogen': ct.Hydrogen(),
    'oxygen': ct.Oxygen(),
    'carbon dioxide': ct.CarbonDioxide(),
    'heptane': ct.Heptane(),
    'hfc134a': ct.Hfc134a()
}

print('Critical State Properties')
print('%20s  %10s  %10s  %10s' % ('Fluid', 'Tc [K]', 'Pc [Pa]', 'Zc'))
for name in fluids:
    f = fluids[name]
    tc = f.critical_temperature
    pc = f.critical_pressure
Esempio n. 15
0
#Define Arrays
aPressureRatios = []
aMDotRatios = []
aCycleEfficiency = []
aNetPower = []
aQin = []
aQout = []

#Define Fluid States
air5 = ct.Solution('air.cti')
air6 = ct.Solution('air.cti')
air7 = ct.Solution('air.cti')
air8 = ct.Solution('air.cti')
air9 = ct.Solution('air.cti')
water1 = ct.Water()
water2 = ct.Water()
water3 = ct.Water()
water4 = ct.Water()

#Define Efficiencies
n_compressor = 0.8
n_turbineAir = 0.85
n_HRSG = 0.86
n_pump = 0.9
n_turb_w = 0.9

for pr in range(3, 20):

    "State 5 - AIR - Inlet to Compressor"
    P5 = 101325
Esempio n. 16
0
import cantera as ct
import matplotlib.pyplot as plt
import Dome as Dome
# create figure and subplots
fig = plt.figure()
ax1 = plt.subplot(311)
ax2 = plt.subplot(312)
ax3 = plt.subplot(313)
# plot using Dome command
P, v = Dome.Dome(ct.Water(), 'P', 'v')
ax1.loglog(v, P, 'k-')
# add plot using Plot command
Dome.Plot(ax2, ct.Water(), 'v', 'P')
# add second plot using Plot command
Dome.Plot(ax3, ct.Water(), 's', 'T')
# display figure
plt.show()
Esempio n. 17
0
import numpy
import cantera

H2O = cantera.Water()
Xi = 0.62345
Pi = 0.6E5
H2O.PX = Pi, Xi
Ti = H2O.T

Ts = 473  #Surface temperature of Al spheres [K]
Ti = 273  #[K]

V = 0.3735  #Fluid Velocity [m/s]
D = 0.01  #Al sphere Diamemter [m]
L = 0.1  #Length of Bed [m]
W = 0.75  #Width of Bed
H = 0.5  #Height of Bed
N = round(W / D, 0) * round(L / D, 0) * round(H / D, 0)  #Number of spheres
N = round(N - N * 0.05, 0)  #Reduction in 5% of spheres due to packing

v_d = numpy.interp(Ti, temperature,
                   Viscosity_dyn)  #Dynamic Viscosity of Fluid [m²/s]
v_g = numpy.interp(Ti, temperature, vg)  #Density of fluid
Pr = numpy.interp(Ti, temperature, Pr)  #Prandtl Number of Fluid
Kf = numpy.interp(Ti, temperature, conductivity)  #Conductivity of Fluid
rho = 1 / v_g

v_ds = numpy.interp(
    Ts, temperature,
    Viscosity_dyn)  #Dynamic viscosity of air at surface temperature
vg_s = numpy.interp(Ts, temperature,
Esempio n. 18
0
 def test_invalid_phase_type(self):
     water = ct.Water()
     with self.assertRaises(Exception):
         self.mix = ct.Mixture([(self.phase1, 1.0), (water, 2.0)])
Esempio n. 19
0
"""
Print the critical state properties for the fluids for which Cantera has
built-in liquid/vapor equations of state.
"""

import cantera as ct

fluids = {'water': ct.Water(),
          'nitrogen': ct.Nitrogen(),
          'methane': ct.Methane(),
          'hydrogen': ct.Hydrogen(),
          'oxygen': ct.Oxygen(),
          'carbon dioxide': ct.CarbonDioxide(),
          'heptane': ct.Heptane(),
          'hfc134a': ct.Hfc134a()
          }

print('Critical State Properties')
print('%20s  %10s  %10s  %10s' % ('Fluid','Tc [K]', 'Pc [Pa]', 'Zc'))
for name in fluids:
    f = fluids[name]
    tc = f.critical_temperature
    pc = f.critical_pressure
    rc = f.critical_density
    mw = f.mean_molecular_weight
    zc = pc * mw / (rc * ct.gas_constant * tc)
    print('%20s   %10.4g   %10.4G  %10.4G' % (name, tc, pc, zc))
Esempio n. 20
0
 def setUpClass(cls):
     cls.water = ct.Water()
Esempio n. 21
0
_X2 = []
_X3 = []
_X4 = []
_h12 = []
_h23 = []
_h34 = []
_h41 = []
_s12 = []
_s23 = []
_s34 = []
_s41 = []

"Define Fluids"
air_1 = ct.Solution('air.cti')
air_2 = ct.Solution('air.cti')
WF_1 = ct.Water()
WF_2 = ct.Water()
WF_3 = ct.Water()
WF_4 = ct.Water()

"Knowns"
T1_air = 0 + 273.15  # T1 ambient = 0C
P1_air = 1 * 10**5  # P1 ambient = 1 bar
T2_air = 40 + 273.15  # T2 into cabin = 40C
P2_air = P1_air  # P2 = 1 bar
air_1.TP = T1_air, P1_air  # Define state
air_2.TP = T2_air, P2_air  # Define state
h1_air = air_1.h
h2_air = air_2.h

"Set variables"
Esempio n. 22
0
"""
This example generates a saturated steam table and plots the vapor dome. The
steam table corresponds to data typically found in thermodynamic text books
and uses the same customary units.

Requires: Cantera >= 2.5.0, matplotlib >= 2.0, pandas >= 1.1.0, numpy >= 1.12
"""

import cantera as ct
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt

w = ct.Water()

# create colums
columns = ['T', 'P',
           'vf', 'vfg', 'vg',
           'uf', 'ufg', 'ug',
           'hf', 'hfg', 'hg',
           'sf', 'sfg', 'sg']

# temperatures correspond to Engineering Thermodynamics, Moran et al. (9th ed),
# Table A-2; additional data points are added close to the critical point;
# w.min_temp is equal to the triple point temperature
degc = np.hstack([np.array([w.min_temp - 273.15, 4, 5, 6, 8]),
                  np.arange(10, 37), np.array([38]),
                  np.arange(40, 100, 5), np.arange(100, 300, 10),
                  np.arange(300, 380, 20), np.arange(370, 374),
                  np.array([w.critical_temperature - 273.15])])
Esempio n. 23
0
eBalanceTurbine = sympy.Eq(W, m_turbine * (h_inTurbine - h_isentropicTurbine))
print('\n', eBalanceTurbine, '\n')

eBalancePump = sympy.Eq(W, m_pump * (h_isentropicPump - h_inPump))
print(eBalancePump, '\n')

eCombined = sympy.Eq(-eBalanceTurbine.lhs + eBalancePump.lhs,
                     -eBalanceTurbine.rhs + eBalancePump.rhs)
print(eCombined, '\n')

mass_Ratio = sympy.Eq(m_ratio, (eBalanceTurbine.rhs / m_turbine) /
                      (eBalancePump.rhs / m_pump))
print(mass_Ratio, '\n')

inSteamValue_Turbine = cantera.Water()
P_inTurbine = 10 * 10**5
T_inTurbine = 240 + 273
inSteamValue_Turbine.TP = T_inTurbine, P_inTurbine
hTi = inSteamValue_Turbine.enthalpy_mass

outWaterValue_Turbine = cantera.Water()
P_OutTurbine = 1.5 * 10**5
S_OutTurbine = inSteamValue_Turbine.entropy_mass
outWaterValue_Turbine.SP = S_OutTurbine, P_OutTurbine
hTo = outWaterValue_Turbine.enthalpy_mass

inWaterValue_Pump = cantera.Water()
T_inPump = 15 + 273
P_inPump = 1 * 10**5
inWaterValue_Pump.TP = T_inPump, P_inPump
Esempio n. 24
0
 h8_IS = air8.enthalpy_mass
 h8.append(h_OutTurbine(n_turbine_Brayton, h8_IS, h7[-1]))
 air8.HP = h8[-1], p8[-1]
 t8.append(air8.T)
 s8.append(air8.entropy_mass)
 
 #State After HRSG
 air9 = cantera.Solution('air.cti')
 p9.append(atm2Pa(1))
 t9.append(450)
 air9.TP = t9[-1], p9[-1]
 h9.append(air9.enthalpy_mass)
 s9.append(air9.entropy_mass)
 
 #State after the Condensor
 water1 = cantera.Water()
 p1.append(5 * 10**3)
 water1.PX = p1[-1], 0.0
 
 h1.append(water1.enthalpy_mass)
 s1.append(water1.entropy_mass)
 t1.append(water1.T)
 
 #State after Pump
 water2 = cantera.Water()
 p2.append(7 * 10**6)
 water2.SP = s1[-1], p2[-1]
 h2_IS = water2.enthalpy_mass
 h2.append(h_OutCompressor(n_pump_Rankine, h2_IS, h1[-1]))
 water2.HP = h2[-1], p2[-1]
 t2.append(water2.T)
Esempio n. 25
0
            Flux_exp = exp_data['Flux_p2 [L/m2/h]']
        elif membrane=='450nm':
            Flux_exp = exp_data['Flux_p45 [L/m2/h]']

        SV_0, _, _ = init(membrane, 1.0, 'DGM', T_feed, T_perm)
        # Depending on transport flags, one of these outputs may be all zeros:
        data_Fick, data_DGM = run_tortuosities(tau_g_vec_0, 
            membrane, DGM, Fick, SV_0, T_feed, T_perm)

        # Check to see if the intended folder exists.  If not, create it:
        ensure_dir(membrane_folder)
        save_string = (membrane_folder+'TortuosityVariation_T_f_'+str(T_feed)
            +'_T_p_'+str(T_perm))

        # Calculate the density of the permeate water:
        liq = ct.Water()
        liq.TP = T_perm + 273.15, ct.one_atm
        rho = liq.density

        # Set up plot color:
        dT = T_feed - T_perm
        i_color = int(dT/10  - 1)

        if DGM:
            np.savetxt(save_string+'_DGM.csv', data_DGM, delimiter=',')
            
            Fluxes = 3600*1000*data_DGM[1,:]/rho
            tau_fit = np.interp(Flux_exp, np.flip(Fluxes,0), 
                np.flip(tau_g_vec_0,0))
            tau_Fitting_DGM[index,:] = tau_fit[0], T_feed, T_perm