def components_extractor(model: myokit.Model):
    i = 0
    components = model.components()
    component_iter = components.__iter__()
    component_size = model.count_components()
    while i < component_size:
        a_component = component_iter.__next__()
        if a_component not in components_list:
            components_list.append(a_component)
        i += 1
Beispiel #2
0
 def remove_component(self):
     """
     Tests the removal of a component.
     """
     # Create model
     m = Model('LotkaVolterra')
     # Simplest case
     X = m.add_component('X')
     self.assertEqual(m.count_components(), 1)
     m.remove_component(X)
     self.assertEqual(m.count_components(), 0)
     self.assertRaises(KeyError, m.remove_component, X)
     # Test if orphaned
     self.assertIsNone(X.parent())
     # Re-adding
     self.assertEqual(m.count_components(), 0)
     X = m.add_component('X')
     self.assertEqual(m.count_components(), 1)
     # With internal variables
     a = X.add_variable('a')
     a.set_rhs(Number(4))
     b = X.add_variable('b')
     b.set_rhs(Name(a))
     m.remove_component(X)
     self.assertEqual(m.count_components(), 0)
     # With dependencies from another component
     X = m.add_component('X')
     a = X.add_variable('a')
     a.set_rhs(Number(45))
     b = X.add_variable('b')
     b.set_rhs(Name(b))
     Y = m.add_component('Y')
     c = Y.add_variable('c')
     c.set_rhs(Name(a))
     d = Y.add_variable('d')
     d.set_rhs(Name(c))
     self.assertEqual(m.count_components(), 2)
     self.assertRaises(IntegrityError, m.remove_component, X)
     self.assertEqual(m.count_components(), 2)
     # In the right order...
     m.remove_component(Y)
     self.assertEqual(m.count_components(), 1)
     m.remove_component(X)
     self.assertEqual(m.count_components(), 0)