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 __init__(self, triangle, knot_multiplicities): self.triangle = triangle self.knot_multiplicities = knot_multiplicities + (10 - len(knot_multiplicities)) * [0] self.knot_indices = [i for i in range(len(knot_multiplicities)) if knot_multiplicities[i] != 0] self.face_indices = KNOT_CONFIGURATION_TO_FACE_INDICES[tuple(self.knot_indices)] self.degree = sum(knot_multiplicities) - 3 self.polynomial_pieces = polynomial_pieces(triangle, knot_multiplicities)
def test_polynomial_pieces_quadratic_basis(): X, Y = symbols('X Y') triangle = np.array([[0, 0], [1, 0], [0, 1]]) # knot multiplicities corresponding to the first quadratic basis function multiplicities = KNOT_MULTIPLICITIES_QUADRATIC[0] expected_polynomials = [ 1.0 * (-2.0 * X - 2.0 * Y + 1)**2, 1.0 * (-2.0 * X - 2.0 * Y + 1)**2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] computed_polynomials = polynomial_pieces(triangle, multiplicities) for e, c in zip(expected_polynomials, computed_polynomials): np.testing.assert_almost_equal(simplify(e - c), 0)
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]))
def test_integration_second_basis_second_triangle(): x, y = sp.symbols('X Y') k = 2 triangle = np.array([[0, 0], [1, 0], [0, 1]]) b_sym = polynomial_pieces(triangle, KNOT_MULTIPLICITIES_QUADRATIC[2])[k] b_num = SplineSpace(triangle, 2).basis()[2] triangle_2 = ps12_sub_triangles(triangle)[k] expected_integral = 0.0117187 b, w = gaussian_quadrature_data(2) b_sym_num = sp.lambdify((x, y), b_sym) def f(p): return b_num(p.T) computed_integral = gaussian_quadrature(triangle_2, b_num, b, w) computed_integral = quadpy.triangle.integrate(f, triangle_2, quadpy.triangle.SevenPoint()) np.testing.assert_almost_equal(computed_integral, expected_integral)