def convertChemkin2Cantera(RMG_results):
    """
    Convert the Chemkin file into a Cantera file.
    
    Does its work inside RMG_results/chemkin
    """
    
    from Cantera import ck2cti
    starting_dir = os.getcwd()
    chemkin_dir = os.path.join(RMG_results,'chemkin')
    infile='chem.inp'
    
    print "Converting chemkin file '%s' into cantera file '%s' in folder '%s/'"%(infile,
        os.path.splitext('chem.inp')[0]+'.cti', chemkin_dir)
    
    os.chdir(chemkin_dir)
    if os.path.exists('ck2cti-validation-failed.log'): os.remove('ck2cti-validation-failed.log')
    try:
        thermodb=''
        trandb=''
        nm='chem'
        ck2cti.ck2cti(infile = infile, thermodb = thermodb,  trandb = trandb, idtag = nm, debug=0, validate=1)
    except:
        print "Conversion from chemkin to cantera did not validate. Trying again without validation."
        os.rename('ck2cti.log', 'ck2cti-validation-failed.log')
        print "Check",os.path.join(chemkin_dir,'ck2cti-validation-failed.log')
        ck2cti.ck2cti(infile = infile, thermodb = thermodb,  trandb = trandb, idtag = nm, debug=0, validate=0)
    finally:
        os.chdir(starting_dir)
Example #2
0
def convertChemkin2Cantera(RMG_results):
    """
    Convert the Chemkin file into a Cantera file.
    
    Does its work inside RMG_results/chemkin
    """

    from Cantera import ck2cti
    starting_dir = os.getcwd()
    chemkin_dir = os.path.join(RMG_results, 'chemkin')
    infile = 'chem.inp'

    print "Converting chemkin file '%s' into cantera file '%s' in folder '%s/'" % (
        infile, os.path.splitext('chem.inp')[0] + '.cti', chemkin_dir)

    os.chdir(chemkin_dir)
    if os.path.exists('ck2cti-validation-failed.log'):
        os.remove('ck2cti-validation-failed.log')
    try:
        thermodb = ''
        trandb = ''
        nm = 'chem'
        ck2cti.ck2cti(infile=infile,
                      thermodb=thermodb,
                      trandb=trandb,
                      idtag=nm,
                      debug=0,
                      validate=1)
    except:
        print "Conversion from chemkin to cantera did not validate. Trying again without validation."
        os.rename('ck2cti.log', 'ck2cti-validation-failed.log')
        print "Check", os.path.join(chemkin_dir,
                                    'ck2cti-validation-failed.log')
        ck2cti.ck2cti(infile=infile,
                      thermodb=thermodb,
                      trandb=trandb,
                      idtag=nm,
                      debug=0,
                      validate=0)
    finally:
        os.chdir(starting_dir)
Example #3
0
def loadChemkinFile(filepath='chem.inp', thermodb='',trandb=''):
	"""Loads a Chemkin file. (Converts to Cantera first)"""
	from Cantera import ck2cti
	import shutil
	import os
	oldpath = os.path.abspath(filepath)
	oldwd	= os.getcwd()
	filename = os.path.basename(filepath)
	newpath = os.path.join(oldwd,rmg.constants.scratchDirectory, filename)
	
	if not os.path.exists(newpath) or not os.path.samefile(oldpath,newpath):
		logging.debug("Copying %s to %s"%(oldpath,newpath))
		shutil.copy2(oldpath, newpath)
	ctifile = os.path.splitext(newpath)[0]+'.cti'
	if os.path.exists(ctifile):
		#move aside old file
		os.rename(ctifile,'%s-%d.cti'%(os.path.splitext(ctifile)[0],
										 os.lstat(ctifile).st_mtime) )
	nm='chem'
	# convert from chemkin to cti
	try:
		os.chdir(rmg.constants.scratchDirectory)
		ck2cti.ck2cti(infile = newpath, thermodb = thermodb,
				  trandb = trandb, idtag = nm, debug=0, validate=1)
	except: 
		logging.error("Conversion from Chemkin to Cantera failed:")
		for line in open('ck2cti.log'):
			 logging.error(line.rstrip())
		os.chdir(oldwd) # change back to where you were
		raise
	logging.info('Converting %s from Chemkin to Cantera:'%filepath)
	for line in open('ck2cti.log'):
		logging.debug(line.rstrip())
	os.chdir(oldwd) # change back to where you were
	model = loadCanteraFile(ctifile)
	return model
Example #4
0
#RMGworkingDir="/Users/rwest/XCodeProjects/RMG/WorkingFolders/v3_from_CVS/diesel_surrogate_.5mod"

RMGworkingDir="/Users/rwest/Documents/AcaPostdoc/ENI/from Amrit/diesel surrogate runs/GP tol=0.1 time=4hrs"

# convert the chemkin file from RMG into a cantera file chem.cti
from Cantera import ck2cti
infile='chem.inp'
oldpath=os.path.join(RMGworkingDir,'chemkin',infile)
newpath=os.path.join(os.getcwd(),infile)
print "copying %s to %s"%(oldpath,newpath)
shutil.copy2(oldpath, newpath) # copy it to the current folder

thermodb=''
trandb=''
nm='chem'
ck2cti.ck2cti(infile = infile, thermodb = thermodb,  trandb = trandb, idtag = nm, debug=0, validate=1)


# convert the Final_Model.txt into approprita CSV file

print "NB  ForMixMaster.csv is wrong. MixMaster wants MASS fractions and we are giving it MOLE fractions" 

temperature=273+150
pressure=208*101325
print " using these settings:\n Temperature: %f K \t Pressure: %f Pa\n"%(temperature,pressure)

# load file
resultFile=file(os.path.join(RMGworkingDir,'Final_Model.txt'))
# search for "Mole Fraction Profile Output"
line=resultFile.next()
while (line.find('Mole Fraction Profile Output')<0):