diff --git a/src/acom_music_box/main.py b/src/acom_music_box/main.py index 9e1c7f8e..f53010c1 100644 --- a/src/acom_music_box/main.py +++ b/src/acom_music_box/main.py @@ -151,13 +151,8 @@ def main(): # Create and load a MusicBox object myBox = MusicBox() logger.debug(f"Configuration file = {musicBoxConfigFile}") - myBox.readConditionsFromJson(musicBoxConfigFile) + myBox.loadJson(musicBoxConfigFile) - # Create solver and solve - config_path = os.path.join( - os.path.dirname(musicBoxConfigFile), - myBox.config_file) - myBox.create_solver(config_path) result = myBox.solve(musicBoxOutputPath) if musicBoxOutputPath is None: diff --git a/src/acom_music_box/music_box.py b/src/acom_music_box/music_box.py index be34c57e..561693cf 100644 --- a/src/acom_music_box/music_box.py +++ b/src/acom_music_box/music_box.py @@ -69,26 +69,6 @@ def add_evolving_condition(self, time_point, conditions): time=[time_point], conditions=[conditions]) self.evolvingConditions.append(evolving_condition) - def create_solver( - self, - path_to_config, - solver_type=musica.micmsolver.rosenbrock, - number_of_grid_cells=1): - """ - Creates a micm solver object using the CAMP configuration files. - - Args: - path_to_config (str): The path to CAMP configuration directory. - - Returns: - None - """ - # Create a solver object using the configuration file - self.solver = musica.create_solver( - path_to_config, - solver_type, - number_of_grid_cells) - def solve(self, output_path=None, callback=None): """ Solves the box model simulation and optionally writes the output to a file. @@ -246,13 +226,13 @@ def solve(self, output_path=None, callback=None): return df - def readConditionsFromJson(self, path_to_json): + def loadJson(self, path_to_json): """ - Reads and parses a JSON file from the CAMP JSON file to set up the box model simulation. + Reads and parses a JSON file and create a solver Args: path_to_json (str): The JSON path to the JSON file. - + Returns: None @@ -279,6 +259,17 @@ def readConditionsFromJson(self, path_to_json): # Set initial conditions self.evolving_conditions = EvolvingConditions.from_config_JSON( path_to_json, data, self.species_list, self.reaction_list) + + camp_path = os.path.join( + os.path.dirname(path_to_json), + self.config_file) + + # Creates a micm solver object using the CAMP configuration files. + self.solver = musica.create_solver( + camp_path, + musica.micmsolver.rosenbrock, + 1) + def speciesOrdering(self): """ diff --git a/tests/integration/test_analytical.py b/tests/integration/test_analytical.py index b1bf43fe..7a293bcd 100644 --- a/tests/integration/test_analytical.py +++ b/tests/integration/test_analytical.py @@ -8,15 +8,9 @@ class TestAnalytical: def test_run(self): box_model = MusicBox() - # configures box model conditions_path = Examples.Analytical.path - box_model.readConditionsFromJson(conditions_path) - camp_path = os.path.join( - os.path.dirname(conditions_path), - box_model.config_file) - - box_model.create_solver(camp_path) + box_model.loadJson(conditions_path) # solves and saves output df = box_model.solve() diff --git a/tests/integration/test_carbon_bond_5.py b/tests/integration/test_carbon_bond_5.py index cc90b64d..5676dc25 100644 --- a/tests/integration/test_carbon_bond_5.py +++ b/tests/integration/test_carbon_bond_5.py @@ -8,16 +8,10 @@ class TestCarbonBond5: def test_run(self): box_model = MusicBox() - - # configures box model + conditions_path = Examples.CarbonBond5.path - box_model.readConditionsFromJson(conditions_path) - - camp_path = os.path.join( - os.path.dirname(conditions_path), - box_model.config_file) - box_model.create_solver(camp_path) + box_model.loadJson(conditions_path) # solves and saves output df = box_model.solve() diff --git a/tests/integration/test_chapman.py b/tests/integration/test_chapman.py index 930fa393..c2b68241 100644 --- a/tests/integration/test_chapman.py +++ b/tests/integration/test_chapman.py @@ -9,15 +9,9 @@ class TestChapman: def test_run(self): box_model = MusicBox() - # configures box model conditions_path = Examples.Chapman.path - box_model.readConditionsFromJson(conditions_path) - - camp_path = os.path.join( - os.path.dirname(conditions_path), - box_model.config_file) - - box_model.create_solver(camp_path) + + box_model.loadJson(conditions_path) # solves and saves output df = box_model.solve() diff --git a/tests/integration/test_flow_tube.py b/tests/integration/test_flow_tube.py index 3e00a3e1..cf47fd79 100644 --- a/tests/integration/test_flow_tube.py +++ b/tests/integration/test_flow_tube.py @@ -9,16 +9,10 @@ class TestWallLoss: def test_run(self): box_model = MusicBox() - # configures box model conditions_path = Examples.FlowTube.path - box_model.readConditionsFromJson(conditions_path) - - camp_path = os.path.join( - os.path.dirname(conditions_path), - box_model.config_file) - - box_model.create_solver(camp_path) + box_model.loadJson(conditions_path) + # solves and saves output df = box_model.solve() model_output = [df.columns.values.tolist()] + df.values.tolist() diff --git a/tests/unit/test_callback.py b/tests/unit/test_callback.py index ade31847..7e8966ab 100644 --- a/tests/unit/test_callback.py +++ b/tests/unit/test_callback.py @@ -11,13 +11,8 @@ def test_run(self, mocker): box_model = MusicBox() conditions_path = Examples.Analytical.path - box_model.readConditionsFromJson(conditions_path) - - camp_path = os.path.join( - os.path.dirname(conditions_path), - box_model.config_file) - - box_model.create_solver(camp_path) + + box_model.loadJson(conditions_path) # Mock the callback function callback_mock = mocker.Mock(side_effect=callback)