Exemplo n.º 1
0
    def __init__(self,temperatureX):
        self.temperatureValue=temperatureX      
        PyChemTB.gererateInputFile(         reactants=[#('CH4',0),
                                                        #('CO',0.0),
                                                        #('CO2',0.15),
                                                        #('H2',0.2),
                                                        ('N2',0.7895),
                                                        ('NH3',0.0003),
                                                        ('NO',0.0002),
                                                        ('O2',0.06),
                                                        ('CO2',0.15)],     # Reactant (mole fraction)

                                            temperature = temperatureX, # Temperature(K)
                                            pressure = 1 ,   # Pressure (bar)
                                            velocity=75.0,
                                            viscosity=0.0,
                                            reactorDiameter=3.2,
                                            endPosition=45.0,
                                            startPosition=0.0 ,
                                            endTime = 0.05 ,   # End Time (sec)
                                            tempFile="testForResiTime.inp")

        fraction_NO_Detail_Reaction,fraction_NH3_Detail_Reaction,residentTimeDetail=getMolesFractions(
                                                        os.path.join(currentDir,"chem_add_ITL.inp"),
                                                            os.path.join(currentDir, "testForResiTime.inp"))

        f_NO_Detail=interp1d(residentTimeDetail.values,fraction_NO_Detail_Reaction.values,kind='linear',fill_value="extrapolate")	
        f_NH3_Detail=interp1d(residentTimeDetail.values,fraction_NH3_Detail_Reaction.values,kind='linear',fill_value="extrapolate")			
        self.comparationListTime = np.linspace(residentTimeDetail.values[0],residentTimeDetail.values[-1],num=20,endpoint=True )
        self.comparationList_NO_Detail = f_NO_Detail(self.comparationListTime)
        self.comparationList_NH3_Detail = f_NH3_Detail(self.comparationListTime)									
Exemplo n.º 2
0
    def resultWithDetailReaction(self):
        
        self.NH3_EndPoint_Detail_Temp=[]
        self.NO_EndPoint_Detail_Temp=[]
        
        for IterAddConctrt in self.listAdd:            
            for temperatureIter in self.temperatureListX:
                PyChemTB.gererateInputFile( reactants=[('N2',0.7895-IterAddConctrt),(self.speciesAdd,IterAddConctrt),
                                            ('NH3',0.0003),
                                            ('NO',0.0002),('O2',0.06),('CO2',0.15)],     # Reactant (mole fraction)

                                            temperature = temperatureIter, # Temperature(K)
                                            pressure = 1 ,   # Pressure (bar)
                                            velocity=75.0,
                                            viscosity=0.0,
                                            reactorDiameter=3.2,
                                            endPosition=45.0,
                                            startPosition=0.0 ,
                                            endTime = 0.05 ,   # End Time (sec)
                                            tempFile="test.inp")                  

                
                fraction_NO_Detail_Reaction_Temp,fraction_NH3_Detail_Reaction_Temp,_=getMolesFractions(
                                                        os.path.join(currentDir,"chem_add_ITL.inp"),
                                                            os.path.join(currentDir, "test.inp"))
                
                
                self.NH3_EndPoint_Detail_Temp.append(fraction_NH3_Detail_Reaction_Temp.iloc[-1]/fraction_NH3_Detail_Reaction_Temp.iloc[0])
                self.NO_EndPoint_Detail_Temp.append(fraction_NO_Detail_Reaction_Temp.iloc[-1]/fraction_NO_Detail_Reaction_Temp.iloc[0])
                with open(self.speciesAdd+"logFile.txt",'a+') as stream:
                    stream.write("Additive:{0:g} ,temperture:{1:g} | Fraction EndPoint {2:g}  Fraction StartPoint {3:g}  \n".format(
                               IterAddConctrt,temperatureIter, fraction_NO_Detail_Reaction_Temp.iloc[-1],fraction_NO_Detail_Reaction_Temp.iloc[0]))
        self.NH3_EndPoint_Detail_Temp_Np=np.array(self.NH3_EndPoint_Detail_Temp)
        self.NO_EndPoint_Detail_Temp_Np=np.array(self.NO_EndPoint_Detail_Temp)
        self.C_NO_Detail=self.NO_EndPoint_Detail_Temp_Np.reshape(len(self.listAdd),len(self.temperatureListX))
Exemplo n.º 3
0
def getMolesFractions(machanismInp,expParameterInp):
    if os.path.exists(tempDir):
        clearDir(tempDir)
    else:
        os.makedirs(tempDir)
    PyChemTB.generateBatFile(machanismInp,expParameterInp,tempDir,"DeNOxExp.bat")
    process=subprocess.Popen(os.path.join(tempDir,"DeNOxExp.bat"), cwd=tempDir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = process.communicate()
    if process.returncode != 0:
        print(stdout)
        print(stderr)
        quit()
    if os.path.exists(os.path.join(tempDir,"CKSoln_solution_no_1.csv")):
        resultFileChemkin=os.path.join(tempDir,"CKSoln_solution_no_1.csv")
    if os.path.exists(os.path.join(tempDir,"CKSoln_solution_no_1_1.csv")):
        resultFileChemkin=os.path.join(tempDir,"CKSoln_solution_no_1_1.csv")
    fraction_NO,fraction_NH3,residentTime=PyChemTB.postProcess(resultFile=resultFileChemkin)
    return fraction_NO,fraction_NH3,residentTime
Exemplo n.º 4
0
    def resultWithDetailReaction(self):
        self.NH3_AllPoint_Detail_Temp_cmprList=[]
        self.NO_AllPoint_Detail_Temp_cmprList=[]
        self.NH3_EndPoint_Detail_Temp=[]
        self.NO_EndPoint_Detail_Temp=[]
        
        
        for temperatureIter in self.temperatureListX:
            PyChemTB.gererateInputFile(        reactants=[#('CH4',0),
                                                    #('CO',0.0),
                                                    #('CO2',0.15),
                                                    #('H2',0.2),
                                                    ('N2',0.7895),
                                                    ('NH3',0.0003),
                                                    ('NO',0.0002),
                                                    ('O2',0.06),
                                                    ('CO2',0.15)],     # Reactant (mole fraction)

                                        temperature = temperatureIter, # Temperature(K)
                                        pressure = 1 ,   # Pressure (bar)
                                        velocity=75.0,
                                        viscosity=0.0,
                                        reactorDiameter=3.2,
                                        endPosition=45.0,
                                        startPosition=0.0 ,
                                        endTime = 0.05 ,   # End Time (sec)
                                        tempFile="test.inp")                  

            
            fraction_NO_Detail_Reaction_Temp,fraction_NH3_Detail_Reaction_Temp,residentTimeDetail_Temp=getMolesFractions(
                                                    os.path.join(currentDir,"chem_add_ITL.inp"),
                                                        os.path.join(currentDir, "test.inp"))

            f_NO_Detail=interp1d(residentTimeDetail_Temp.values,fraction_NO_Detail_Reaction_Temp.values,kind='linear',fill_value="extrapolate")	
            f_NH3_Detail=interp1d(residentTimeDetail_Temp.values,fraction_NH3_Detail_Reaction_Temp.values,kind='linear',fill_value="extrapolate")			
            self.comparationListTime = np.linspace(residentTimeDetail_Temp.values[0],residentTimeDetail_Temp.values[-1],num=self.timeListNumber,endpoint=True )
            comparationList_NO_Detail_1T = f_NO_Detail(self.comparationListTime)
            comparationList_NH3_Detail_1T = f_NH3_Detail(self.comparationListTime)	
            
            self.NH3_AllPoint_Detail_Temp_cmprList=np.hstack((self.NH3_AllPoint_Detail_Temp_cmprList,comparationList_NH3_Detail_1T))           
            self.NO_AllPoint_Detail_Temp_cmprList=np.hstack((self.NO_AllPoint_Detail_Temp_cmprList,comparationList_NO_Detail_1T))  	
            self.NH3_EndPoint_Detail_Temp.append(fraction_NH3_Detail_Reaction_Temp.iloc[-1])
            self.NO_EndPoint_Detail_Temp.append(fraction_NO_Detail_Reaction_Temp.iloc[-1])
Exemplo n.º 5
0
    def difference_Overall_Detail(self,Coefficient,draw=False):

        PyChemTB.generateChemInput(Coefficient[0],Coefficient[1],Coefficient[2],
                                    Coefficient[3],Coefficient[4],Coefficient[5],
                                    tempFile=os.path.join(currentDir,"ChemInput_OverallReaction.inp"))

        
        fraction_NO_Overall_Reaction,fraction_NH3_Overall_Reaction,residentTimeOverall=getMolesFractions(
                                                        #"G:\SNCR\SNCR\chem_add_ITL.inp",
                                                        os.path.join(currentDir,"ChemInput_OverallReaction.inp"),
                                                        os.path.join(currentDir, "testForResiTime.inp"))
        # print(fraction_NO_Overall_Reaction.ilpoc[])

        
        
        f_NO_Overall=interp1d(residentTimeOverall.values,fraction_NO_Overall_Reaction.values,kind='linear',fill_value="extrapolate")
        f_NH3_Overall=interp1d(residentTimeOverall.values,fraction_NH3_Overall_Reaction.values,kind='linear',fill_value="extrapolate")

        
        self.comparationList_NO_Overall = f_NO_Overall(self.comparationListTime)
        self.comparationList_NH3_Overall = f_NH3_Overall(self.comparationListTime)

        self.diff2_NO = ((self.comparationList_NO_Detail-self.comparationList_NO_Overall)/fraction_NO_Overall_Reaction[0])**2
        self.diff2_NH3 = ((self.comparationList_NH3_Detail-self.comparationList_NH3_Overall)/fraction_NH3_Overall_Reaction[0])**2
        
        currentTime = time.strftime("%Y%m%d_%H%M%S")
        df=pd.DataFrame(data={'Time':self.comparationListTime})
        df1=pd.DataFrame(data={'NO_Overall':self.comparationList_NO_Overall,'NO_Detail':self.comparationList_NO_Detail})
        df2=pd.DataFrame(data={'NH3_Overall':self.comparationList_NH3_Overall,'NH3_Detail':self.comparationList_NH3_Detail})
        df3=pd.DataFrame(data={"Err_NO":self.diff2_NO,"Err_NH3":self.diff2_NH3})
        dfToWrite=pd.concat([df,df1,df2,df3], axis=1)
        dfToWrite.to_csv("DataAnalyse\\OverallForOneT\\"+str(self.temperatureValue)+"K"+"ResultOverallCompare.csv")

        if(draw):
            
            plt.figure()
            pic01=plt.plot(self.comparationListTime,self.comparationList_NO_Overall/self.comparationList_NO_Overall[0],'^',
                    self.comparationListTime,self.comparationList_NO_Detail/self.comparationList_NO_Detail[0],'-.',
                    self.comparationListTime,self.comparationList_NH3_Overall/self.comparationList_NH3_Overall[0],'v',
                    self.comparationListTime,self.comparationList_NH3_Detail/self.comparationList_NH3_Detail[0],'--',
                    )
            
            plt.xlabel('ResidentTime',fontsize='large')
            plt.ylabel('Fraction out/ Fraction in',fontsize='large')
            plt.title("De NOx Result with Temperature {0:.2f}K".format(self.temperatureValue))
            plt.legend(["NO: Overall Reaction","NO: Detail Reaction",
            "NH3: Overall Reaction","NH3: Detail Reaction"])
            plt.subplots_adjust(left=0.18, wspace=0.25, hspace=0.25,
                    bottom=0.13, top=0.91)
            plt.savefig(os.path.join(ImageResult,currentTime+'NH3NO.png'))

            plt.figure()
            pic02=plt.plot(self.comparationListTime,self.diff2_NO,'--',
                    self.comparationListTime,self.diff2_NH3,'-.',
                    #residentTimeOverall,fraction_NH3_Overall_Reaction,'v',
                    #residentTimeDetail,fraction_NH3_Detail_Reaction,'^',
                    )
            plt.xlabel('ResidentTime',fontsize='large')
            plt.ylabel('Fraction out/ Fraction in',fontsize='large')
            plt.title("Errors with Temperature {0:.2f}K".format(self.temperatureValue))
            plt.legend(["NO Errors between Overall Reaction Detail Reaction",
            "NH3 Errors between Overall Reaction Detail Reaction"])
            plt.subplots_adjust(left=0.18, wspace=0.25, hspace=0.25,
                    bottom=0.13, top=0.91)
            plt.savefig(os.path.join(ImageResult,currentTime+'Err.png')) 
            
        return (2*self.diff2_NO.mean()+self.diff2_NH3.mean())/3
Exemplo n.º 6
0
    def Detail_Overall_withAdd(self,coeficientAddDict,funEmploye=1,draw=False):
        self.NH3_EndPoint_Overall=[]
        self.NO_EndPoint_Overall=[]   
        coefAdd=coeficientAddDict[self.speciesAdd]
        
        for IterAddConctrt in self.listAdd:
            for temperatureIter in self.temperatureListX:
                if funEmploye==1:
                    temperatureShift=coefAdd[0]*np.log(coefAdd[1]*IterAddConctrt+1)
                else:
                    temperatureShift=coefAdd[0]*IterAddConctrt/(coefAdd[1]+IterAddConctrt)
                temperatureIter+=temperatureShift
                PyChemTB.gererateInputFile( reactants=[('N2',0.7895-IterAddConctrt),(self.speciesAdd,IterAddConctrt),
                                            ('NH3',0.0003),
                                            ('NO',0.0002),('O2',0.06),('CO2',0.15)],     # Reactant (mole fraction)

                                            temperature = temperatureIter, # Temperature(K)
                                            pressure = 1 ,   # Pressure (bar)
                                            velocity=75.0,
                                            viscosity=0.0,
                                            reactorDiameter=3.2,
                                            endPosition=45.0,
                                            startPosition=0.0 ,
                                            endTime = 0.05 ,   # End Time (sec)
                                            tempFile="test.inp")                     

                if  temperatureIter<1200:
                    Coeficients=[40609356.32837867,4.591567103723157,59293.190204797174,
                                1.2500592750801196e+48,0.2384295271582183,227638.0184552551]
                if  temperatureIter>=1200:
                    Coeficients=[2.1489719679116273,3.6556482376087636,14.912031071151327,
                                10.977243831448774,3.883371131587305,26418.321246185045]
                
                PyChemTB.generateChemInput(#1.49e19,0,3.6e5,1.2e15,0,3.4e5,
                        Coeficients[0],Coeficients[1],Coeficients[2],Coeficients[3],Coeficients[4],Coeficients[5],
                        tempFile=os.path.join(currentDir,"ChemInput_OverallReaction.inp"))

                fraction_NO_Overall_Reaction,fraction_NH3_Overall_Reaction,residentTimeOverall=getMolesFractions(
                                                #"G:\SNCR\SNCR\chem_add_ITL.inp",
                                                os.path.join(currentDir,"ChemInput_OverallReaction.inp"),
                                                os.path.join(currentDir, "test.inp"))
                
                with open(self.speciesAdd+"{0:g}logFile.txt".format(funEmploye),'a+') as stream:
                    stream.write("Additive:{0:g} ,temperture:{1:g} | Fraction EndPoint {2:g}  Fraction StartPoint {3:g}  \n".format(
                               IterAddConctrt,temperatureIter, fraction_NO_Overall_Reaction.iloc[-1],fraction_NO_Overall_Reaction.iloc[0]))
                self.NH3_EndPoint_Overall.append(fraction_NH3_Overall_Reaction.iloc[-1]/fraction_NH3_Overall_Reaction.iloc[0])        
                self.NO_EndPoint_Overall.append(fraction_NO_Overall_Reaction.iloc[-1]/fraction_NO_Overall_Reaction.iloc[0])
        self.NO_EndPoint_Overall_Temp_Np=np.array(self.NO_EndPoint_Overall)
        self.C_NO_overall=self.NO_EndPoint_Overall_Temp_Np.reshape(len(self.listAdd),len(self.temperatureListX))
        d={self.speciesAdd+'Overall':self.NO_EndPoint_Overall_Temp_Np,self.speciesAdd+'Detail':self.NO_EndPoint_Detail_Temp_Np}
        df=pd.DataFrame(data=d)
        df1=pd.DataFrame(data={"temperatureListX":self.temperatureListX})
        df2=pd.DataFrame(data={self.speciesAdd+"listAdd":self.listAdd})
        dfForAdditive=pd.concat([df,df1,df2], axis=1)
        dfForAdditive.to_csv("DataAnalyse\\Additive\\"+self.speciesAdd+"ResultAdditiveCompare{0:g}.csv".format(funEmploye))
        if(draw):            
            currentTime = time.strftime("%Y%m%d_%H%M%S")    
            plt.figure()
            symbolOverall=['o','v','^','<','>']
            symbolDetail=['.-','--',':','.--','-']
            for ithAdd in np.arange(len(self.C_NO_Detail)):            
                plt.plot(self.temperatureListX,self.C_NO_Detail[ithAdd],symbolDetail[ithAdd%14])
                plt.plot(self.temperatureListX,self.C_NO_overall[ithAdd],symbolOverall[ithAdd%14])
            plt.ylabel("[NO](out)/[NO](in)")
            plt.xlabel("Temperature ($^\circ$C)")
            plt.savefig(os.path.join(ImageResult,self.speciesAdd+currentTime+'DeNOx.png'))
            plt.show()
Exemplo n.º 7
0
    def difference_Overall_Detail_temperature(self,CoeficientsForM,draw=False):
        self.NH3_EndPoint_Overall=[]
        self.NO_EndPoint_Overall=[]  
        self.NH3_AllPoint_Overall_Temp_cmprList=[]
        self.NO_AllPoint_Overall_Temp_cmprList=[]             
    

        for IterAddConctrt in self.listAdd:
            for temperatureIter in self.temperatureListX:
                PyChemTB.gererateInputFile( reactants=[('N2',0.7895-IterAddConctrt),(self.speciesAdd,IterAddConctrt),
                                            ('NH3',0.0003),
                                            ('NO',0.0002),('O2',0.06),('CO2',0.15)],     # Reactant (mole fraction)

                                            temperature = temperatureIter, # Temperature(K)
                                            pressure = 1 ,   # Pressure (bar)
                                            velocity=75.0,
                                            viscosity=0.0,
                                            reactorDiameter=3.2,
                                            endPosition=45.0,
                                            startPosition=0.0 ,
                                            endTime = 0.05 ,   # End Time (sec)
                                            tempFile="test.inp")                     

                if  temperatureIter<1200:
                    Coeficients=[40609356.32837867,4.591567103723157,59293.190204797174,
                                1.2500592750801196e+48,0.2384295271582183,227638.0184552551]
                if  temperatureIter>=1200:
                    Coeficients=[2.1489719679116273,3.6556482376087636,14.912031071151327,
                                10.977243831448774,3.883371131587305,26418.321246185045]
                
                PyChemTB.generateChemInput(#1.49e19,0,3.6e5,1.2e15,0,3.4e5,
                        Coeficients[0],Coeficients[1],Coeficients[2],Coeficients[3],Coeficients[4],Coeficients[5],
                        tempFile=os.path.join(currentDir,"ChemInput_OverallReaction.inp"),
                        withAdditive=True,speciesAdd=self.speciesAdd,enhenceFactor=CoeficientsForM)

                fraction_NO_Overall_Reaction,fraction_NH3_Overall_Reaction,residentTimeOverall=getMolesFractions(
                                                #"G:\SNCR\SNCR\chem_add_ITL.inp",
                                                os.path.join(currentDir,"ChemInput_OverallReaction.inp"),
                                                os.path.join(currentDir, "test.inp"))



                f_NO_Overall=interp1d(residentTimeOverall.values,fraction_NO_Overall_Reaction.values,kind='linear',fill_value="extrapolate")	
                f_NH3_Overall=interp1d(residentTimeOverall.values,fraction_NH3_Overall_Reaction.values,kind='linear',fill_value="extrapolate")			
                
                comparationList_NO_Overall_1T = f_NO_Overall(self.comparationListTime)
                comparationList_NH3_Overall_1T = f_NH3_Overall(self.comparationListTime)	
                
                self.NH3_AllPoint_Overall_Temp_cmprList=np.hstack((self.NH3_AllPoint_Overall_Temp_cmprList,comparationList_NH3_Overall_1T))           
                self.NO_AllPoint_Overall_Temp_cmprList=np.hstack((self.NO_AllPoint_Overall_Temp_cmprList,comparationList_NO_Overall_1T))  	
        

                self.NH3_EndPoint_Overall.append(fraction_NH3_Overall_Reaction.iloc[-1])        
                self.NO_EndPoint_Overall.append(fraction_NO_Overall_Reaction.iloc[-1])
        '''
        print("NH3 Detail: {} \n".format(self.NH3_AllPoint_Detail_Temp_cmprList))    
        print("NH3 Overal: {} \n".format(self.NH3_AllPoint_Overall_Temp_cmprList))
        print("NO Detail: {} \n".format(self.NO_AllPoint_Detail_Temp_cmprList))    
        print("NO Overal: {} \n".format(self.NO_AllPoint_Overall_Temp_cmprList))
        print("Temperature list:{} \n".format(self.temperatureListX))
        '''
        diff_NH3=((self.NH3_AllPoint_Detail_Temp_cmprList-self.NH3_AllPoint_Overall_Temp_cmprList)/fraction_NH3_Overall_Reaction.iloc[0])**2
        diff_NO=((self.NO_AllPoint_Detail_Temp_cmprList-self.NO_AllPoint_Overall_Temp_cmprList)/fraction_NO_Overall_Reaction.iloc[0])**2
        if(draw):
            
            currentTime = time.strftime("%Y%m%d_%H%M%S")
            
            plt.figure()
            plt.plot(self.temperatureListX,self.NH3_EndPoint_Detail_Temp/fraction_NH3_Overall_Reaction.iloc[0],'--',self.temperatureListX,self.NH3_EndPoint_Overall/fraction_NH3_Overall_Reaction.iloc[0],'^')
            plt.xlabel('Temperature/K',fontsize='large')
            plt.ylabel('Fraction out/ Fraction in',fontsize='large')
            plt.title("Concentration of NH3 at Endpoint of Reactor",fontsize='large')
            plt.legend(["NH3: Detail Reaction","NH3: Overall Reaction"],fontsize='large')
            plt.subplots_adjust(left=0.18, wspace=0.25, hspace=0.25,
                    bottom=0.13, top=0.91)
            plt.savefig(os.path.join(ImageResult,currentTime+'NH3EndPoint.png'))
            plt.figure()
            plt.plot(self.temperatureListX,self.NO_EndPoint_Detail_Temp/fraction_NO_Overall_Reaction.iloc[0],'-.',self.temperatureListX,self.NO_EndPoint_Overall/fraction_NO_Overall_Reaction.iloc[0],'v')
            plt.xlabel('Temperature/K',fontsize='large')
            plt.ylabel('Fraction out/ Fraction in',fontsize='large')
            plt.title("Concentration of NO at Endpoint of Reactor",fontsize='large')
            plt.legend(["NO: Detail Reaction","NO: Overall Reaction"],fontsize='large')
            plt.subplots_adjust(left=0.18, wspace=0.25, hspace=0.25,
                    bottom=0.13, top=0.91)
            plt.savefig(os.path.join(ImageResult,currentTime+'NOEndPoint.png'))
           

            
        return (diff_NH3.mean()+2*diff_NO.mean())/3
Exemplo n.º 8
0
    def difference_Overall_Detail_temperature(self,Coeficients,draw=False):
        self.NH3_EndPoint_Overall=[]
        self.NO_EndPoint_Overall=[]  
        self.NH3_AllPoint_Overall_Temp_cmprList=[]
        self.NO_AllPoint_Overall_Temp_cmprList=[]             
    
        for temperatureIter in self.temperatureListX:
            PyChemTB.gererateInputFile(        reactants=[#('CH4',0),
                                                    #('CO',0.0),
                                                    #('CO2',0.15),
                                                    #('H2',0.2),
                                                    ('N2',0.7895),
                                                    ('NH3',0.0003),
                                                    ('NO',0.0002),
                                                    ('O2',0.06),
                                                    ('CO2',0.15)],     # Reactant (mole fraction)

                                        temperature = temperatureIter, # Temperature(K)
                                        pressure = 1 ,   # Pressure (bar)
                                        velocity=75.0,
                                        viscosity=0.0,
                                        reactorDiameter=3.2,
                                        endPosition=45.0,
                                        startPosition=0.0 ,
                                        endTime = 0.05 ,   # End Time (sec)
                                        tempFile="test.inp")
            
            #for the plot 
            '''         
            if  temperatureIter<1200:
                Coeficients=[40609356.32837867,4.591567103723157,59293.190204797174,
                                1.2500592750801196e+48,0.2384295271582183,227638.0184552551]
            if  temperatureIter>=1200:
                Coeficients=[2.1489719679116273,3.6556482376087636,14.912031071151327,
                                10.977243831448774,3.883371131587305,26418.321246185045]
            '''
            PyChemTB.generateChemInput(#1.49e19,0,3.6e5,1.2e15,0,3.4e5,
                                Coeficients[0],Coeficients[1],Coeficients[2],Coeficients[3],Coeficients[4],Coeficients[5],
                                tempFile=os.path.join(currentDir,"ChemInput_OverallReaction.inp"))
            
            fraction_NO_Overall_Reaction,fraction_NH3_Overall_Reaction,residentTimeOverall=getMolesFractions(
                                                        #"G:\SNCR\SNCR\chem_add_ITL.inp",
                                                        os.path.join(currentDir,"ChemInput_OverallReaction.inp"),
                                                        os.path.join(currentDir, "test.inp"))
        

            
            f_NO_Overall=interp1d(residentTimeOverall.values,fraction_NO_Overall_Reaction.values,kind='linear',fill_value="extrapolate")	
            f_NH3_Overall=interp1d(residentTimeOverall.values,fraction_NH3_Overall_Reaction.values,kind='linear',fill_value="extrapolate")			
            
            comparationList_NO_Overall_1T = f_NO_Overall(self.comparationListTime)
            comparationList_NH3_Overall_1T = f_NH3_Overall(self.comparationListTime)	
            
            self.NH3_AllPoint_Overall_Temp_cmprList=np.hstack((self.NH3_AllPoint_Overall_Temp_cmprList,comparationList_NH3_Overall_1T))           
            self.NO_AllPoint_Overall_Temp_cmprList=np.hstack((self.NO_AllPoint_Overall_Temp_cmprList,comparationList_NO_Overall_1T))  	
	

            self.NH3_EndPoint_Overall.append(fraction_NH3_Overall_Reaction.iloc[-1])        
            self.NO_EndPoint_Overall.append(fraction_NO_Overall_Reaction.iloc[-1])
        '''
        print("NH3 Detail: {} \n".format(self.NH3_AllPoint_Detail_Temp_cmprList))    
        print("NH3 Overal: {} \n".format(self.NH3_AllPoint_Overall_Temp_cmprList))
        print("NO Detail: {} \n".format(self.NO_AllPoint_Detail_Temp_cmprList))    
        print("NO Overal: {} \n".format(self.NO_AllPoint_Overall_Temp_cmprList))
        print("Temperature list:{} \n".format(self.temperatureListX))
        '''
        diff_NH3=((self.NH3_AllPoint_Detail_Temp_cmprList-self.NH3_AllPoint_Overall_Temp_cmprList)/fraction_NH3_Overall_Reaction.iloc[0])**2
        diff_NO=((self.NO_AllPoint_Detail_Temp_cmprList-self.NO_AllPoint_Overall_Temp_cmprList)/fraction_NO_Overall_Reaction.iloc[0])**2
        if(draw):
            
            currentTime = time.strftime("%Y%m%d_%H%M%S")
            
            plt.figure()
            plt.plot(self.temperatureListX,self.NH3_EndPoint_Detail_Temp/fraction_NH3_Overall_Reaction.iloc[0],'--',self.temperatureListX,self.NH3_EndPoint_Overall/fraction_NH3_Overall_Reaction.iloc[0],'^')
            plt.xlabel('Temperature/K',fontsize='large')
            plt.ylabel('Fraction out/ Fraction in',fontsize='large')
            plt.title("Concentration of NH3 at Endpoint of Reactor",fontsize='large')
            plt.legend(["NH3: Detail Reaction","NH3: Overall Reaction"],fontsize='large')
            plt.subplots_adjust(left=0.18, wspace=0.25, hspace=0.25,
                    bottom=0.13, top=0.91)
            plt.savefig(os.path.join(ImageResult,currentTime+'NH3EndPoint.png'))
            plt.figure()
            plt.plot(self.temperatureListX,self.NO_EndPoint_Detail_Temp/fraction_NO_Overall_Reaction.iloc[0],'-.',self.temperatureListX,self.NO_EndPoint_Overall/fraction_NO_Overall_Reaction.iloc[0],'v')
            plt.xlabel('Temperature/K',fontsize='large')
            plt.ylabel('Fraction out/ Fraction in',fontsize='large')
            plt.title("Concentration of NO at Endpoint of Reactor",fontsize='large')
            plt.legend(["NO: Detail Reaction","NO: Overall Reaction"],fontsize='large')
            plt.subplots_adjust(left=0.18, wspace=0.25, hspace=0.25,
                    bottom=0.13, top=0.91)
            plt.savefig(os.path.join(ImageResult,currentTime+'NOEndPoint.png'))
            #----------3D Plot---------------#
            fig = plt.figure()
            ax3d = Axes3D(fig)
            df=pd.DataFrame(data={'NO_Detail':self.NO_AllPoint_Detail_Temp_cmprList,'NH3_Detail':self.NH3_AllPoint_Detail_Temp_cmprList})
            df1=pd.DataFrame(data={'NO_Overall':self.NO_AllPoint_Overall_Temp_cmprList,'NH3_Overall':self.NH3_AllPoint_Overall_Temp_cmprList})
            df2=pd.DataFrame(data={'Time':self.comparationListTime})
            df3=pd.DataFrame(data={'temperature':self.temperatureListX})
            dfToWrite=pd.concat([df,df1,df2,df3], axis=1)
            dfToWrite.to_csv("DataAnalyse\\OverallReactionForAllT\\ResultOverallCompareForAllTemperatureNewData.csv")


            C_NO_Detail=self.NO_AllPoint_Detail_Temp_cmprList.reshape(-1,self.timeListNumber)/fraction_NO_Overall_Reaction.iloc[0]
            time3DIndex,temperature3DIndex=np.meshgrid(self.comparationListTime,self.temperatureListX)
            ax3d.plot_surface(time3DIndex,temperature3DIndex, C_NO_Detail, rstride=1, cstride=1, cmap=plt.cm.spring,alpha=0.8)

            C_NO_Overall=self.NO_AllPoint_Overall_Temp_cmprList.reshape(-1,self.timeListNumber)/fraction_NO_Overall_Reaction.iloc[0]
            
            ax3d.scatter( time3DIndex,temperature3DIndex, C_NO_Overall, c='b',marker='*')            
            ax3d.set_xlabel('Residence Time/s')
            ax3d.set_ylabel('Temperature/K')
            ax3d.set_zlabel('NO out/NO in') 
            plt.show()

            fig = plt.figure()
            ax3d = Axes3D(fig)
            C_NH3_Detail=self.NH3_AllPoint_Detail_Temp_cmprList.reshape(-1,self.timeListNumber)/fraction_NH3_Overall_Reaction.iloc[0]
            time3DIndex,temperature3DIndex=np.meshgrid(self.comparationListTime,self.temperatureListX)
            ax3d.plot_surface(time3DIndex,temperature3DIndex, C_NH3_Detail, rstride=1, cstride=1, cmap=plt.cm.spring,alpha=0.8)

            C_NH3_Overall=self.NH3_AllPoint_Overall_Temp_cmprList.reshape(-1,self.timeListNumber)/fraction_NH3_Overall_Reaction.iloc[0]
            
            ax3d.scatter( time3DIndex,temperature3DIndex, C_NH3_Overall, c='b',marker='*')            
            ax3d.set_xlabel('Residence Time/s')
            ax3d.set_ylabel('Temperature/K')
            ax3d.set_zlabel('NH3 out/NH3 in') 
            plt.show()


            
        return (diff_NH3.mean()+2*diff_NO.mean())/3
Exemplo n.º 9
0
    cNH3 = NSR * cNO

    for concentrationIter in concentrationList:
        for temperatureIter in temperatureListX:
            cH2Add = concentrationIter * GasCompent[0]
            cCOAdd = concentrationIter * GasCompent[1]
            cCO2 = concentrationIter * GasCompent[2] + 0.15
            cCH4Add = concentrationIter * GasCompent[3]
            PyChemTB.gererateInputFile(
                reactants=[
                    ('N2',
                     1 - cCOAdd - cCO2 - cH2Add - cCH4Add - cNH3 - cNO - cO2),
                    ('CO', cCOAdd), ('CO2', cCO2), ('H2', cH2Add),
                    ('CH4', cCH4Add), ('NH3', cNH3), ('NO', cNO), ('O2', cO2)
                ],  # Reactant (mole fraction)
                temperature=temperatureIter,  # Temperature(K)
                pressure=1,  # Pressure (bar)
                velocity=75.0,
                viscosity=0.0,
                reactorDiameter=3.2,
                endPosition=45.0,
                startPosition=0.0,
                endTime=0.05,  # End Time (sec)
                tempFile="test.inp")

            fraction_NO_Detail_Reaction_Temp, fraction_NH3_Detail_Reaction_Temp, _ = getMolesFractions(
                os.path.join(currentDir, "chem_add_ITL.inp"),
                os.path.join(currentDir, "test.inp"))

            NO_EndPoint_Detail_Temp.append(
                fraction_NO_Detail_Reaction_Temp.iloc[-1] /
                fraction_NO_Detail_Reaction_Temp.iloc[0])