Exemple #1
0
	def test4CanteraVsRMGComplex(self):

		# run it in RMG
		filename = 'canteraHXD13.cti'
		filepath = os.path.join(self.testfolder,filename)

		model = rmg.cantera_loader.loadCanteraFile(filepath)
		system = rmg.model.BatchReactor()
		initializeRMGSimulation(T=self.T, P=self.P, tf=self.tf, model=model, system=system)

		HXD13 = rmg.cantera_loader._speciesByName['HXD13(1)'].getRmgSpecies()
		molarVolume = system.equationOfState.getVolume(T=self.T, P=self.P, N=1.0)
		system.initialConcentration[HXD13] = 1.0/molarVolume

		logging.info('Running RMG simulation...')

		rmg_t, rmg_y = runRMGSimulation(model, system)
		postprocessRMGOutput(rmg_t, rmg_y, model)

		gas, gasAir, reactor, environment, wall, sim, maxtime = \
			initializeCanteraSimulation(filepath=filepath, T=self.T, P=self.P, tf=self.tf)

		speciesA = gas.speciesIndex('HXD13(1)')
		gas.setMoleFractions("HXD13(1):1")

		logging.info('Running cantera simulation...')

		cantera_t, cantera_y = runCanteraSimulation(rmg_t, gas, gasAir, 
									reactor, environment, wall, sim, maxtime)
		postprocessCanteraOutput(cantera_t, cantera_y)
		
		#check the results are the same shape
		self.assert_( cantera_y.shape == rmg_y.shape )
		
		#compare times
		for i in range(1,len(rmg_t)): #skip time[0]
			# NB. assertAlmostEqual compares *decimal places* not significant 
			# figures so instead of aAE(A,B,3) do aAE(A/B,1.0,3) 
			self.assertAlmostEqual(rmg_t[i] / cantera_t[i], 1.0, 3, 
				"Times diverged at %g sec"%rmg_t[i] )
		#compare pressures
		for i in rmg_y[:,0]/cantera_y[:,0]:
			self.assertAlmostEqual(i,1.0,2)
		#compare volumes
		for i in range(len(rmg_t)):
			self.assertAlmostEqual(rmg_y[i,1]/cantera_y[i,1], 1.0, 2, 
				"Volumes diverged at %g sec"%rmg_t[i] )
		#compare temperatures
		for i in rmg_y[:,2]/cantera_y[:,2]:
			self.assertAlmostEqual(i,1.0,2)
		
		#compare concentration profiles
		ratio = rmg_y[1:,3:] / cantera_y[1:,3:]
		for i in ratio.reshape(ratio.size,1):
			self.assertAlmostEqual(i,1.0,2)
Exemple #2
0
	def test3CanteraVsRMGSimple(self):

		# run it in RMG
		filename = 'canteraA=B_2B.cti'
		filepath = os.path.join(self.testfolder,filename)

		model = rmg.cantera_loader.loadCanteraFile(filepath)
		system = rmg.model.BatchReactor()
		initializeRMGSimulation(T=self.T, P=self.P, tf=self.tf, 
									model=model, system=system)
		
		speciesA = rmg.cantera_loader._speciesByName['A'].getRmgSpecies()
		molarVolume = system.equationOfState.getVolume(T=self.T, P=self.P, N=1.0)
		system.initialConcentration[speciesA] = 1.0/molarVolume
		
		rmg_t, rmg_y = runRMGSimulation(model, system)
		postprocessRMGOutput(rmg_t, rmg_y)
		
		#run it in Cantera
		gas, gasAir, reactor, environment, wall, sim, maxtime = \
			initializeCanteraSimulation(filepath=filepath, T=self.T, P=self.P, tf=self.tf)
		
		speciesA_index = gas.speciesIndex('A')
		gas.setMoleFractions("A:1")

		cantera_t, cantera_y = runCanteraSimulation(rmg_t, gas, gasAir, 
								reactor, environment, wall, sim, maxtime)
		postprocessCanteraOutput(cantera_t, cantera_y)

		#check the results are the same shape
		self.assert_( cantera_y.shape == rmg_y.shape )

		#compare pressures
		for i in rmg_y[:,0]/cantera_y[:,0]:
			self.assertAlmostEqual(i,1.0,3)
		#compare volumes
		for i in rmg_y[:,1]/cantera_y[:,1]:
			self.assertAlmostEqual(i,1.0,3)
		#compare temperatures
		for i in rmg_y[:,2]/cantera_y[:,2]:
			self.assertAlmostEqual(i,1.0,3)

		#compare concentration profiles
		ratio = rmg_y[1:,3:] / cantera_y[1:,3:]
		for i in ratio.reshape(ratio.size,1):
			self.assertAlmostEqual(i,1.0,3)