From 8fd171cc52f2c910c917d454132ebe4b49862c09 Mon Sep 17 00:00:00 2001 From: MaxBalmus Date: Wed, 12 Feb 2025 11:22:38 +0000 Subject: [PATCH 1/2] A first version of the comments. --- tests/test_KorakianitisMixedModel.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/test_KorakianitisMixedModel.py b/tests/test_KorakianitisMixedModel.py index c1da966..0dc99b6 100644 --- a/tests/test_KorakianitisMixedModel.py +++ b/tests/test_KorakianitisMixedModel.py @@ -9,6 +9,7 @@ class TestKorakianitisMixedModel(unittest.TestCase): def setUp(self): + # Define the duration of the simulation (no of cycles), duration of the cycle, maximum time step size, and minimum number of cycles to run self.time_setup_dict = { 'name': 'TimeTest', 'ncycles': 40, @@ -16,16 +17,22 @@ def setUp(self): 'dt': 0.001, 'export_min': 1 } + # Initializing the parameter objecty self.parobj = KorakianitisMixedModel_parameters() + # Initializing the model self.model = KorakianitisMixedModel(time_setup_dict=self.time_setup_dict, parobj=self.parobj, suppress_printing=True) + # Initializing the solver self.solver = Solver(model=self.model) + # Solver is being setup: switching off console printing and setting the solver method to "LSODA" self.solver.setup(suppress_output=True, method='LSODA') self.initial_values = {} + # Define the indexes of the equivalent to the last cycles self.tind_init = np.arange(start=self.model.time_object.n_t-self.model.time_object.n_c * self.model.time_object.export_min, stop =self.model.time_object.n_t) + # From each of the components, retrieve the volume (), pressure () and flow () for key, value in self.model.components.items(): self.initial_values[key] = { 'V': value.V.values[self.tind_init].mean(), @@ -38,24 +45,41 @@ def setUp(self): self.expected_values = json.load(f) def test_model_initialization(self): + ''' + Testing the initialization of the solver, model and parameter objects. + ''' + # Verify model is an instance of self.assertIsInstance(self.model, KorakianitisMixedModel) + # Verify model has attribute self.assertTrue(hasattr(self.solver.model, 'components')) + # Verify is a component self.assertIn('lv', self.solver.model.components) + # Verify correct assignment of parameters from parobj to model self.assertEqual(self.solver.model.components['lv'].E_pas, self.parobj.components['lv']['E_pas']) self.assertEqual(self.solver.model.components['ao'].CQ, self.parobj.components['ao']['CQ']) def test_solver_initialization(self): + # Verify is an instance of self.assertIsInstance(self.solver, Solver) + # Verify the instance of that is an atribute of is the same as the original self.assertEqual(self.solver.model, self.model) def test_solver_run(self): + ''' + Testing running the solver: all the components (their associated equations) are assembled within a system. The system + of equations is then passed to solve_ivp (retrieved from scipy). + ''' + + # Running the model self.solver.solve() + # Verifying the model changed the state variables stored within components. self.assertTrue(len(self.solver.model.components['lv'].V.values) > 0) self.assertTrue(len(self.solver.model.components['lv'].P_i.values) > 0) - + # Redefine tind based on how many heart cycle have actually been necessary to reach steady state self.tind_fin = np.arange(start=self.model.time_object.n_t-self.model.time_object.n_c * self.model.time_object.export_min, stop=self.model.time_object.n_t) - + # Retrieve the component state variables, compute the mean of the values during the last cycle and store them within + # the new solution dictionary new_dict = {} for key, value in self.model.components.items(): From b60c1a7f7cff4a24e68c4a0d8665f9f7ea3d68a5 Mon Sep 17 00:00:00 2001 From: Levan Bokeria Date: Wed, 12 Feb 2025 12:22:53 +0000 Subject: [PATCH 2/2] minor typo --- tests/test_KorakianitisMixedModel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_KorakianitisMixedModel.py b/tests/test_KorakianitisMixedModel.py index 0dc99b6..439bcb2 100644 --- a/tests/test_KorakianitisMixedModel.py +++ b/tests/test_KorakianitisMixedModel.py @@ -17,7 +17,7 @@ def setUp(self): 'dt': 0.001, 'export_min': 1 } - # Initializing the parameter objecty + # Initializing the parameter object self.parobj = KorakianitisMixedModel_parameters() # Initializing the model self.model = KorakianitisMixedModel(time_setup_dict=self.time_setup_dict, parobj=self.parobj, suppress_printing=True)