def test_tet(order): celltype = basix.CellType.tetrahedron g = sympy_rt(celltype, order) x = sympy.Symbol("x") y = sympy.Symbol("y") z = sympy.Symbol("z") rt = basix.create_element(basix.ElementFamily.RT, basix.CellType.tetrahedron, order) pts = basix.create_lattice(celltype, 5, basix.LatticeType.equispaced, True) nderiv = 1 wtab = rt.tabulate(nderiv, pts) for kx in range(nderiv + 1): for ky in range(nderiv + 1 - kx): for kz in range(nderiv + 1 - kx - ky): wsym = numpy.zeros_like(wtab[0]) for i, gi in enumerate(g): for j, gij in enumerate(gi): wd = sympy.diff(gij, x, kx, y, ky, z, kz) for k, p in enumerate(pts): wsym[k, i, j] = wd.subs([(x, p[0]), (y, p[1]), (z, p[2])]) assert (numpy.isclose(wtab[basix.index(kx, ky, kz)], wsym).all())
def test_tensor_product_factorisation(cell_type, degree, element_type, element_args): element = basix.create_element(element_type, cell_type, degree, *element_args) tdim = len(basix.topology(cell_type)) - 1 # These elements should have a factorisation if cell_type in [basix.CellType.quadrilateral, basix.CellType.hexahedron] and element_type in [ basix.ElementFamily.P ] and basix.LagrangeVariant.equispaced in element_args: assert element.has_tensor_product_factorisation if not element.has_tensor_product_factorisation: with pytest.raises(RuntimeError): element.get_tensor_product_representation() pytest.skip() factors = element.get_tensor_product_representation() lattice = basix.create_lattice(cell_type, 1, basix.LatticeType.equispaced, True) tab1 = element.tabulate(1, lattice) for i, point in enumerate(lattice): for ds in product(range(2), repeat=tdim): if sum(ds) > 1: continue deriv = basix.index(*ds) values1 = tab1[deriv, i, :, :] values2 = np.empty((element.dim, 1)) for fs, perm in factors: evals = [ e.tabulate(d, [p])[d, 0, :, 0] for e, p, d in zip(fs, point, ds) ] tab2 = tensor_product(*evals) for a, b in enumerate(perm): if b != -1: values2[b, 0] = tab2[a] assert np.allclose(values1, values2)
def test_tri(order): celltype = basix.CellType.triangle g = sympy_nedelec(celltype, order) x = sympy.Symbol("x") y = sympy.Symbol("y") nedelec = basix.create_element(basix.ElementFamily.N1E, basix.CellType.triangle, order) pts = basix.create_lattice(celltype, 6, basix.LatticeType.equispaced, True) nderiv = 3 wtab = nedelec.tabulate(nderiv, pts) for kx in range(nderiv + 1): for ky in range(nderiv + 1 - kx): wsym = numpy.zeros_like(wtab[0]) for i, gi in enumerate(g): for j, gij in enumerate(gi): wd = sympy.diff(gij, x, kx, y, ky) for k, p in enumerate(pts): wsym[k, i, j] = wd.subs([(x, p[0]), (y, p[1])]) assert(numpy.isclose(wtab[basix.index(kx, ky)], wsym).all())
def test_tri(degree): celltype = basix.CellType.triangle g = sympy_lagrange(celltype, degree) x = sympy.Symbol("x") y = sympy.Symbol("y") lagrange = basix.create_element(basix.ElementFamily.P, basix.CellType.triangle, degree, basix.LagrangeVariant.equispaced) pts = basix.create_lattice(celltype, 6, basix.LatticeType.equispaced, True) nderiv = 3 wtab = lagrange.tabulate(nderiv, pts) for kx in range(nderiv): for ky in range(0, nderiv - kx): wsym = numpy.zeros_like(wtab[0]) for i in range(len(g)): wd = sympy.diff(g[i], x, kx, y, ky) for j, p in enumerate(pts): wsym[j, i] = wd.subs([(x, p[0]), (y, p[1])]) assert numpy.allclose(wtab[basix.index(kx, ky)], wsym)
def test_tet(degree): celltype = basix.CellType.tetrahedron g = sympy_lagrange(celltype, degree) x = sympy.Symbol("x") y = sympy.Symbol("y") z = sympy.Symbol("z") lagrange = basix.create_element(basix.ElementFamily.P, basix.CellType.tetrahedron, degree, basix.LagrangeVariant.equispaced) pts = basix.create_lattice(celltype, 6, basix.LatticeType.equispaced, True) nderiv = 1 wtab = lagrange.tabulate(nderiv, pts) for k in range(nderiv + 1): for q in range(k + 1): for kx in range(q + 1): ky = q - kx kz = k - q wsym = numpy.zeros_like(wtab[0]) for i in range(len(g)): wd = sympy.diff(g[i], x, kx, y, ky, z, kz) for j, p in enumerate(pts): wsym[j, i] = wd.subs([(x, p[0]), (y, p[1]), (z, p[2])]) assert numpy.allclose(wtab[basix.index(kx, ky, kz)], wsym)
def basix_index(*args): """Get the Basix index of a derivative.""" return basix.index(*args)
def basix_index(*args): return basix.index(*args)