Example #1
0
    def h_fuel(self, wf, eta_b, w0, h0, comp):
        if self.burn_model == 'CEA':

            fuel_comp = cl.Composition(comp_def='Jet-A1')
            my_fluid = cl.CeaFluid()

            enthalpy_fuel = my_fluid.tp2h(self.tf, StandartPressure, fuel_comp)

            # fuel to air mass ratio
            fmr = wf * eta_b / (w0 * AirToFuelFlow)

            # enthalpy combustion products
            return (h0 + enthalpy_fuel * fmr) / (1 + fmr)

        elif self.burn_model == 'RRD':
            comp_air = cl.Composition('Air')
            comp_stoi = cl.Composition('Air')
            comp_stoi.FAR = FARStoi
            my_fluid = cl.RRDFluid()

            h_air = my_fluid.tp2h(self.t_ref, StandartPressure, comp_air)
            h_stoi = my_fluid.tp2h(self.t_ref, StandartPressure, comp_stoi)

            heating_corr = h_stoi + (h_stoi - h_air) / comp_stoi.FAR

            # fuel to air mass ratio
            fmr = wf * eta_b / (w0 * AirToFuelFlow)
            # corrected fuel heating value
            enthalpy_fuel = self.hv + heating_corr  # +CP*(self.tf-self.t_ref)
            # enthalpy combustion products
            return (h0 + enthalpy_fuel * fmr) / (1 + fmr)
Example #2
0
    def heat_balance_calcs(self):
        self.fgrc = self.wf / (self.in_station.w * AirToFuelFlow)

        # set composition of combustion products
        self.out_station.comp = self.current_fluid.burn_comp(
            self.in_station.comp, cl.Composition(), self.fgrc)

        # calc enthalpy of air at entry
        self.in_station.h = self.current_fluid.tp2h(self.in_station.t,
                                                    self.in_station.p,
                                                    self.in_station.comp)

        # calc enthalpy of combustion products
        self.out_station.h = self.current_fuel.h_fuel(self.wf, self.eta_b,
                                                      self.in_station.w,
                                                      self.in_station.h,
                                                      self.out_station.comp)

        # calculate outlet temperature
        self.out_station.t = self.current_fluid.hp2t(self.out_station.h,
                                                     self.in_station.p,
                                                     self.out_station.comp)

        # calculate outlet mass flow
        self.out_station.w = self.in_station.w + self.wf / AirToFuelFlow * self.eta_b
Example #3
0
 def test_create_jeta1(self):
     '''test if Jet-A1 is set up correctly'''
     my_comp = cl.Composition(comp_def='Jet-A1')
     self.assertEqual(my_comp.name, 'Jet-A1')
     self.assertEqual(len(my_comp.structure), 1)
     self.assertEqual(round(my_comp.r_spec, SignificantDigits),
                      round(48.878894767783656, SignificantDigits))
     self.assertEqual(my_comp.mol_wgt, 0.1701)
     self.assertEqual(my_comp.FAR, 1)
     self.assertEqual(my_comp.WGR, 0)
Example #4
0
 def test_create_dry_air(self):
     '''test if dry air is set up correctly'''
     my_comp = cl.Composition(comp_def='Air')
     self.assertEqual(my_comp.name, 'Air')
     self.assertEqual(len(my_comp.structure), 4)
     self.assertEqual(round(my_comp.r_spec, SignificantDigits),
                      round(287.0689197920102, SignificantDigits))
     self.assertEqual(round(my_comp.mol_wgt, SignificantDigits),
                      round(0.02896273134, SignificantDigits))
     self.assertEqual(my_comp.FAR, 0)
     self.assertEqual(my_comp.WGR, 0)
Example #5
0
 def __init__(self,t=None,p=None,w=None,comp=None):
     if t!=None and p!=None and w!=None and comp!=None:
         self.set_sation(t, p, w, comp)
     else:
         self.t=0
         self.p=0
         self.cp=0
         self.h=0
         self.s=0
         self.fluid = cl.CeaFluid()
         self.comp = cl.Composition()
         self.w=0 
def plot_work_press_ratio(pressure_ratio, t_in):
    comp = cl.Composition()
    fluid_cea = cl.CeaFluid(eos_model='SOA')
    fluid_cea.eos.set_coeffs(comp)
    fluid_rrd = cl.RRDFluid()

    delta_h_const = []
    delta_h_mean_ideal = []
    delta_h_mean_real = []

    for pr in pressure_ratio:
        kappa = fluid_cea.tp2kappa(t_in, StandartPressure, comp)
        t_out_const = t_in * (pr)**((kappa - 1) / kappa)
        t_out_mean_ideal = fluid_cea.isentropic_compression(
            t_in, StandartPressure, pr * StandartPressure, comp)
        t_out_mean_real = fluid_cea.isentropic_compression(t_in,
                                                           StandartPressure,
                                                           pr *
                                                           StandartPressure,
                                                           comp,
                                                           mode='real')
        delta_h_const.append(
            fluid_cea.tp2h(t_out_const, StandartPressure, comp) -
            fluid_cea.tp2h(t_in, pr * StandartPressure, comp))
        delta_h_mean_ideal.append(
            fluid_cea.tp2h(t_out_mean_ideal, StandartPressure, comp) -
            fluid_cea.tp2h(t_in, pr * StandartPressure, comp))
        delta_h_mean_real.append(
            fluid_cea.tp2h(
                t_out_mean_real, StandartPressure, comp, mode='real') -
            fluid_cea.tp2h(t_in, pr * StandartPressure, comp, mode='real'))

    fig = plt.figure()
    ax1 = fig.add_subplot(1, 1, 1)
    #ax1.plot(pressure_ratio,eta_const,pressure_ratio,eta_mean_ideal,pressure_ratio,eta_mean_real)
    ax1.plot(pressure_ratio, delta_h_const, pressure_ratio, delta_h_mean_ideal,
             pressure_ratio, delta_h_mean_real)
    ax1.set_xlabel('Pressure ratio [1]')
    ax1.set_ylabel('spec. compressor work [J/kg]')
    ax1.grid(True)
    ax1.legend([
        '$\delta h$ mit $\kappa=const$',
        '$\delta h_{id}$ mit $\kappa=(T_{in}+T_{out})/2$',
        '$\delta h_{re}$ mit $\kappa=(T_{in}+T_{out})/2$'
    ])
    plt.show()
Example #7
0
 def test_create_wet_air_with_RH(self):
     '''test if wet air is set up correctly using relative humidity'''
     my_fluid = cl.CeaFluid()
     my_comp = cl.Composition(comp_def='Air')
     my_fluid.set_humidity(StandartTemperature + 20,
                           StandartPressure,
                           my_comp,
                           RH=1)
     self.assertEqual(my_comp.name, 'Air')
     self.assertEqual(len(my_comp.structure), 5)
     self.assertEqual(round(my_comp.r_spec, SignificantDigits),
                      round(293.269688447603, SignificantDigits))
     self.assertEqual(round(my_comp.mol_wgt, SignificantDigits),
                      round(0.028350355756201765, SignificantDigits))
     self.assertEqual(my_comp.FAR, 0)
     self.assertEqual(round(my_comp.WGR, SignificantDigits),
                      round(0.036854216859696774, SignificantDigits))
     self.assertEqual(round(my_comp.get_fraction('H2O'), SignificantDigits),
                      round(0.05593629993099881, SignificantDigits))
def plot_pr_kappa(t_in, pressure_ratio):
    comp = cl.Composition()
    fluid_cea = cl.CeaFluid(eos_model='SOA')
    fluid_cea.eos.set_coeffs(comp)
    eta_is = 0.9

    kappa_mean = []
    kappa_ideal = fluid_cea.tp2kappa(t_in, StandartPressure, comp)

    f1 = []
    f2 = []

    for pr in pressure_ratio:
        t_out = fluid_cea.isentropic_compression(t_in,
                                                 StandartPressure,
                                                 pr * StandartPressure,
                                                 comp,
                                                 eta_isentropic=eta_is)
        kappa_mean.append(
            (kappa_ideal +
             fluid_cea.tp2kappa(t_out, pr * StandartPressure, comp)) / 2)
        f1.append(pr**((kappa_ideal - 1) / kappa_ideal))
        f2.append(pr**((kappa_mean[-1] - 1) / kappa_mean[-1]))

    fig = plt.figure()
    ax1 = fig.add_subplot(1, 1, 1)

    ax1.plot(pressure_ratio, f1, pressure_ratio, f2)
    ax1.set_xlabel('Pressure ratio [1]')
    ax1.set_ylabel('f(pressure ratio)')
    #ax1.set_xticks([1,20,30,40,50,60,70,80,90,100])
    #ax1.set_yticks([StandartTemperature,400,600,800,1000,1200,1400])
    ax1.grid(True)
    ax1.legend([
        '$\kappa_{ideal}=const$',
        '$\kappa_{ideal}=(\kappa_{in}+\kappa_{out})/2$'
    ])

    plt.show()
def plot_cp(t_range=np.linspace(300, 2000, 100), p=1e5, RH=0):
    fl_cea = cl.CeaFluid()
    fl_rrd = cl.RRDFluid()
    std_air = cl.Composition('Air')

    fl_cea.set_humidity(StandartTemperature + 20,
                        StandartPressure,
                        std_air,
                        RH=RH)

    cea_cp = []
    rrd_cp = []

    for t in t_range:
        cea_cp.append(fl_cea.tp2cp(t, p, std_air))
        rrd_cp.append(fl_rrd.tp2cp(t, p, std_air))
    janaf_cp = get_ref_cp(t_range, p, std_air)
    cea_cp = np.array(cea_cp)
    rrd_cp = np.array(rrd_cp)

    diff_cp_cea = (cea_cp - janaf_cp) / janaf_cp
    diff_cp_rrd = (rrd_cp - janaf_cp) / janaf_cp

    fig_cp = plt.figure()

    ax = fig_cp.add_subplot(1, 2, 1)
    ax.plot(t_range, janaf_cp)
    ax.plot(t_range, cea_cp)
    ax.plot(t_range, rrd_cp)

    plt.legend(['JANAF', 'CEA', 'RRD'])

    ax = fig_cp.add_subplot(1, 2, 2)
    ax.plot(t_range, diff_cp_cea)
    ax.plot(t_range, diff_cp_rrd)
    plt.legend(['CEA', 'RRD'])

    plt.show()
Example #10
0
import numpy as np  # numerical python for vector calcs
from constants import *  # import all constants
# import matplotlib environment for plotting
import matplotlib as mpl
import matplotlib.pyplot as plt

####### INPUTS #######
t_in = 846  # temperature [K]
p_in = 512  # pressure [psi]
w_in = 56  # air flow [lb/s]
dtamb = 20
rh = 1

# init dummy fluid class and standart air as composition
dummy_fluid = cl.CeaFluid()
comp = cl.Composition('Air')
# set relative humidity of air to 1
dummy_fluid.set_humidity(StandartTemperature + dtamb,
                         StandartPressure,
                         comp,
                         RH=rh)

####### CALCULATIONS #######
# baseline for the plot will be online CEA results for rh=1
# initiate empty numpy arrays
eqr_range = np.array([])
t_range = np.array([])

# declare file handle
file1 = 'data/CEA_tool/cea_full_rh=1.dat'
# open file handle
Example #11
0
'''
This is the main plot file. It imports all necessary libs and calls various plotting functions
'''
import sys
sys.path.insert(0, 'lib')
import plot_functions as plotfcn
import classes as cl
import numpy as np
from constants import PressureConversion, FLowConversion, StandartPressure, StandartTemperature

# init dummy fluid class and standart air as composition
dummy_fluid = cl.CeaFluid()
std_air = cl.Composition('Air')
# set relative humidity of air to 1
dummy_fluid.set_humidity(StandartTemperature + 20,
                         StandartPressure,
                         std_air,
                         RH=1)

#plotfcn.plot_combustion_temperature(846,512*PressureConversion,57*FLowConversion,std_air,baseline='Online CEA')

#plotfcn.plot_cp()

pressure_ratio = np.linspace(1, 100, 400)
#plotfcn.plot_work_press_ratio(pressure_ratio,StandartTemperature)
#plotfcn.plot_eff_press_ratio(pressure_ratio,StandartTemperature)
plotfcn.plot_burn_temp_comparison(512, 846, 56, t_fuel=382.5948)
Example #12
0
 def add_fluid(self, fluid_dict):
     self.fluids.add(
         cl.Composition('Mixture_' + str(len(self.fluids.data)), comp_def))
def plot_burn_temp_comparison(p_in, t_in, w_in, t_fuel=382.5948):
    # load large and reduced chemestry set data from CEA website
    FileNames = [
        'data/online_cea_combustion/reducedChemSet_EQR_below1.dat',
        'data/online_cea_combustion/reducedChemSet_EQR_above1.dat',
        'data/online_cea_combustion/largeChemSet_EQR_below1.dat',
        'data/online_cea_combustion/largeChemSet_EQR_above1.dat'
    ]

    # read data from loaded files
    T = np.array([])
    CP = np.array([])
    EQR = np.array([])

    for i, inFile in enumerate(FileNames):
        if i == 2:
            Tred = T
            CPred = CP
            EQRred = EQR

            T = np.array([])
            CP = np.array([])
            EQR = np.array([])
        inputFile = open(inFile, 'r')

        for line in inputFile:
            if 'T, K' in line:
                line = line.split()
                T = np.append(T, float(line[2]))
            if 'Cp, KJ/(KG)(K)' in line:
                line = line.split()
                CP = np.append(CP, float(line[2]))
            if 'EQ.RATIO' in line:
                line = line.split(',')
                EQR = np.append(EQR, float(line[-1].split('=')[1]))

        inputFile.close()

    # reduced set of species using my cea calculation
    dummy_fluid = cl.CeaFluid()
    std_air = cl.Composition('Air')
    dummy_fluid.set_humidity(StandartTemperature + 20,
                             StandartPressure,
                             std_air,
                             RH=1)

    # set up combustor
    comb = cmb.Combustor()
    comb.current_fluid = cl.CeaFluid()
    comb.in_station = stat.Station(t_in, p_in * PressureConversion,
                                   w_in * FLowConversion, std_air)
    comb.out_station = stat.Station(t_in, p_in * PressureConversion,
                                    w_in * FLowConversion, std_air)
    comb.current_fuel.tf = t_fuel

    eqr_vec = np.linspace(0.25, 2, 20)
    far_vec = eqr_vec * FARStoi
    wf_vec = far_vec * comb.in_station.w * AirToFuelFlow

    t_cea = np.array([])

    for fuel_flow in np.nditer(wf_vec):
        comb.wf = fuel_flow
        comb.heat_balance_calcs()
        t_cea = np.append(t_cea, comb.out_station.t)

    comb.current_fluid = cl.RRDFluid()
    comb.current_fuel.burn_model = 'RRD'

    t_rrd = np.array([])

    for fuel_flow in np.nditer(wf_vec):
        comb.wf = fuel_flow
        comb.heat_balance_calcs()
        t_rrd = np.append(t_rrd, comb.out_station.t)

    diff_CP = (CPred - CP) / CP
    diff_T = (Tred - T) / T
    diff_T_cea = (np.interp(EQR, eqr_vec, t_cea) - T) / T
    diff_T_rrd = (np.interp(EQR, eqr_vec, t_rrd) - T) / T

    ######## CANTERA calculation ############
    # Get all of the Species objects defined in the GRI 3.0 mechanism
    species = {S.name: S for S in ct.Species.listFromFile('nasa.cti')}
    # Create an IdealGas object including incomplete combustion species
    complete_species = [
        species[S] for S in ('Jet-A(g)', 'O2', 'N2', 'CO2', 'H2O', 'Ar')
    ]
    gas2 = ct.Solution(thermo='IdealGas',
                       species=complete_species)  #species.values())
    T_incomplete = np.zeros(EQR.shape)
    for i in range(len(EQR)):
        gas2.TP = t_in, p_in * PressureConversion
        gas2.set_equivalence_ratio(
            EQR[i], 'Jet-A(g)',
            'O2:0.19775868763, N2:0.7371626995, AR:0.008841156551, CO2:0.0003011563203 , H2O: 0.05593629993'
        )
        gas2.equilibrate('HP')
        T_incomplete[i] = gas2.T

    ##### PLOT
    fig = plt.figure()

    ax = fig.add_subplot(1, 2, 1)
    ax.plot(EQRred, Tred)
    ax.plot(EQR, T)
    ax.plot(eqr_vec, t_cea)
    ax.plot(eqr_vec, t_rrd)
    ax.plot(EQR, T_incomplete)

    plt.xlim(0.25, 1.5)
    plt.xlabel('Equivalence ratio, $\phi$')
    plt.ylabel('Temperature [K]')
    plt.grid(True)
    plt.legend(
        ['Onl. CEA RCS', 'Onl. CEA full CS', 'My CEA', 'RRD', 'Cantera'])

    ax = fig.add_subplot(1, 2, 2)
    ax.plot(EQRred, diff_T)
    ax.plot(EQR, diff_T_cea)
    ax.plot(EQR, diff_T_rrd)
    plt.grid(True)

    plt.xlabel('Equivalence ratio, $\phi$')
    plt.ylabel('delta T')

    plt.xlim(0.25, 1.5)
    plt.legend(['Onl. CEA RCS', 'My CEA', 'RRD'])

    plt.show()
def plot_eff_press_ratio(pressure_ratio, t_in):
    comp = cl.Composition()
    fluid_cea = cl.CeaFluid(eos_model='SOA')
    fluid_cea.eos.set_coeffs(comp)
    eta_is = 0.9

    eta_const = []
    eta_real = []
    t_out_test = []
    t_out_ref = []
    t_out_real = []
    eta_base1 = []
    eta_base2 = []

    for pr in pressure_ratio:
        #if pr == 1:
        #    eta_const.append(eta_is)
        #    eta_real.append(eta_is)
        #else:
        h_in = fluid_cea.tp2h(t_in, StandartPressure, comp)
        kappa = fluid_cea.tp2kappa(t_in, StandartPressure, comp)
        t_out_test.append(t_in *
                          (((pr**((kappa - 1) / kappa) - 1) / eta_is) + 1))
        t_out_ref.append(
            fluid_cea.isentropic_compression(t_in,
                                             StandartPressure,
                                             pr * StandartPressure,
                                             comp,
                                             eta_isentropic=eta_is))
        t_out_real.append(
            fluid_cea.isentropic_compression(t_in,
                                             StandartPressure,
                                             pr * StandartPressure,
                                             comp,
                                             mode='real',
                                             eta_isentropic=eta_is))

        kappa_mean = (kappa + fluid_cea.tp2kappa(
            t_out_ref[-1], pr * StandartPressure, comp)) / 2

        eta_base1.append(
            (pr**((kappa - 1) / kappa) - 1) / ((t_out_test[-1] / t_in) - 1))
        eta_base2.append((pr**((kappa_mean - 1) / kappa_mean) - 1) /
                         ((t_out_ref[-1] / t_in) - 1))

        s_is = fluid_cea.tp2s(t_in, StandartPressure, comp)
        t_out_ref_is = fluid_cea.sp2t(s_is, pr * StandartPressure, comp)
        h_out_ref_is = fluid_cea.tp2h(t_out_ref_is, pr * StandartPressure,
                                      comp)
        #h_out_const = fluid_cea.tp2h(t_out_ref[-1],pr*StandartPressure,comp)
        #h_out_real = fluid_cea.tp2h(t_out_ref[-1],pr*StandartPressure,comp,mode='real')
        h_out_const = fluid_cea.tp2h(t_out_real[-1], pr * StandartPressure,
                                     comp)
        h_out_real = fluid_cea.tp2h(t_out_real[-1],
                                    pr * StandartPressure,
                                    comp,
                                    mode='real')

        eta_const.append((h_out_ref_is - h_in) / (h_out_const - h_in))
        eta_real.append((h_out_ref_is - h_in) / (h_out_real - h_in))
        #eta_const.append((t_out_ref_is-t_in)/(t_out_real[-1]-t_in))
    eta_const = np.array(eta_const)
    eta_real = np.array(eta_real)
    t_out_test = np.array(t_out_test)
    t_out_ref = np.array(t_out_ref)
    eta_base1 = np.array(eta_base1)
    eta_base2 = np.array(eta_base2)

    fig = plt.figure()
    ax1 = fig.add_subplot(1, 1, 1)
    #ax1.plot(pressure_ratio,eta_const,pressure_ratio,eta_mean_ideal,pressure_ratio,eta_mean_real)
    ax1.plot(pressure_ratio, eta_const, pressure_ratio, eta_real,
             [pressure_ratio[0], pressure_ratio[len(pressure_ratio) - 1]],
             [0.9, 0.9])
    ax1.set_xlabel('Pressure ratio [1]')
    ax1.set_ylabel('isentropic efficiency [1]')
    ax1.grid(True)
    ax1.legend(['ideal $\eta_{is}$', 'real $\eta_{is}$'])
    '''
    ax2 = fig.add_subplot(2,2,2)
    ax2.plot(pressure_ratio,(eta_real-eta_const))
    ax2.set_xlabel('Pressure ratio [1]')
    ax2.set_ylabel('delta isentropic efficiency [1]')
    ax2.grid(True)
    ax2.legend(['dev. real $\eta_{is}$'])
    
    ax3 = fig.add_subplot(2,2,3)
    ax3.plot(pressure_ratio,t_out_test/t_in,pressure_ratio,t_out_ref/t_in)
    ax3.set_xlabel('Pressure ratio [1]')
    ax3.set_ylabel('Outlet Temperature [K]')
    ax3.grid(True)
    ax3.legend(['$\kappa=const$','$\kappa=(\kappa_{in}+\kappa_{out})/2$'])
    
    ax4 = fig.add_subplot(2,2,4)
    ax4.plot(pressure_ratio,eta_base1,pressure_ratio,eta_base2)
    ax4.set_xlabel('Pressure ratio [1]')
    ax4.set_ylabel('isentropic efficiency [1]')
    ax4.set_ylim([0.85,0.95])
    ax4.grid(True)
    ax4.legend(['$\kappa=const$','$\kappa=(\kappa_{in}+\kappa_{out})/2$'])
    '''
    plt.show()

    #plot_t_out(t_in,t_out_test,t_out_ref,t_out_real)
    plot_pr_kappa(t_in, pressure_ratio)