def test_compute_flux(self): """ Test the liquid batch reactor with a simple kinetic model. """ rxn1 = Reaction(reactants=[self.C2H6, self.CH3], products=[self.C2H5, self.CH4], kinetics=Arrhenius(A=(686.375 * 6, 'm^3/(mol*s)'), n=4.40721, Ea=(7.82799, 'kcal/mol'), T0=(298.15, 'K'))) core_species = [self.CH4, self.CH3, self.C2H6, self.C2H5] edge_species = [] core_reactions = [rxn1] edge_reactions = [] c0 = {self.C2H5: 0.1, self.CH3: 0.1, self.CH4: 0.4, self.C2H6: 0.4} rxn_system = LiquidReactor(self.T, c0, 1, termination=[]) rxn_system.initialize_model(core_species, core_reactions, edge_species, edge_reactions) tlist = np.array([10**(i / 10.0) for i in range(-130, -49)], np.float64) # Integrate to get the solution at each time point t, y, reaction_rates, species_rates = [], [], [], [] for t1 in tlist: rxn_system.advance(t1) t.append(rxn_system.t) # You must make a copy of y because it is overwritten by DASSL at # each call to advance() y.append(rxn_system.y.copy()) reaction_rates.append(rxn_system.core_reaction_rates.copy()) species_rates.append(rxn_system.core_species_rates.copy()) # Convert the solution vectors to np arrays t = np.array(t, np.float64) reaction_rates = np.array(reaction_rates, np.float64) species_rates = np.array(species_rates, np.float64) # Check that we're computing the species fluxes correctly for i in range(t.shape[0]): self.assertAlmostEqual(reaction_rates[i, 0], species_rates[i, 0], delta=1e-6 * reaction_rates[i, 0]) self.assertAlmostEqual(reaction_rates[i, 0], -species_rates[i, 1], delta=1e-6 * reaction_rates[i, 0]) self.assertAlmostEqual(reaction_rates[i, 0], -species_rates[i, 2], delta=1e-6 * reaction_rates[i, 0]) self.assertAlmostEqual(reaction_rates[i, 0], species_rates[i, 3], delta=1e-6 * reaction_rates[i, 0]) # Check that we've reached equilibrium self.assertAlmostEqual(reaction_rates[-1, 0], 0.0, delta=1e-2)
def test_corespeciesRate(self): """ Test if a specific core species rate is equal to 0 over time. """ c0 = {self.C2H5: 0.1, self.CH3: 0.1, self.CH4: 0.4, self.C2H6: 0.4} rxn1 = Reaction( reactants=[self.C2H6, self.CH3], products=[self.C2H5, self.CH4], kinetics=Arrhenius(A=(686.375*6, 'm^3/(mol*s)'), n=4.40721, Ea=(7.82799, 'kcal/mol'), T0=(298.15, 'K')) ) coreSpecies = [self.CH4, self.CH3, self.C2H6, self.C2H5] edgeSpecies = [] coreReactions = [rxn1] edgeReactions = [] sensitivity = [] terminationConversion = [] sensitivityThreshold = 0.001 ConstSpecies = ["CH4"] rxnSystem = LiquidReactor(self.T, c0, terminationConversion, sensitivity, sensitivityThreshold, ConstSpecies) # The test regarding the writing of constantSPCindices from input file is check with the previous test. rxnSystem.constSPCIndices = [0] rxnSystem.initializeModel(coreSpecies, coreReactions, edgeSpecies, edgeReactions) tlist = numpy.array([10**(i/10.0) for i in range(-130, -49)], numpy.float64) # Integrate to get the solution at each time point t, y, reactionRates, speciesRates = [], [], [], [] for t1 in tlist: rxnSystem.advance(t1) t.append(rxnSystem.t) self.assertEqual(rxnSystem.coreSpeciesRates[0], 0, "Core species rate has to be equal to 0 for species hold constant. Here it is equal to {0}".format(rxnSystem.coreSpeciesRates[0]))
def test_corespeciesRate(self): "Test if a specific core species rate is equal to 0 over time" c0={self.C2H5: 0.1, self.CH3: 0.1, self.CH4: 0.4, self.C2H6: 0.4} rxn1 = Reaction(reactants=[self.C2H6,self.CH3], products=[self.C2H5,self.CH4], kinetics=Arrhenius(A=(686.375*6,'m^3/(mol*s)'), n=4.40721, Ea=(7.82799,'kcal/mol'), T0=(298.15,'K'))) coreSpecies = [self.CH4,self.CH3,self.C2H6,self.C2H5] edgeSpecies = [] coreReactions = [rxn1] edgeReactions = [] sensitivity=[] terminationConversion = [] sensitivityThreshold=0.001 ConstSpecies = ["CH4"] rxnSystem = LiquidReactor(self.T, c0, terminationConversion, sensitivity,sensitivityThreshold,ConstSpecies) ##The test regarding the writting of constantSPCindices from input file is check with the previous test. rxnSystem.constSPCIndices=[0] rxnSystem.initializeModel(coreSpecies, coreReactions, edgeSpecies, edgeReactions) tlist = numpy.array([10**(i/10.0) for i in range(-130, -49)], numpy.float64) # Integrate to get the solution at each time point t = []; y = []; reactionRates = []; speciesRates = [] for t1 in tlist: rxnSystem.advance(t1) t.append(rxnSystem.t) self.assertEqual(rxnSystem.coreSpeciesRates[0], 0,"Core species rate has to be equal to 0 for species hold constant. Here it is equal to {0}".format(rxnSystem.coreSpeciesRates[0]))
def testComputeFlux(self): """ Test the liquid batch reactor with a simple kinetic model. """ rxn1 = Reaction( reactants=[self.C2H6, self.CH3], products=[self.C2H5, self.CH4], kinetics=Arrhenius(A=(686.375*6, 'm^3/(mol*s)'), n=4.40721, Ea=(7.82799, 'kcal/mol'), T0=(298.15, 'K')) ) coreSpecies = [self.CH4, self.CH3, self.C2H6, self.C2H5] edgeSpecies = [] coreReactions = [rxn1] edgeReactions = [] c0 = {self.C2H5: 0.1, self.CH3: 0.1, self.CH4: 0.4, self.C2H6: 0.4} rxnSystem = LiquidReactor(self.T, c0, 1, termination=[]) rxnSystem.initializeModel(coreSpecies, coreReactions, edgeSpecies, edgeReactions) tlist = numpy.array([10**(i/10.0) for i in xrange(-130, -49)], numpy.float64) # Integrate to get the solution at each time point t, y, reactionRates, speciesRates = [], [], [], [] for t1 in tlist: rxnSystem.advance(t1) t.append(rxnSystem.t) # You must make a copy of y because it is overwritten by DASSL at # each call to advance() y.append(rxnSystem.y.copy()) reactionRates.append(rxnSystem.coreReactionRates.copy()) speciesRates.append(rxnSystem.coreSpeciesRates.copy()) # Convert the solution vectors to numpy arrays t = numpy.array(t, numpy.float64) reactionRates = numpy.array(reactionRates, numpy.float64) speciesRates = numpy.array(speciesRates, numpy.float64) # Check that we're computing the species fluxes correctly for i in xrange(t.shape[0]): self.assertAlmostEqual(reactionRates[i, 0], speciesRates[i, 0], delta=1e-6*reactionRates[i, 0]) self.assertAlmostEqual(reactionRates[i, 0], -speciesRates[i, 1], delta=1e-6*reactionRates[i, 0]) self.assertAlmostEqual(reactionRates[i, 0], -speciesRates[i, 2], delta=1e-6*reactionRates[i, 0]) self.assertAlmostEqual(reactionRates[i, 0], speciesRates[i, 3], delta=1e-6*reactionRates[i, 0]) # Check that we've reached equilibrium self.assertAlmostEqual(reactionRates[-1, 0], 0.0, delta=1e-2)