Esempio n. 1
0
def solver(conditions):
    nominal_model = conditions[0]
    modified_model = conditions[1]
    P = conditions[2]
    phi = conditions[3]
    fuels = conditions[4]
    X = conditions[5]
    T = conditions[6]
    print('Working on ' + fuels + ' at phi=' + str(phi) + ', ' + str(P) +
          ' atm.')

    #X={Fuels[f]:phi[x],'O2':num[f],'N2':3.76*num[f]}
    #efficiency_manipulate=True
    reactorType = 'cv'
    nominalDelays = []
    modifiedDelays = []
    for j in np.arange(len(T)):
        try:
            try:
                nominalDelays.append(
                    ig.ignition_delay(nominal_model,
                                      T[j],
                                      P,
                                      X,
                                      options=reactorType))
            except:
                new_dict = {}
                new_dict[fuels] = X.pop(fuels)
                new_dict['o2'] = X.pop('O2')
                new_dict['n2'] = X.pop('N2')
                nominalDelays.append(
                    ig.ignition_delay(nominal_model,
                                      T[j],
                                      P,
                                      new_dict,
                                      options=reactorType))
        except:
            nominalDelays.append('Temperature ' + str(T[j]) + 'K failed')
    for j in np.arange(len(T)):
        try:
            try:
                modifiedDelays.append(
                    ig.ignition_delay(modified_model,
                                      T[j],
                                      P,
                                      X,
                                      options=reactorType))
            except:
                new_dict = {}
                new_dict[fuels] = X.pop(fuels)
                new_dict['o2'] = X.pop('O2')
                new_dict['n2'] = X.pop('N2')
                modifiedDelays.append(
                    ig.ignition_delay(modified_model,
                                      T[j],
                                      P,
                                      new_dict,
                                      options=reactorType))
        except:
            modifiedDelays.append('Temperature ' + str(T[j]) + 'K failed')


#            for i in np.arange(len(files)):
#                #gas=ct.Solution(mechanism[i])
#                delays.append([])
#                for j in np.arange(len(T)):
#                    try:
#                        delays[i].append(ig.ignition_delay(files[i],T[j],p,X,options=reactorType))
#                    except:
#                        delays[i].append('Temperature '+str(T[j])+'K failed')
    plt.figure()
    #colors=['b','r','k','g','c','m']
    #for i in np.arange(len(files)):
    tempdel = []
    tempT = []
    for j in np.arange(len(np.array(nominalDelays))):
        if str(type(nominalDelays[j])) != "<type 'str'>":
            tempdel.append(nominalDelays[j])
            tempT.append(T[j])
    plt.semilogy(1000.0 / np.array(tempT), tempdel, 'b-')
    plt.title(fuels + ' at phi= ' + str(phi) + ', ' + str(P) + ' atm')
    tempdel = []
    tempT = []
    for j in np.arange(len(np.array(modifiedDelays))):
        if str(type(modifiedDelays[j])) != "<type 'str'>":
            tempdel.append(modifiedDelays[j])
            tempT.append(T[j])
    plt.semilogy(1000.0 / np.array(tempT), tempdel, 'r--')
    plt.savefig(os.getcwd() + '\\figures\\collider_screening\\' +
                ntpath.dirname(nominal_model).split('\\')[-1] + '_' + fuels +
                '_' + str(P) + 'atm_phi' + str(phi) + '.pdf',
                dpi=1200,
                bbox_inches='tight')
Esempio n. 2
0
                    import soln2cti as ctiw
                    new_file = ctiw.write(gas)
                    #gas2=ct.Solution(os.getcwd()+'\\pym_gas.cti')
                    files.append(new_file)
                    manipulated = True

            delays = []
            for i in np.arange(len(files)):
                #gas=ct.Solution(mechanism[i])
                delays.append([])
                for j in np.arange(len(T)):
                    try:
                        delays[i].append(
                            ig.ignition_delay(files[i],
                                              T[j],
                                              p,
                                              X,
                                              options=reactorType))
                    except:
                        delays[i].append('Temperature ' + str(T[j]) +
                                         'K failed')
            plt.figure()
            colors = ['b', 'r', 'k', 'g', 'c', 'm']
            for i in np.arange(len(files)):
                tempdel = []
                tempT = []
                for j in np.arange(len(delays[i])):
                    if str(type(delays[i][j])) != "<type 'str'>":
                        tempdel.append(delays[i][j])
                        tempT.append(T[j])
                plt.semilogy(1000.0 / np.array(tempT),
Esempio n. 3
0
if efficiency_manipulate:
    gases=[]
    for i in np.arange(len(mechanism)):
        gas=ct.Solution(mechanism[i])
        gases.append(gas)
        gas.name='igDelayRateSwap_'+mechanism[i].split('\\')[-1].rstrip('.cti')
        gas2=em.efficiency_rate_swap(gas,[val])
        gases.append(gas2)
        import soln2cti as ctiw
        new_file=ctiw.write(gas)
        #gas2=ct.Solution(os.getcwd()+'\\pym_gas.cti')
        mechanism.append(new_file)


delays=[]
for i in np.arange(len(mechanism)):
    #gas=ct.Solution(mechanism[i])
    delays.append([])
    for j in np.arange(len(T)):
        delays[i].append(ig.ignition_delay(mechanism[i],T[j],P,X,options=reactorType))
plt.figure()
colors=['b','r','k','g','c','m']
for i in np.arange(len(mechanism)):
    plt.semilogy(1000.0/T,delays[i],color=colors[i])
    

    


Esempio n. 4
0
def solver(conditions, output):
    import matplotlib.pyplot as plt

    nominal_model = conditions[0]
    modified_model = conditions[1]
    P = conditions[2]
    phi = conditions[3]
    fuels = conditions[4]
    X = conditions[5]
    T = conditions[6]
    print('Working on ' + fuels + ' at phi=' + str(phi) + ', ' + str(P) +
          ' atm.')

    #X={Fuels[f]:phi[x],'O2':num[f],'N2':3.76*num[f]}
    #efficiency_manipulate=True
    reactorType = 'cv'
    nominalDelays = []
    modifiedDelays = []
    for j in np.arange(len(T)):
        try:
            try:
                nominalDelays.append(
                    ig.ignition_delay(nominal_model,
                                      T[j],
                                      P,
                                      X,
                                      options=reactorType))
            except:
                new_dict = {}
                new_dict[fuels] = X.pop(fuels)
                new_dict['o2'] = X.pop('O2')
                new_dict['n2'] = X.pop('N2')
                nominalDelays.append(
                    ig.ignition_delay(nominal_model,
                                      T[j],
                                      P,
                                      new_dict,
                                      options=reactorType))
        except:
            nominalDelays.append('Temperature ' + str(T[j]) + 'K failed')
    for j in np.arange(len(T)):
        try:
            try:
                modifiedDelays.append(
                    ig.ignition_delay(modified_model,
                                      T[j],
                                      P,
                                      X,
                                      options=reactorType))
            except:
                new_dict = {}
                new_dict[fuels] = X.pop(fuels)
                new_dict['o2'] = X.pop('O2')
                new_dict['n2'] = X.pop('N2')
                modifiedDelays.append(
                    ig.ignition_delay(modified_model,
                                      T[j],
                                      P,
                                      new_dict,
                                      options=reactorType))
        except:
            modifiedDelays.append('Temperature ' + str(T[j]) + 'K failed')


#            for i in np.arange(len(files)):
#                #gas=ct.Solution(mechanism[i])
#                delays.append([])
#                for j in np.arange(len(T)):
#                    try:
#                        delays[i].append(ig.ignition_delay(files[i],T[j],p,X,options=reactorType))
#                    except:
#                        delays[i].append('Temperature '+str(T[j])+'K failed')
    plt.figure()
    #colors=['b','r','k','g','c','m']
    #for i in np.arange(len(files)):
    tempdel = []
    tempT = []
    for j in np.arange(len(np.array(nominalDelays))):
        if str(type(nominalDelays[j])) != "<type 'str'>":
            tempdel.append(nominalDelays[j])
            tempT.append(T[j])
    plt.plot(1000.0 / np.array(tempT), np.log10(tempdel), 'b-')
    plt.title(fuels + ' at phi= ' + str(phi) + ', ' + str(P) + ' atm')
    tempdel1 = []
    tempT1 = []
    for j in np.arange(len(np.array(modifiedDelays))):
        if str(type(modifiedDelays[j])) != "<type 'str'>":
            tempdel1.append(modifiedDelays[j])
            tempT1.append(T[j])
    plt.plot(1000.0 / np.array(tempT1), np.log10(tempdel1), 'r--')
    plt.savefig(os.getcwd() + '\\figures\\collider_screening\\' +
                ntpath.dirname(nominal_model).split('\\')[-1] + '_' + fuels +
                '_' + str(P) + 'atm_phi' + str(phi) + '.pdf',
                dpi=1200,
                bbox_inches='tight')
    try:
        differences = np.subtract(tempdel, tempdel1)
        percent_diff = 100 * np.divide(differences, tempdel)
        max_dif = np.max(np.abs(percent_diff))
        conditions.append(max_dif)
        logdiffs = np.subtract(np.log10(tempdel), np.log10(tempdel1))
        percent_logdiff = 100 * np.divide(logdiffs, np.log10(tempdel))
        max_logdif = np.max(np.abs(percent_logdiff))
        l = [tempT, tempdel, tempT1, tempdel1]
        l = zip(*l)
        datafile = os.getcwd(
        ) + '\\figures\\collider_screening\\' + nominal_model.split('\\')[
            -2] + '_P' + str(P) + '_phi' + str(phi) + '_' + fuels + '.txt'
        with open(output, 'a') as f:
            f.write('Model: ' + nominal_model.split('\\')[-2] +
                    ', Pressure: ' + str(P) + ', phi: ' + str(phi) +
                    ', Fuel: ' + fuels + '\n   Max Percent Difference: ' +
                    str(max_dif) + ', Max Percent Difference log: ' +
                    str(max_logdif) + '\n')
        #print(l)
        with open(datafile, 'w') as f:
            f.write('T,t,T1,t1\n')
            for i in l:
                f.write(
                    str(i[0]) + ', ' + str(i[1]) + ', ' + str(i[2]) + ', ' +
                    str(i[3]) + '\n')
    except:
        conditions.append(
            'Failed to find max for some reason-maybe modified mechanism failed'
        )
        with open(output, 'a') as f:
            f.write('Model: ' + nominal_model.split('\\')[-2] +
                    ', Pressure: ' + str(P) + ', phi: ' + str(phi) +
                    ', Fuel: ' + fuels + '\n   Max Percent Difference: ' +
                    'failed' + ', Max Percent Difference log: ' + 'failed' +
                    '\n')

    return conditions