Ejemplo n.º 1
0
    def test_accuracy02(self):
        N = 2**10
        t = np.linspace(0, 1, num=N)
        y0 = np.array([1.0, 1.0]).T
        exactSol = ExampleFunc02_solution(y0, t)
        # Compute numerical solution:
        solver = BDF6Method(N, y0, [0, 1], ExampleFunc02())
        solution = solver.generate()
        numericSol = []
        for (time, val) in solution:
            numericSol.append(val)

        numericSol = np.array(numericSol).T
        err = np.max(np.abs(exactSol - numericSol))
        self.assertTrue(err < 5.0 * 10**(-13))
Ejemplo n.º 2
0
    def test_accuracy02(self):
        N = 2**14
        t = np.linspace(0, 1, num=N)
        y0 = np.array([1.0, 1.0]).T
        exactSol = ExampleFunc02_solution(y0, t)

        # Compute numerical solution:
        ee_solver = ExplicitEuler(N, y0, [0, 1], ExampleFunc02())
        solution = ee_solver.generate()
        numericSol = []
        for (time, val) in solution:
            numericSol.append(val)

        numericSol = np.array(numericSol).T
        err = np.max(np.abs(exactSol - numericSol))
        print(err)
        self.assertTrue(err < 1.2 * 10**(-5))
Ejemplo n.º 3
0
    def test_accuracy01(self):
        N = 2**6
        t = np.linspace(0, 1, num=N)
        y0 = np.array([1, 1]).T
        exactSol = ExampleFunc02_solution(y0, t).T

        #  Compute Numerical Solution:
        t1 = timedomain.time()
        GaussLegendre_solver = GaussLegendre(N, y0, [0, 1], ExampleFunc02())
        solution = GaussLegendre_solver.generate()
        numericSol = np.zeros_like(exactSol)
        idx = 0
        for (time, val) in solution:
            numericSol[idx, :] = val.T
            idx += 1
        t2 = timedomain.time()
        print(t2 - t1)
        err = np.max(np.abs(exactSol - numericSol))
        #            for i in range(N):
        #               print(np.abs(exactSol[i]-numericSol[i]))
        self.assertTrue(err < 4 * 10**(-7))
Ejemplo n.º 4
0
        def computeErr(N):
            """TODO: Docstring for computeErr.

                :N: Number of gridpoints
                :returns: err in inf norm

                """
            t = np.linspace(0, 1, num=N)
            # y0 = np.sin(np.linspace(-1.0*np.pi, 1.0*np.pi))
            y0 = np.array([1, 1])
            exactSol = ExampleFunc02_solution(y0, t).T
            # Compute numerical solution:
            GL_solver = GaussLegendre(N, y0, [0, 1], ExampleFunc02())
            solution = GL_solver.generate()
            numericSol = np.zeros_like(exactSol)
            idx = 0
            for (time, val) in solution:
                numericSol[idx, :] = val.T
                idx += 1

            err = np.max(np.abs(exactSol - numericSol))
            return err