Skip to content

Commit

Permalink
Allows constant concentration species in simple gas phase reactors
Browse files Browse the repository at this point in the history
  • Loading branch information
rgillis8 committed Oct 4, 2019
1 parent d9217ec commit 1b97fb6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
15 changes: 11 additions & 4 deletions rmgpy/rmg/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def simple_reactor(temperature,
sensitivityTemperature=None,
sensitivityPressure=None,
sensitivityMoleFractions=None,
):
constantSpecies=None):
logging.debug('Found SimpleReactor reaction system')

for key, value in initialMoleFractions.items():
Expand Down Expand Up @@ -249,7 +249,15 @@ def simple_reactor(temperature,
else:
sensitive_species.append('all')

if not isinstance(T, list):
#Check the constant species exist
if constantSpecies is not None:
logging.debug(' Generation with constant species:')
for constantSpecie in constantSpecies:
logging.debug(" {0}".format(constantSpecie))
if constantSpecie not in species_dict:
raise InputError('Species {0} not found in the input file'.format(constantSpecie))

if not isinstance(T,list):
sensitivityTemperature = T
if not isinstance(P, list):
sensitivityPressure = P
Expand All @@ -262,8 +270,7 @@ def simple_reactor(temperature,
sens_conditions['T'] = Quantity(sensitivityTemperature).value_si
sens_conditions['P'] = Quantity(sensitivityPressure).value_si

system = SimpleReactor(T, P, initialMoleFractions, nSims, termination, sensitive_species, sensitivityThreshold,
sens_conditions)
system = SimpleReactor(T, P, initialMoleFractions, nSims, termination, sensitive_species, sensitivityThreshold, sens_conditions, constantSpecies)
rmg.reaction_systems.append(system)

assert balanceSpecies is None or isinstance(balanceSpecies, str), 'balanceSpecies should be the string corresponding to a single species'
Expand Down
4 changes: 3 additions & 1 deletion rmgpy/solver/mbSampled.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ cdef class MBSampledReactor(ReactionSystem):
cdef public bint constant_volume
cdef public dict initial_mole_fractions
cdef public list constantSpeciesList
cdef public list const_spc_names

# collider variables

Expand Down Expand Up @@ -112,13 +113,14 @@ cdef class MBSampledReactor(ReactionSystem):
cdef public np.ndarray pdep_specific_collider_reaction_indices

def __init__(self, T, P, initial_mole_fractions, k_sampling, constantSpeciesList, termination, sensitive_species=None,
sensitivity_threshold=1e-3):
sensitivity_threshold=1e-3, const_spc_names=None):
ReactionSystem.__init__(self, termination, sensitive_species, sensitivity_threshold)
self.T = Quantity(T)
self.P = Quantity(P)
self.initial_mole_fractions = initial_mole_fractions
self.k_sampling = RateCoefficient(k_sampling)
self.constantSpeciesList = constantSpeciesList
self.const_spc_names = const_spc_names

self.V = 0 # will be set in initialize_model
self.constant_volume = False
Expand Down
21 changes: 20 additions & 1 deletion rmgpy/solver/simple.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ cdef class SimpleReactor(ReactionSystem):
cdef public double V
cdef public bint constant_volume
cdef public dict initial_mole_fractions
cdef public list const_spc_names
cdef public list const_spc_indices

# collider variables

Expand Down Expand Up @@ -110,7 +112,7 @@ cdef class SimpleReactor(ReactionSystem):
cdef public int n_sims

def __init__(self, T, P, initial_mole_fractions, n_sims=1, termination=None, sensitive_species=None,
sensitivity_threshold=1e-3, sens_conditions=None):
sensitivity_threshold=1e-3, sens_conditions=None, const_spc_names=None):
ReactionSystem.__init__(self, termination, sensitive_species, sensitivity_threshold)

if type(T) != list:
Expand All @@ -125,6 +127,10 @@ cdef class SimpleReactor(ReactionSystem):

self.initial_mole_fractions = initial_mole_fractions

#Constant Species Properties
self.const_spc_indices=None
self.const_spc_names = const_spc_names #store index of constant species

self.V = 0 # will be set in initialize_model
self.constant_volume = False

Expand Down Expand Up @@ -163,6 +169,15 @@ cdef class SimpleReactor(ReactionSystem):
conditions[species_dict[label]] = value
self.sens_conditions = conditions

def get_const_spc_indices (self, coreSpecies):
"Allow to identify constant Species position in solver"
for spc in self.const_spc_names:
if self.const_spc_indices is None: #initialize once the list if constant SPC declared
self.const_spc_indices=[]
for iter in coreSpecies: #Need to identify the species object corresponding to the the string written in the input file
if iter.label == spc:
self.const_spc_indices.append(coreSpecies.index(iter))#get

cpdef initialize_model(self, list core_species, list core_reactions, list edge_species, list edge_reactions,
list surface_species=None, list surface_reactions=None, list pdep_networks=None,
atol=1e-16, rtol=1e-8, sensitivity=False, sens_atol=1e-6, sens_rtol=1e-4,
Expand Down Expand Up @@ -504,6 +519,10 @@ cdef class SimpleReactor(ReactionSystem):
reaction_rate = k * C[inet[j, 0]] * C[inet[j, 1]] * C[inet[j, 2]]
network_leak_rates[j] = reaction_rate

if self.const_spc_indices is not None:
for spcIndice in self.const_spc_indices:
core_species_rates[spcIndice] = 0

self.core_species_concentrations = core_species_concentrations
self.core_species_rates = core_species_rates
self.core_species_production_rates = core_species_production_rates
Expand Down
8 changes: 4 additions & 4 deletions rmgpy/tools/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ def simulate(rmg, diffusion_limited=True):
rmg.load_database()
solvent_data = rmg.database.solvation.get_solvent_data(rmg.solvent)
diffusion_limiter.enable(solvent_data, rmg.database.solvation)

# Store constant species indices
if reaction_system.const_spc_names is not None:
reaction_system.get_const_spc_indices(rmg.reaction_model.core.species)
elif rmg.uncertainty is not None:
rmg.verbose_comments = True
rmg.load_database()

# Store constant species indices
if reaction_system.const_spc_names is not None:
reaction_system.get_const_spc_indices(rmg.reaction_model.core.species)

reaction_system.simulate(
core_species=rmg.reaction_model.core.species,
core_reactions=rmg.reaction_model.core.reactions,
Expand Down

0 comments on commit 1b97fb6

Please sign in to comment.