Skip to content

Commit

Permalink
Merge pull request #26 from alan-turing-institute/18-KorakianitisMM-a…
Browse files Browse the repository at this point in the history
…dd-comments

18-KorakianitisMM-add-comments
  • Loading branch information
LevanBokeria authored Feb 12, 2025
2 parents 5f749dc + b60c1a7 commit 8593a1f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tests/test_KorakianitisMixedModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@
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,
'tcycle': 1.0,
'dt': 0.001,
'export_min': 1
}
# 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)
# 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 (<V>), pressure (<P_i>) and flow (<Q_i>)
for key, value in self.model.components.items():
self.initial_values[key] = {
'V': value.V.values[self.tind_init].mean(),
Expand All @@ -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 <KorakianitisMixedModel>
self.assertIsInstance(self.model, KorakianitisMixedModel)
# Verify model has attribute <components>
self.assertTrue(hasattr(self.solver.model, 'components'))
# Verify <lv> 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 <solver> is an instance of <Solver>
self.assertIsInstance(self.solver, Solver)
# Verify the instance of <model> that is an atribute of <solver> is the same as the original <model>
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():

Expand Down

0 comments on commit 8593a1f

Please sign in to comment.