diff --git a/SConstruct b/SConstruct index ae4ac26a6..a1e215365 100644 --- a/SConstruct +++ b/SConstruct @@ -1003,6 +1003,23 @@ env.SConsignFile() env.Append(CPPPATH=[], LIBPATH=[Dir('build/lib')]) +# preprocess input files (cti -> xml) +convertedInputFiles = set() +for cti in mglob(env, 'data/inputs', 'cti'): + build(env.Command('build/data/%s' % cti.name, cti.path, + Copy('$TARGET', '$SOURCE'))) + outName = os.path.splitext(cti.name)[0] + '.xml' + convertedInputFiles.add(outName) + build(env.Command('build/data/%s' % outName, cti.path, + '$python_cmd interfaces/python/ctml_writer.py $SOURCE $TARGET')) + + +# Copy input files which are not present as cti: +for xml in mglob(env, 'data/inputs', 'xml'): + dest = pjoin('build','data',xml.name) + if xml.name not in convertedInputFiles: + build(env.Command(dest, xml.path, Copy('$TARGET', '$SOURCE'))) + if addInstallActions: # Put headers in place headerBase = 'include/cantera' @@ -1039,7 +1056,7 @@ if addInstallActions: pjoin(headerdir, name, filename), cmd) # Data files - install('$inst_datadir', mglob(env, pjoin('data','inputs'), 'cti', 'xml')) + install('$inst_datadir', mglob(env, pjoin('build','data'), 'cti', 'xml')) # Converter scripts pyExt = '.py' if env['OS'] == 'Windows' else '' diff --git a/interfaces/python/ctml_writer.py b/interfaces/python/ctml_writer.py index c4ef4fb35..3456032ec 100644 --- a/interfaces/python/ctml_writer.py +++ b/interfaces/python/ctml_writer.py @@ -297,7 +297,7 @@ def ufmt(base, n): if n > 0: return '-'+base+str(n) if n < 0: return '/'+base+str(-n) -def write(): +def write(outName=None): """write the CTML file.""" x = XMLnode("ctml") v = x.addChild("validate") @@ -319,7 +319,9 @@ def write(): for rx in _reactions: rx.build(r) - if _name != 'noname': + if outName is not None: + x.write(outName) + elif _name != 'noname': x.write(_name+'.xml') else: print x @@ -2384,7 +2386,7 @@ class Lindemann: #get_atomic_wts() validate() -def convert(filename): +def convert(filename, outName=None): import os, sys base = os.path.basename(filename) root, _ = os.path.splitext(base) @@ -2426,8 +2428,10 @@ def convert(filename): sys.exit(4) - write() + write(outName) if __name__ == "__main__": import sys - convert(sys.argv[1]) + if len(sys.argv) not in (2,3): + raise ValueError('Incorrect number of command line arguments.') + convert(*sys.argv[1:]) diff --git a/test/SConscript b/test/SConscript index 8ac93020f..aa32410ec 100644 --- a/test/SConscript +++ b/test/SConscript @@ -9,7 +9,7 @@ localenv.Append(CPPPATH=['#ext/gtest/include', '#include'], LIBS=['gtest'] + localenv['cantera_libs']) localenv['ENV']['PYTHONPATH'] = Dir('#interfaces/python').abspath -localenv['ENV']['CANTERA_DATA'] = Dir('#data/inputs').abspath +localenv['ENV']['CANTERA_DATA'] = Dir('#build/data').abspath # Needed for Intel runtime libraries when compiling with ICC if 'LD_LIBRARY_PATH' in os.environ: diff --git a/test/python/testReactors.py b/test/python/testReactors.py index fc9c9cdd8..6ec516147 100644 --- a/test/python/testReactors.py +++ b/test/python/testReactors.py @@ -21,7 +21,7 @@ class CombustorTestImplementation(object): referenceFile = '../data/CombustorTest-integrateWithAdvance.csv' def setUp(self): - self.gas = ct.importPhase('../../data/inputs/h2o2.cti') + self.gas = ct.importPhase('h2o2.cti') # create a reservoir for the fuel inlet, and set to pure methane. self.gas.set(T=300.0, P=ct.OneAtm, X='H2:1.0') @@ -120,17 +120,17 @@ class WallTestImplementation(object): referenceFile = '../data/WallTest-integrateWithAdvance.csv' def setUp(self): # reservoir to represent the environment - self.gas0 = ct.importPhase('../../data/inputs/air.cti') + self.gas0 = ct.importPhase('air.cti') self.gas0.set(T=300, P=ct.OneAtm) self.env = reactors.Reservoir(self.gas0) # reactor to represent the side filled with Argon - self.gas1 = ct.importPhase('../../data/inputs/air.cti') + self.gas1 = ct.importPhase('air.cti') self.gas1.set(T=1000.0, P=30*ct.OneAtm, X='AR:1.0') self.r1 = reactors.Reactor(self.gas1) # reactor to represent the combustible mixture - self.gas2 = ct.importPhase('../../data/inputs/h2o2.cti') + self.gas2 = ct.importPhase('h2o2.cti') self.gas2.set(T=500.0, P=1.5*ct.OneAtm, X='H2:0.5, O2:1.0, AR:10.0') self.r2 = reactors.Reactor(self.gas2)