Skip to content

Commit

Permalink
Merge pull request #565 from ReactionMechanismGenerator/anotherPdepFix
Browse files Browse the repository at this point in the history
Fix pressure dependence convergence issue with filterReactions on
  • Loading branch information
connie committed Feb 4, 2016
2 parents 42a2be7 + eb429be commit 9f3e089
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 34 deletions.
75 changes: 75 additions & 0 deletions examples/rmg/heptane-filterReactions/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Data sources
database(
thermoLibraries = ['primaryThermoLibrary'],
reactionLibraries = [],
seedMechanisms = [],
kineticsDepositories = ['training'],
kineticsFamilies = 'default',
kineticsEstimator = 'rate rules',
)

# Constraints on generated species
generatedSpeciesConstraints(
maximumCarbonAtoms = 7,
)

# List of species
species(
label='n-heptane',
structure=SMILES("CCCCCCC"),
)

species(
label='Ar',
reactive=False,
structure=SMILES("[Ar]"),
)


simpleReactor(
temperature=(1600,'K'),
pressure=(400,'Pa'),
initialMoleFractions={
"n-heptane": 0.02,
"Ar": 0.98,
},
terminationConversion={
'n-heptane': 0.99,
},
terminationTime=(1e6,'s'),
)

simpleReactor(
temperature=(2000,'K'),
pressure=(400,'Pa'),
initialMoleFractions={
"n-heptane": 0.02,
"Ar": 0.98,
},
terminationConversion={
'n-heptane': 0.99,
},
terminationTime=(1e6,'s'),
)

simulator(
atol=1e-16,
rtol=1e-8,
)

model(
toleranceMoveToCore=0.01,
toleranceInterruptSimulation=0.01,
filterReactions=True,
)

pressureDependence(
method='modified strong collision',
maximumGrainSize=(0.5,'kcal/mol'),
minimumNumberOfGrains=250,
temperatures=(300,3000,'K',8),
pressures=(0.001,100,'bar',5),
interpolation=('Chebyshev', 6, 4),
)


65 changes: 31 additions & 34 deletions rmgpy/rmg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,35 +609,37 @@ def execute(self, inputFile, output_directory, **kwargs):
for objectToEnlarge in objectsToEnlarge:
self.reactionModel.enlarge(objectToEnlarge)

if self.filterReactions:
# Run a raw simulation to get updated reaction system threshold values
for index, reactionSystem in enumerate(self.reactionSystems):
# Run with the same conditions as with pruning off
reactionSystem.simulate(
coreSpecies = self.reactionModel.core.species,
coreReactions = self.reactionModel.core.reactions,
edgeSpecies = [],
edgeReactions = [],
toleranceKeepInEdge = 0,
toleranceMoveToCore = self.fluxToleranceMoveToCore,
toleranceInterruptSimulation = self.fluxToleranceMoveToCore,
pdepNetworks = self.reactionModel.networkList,
absoluteTolerance = self.absoluteTolerance,
relativeTolerance = self.relativeTolerance,
filterReactions=True,
)
reactEdge = self.updateReactionThresholdAndReactFlags(
rxnSysUnimolecularThreshold = reactionSystem.unimolecularThreshold,
rxnSysBimolecularThreshold = reactionSystem.bimolecularThreshold)

logging.info('')
else:
reactEdge = self.updateReactionThresholdAndReactFlags()

if reactEdge:
if len(self.reactionModel.core.species) > numCoreSpecies:
# If there were core species added, then react the edge
# If there were no new core species, it means the pdep network needs be updated through another enlarge core step
if self.filterReactions:
# Run a raw simulation to get updated reaction system threshold values
for index, reactionSystem in enumerate(self.reactionSystems):
# Run with the same conditions as with pruning off
reactionSystem.simulate(
coreSpecies = self.reactionModel.core.species,
coreReactions = self.reactionModel.core.reactions,
edgeSpecies = [],
edgeReactions = [],
toleranceKeepInEdge = 0,
toleranceMoveToCore = self.fluxToleranceMoveToCore,
toleranceInterruptSimulation = self.fluxToleranceMoveToCore,
pdepNetworks = self.reactionModel.networkList,
absoluteTolerance = self.absoluteTolerance,
relativeTolerance = self.relativeTolerance,
filterReactions=True,
)
self.updateReactionThresholdAndReactFlags(
rxnSysUnimolecularThreshold = reactionSystem.unimolecularThreshold,
rxnSysBimolecularThreshold = reactionSystem.bimolecularThreshold)

logging.info('')
else:
self.updateReactionThresholdAndReactFlags()

self.reactionModel.enlarge(reactEdge=True,
unimolecularReact=self.unimolecularReact,
bimolecularReact=self.bimolecularReact)
unimolecularReact=self.unimolecularReact,
bimolecularReact=self.bimolecularReact)

self.saveEverything()

Expand Down Expand Up @@ -715,7 +717,6 @@ def updateReactionThresholdAndReactFlags(self, rxnSysUnimolecularThreshold=None,
prevNumCoreSpecies = len(self.unimolecularReact)
stale = True if numCoreSpecies > prevNumCoreSpecies else False

reactEdge = True

if self.filterReactions:
if stale:
Expand Down Expand Up @@ -759,11 +760,7 @@ def updateReactionThresholdAndReactFlags(self, rxnSysUnimolecularThreshold=None,
for i in xrange(numCoreSpecies):
for j in xrange(prevNumCoreSpecies,numCoreSpecies):
self.bimolecularReact[i,j] = True
else:
# No reacting of edge because unimolecularReact and bimolecularReact will be False
reactEdge = False

return reactEdge


def saveEverything(self):
"""
Expand Down

0 comments on commit 9f3e089

Please sign in to comment.