Example #1
0
    def test_local_stencil_operator_multiplication(self):
        x = np.linspace(0, 10, 101)
        y = np.linspace(0, 10, 101)
        X, Y = np.meshgrid(x, y, indexing='ij')
        u = X * Y
        dx = x[1] - x[0]
        dy = y[1] - y[0]
        d1x = FinDiff(0, dx) * FinDiff(1, dy)
        stencil1 = d1x.stencil(u.shape)
        du_dx = stencil1.apply_all(u)

        np.testing.assert_array_almost_equal(np.ones_like(X), du_dx)
Example #2
0
    def test_local_stencil_single_axis_center_2d_compared_with_findiff(self):
        n = 70
        (X, Y), _, (dx, dy) = grid(2, n, -1, 1)

        u = X**3 * Y**3

        d4_dx2dy2 = FinDiff(1, dx, 2)
        expected = d4_dx2dy2(u)

        stl = d4_dx2dy2.stencil(u.shape)

        actual = stl.apply_all(u)

        np.testing.assert_array_almost_equal(expected, actual)
Example #3
0
    def test_local_stencil_operator_addition(self):

        n = 100
        (X, Y), _, (dx, dy) = grid(2, n, -1, 1)

        u = X**3 + Y**3

        d = FinDiff(0, dx, 2) + FinDiff(1, dy, 2)
        expected = d(u)

        stl = d.stencil(u.shape)

        actual = stl.apply_all(u)
        np.testing.assert_array_almost_equal(expected, actual)
Example #4
0
    def test_local_stencil_single_axis_center_1d(self):

        x = np.linspace(0, 1, 50)
        dx = x[1] - x[0]
        u = x**3
        d2_dx2 = FinDiff((0, dx, 2))

        stl = d2_dx2.stencil(u.shape)
        idx = 5
        actual = stl.apply(u, idx)

        d2u_dx2 = d2_dx2(u)
        expected = d2u_dx2[idx]

        self.assertAlmostEqual(expected, actual)

        actual = stl.apply_all(u)
        expected = d2u_dx2

        np.testing.assert_array_almost_equal(expected, actual)