Skip to content

Commit

Permalink
Fixed bugs with chapman example (#148)
Browse files Browse the repository at this point in the history
* does not add rel tolerance to species list

* updates m according to temp and pressure

* commented out concentration array override

* changed Type to type

* removes unecessary code
  • Loading branch information
alexjamesgarza authored Apr 12, 2024
1 parent d77109b commit 4afde18
Show file tree
Hide file tree
Showing 11 changed files with 2,400 additions and 126 deletions.
30 changes: 17 additions & 13 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ def generateSpeciesConfig(self):
speciesArray = []

#Adds relative tolerance if value is set
# if(self.species_list.relative_tolerance != None):
# relativeTolerance = {}
# relativeTolerance["Type"] = "RELATIVE_TOLERANCE"
# relativeTolerance["value"] = self.species_list.relative_tolerance
# speciesArray.append(relativeTolerance)
if(self.species_list.relative_tolerance != None):
relativeTolerance = {}
relativeTolerance["type"] = "RELATIVE_TOLERANCE"
relativeTolerance["value"] = self.species_list.relative_tolerance
speciesArray.append(relativeTolerance)

#Adds species to config
for species in self.species_list.species:
Expand Down Expand Up @@ -420,6 +420,7 @@ def solve(self, path_to_output = None):

rate_constant_ordering = musica.user_defined_reaction_rates(self.solver)
species_constant_ordering = musica.species_ordering(self.solver)


#adds species headers to output
ordered_species_headers = [k for k, v in sorted(species_constant_ordering.items(), key=lambda item: item[1])]
Expand All @@ -428,6 +429,7 @@ def solve(self, path_to_output = None):

ordered_concentrations = self.order_species_concentrations(curr_conditions, species_constant_ordering)
ordered_rate_constants = self.order_reaction_rates(curr_conditions, rate_constant_ordering)


output_array.append(headers)

Expand All @@ -453,28 +455,30 @@ def solve(self, path_to_output = None):
#iterates evolvings conditons if enough time has elapsed
while(next_conditions != None and next_conditions_time <= curr_time):

#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):
next_conditions_index += 1
next_conditions = self.evolving_conditions.conditions[next_conditions_index]
next_conditions_time = self.evolving_conditions.times[next_conditions_index]


#overrides concentrations if specified by conditions
if(len(curr_conditions.get_concentration_array()) != 0):
ordered_concentrations = self.order_species_concentrations(curr_conditions, species_constant_ordering)

ordered_rate_constants = self.order_reaction_rates(curr_conditions, rate_constant_ordering)

else:
next_conditions = None


#updates M accordingly
if 'M' in species_constant_ordering:
BOLTZMANN_CONSTANT = 1.380649e-23
AVOGADRO_CONSTANT = 6.02214076e23;
GAS_CONSTANT = BOLTZMANN_CONSTANT * AVOGADRO_CONSTANT
ordered_concentrations[species_constant_ordering['M']] = curr_conditions.pressure / (GAS_CONSTANT * curr_conditions.temperature)

#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, ordered_concentrations, ordered_rate_constants)




Expand Down Expand Up @@ -582,13 +586,13 @@ def order_reaction_rates(self, curr_conditions, rate_constant_ordering):
@classmethod
def order_species_concentrations(self, curr_conditions, species_constant_ordering):
concentrations = {}

for concentraton in curr_conditions.species_concentrations:
concentrations[concentraton.species.name] = concentraton.concentration

ordered_concentrations = len(concentrations.keys()) * [0.0]

for key, value in concentrations.items():

ordered_concentrations[species_constant_ordering[key]] = value
return ordered_concentrations

Expand Down
7 changes: 4 additions & 3 deletions src/acom_music_box/music_box_species_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SpeciesList:
relativeTolerance (float): The relative tolerance for the species list.
"""

def __init__(self, species=None, relative_tolerance=0.0):
def __init__(self, species=None, relative_tolerance=1.0e-4):
"""
Initializes a new instance of the SpeciesList class.
Expand Down Expand Up @@ -66,8 +66,9 @@ def from_config_JSON(cls, path_to_json, config_JSON):
species_data = json.load(species_file)
#loads species by names from camp files
for properties in species_data['camp-data']:
name = properties.get('name')
species_from_json.append(Species(name, None, None, None, None))
if properties.get('name') is not None:
name = properties.get('name')
species_from_json.append(Species(name, None, None, None, None))


#chceks if species are in the config file and updates attributes accordingly
Expand Down
Loading

0 comments on commit 4afde18

Please sign in to comment.