Exemplo n.º 1
0
def test_values_quadratic_basis():
    """
    tests that the polynomial pieces and the numerical splines evaluate to the same value over all the
    subtriangles.
    """
    X, Y = sy.symbols('X Y')

    triangle = np.array([[0, 0], [1, 0], [0, 1]])

    S = SplineSpace(triangle, 2)

    for basis_num in range(12):
        b_num = S.basis()[basis_num]
        b_sym = polynomial_pieces(triangle,
                                  KNOT_MULTIPLICITIES_QUADRATIC[basis_num])

        subtriangles = ps12_sub_triangles(triangle)

        for k in range(12):
            t = subtriangles[k]
            points = sample_triangle(t, 1)
            num_b_sym = sy.lambdify([X, Y], b_sym[k])

            for p in points:
                np.testing.assert_almost_equal(b_num(p), num_b_sym(p[0], p[1]))
def test_laplacian_quadratic_basis_functions():
    X, Y = sy.symbols('X Y')

    triangle = np.array([[0, 0], [1, 0], [0, 1]])

    S = SplineSpace(triangle, 2)
    points = sample_triangle(triangle, 10)
    for basis_num in range(12):
        b_num = S.basis()[basis_num]
        b_sym = polynomial_pieces(triangle,
                                  KNOT_MULTIPLICITIES_QUADRATIC[basis_num])

        for p in points:
            b = barycentric_coordinates(triangle, p)
            k = determine_sub_triangle(b)[0]
            b_lapl = sy.diff(b_sym[k], X, X) + sy.diff(b_sym[k], Y, Y)
            num_b_sym = sy.lambdify([X, Y], b_lapl)
            np.testing.assert_almost_equal(b_num.lapl(p),
                                           num_b_sym(p[0], p[1]))