Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pressure dependence convergence issue with filterReactions on #565

Merged
merged 2 commits into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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