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

Debugging2 #149

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 12 additions & 2 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,15 @@ def generateConfig(self, directory):
data["initial conditions"] = {}

for reaction_rate in self.initial_conditions.reaction_rates:
name = "PHOT." + reaction_rate.reaction.name + ".s-1"
data["initial conditions"][name] = reaction_rate.rate
if(reaction_rate.reaction.reaction_type == "PHOTOLYSIS"):
name = "PHOT." + reaction_rate.reaction.name + ".s-1"
data["initial conditions"][name] = reaction_rate.rate
elif(reaction_rate.reaction.reaction_type == "LOSS"):
name = "LOSS." + reaction_rate.reaction.name + ".s-1"
data["initial conditions"][name] = reaction_rate.rate
elif (reaction_rate.reaction.reaction_type =="EMISSION"):
name = "EMISSION." + reaction_rate.reaction.name + ".s-1"
data["initial conditions"][name] = reaction_rate.rate

data["model components"] = [
{
Expand Down Expand Up @@ -358,6 +365,9 @@ def generateReactionConfig(self):
if(reaction.name != None):
reac["MUSICA name"] = reaction.name

if(reaction.scaling_factor != None):
reac["scaling factor"] = reaction.scaling_factor

reactionsArray.append(reac)

reacList["reactions"] = reactionsArray
Expand Down
16 changes: 13 additions & 3 deletions src/acom_music_box/music_box_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,22 @@ def from_config_JSON(cls, config_JSON, species_list, reaction_list):

# Set initial species concentrations
species_concentrations = []
reaction_rates = []

#reads initial conditions from csv if it is given
if 'initial conditions' in config_JSON:
initial_conditions_csv = config_JSON['initial conditions']
#initial_conditions_csv = config_JSON['initial conditions']

#read_initial_conditions_from_csv(initial_conditions_csv)
for reaction_rate in config_JSON['initial conditions']:

match = filter(lambda x: x.name == reaction_rate.split('.')[1], reaction_list.reactions)

reaction = next(match, None)

rate = config_JSON['initial conditions'][reaction_rate]

reaction_rates.append(ReactionRate(reaction, rate))

#reads from config file directly if present
if 'chemical species' in config_JSON:
Expand All @@ -105,13 +116,12 @@ def from_config_JSON(cls, config_JSON, species_list, reaction_list):

#TODO: may or may not be necessary
# Set initial reaction rates
reaction_rates = []

for reaction in reaction_list.reactions:
if reaction.name != None and not any(reac.reaction.name == reaction.name for reac in reaction_rates):
reaction_rates.append(ReactionRate(reaction, 0))


return cls(pressure, temperature, species_concentrations, reaction_rates)


Expand Down
3 changes: 2 additions & 1 deletion src/acom_music_box/music_box_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Reaction:
products (List[Product]): A list of Product instances representing the products. Default is an empty list.
"""

def __init__(self, name=None, reaction_type=None, reactants=None, products=None):
def __init__(self, name=None, reaction_type=None, reactants=None, products=None, scaling_factor=None):
"""
Initializes a new instance of the Reaction class.

Expand All @@ -25,6 +25,7 @@ def __init__(self, name=None, reaction_type=None, reactants=None, products=None)
self.reaction_type = reaction_type
self.reactants = reactants if reactants is not None else []
self.products = products if products is not None else []
self.scaling_factor = scaling_factor

def add_reactant(self, reactant):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/acom_music_box/music_box_reaction_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def get_products_from_JSON(self, reaction, species_list):
def get_reactions_from_JSON(self, reaction, species_list):

name = reaction['MUSICA name'] if 'MUSICA name' in reaction else None
scaling_factor = reaction['scaling factor'] if 'scaling factor' in reaction else None
reaction_type = reaction['type']

reactants = ReactionList.get_reactants_from_JSON(reaction, species_list)
Expand Down Expand Up @@ -163,4 +164,4 @@ def get_reactions_from_JSON(self, reaction, species_list):
N = reaction.get('N')
return Troe_Ternary(name, reaction_type, reactants, products, k0_A, k0_B, k0_C, kinf_A, kinf_B, kinf_C, Fc, N)
else:
return Reaction(name, reaction_type, reactants, products)
return Reaction(name, reaction_type, reactants, products, scaling_factor)
Loading
Loading