Beispiel #1
0
    def set_initial_conditions(self, q_initial_value_list: List[float], p_initial_value_list: List[float]):
        """
        Set the initial conditions for the integrator.
        :param q_initial_value_list:  List of initial q values.
        :param p_initial_value_list: List of initial v = $\dot{q}$ values.
        """

        Assertions.assert_list_of_floats(q_initial_value_list, 'Initial q values')
        Assertions.assert_dimensions_match(self.q_list, 'q variables', q_initial_value_list, 'Initial q values')

        Assertions.assert_list_of_floats(p_initial_value_list, 'Initial p values')
        Assertions.assert_dimensions_match(self.q_list, 'q variables', p_initial_value_list, 'Initial p values')

        self.q_initial_value_list = q_initial_value_list
        self.p_initial_value_list = p_initial_value_list
Beispiel #2
0
    def test_assert_list_of_floats(self):
        # Array of strings should pass
        Assertions.assert_list_of_floats([1.0, 2.0, 3.0], 'list of floats')

        # Array including integers should fail
        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_floats(['a', 1],
                                             'list including integer')

        # Array including lists should fail
        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_floats([1.0, [2.0]],
                                             'list with nested list')

        # Passing any type other than a list to the assertion should throw an error
        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_floats('yeet', 'a string')

        with self.assertRaises(AssertionError):
            Assertions.assert_list_of_floats(1, 2)