def test_change_of_basis_matrix_linear(): knots = [[0, 0, 1 / 3, 2 / 3, 1, 1]] d = [1] dim = 1 T = HierarchicalSpace(knots, d, dim) cells = {0: [1]} T = refine(T, cells) C = T.get_basis_conversion_matrix(0) np.testing.assert_allclose( C.toarray(), np.array([[1, 0, 0, 0], [0.5, 0.5, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0.5, 0.5], [0, 0, 0, 1]]))
def create_subdivision_matrix(hspace: HierarchicalSpace) -> dict: """ Returns hspace.nlevels-1 matrices used for representing coarse B-splines in terms of the finer B-splines. :param hspace: HierarchicalSpace containing the needed information :return: a dictionary mapping """ mesh = hspace.mesh C = {} C[0] = sp.identity(hspace.spaces[0].nfuncs, format='lil') C[0] = C[0][:, hspace.afunc_level[0]] for level in range(1, hspace.nlevels): I = sp.identity(hspace.spaces[level].nfuncs, format='lil') aux = sp.lil_matrix(hspace.get_basis_conversion_matrix(level - 1)) C[level] = sp.hstack( [aux @ C[level - 1], I[:, hspace.afunc_level[level]]]) return C