def test_integration_second_basis_model_problem_rhs_subdomain_integration(): k = 2 triangle = np.array([[0, 0], [1, 0], [0, 1]]) b_num = SplineSpace(triangle, 2).basis()[2] triangle_2 = ps12_sub_triangles(triangle)[k] expected_integral = 188.32704191224434 def f(p): """ The exact source term for the model problem for the biharmonic equation. """ x, y = p[:, 0], p[:, 1] return 8 * np.pi**4 * ( np.sin(2 * np.pi * x) - 8 * np.sin(4 * np.pi * x) + 25 * np.sin(2 * np.pi * (x - 2 * y)) - 32 * np.sin(4 * np.pi * (x - y)) - np.sin(2 * np.pi * y) + 8 * (np.sin(4 * np.pi * y) + np.sin(2 * np.pi * (-x + y))) + 25 * np.sin(4 * np.pi * x - 2 * np.pi * y)) def integrand(p): return b_num(p.T) * f(p.T) sub_triangles = ps12_sub_triangles(triangle_2) computed_integral = 0 for sub_triangle in sub_triangles: computed_integral += quadpy.triangle.integrate( integrand, sub_triangle, quadpy.triangle.XiaoGimbutas(12)) np.testing.assert_almost_equal(computed_integral, expected_integral)
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, mesh): """ Initializes a Composite C^1 spline space over the given mesh. :param mesh: """ self.mesh = mesh self.dimension = 3*len(mesh.vertices) + len(mesh.edges) self.local_to_global_map, self.dof_to_edge_map, self.dof_to_vertex_map = local_to_global(mesh.vertices, mesh.triangles) self.local_spline_spaces = [SplineSpace(mesh.vertices[triangle], degree=2) for triangle in mesh.triangles] self.local_spline_bases = [S.hermite_basis() for S in self.local_spline_spaces] self._construct_basis_to_triangle_map() self._construct_global_to_local_map() self._construct_interior_and_boundary_dofs() self.basis = [self._construct_global_basis_function(i) for i in range(self.dimension)]
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)