Beispiel #1
0
    def test_midpoint(self):
        """ A_numerical should be approximately equal to A_analytical """
        self.parameters["method"] = "MIDPOINT"

        self.parameters["total_steps"] = 50
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_equal(A_numerical, 0.71663952968427402)

        self.parameters["total_steps"] = 500
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_equal(A_numerical, 0.71669512731047913)
Beispiel #2
0
    def test_bs(self):
        """ A_numerical should be approximately equal to A_analytical """
        self.parameters["method"] = "BS"

        self.parameters["total_steps"] = 50
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_equal(A_numerical, 0.71669591977945657)

        self.parameters["total_steps"] = 500
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_equal(A_numerical, 0.71669567831028291)
Beispiel #3
0
    def test_euler(self):
        """ A_numerical should be approximately equal to A_analytical """
        self.parameters["method"] = "EULER"

        self.parameters["total_steps"] = 50
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_equal(A_numerical, 0.72152686293820223)

        self.parameters["total_steps"] = 500
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_equal(A_numerical, 0.71717199224362427)
Beispiel #4
0
    def test_dp(self):
        """ A_numerical should be approximately equal to A_analytical """
        self.parameters["method"] = "DP"

        self.parameters["total_steps"] = 50
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_almost_equal(A_numerical, self.A_analytical)
        assert_equal(A_numerical, 0.71669567807314427)

        self.parameters["total_steps"] = 500
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_almost_equal(A_numerical, self.A_analytical)
        assert_equal(A_numerical, 0.71669567807368462)
Beispiel #5
0
    def test_rk4(self):
        """ A_numerical should be approximately equal to A_analytical """
        self.parameters["method"] = "RK4"

        self.parameters["total_steps"] = 50
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_almost_equal(A_numerical, self.A_analytical)
        assert_equal(A_numerical, 0.71669567757603803)

        self.parameters["total_steps"] = 500
        stepper = Stepper(**self.parameters)
        A_numerical = stepper(self.A_initial)
        assert_almost_equal(A_numerical, self.A_analytical)
        assert_equal(A_numerical, 0.71669567807363854)
Beispiel #6
0
    def test_rk4ip(self):
        """ Test Runge-kutta in the interaction picture. """
        self.parameters["method"] = "RK4IP"
        stepper = Stepper(**self.parameters)
        A_out = stepper(self.A_in)

        assert_almost_equal(max(np.abs(A_out) ** 2), self.P_analytical, 5)
Beispiel #7
0
    def test_ss_sym_rk4(self):
        """ Test symmetric splitstep with Runge-Kutta method. """
        self.parameters["method"] = "SS_SYM_RK4"
        stepper = Stepper(**self.parameters)
        A_out = stepper(self.A_in)

        assert_almost_equal(max(np.abs(A_out) ** 2), self.P_analytical, 3)
Beispiel #8
0
    def test_ss_sym_midpoint(self):
        """ Test symmetric splitstep with midpoint method. """
        self.parameters["method"] = "SS_SYM_MIDPOINT"
        stepper = Stepper(**self.parameters)
        A_out = stepper(self.A_in)

        assert_almost_equal(max(np.abs(A_out) ** 2), self.P_analytical, 2)
Beispiel #9
0
    def test_ss_agrawal(self):
        """ Test splitstep Agrawal method. """
        self.parameters["method"] = "SS_AGRAWAL"
        stepper = Stepper(**self.parameters)
        A_out = stepper(self.A_in)

        assert_almost_equal(max(np.abs(A_out) ** 2), self.P_analytical, 4)
Beispiel #10
0
    def test_ss_reduced(self):
        """ Test reduced splitstep method. """
        self.parameters["method"] = "SS_REDUCED"
        stepper = Stepper(**self.parameters)
        A_out = stepper(self.A_in)

        assert_almost_equal(max(np.abs(A_out) ** 2), self.P_analytical, 3)
Beispiel #11
0
    def test_ss_symmetric(self):
        """ Test symmetric splitstep method. """
        self.parameters["method"] = "SS_SYMMETRIC"
        stepper = Stepper(**self.parameters)
        A_out = stepper(self.A_in)

        assert_almost_equal(max(np.abs(A_out) ** 2), self.P_analytical, 0)
Beispiel #12
0
    def test_ss_simple(self):
        """ Test simple splitstep method. """
        self.parameters["method"] = "SS_SIMPLE"
        stepper = Stepper(**self.parameters)
        A_out = stepper(self.A_in)

        assert_almost_equal(max(np.abs(A_out) ** 2), self.P_analytical, 3)
Beispiel #13
0
    def test_default(self):
        """ Should use default values (except for f) """
        stepper = Stepper(f=self.default_function)

        self.assertEqual(stepper.traces, 1)
        self.assertEqual(stepper.local_error, 1e-6)
        self.assertEqual(stepper.method, "RK4")
        self.assertEqual(stepper.length, 1.0)
        self.assertEqual(stepper.total_steps, 100)
        self.assertEqual(stepper.adaptive, False)