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

Fixed bugs with chapman example #148

Merged
merged 5 commits into from
Apr 12, 2024
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
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
Loading