Skip to content

Commit

Permalink
reads reaction list from config json
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjamesgarza committed Apr 2, 2024
1 parent 2cb5e74 commit 4d4f1ef
Show file tree
Hide file tree
Showing 14 changed files with 5,662 additions and 79 deletions.
25 changes: 19 additions & 6 deletions src/box_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def __init__(self, box_model_options=None, species_list=None, reaction_list=None
config_file (String): File path for the configuration file to be located. Default is "camp_data/config.json".
"""
self.box_model_options = box_model_options
self.species_list = species_list if species_list is not None else []
self.reaction_list = reaction_list if reaction_list is not None else []
self.species_list = species_list if species_list is not None else SpeciesList()
self.reaction_list = reaction_list if reaction_list is not None else ReactionList()
self.initial_conditions = initial_conditions
self.evolving_conditions = evolving_conditions if evolving_conditions is not None else []
self.evolving_conditions = evolving_conditions if evolving_conditions is not None else EvolvingConditions([], [])
self.config_file = config_file if config_file is not None else "camp_data/config.json"


Expand Down Expand Up @@ -395,6 +395,8 @@ def solve(self, path_to_output = None):
curr_time = 0
next_output_time = curr_time
#runs the simulation at each timestep


while(curr_time <= self.box_model_options.simulation_length):

#outputs to output_array if enough time has elapsed
Expand All @@ -410,7 +412,8 @@ def solve(self, path_to_output = None):

#iterates evolvings conditons if enough time has elapsed
if(next_conditions != None and next_conditions_time <= curr_time):
curr_conditions = next_conditions
#curr_conditions = next_conditions
curr_conditions.update_conditions(next_conditions)

#iterates next_conditions if there are remaining evolving conditions
if(len(self.evolving_conditions) > next_conditions_index + 1):
Expand All @@ -425,7 +428,7 @@ def solve(self, path_to_output = None):
next_conditions = None

#solves and updates concentration values in concentration array
musica.micm_solve(self.solver, self.box_model_options.chem_step_time, curr_conditions.temperature, curr_conditions.pressure, curr_concentrations)
musica.micm_solve(self.solver, self.box_model_options.chem_step_time, curr_conditions.temperature, curr_conditions.pressure, curr_concentrations, [])


#increments time
Expand Down Expand Up @@ -474,11 +477,21 @@ def readConditionsFromJson(self, path_to_json):
# Set species list
self.species_list = SpeciesList.from_config_JSON(path_to_json, data)

self.reaction_list = ReactionList.from_config_JSON(path_to_json, data, self.species_list)

# Set initial conditions
self.initial_conditions = Conditions.from_config_JSON(data, self.species_list )
self.initial_conditions = Conditions.from_config_JSON(data, self.species_list, self.reaction_list)

# Set initial conditions
self.evolving_conditions = EvolvingConditions.from_config_JSON(path_to_json, data, self.species_list, self.reaction_list)


def speciesOrdering(self):
return musica.species_ordering(self.solver)

def userDefinedReactionRates(self):
return musica.user_defined_reaction_rates(self.solver)


# for testing purposes
def __main__():
Expand Down
50 changes: 49 additions & 1 deletion src/configs/test_config_1/camp_data/reactions.json
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
{"camp-data": [{"type": "MECHANISM", "name": "music box interactive configuration", "reactions": [{"type": "ARRHENIUS", "A": 0.00012, "B": 7, "C" : 75, "D": 50, "E": 0.5, "reactants": {"B": {"qty": 1}}, "products": {"C": {"yield": 1}, "irr__089f1f45-4cd8-4278-83d5-d638e98e4315": {"yield": 1}}}, {"type": "ARRHENIUS", "A": 0.004, "C" : 50, "reactants": {"A": {"qty": 1}}, "products": {"B": {"yield": 1}, "irr__2a109b21-bb24-41ae-8f06-7485fd36f1a7": {"yield": 1}}}]}]}
{
"camp-data": [
{
"type": "MECHANISM",
"name": "music box interactive configuration",
"reactions": [
{
"type": "ARRHENIUS",
"A": 0.00012,
"B": 7,
"C": 75,
"D": 50,
"E": 0.5,
"reactants": {
"B": {
"qty": 1
}
},
"products": {
"C": {
"yield": 1
},
"irr__089f1f45-4cd8-4278-83d5-d638e98e4315": {
"yield": 1
}
}
},
{
"type": "ARRHENIUS",
"A": 0.004,
"C": 50,
"reactants": {
"A": {
"qty": 1
}
},
"products": {
"B": {
"yield": 1
},
"irr__2a109b21-bb24-41ae-8f06-7485fd36f1a7": {
"yield": 1
}
}
}
]
}
]
}
25 changes: 24 additions & 1 deletion src/configs/test_config_1/camp_data/species.json
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
{"camp-data": [{"name": "A", "type": "CHEM_SPEC"}, {"name": "B", "type": "CHEM_SPEC"}, {"name": "C", "type": "CHEM_SPEC"}, {"name": "irr__089f1f45-4cd8-4278-83d5-d638e98e4315", "type": "CHEM_SPEC"}, {"name": "irr__2a109b21-bb24-41ae-8f06-7485fd36f1a7", "type": "CHEM_SPEC"}]}
{
"camp-data": [
{
"name": "A",
"type": "CHEM_SPEC"
},
{
"name": "B",
"type": "CHEM_SPEC"
},
{
"name": "C",
"type": "CHEM_SPEC"
},
{
"name": "irr__089f1f45-4cd8-4278-83d5-d638e98e4315",
"type": "CHEM_SPEC"
},
{
"name": "irr__2a109b21-bb24-41ae-8f06-7485fd36f1a7",
"type": "CHEM_SPEC"
}
]
}
1 change: 1 addition & 0 deletions src/configs/test_config_2/camp_data/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"camp-files": ["species.json", "reactions.json"]}
169 changes: 169 additions & 0 deletions src/configs/test_config_2/camp_data/reactions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"camp-data": [
{
"type": "MECHANISM",
"name": "music box interactive configuration",
"reactions": [
{
"type": "PHOTOLYSIS",
"MUSICA name": "O3_1",
"reactants": {
"O3": {}
},
"products": {
"O1D": {
"yield": 1
},
"O2": {
"yield": 1
},
"irr__1034482c-136b-4c33-ba70-c2d35a32b70f": {
"yield": 1
}
}
},
{
"type": "ARRHENIUS",
"A": 8e-12,
"Ea": 2.8428e-20,
"B": 0,
"D": 300,
"E": 0,
"reactants": {
"O": {
"qty": 1
},
"O3": {
"qty": 1
}
},
"products": {
"O2": {
"yield": 2
},
"irr__5155b7b1-9e3b-45e5-9572-3050b847e843": {
"yield": 1
}
}
},
{
"type": "ARRHENIUS",
"A": 6e-34,
"Ea": 0,
"B": -2.4,
"D": 300,
"E": 0,
"reactants": {
"O": {
"qty": 1
},
"O2": {
"qty": 1
},
"M": {
"qty": 1
}
},
"products": {
"O3": {
"yield": 1
},
"M": {
"yield": 1
},
"irr__55dbd5d1-43e2-4e2c-85c7-74d5d67ef8b9": {
"yield": 1
}
}
},
{
"type": "PHOTOLYSIS",
"MUSICA name": "O3_2",
"reactants": {
"O3": {}
},
"products": {
"O": {
"yield": 1
},
"O2": {
"yield": 1
},
"irr__ab8ec0e6-1802-49cf-9bbf-63647ae53b3c": {
"yield": 1
}
}
},
{
"type": "ARRHENIUS",
"A": 2.15e-11,
"Ea": -1.518e-21,
"B": 0,
"D": 300,
"E": 0,
"reactants": {
"O1D": {
"qty": 1
},
"N2": {
"qty": 1
}
},
"products": {
"O": {
"yield": 1
},
"N2": {
"yield": 1
},
"irr__abb66d47-34f9-45f9-92bb-31cd85e45985": {
"yield": 1
}
}
},
{
"type": "PHOTOLYSIS",
"MUSICA name": "O2_1",
"reactants": {
"O2": {}
},
"products": {
"O": {
"yield": 2
},
"irr__b0127bc4-3658-4b92-938d-cf22e8576c5d": {
"yield": 1
}
}
},
{
"type": "ARRHENIUS",
"A": 3.3e-11,
"Ea": -7.59e-22,
"B": 0,
"D": 300,
"E": 0,
"reactants": {
"O1D": {
"qty": 1
},
"O2": {
"qty": 1
}
},
"products": {
"O": {
"yield": 1
},
"O2": {
"yield": 1
},
"irr__ffa95a94-fc71-4629-905e-cbc7119235d8": {
"yield": 1
}
}
}
]
}
]
}
63 changes: 63 additions & 0 deletions src/configs/test_config_2/camp_data/species.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"camp-data": [
{
"name": "M",
"type": "CHEM_SPEC",
"tracer type": "CONSTANT"
},

{
"name": "O1D",
"type": "CHEM_SPEC",
"absolute tolerance": 1e-12
},
{
"name": "O",
"type": "CHEM_SPEC",
"absolute tolerance": 1e-12
},
{
"name": "O2",
"type": "CHEM_SPEC",
"absolute tolerance": 1e-12
},
{
"name": "O3",
"type": "CHEM_SPEC",
"absolute tolerance": 1e-12
},
{
"name": "N2",
"type": "CHEM_SPEC",
"absolute tolerance": 1e-12
},
{
"name": "irr__1034482c-136b-4c33-ba70-c2d35a32b70f",
"type": "CHEM_SPEC"
},
{
"name": "irr__5155b7b1-9e3b-45e5-9572-3050b847e843",
"type": "CHEM_SPEC"
},
{
"name": "irr__55dbd5d1-43e2-4e2c-85c7-74d5d67ef8b9",
"type": "CHEM_SPEC"
},
{
"name": "irr__ab8ec0e6-1802-49cf-9bbf-63647ae53b3c",
"type": "CHEM_SPEC"
},
{
"name": "irr__abb66d47-34f9-45f9-92bb-31cd85e45985",
"type": "CHEM_SPEC"
},
{
"name": "irr__b0127bc4-3658-4b92-938d-cf22e8576c5d",
"type": "CHEM_SPEC"
},
{
"name": "irr__ffa95a94-fc71-4629-905e-cbc7119235d8",
"type": "CHEM_SPEC"
}
]
}
Loading

0 comments on commit 4d4f1ef

Please sign in to comment.