def extr_cell(request): if request.param == "extr_interval": return TensorProductCell(UFCInterval(), UFCInterval()) elif request.param == "extr_triangle": return TensorProductCell(UFCTriangle(), UFCInterval()) elif request.param == "extr_quadrilateral": return TensorProductCell(UFCQuadrilateral(), UFCInterval())
def test_quad_rtcf(): W0_h = FIAT.Lagrange(UFCInterval(), 1) W1_h = FIAT.DiscontinuousLagrange(UFCInterval(), 0) W0_v = FIAT.DiscontinuousLagrange(UFCInterval(), 0) W0 = FIAT.Hdiv(FIAT.TensorProductElement(W0_h, W0_v)) W1_v = FIAT.Lagrange(UFCInterval(), 1) W1 = FIAT.Hdiv(FIAT.TensorProductElement(W1_h, W1_v)) elem = FIAT.EnrichedElement(W0, W1) assert {0: [0, 1, 2], 1: [0, 1, 3]} == entity_support_dofs(elem, (1, 0)) assert {0: [0, 2, 3], 1: [1, 2, 3]} == entity_support_dofs(elem, (0, 1))
def test_prism_hcurl(space, degree, horiz_expected, vert_expected): W0_h = FIAT.Lagrange(UFCTriangle(), degree) W1_h = FIAT.supported_elements[space](UFCTriangle(), degree) W0_v = FIAT.DiscontinuousLagrange(UFCInterval(), degree - 1) W0 = FIAT.Hcurl(FIAT.TensorProductElement(W0_h, W0_v)) W1_v = FIAT.Lagrange(UFCInterval(), degree) W1 = FIAT.Hcurl(FIAT.TensorProductElement(W1_h, W1_v)) elem = FIAT.EnrichedElement(W0, W1) assert horiz_expected == entity_support_dofs(elem, (2, 0)) assert vert_expected == entity_support_dofs(elem, (1, 1))
def test_TFE_2Dx1D_vector_triangle_hcurl(): S = UFCTriangle() T = UFCInterval() Ned1 = Nedelec(S, 1) P1 = Lagrange(T, 1) elt = Hcurl(TensorProductElement(Ned1, P1)) assert elt.value_shape() == (3, ) tab = elt.tabulate(1, [(0.1, 0.2, 0.3)]) tabA = Ned1.tabulate(1, [(0.1, 0.2)]) tabB = P1.tabulate(1, [(0.3, )]) for da, db in [[(0, 0), (0, )], [(1, 0), (0, )], [(0, 1), (0, )], [(0, 0), (1, )]]: dc = da + db assert np.isclose(tab[dc][0][0][0], tabA[da][0][0][0] * tabB[db][0][0]) assert np.isclose(tab[dc][1][0][0], tabA[da][0][0][0] * tabB[db][1][0]) assert np.isclose(tab[dc][2][0][0], tabA[da][1][0][0] * tabB[db][0][0]) assert np.isclose(tab[dc][3][0][0], tabA[da][1][0][0] * tabB[db][1][0]) assert np.isclose(tab[dc][4][0][0], tabA[da][2][0][0] * tabB[db][0][0]) assert np.isclose(tab[dc][5][0][0], tabA[da][2][0][0] * tabB[db][1][0]) assert np.isclose(tab[dc][0][1][0], tabA[da][0][1][0] * tabB[db][0][0]) assert np.isclose(tab[dc][1][1][0], tabA[da][0][1][0] * tabB[db][1][0]) assert np.isclose(tab[dc][2][1][0], tabA[da][1][1][0] * tabB[db][0][0]) assert np.isclose(tab[dc][3][1][0], tabA[da][1][1][0] * tabB[db][1][0]) assert np.isclose(tab[dc][4][1][0], tabA[da][2][1][0] * tabB[db][0][0]) assert np.isclose(tab[dc][5][1][0], tabA[da][2][1][0] * tabB[db][1][0]) assert tab[dc][0][2][0] == 0.0 assert tab[dc][1][2][0] == 0.0 assert tab[dc][2][2][0] == 0.0 assert tab[dc][3][2][0] == 0.0 assert tab[dc][4][2][0] == 0.0 assert tab[dc][5][2][0] == 0.0
def test_TFE_2Dx1D_vector_triangle_hdiv(): S = UFCTriangle() T = UFCInterval() RT1 = RaviartThomas(S, 1) P1_DG = DiscontinuousLagrange(T, 1) elt = Hdiv(TensorProductElement(RT1, P1_DG)) assert elt.value_shape() == (3, ) tab = elt.tabulate(1, [(0.1, 0.2, 0.3)]) tabA = RT1.tabulate(1, [(0.1, 0.2)]) tabB = P1_DG.tabulate(1, [(0.3, )]) for da, db in [[(0, 0), (0, )], [(1, 0), (0, )], [(0, 1), (0, )], [(0, 0), (1, )]]: dc = da + db assert np.isclose(tab[dc][0][0][0], tabA[da][0][0][0] * tabB[db][0][0]) assert np.isclose(tab[dc][1][0][0], tabA[da][0][0][0] * tabB[db][1][0]) assert np.isclose(tab[dc][2][0][0], tabA[da][1][0][0] * tabB[db][0][0]) assert np.isclose(tab[dc][3][0][0], tabA[da][1][0][0] * tabB[db][1][0]) assert np.isclose(tab[dc][4][0][0], tabA[da][2][0][0] * tabB[db][0][0]) assert np.isclose(tab[dc][5][0][0], tabA[da][2][0][0] * tabB[db][1][0]) assert np.isclose(tab[dc][0][1][0], tabA[da][0][1][0] * tabB[db][0][0]) assert np.isclose(tab[dc][1][1][0], tabA[da][0][1][0] * tabB[db][1][0]) assert np.isclose(tab[dc][2][1][0], tabA[da][1][1][0] * tabB[db][0][0]) assert np.isclose(tab[dc][3][1][0], tabA[da][1][1][0] * tabB[db][1][0]) assert np.isclose(tab[dc][4][1][0], tabA[da][2][1][0] * tabB[db][0][0]) assert np.isclose(tab[dc][5][1][0], tabA[da][2][1][0] * tabB[db][1][0]) assert tab[dc][0][2][0] == 0.0 assert tab[dc][1][2][0] == 0.0 assert tab[dc][2][2][0] == 0.0 assert tab[dc][3][2][0] == 0.0 assert tab[dc][4][2][0] == 0.0 assert tab[dc][5][2][0] == 0.0
def test_TFE_2Dx1D_scalar_quad(): T = UFCInterval() P1 = Lagrange(T, 1) P1_DG = DiscontinuousLagrange(T, 1) elt = TensorProductElement(TensorProductElement(P1, P1_DG), P1) assert elt.value_shape() == () tab = elt.tabulate(1, [(0.1, 0.2, 0.3)]) tA = P1.tabulate(1, [(0.1, )]) tB = P1_DG.tabulate(1, [(0.2, )]) tC = P1.tabulate(1, [(0.3, )]) for da, db, dc in [[(0, ), (0, ), (0, )], [(1, ), (0, ), (0, )], [(0, ), (1, ), (0, )], [(0, ), (0, ), (1, )]]: dd = da + db + dc assert np.isclose(tab[dd][0][0], tA[da][0][0] * tB[db][0][0] * tC[dc][0][0]) assert np.isclose(tab[dd][1][0], tA[da][0][0] * tB[db][0][0] * tC[dc][1][0]) assert np.isclose(tab[dd][2][0], tA[da][0][0] * tB[db][1][0] * tC[dc][0][0]) assert np.isclose(tab[dd][3][0], tA[da][0][0] * tB[db][1][0] * tC[dc][1][0]) assert np.isclose(tab[dd][4][0], tA[da][1][0] * tB[db][0][0] * tC[dc][0][0]) assert np.isclose(tab[dd][5][0], tA[da][1][0] * tB[db][0][0] * tC[dc][1][0]) assert np.isclose(tab[dd][6][0], tA[da][1][0] * tB[db][1][0] * tC[dc][0][0]) assert np.isclose(tab[dd][7][0], tA[da][1][0] * tB[db][1][0] * tC[dc][1][0])
def get_line_nodes(V): # Return the Line nodes for Q, DQ, RTCF/E, NCF/E from FIAT.reference_element import UFCInterval from FIAT import quadrature use_tensorproduct, N, ndim, sub_families, variant = tensor_product_space_query( V) assert use_tensorproduct cell = UFCInterval() if variant == "equispaced" and sub_families <= { "Q", "DQ", "Lagrange", "Discontinuous Lagrange" }: return [cell.make_points(1, 0, N + 1)] * ndim elif sub_families <= {"Q", "Lagrange"}: rule = quadrature.GaussLobattoLegendreQuadratureLineRule(cell, N + 1) return [rule.get_points()] * ndim elif sub_families <= {"DQ", "Discontinuous Lagrange"}: rule = quadrature.GaussLegendreQuadratureLineRule(cell, N + 1) return [rule.get_points()] * ndim elif sub_families < {"RTCF", "NCF"}: cg = quadrature.GaussLobattoLegendreQuadratureLineRule(cell, N + 1) dg = quadrature.GaussLegendreQuadratureLineRule(cell, N) return [cg.get_points()] + [dg.get_points()] * (ndim - 1) elif sub_families < {"RTCE", "NCE"}: cg = quadrature.GaussLobattoLegendreQuadratureLineRule(cell, N + 1) dg = quadrature.GaussLegendreQuadratureLineRule(cell, N) return [dg.get_points()] + [cg.get_points()] * (ndim - 1) else: raise ValueError("Don't know how to get line nodes for %s" % V.ufl_element())
def get_line_element(V): # Return the Line elements for Q, DQ, RTCF/E, NCF/E from FIAT.reference_element import UFCInterval from FIAT import gauss_legendre, gauss_lobatto_legendre, lagrange, discontinuous_lagrange use_tensorproduct, N, ndim, sub_families, variant = tensor_product_space_query( V) assert use_tensorproduct cell = UFCInterval() if sub_families <= {"Q", "Lagrange"}: if variant == "equispaced": element = lagrange.Lagrange(cell, N) else: element = gauss_lobatto_legendre.GaussLobattoLegendre(cell, N) element = [element] * ndim elif sub_families <= {"DQ", "Discontinuous Lagrange"}: if variant == "equispaced": element = discontinuous_lagrange.DiscontinuousLagrange(cell, N) else: element = gauss_legendre.GaussLegendre(cell, N) element = [element] * ndim elif sub_families < {"RTCF", "NCF"}: cg = gauss_lobatto_legendre.GaussLobattoLegendre(cell, N) dg = gauss_legendre.GaussLegendre(cell, N - 1) element = [cg] + [dg] * (ndim - 1) elif sub_families < {"RTCE", "NCE"}: cg = gauss_lobatto_legendre.GaussLobattoLegendre(cell, N) dg = gauss_legendre.GaussLegendre(cell, N - 1) element = [dg] + [cg] * (ndim - 1) else: raise ValueError("Don't know how to get line element for %s" % V.ufl_element()) return element
def test_TFE_1Dx1D_vector(): T = UFCInterval() P1_DG = DiscontinuousLagrange(T, 1) P2 = Lagrange(T, 2) elt = TensorProductElement(P1_DG, P2) hdiv_elt = Hdiv(elt) hcurl_elt = Hcurl(elt) assert hdiv_elt.value_shape() == (2, ) assert hcurl_elt.value_shape() == (2, ) tabA = P1_DG.tabulate(1, [(0.1, )]) tabB = P2.tabulate(1, [(0.2, )]) hdiv_tab = hdiv_elt.tabulate(1, [(0.1, 0.2)]) for da, db in [[(0, ), (0, )], [(1, ), (0, )], [(0, ), (1, )]]: dc = da + db assert hdiv_tab[dc][0][0][0] == 0.0 assert hdiv_tab[dc][1][0][0] == 0.0 assert hdiv_tab[dc][2][0][0] == 0.0 assert hdiv_tab[dc][3][0][0] == 0.0 assert hdiv_tab[dc][4][0][0] == 0.0 assert hdiv_tab[dc][5][0][0] == 0.0 assert np.isclose(hdiv_tab[dc][0][1][0], tabA[da][0][0] * tabB[db][0][0]) assert np.isclose(hdiv_tab[dc][1][1][0], tabA[da][0][0] * tabB[db][1][0]) assert np.isclose(hdiv_tab[dc][2][1][0], tabA[da][0][0] * tabB[db][2][0]) assert np.isclose(hdiv_tab[dc][3][1][0], tabA[da][1][0] * tabB[db][0][0]) assert np.isclose(hdiv_tab[dc][4][1][0], tabA[da][1][0] * tabB[db][1][0]) assert np.isclose(hdiv_tab[dc][5][1][0], tabA[da][1][0] * tabB[db][2][0]) hcurl_tab = hcurl_elt.tabulate(1, [(0.1, 0.2)]) for da, db in [[(0, ), (0, )], [(1, ), (0, )], [(0, ), (1, )]]: dc = da + db assert np.isclose(hcurl_tab[dc][0][0][0], tabA[da][0][0] * tabB[db][0][0]) assert np.isclose(hcurl_tab[dc][1][0][0], tabA[da][0][0] * tabB[db][1][0]) assert np.isclose(hcurl_tab[dc][2][0][0], tabA[da][0][0] * tabB[db][2][0]) assert np.isclose(hcurl_tab[dc][3][0][0], tabA[da][1][0] * tabB[db][0][0]) assert np.isclose(hcurl_tab[dc][4][0][0], tabA[da][1][0] * tabB[db][1][0]) assert np.isclose(hcurl_tab[dc][5][0][0], tabA[da][1][0] * tabB[db][2][0]) assert hcurl_tab[dc][0][1][0] == 0.0 assert hcurl_tab[dc][1][1][0] == 0.0 assert hcurl_tab[dc][2][1][0] == 0.0 assert hcurl_tab[dc][3][1][0] == 0.0 assert hcurl_tab[dc][4][1][0] == 0.0 assert hcurl_tab[dc][5][1][0] == 0.0
def cell(request): if request.param == "interval": return UFCInterval() elif request.param == "triangle": return UFCTriangle() elif request.param == "quadrilateral": return UFCTriangle() elif request.param == "hexahedron": return UFCTriangle()
def test_dual_tensor_versus_ufc(): K0 = UFCQuadrilateral() ell = UFCInterval() K1 = TensorProductCell(ell, ell) S0 = Serendipity(K0, 2) S1 = Serendipity(K1, 2) # since both elements go through the flattened cell to produce the # dual basis, they ought to do *exactly* the same calculations and # hence form exactly the same nodes. for i in range(S0.space_dimension()): assert S0.dual.nodes[i].pt_dict == S1.dual.nodes[i].pt_dict
def __init__(self, cell, order): assert cell == UFCInterval() and order == 3 entity_ids = {0: {0: [0], 1: [1]}, 1: {0: [2, 3]}} vertnodes = [PointEvaluation(cell, xx) for xx in cell.vertices] Q = make_quadrature(cell, 3) # 1st integral moment node is integral(1*f(x)*dx) ones = np.asarray([1.0 for x in Q.pts]) # 2nd integral moment node is integral(x*f(x)*dx) xs = np.asarray([x for (x, ) in Q.pts]) intnodes = [IntegralMoment(cell, Q, ones), IntegralMoment(cell, Q, xs)] nodes = vertnodes + intnodes super().__init__(nodes, cell, entity_ids)
def test_TFE_2Dx1D_vector_quad_hdiv(): T = UFCInterval() P1 = Lagrange(T, 1) P0 = DiscontinuousLagrange(T, 0) P1_DG = DiscontinuousLagrange(T, 1) P1P0 = Hdiv(TensorProductElement(P1, P0)) P0P1 = Hdiv(TensorProductElement(P0, P1)) horiz_elt = EnrichedElement(P1P0, P0P1) elt = Hdiv(TensorProductElement(horiz_elt, P1_DG)) assert elt.value_shape() == (3, ) tab = elt.tabulate(1, [(0.1, 0.2, 0.3)]) tA = P1.tabulate(1, [(0.1, )]) tB = P0.tabulate(1, [(0.2, )]) tC = P0.tabulate(1, [(0.1, )]) tD = P1.tabulate(1, [(0.2, )]) tE = P1_DG.tabulate(1, [(0.3, )]) for da, db, dc in [[(0, ), (0, ), (0, )], [(1, ), (0, ), (0, )], [(0, ), (1, ), (0, )], [(0, ), (0, ), (1, )]]: dd = da + db + dc assert np.isclose(tab[dd][0][0][0], -tA[da][0][0] * tB[db][0][0] * tE[dc][0][0]) assert np.isclose(tab[dd][1][0][0], -tA[da][0][0] * tB[db][0][0] * tE[dc][1][0]) assert np.isclose(tab[dd][2][0][0], -tA[da][1][0] * tB[db][0][0] * tE[dc][0][0]) assert np.isclose(tab[dd][3][0][0], -tA[da][1][0] * tB[db][0][0] * tE[dc][1][0]) assert tab[dd][4][0][0] == 0.0 assert tab[dd][5][0][0] == 0.0 assert tab[dd][6][0][0] == 0.0 assert tab[dd][7][0][0] == 0.0 assert tab[dd][0][1][0] == 0.0 assert tab[dd][1][1][0] == 0.0 assert tab[dd][2][1][0] == 0.0 assert tab[dd][3][1][0] == 0.0 assert np.isclose(tab[dd][4][1][0], tC[da][0][0] * tD[db][0][0] * tE[dc][0][0]) assert np.isclose(tab[dd][5][1][0], tC[da][0][0] * tD[db][0][0] * tE[dc][1][0]) assert np.isclose(tab[dd][6][1][0], tC[da][0][0] * tD[db][1][0] * tE[dc][0][0]) assert np.isclose(tab[dd][7][1][0], tC[da][0][0] * tD[db][1][0] * tE[dc][1][0]) assert tab[dd][0][2][0] == 0.0 assert tab[dd][1][2][0] == 0.0 assert tab[dd][2][2][0] == 0.0 assert tab[dd][3][2][0] == 0.0 assert tab[dd][4][2][0] == 0.0 assert tab[dd][5][2][0] == 0.0 assert tab[dd][6][2][0] == 0.0 assert tab[dd][7][2][0] == 0.0
def test_flattened_against_tpe_quad(): T = UFCInterval() P1 = Lagrange(T, 1) tpe_quad = TensorProductElement(P1, P1) flattened_quad = FlattenedDimensions(tpe_quad) assert tpe_quad.value_shape() == () tpe_tab = tpe_quad.tabulate(1, [(0.1, 0.2)]) flattened_tab = flattened_quad.tabulate(1, [(0.1, 0.2)]) for da, db in [[(0, ), (0, )], [(1, ), (0, )], [(0, ), (1, )]]: dc = da + db assert np.isclose(tpe_tab[dc][0][0], flattened_tab[dc][0][0]) assert np.isclose(tpe_tab[dc][1][0], flattened_tab[dc][1][0]) assert np.isclose(tpe_tab[dc][2][0], flattened_tab[dc][2][0]) assert np.isclose(tpe_tab[dc][3][0], flattened_tab[dc][3][0])
def get_line_nodes(V): # Return the corresponding nodes in the Line for CG / DG from FIAT.reference_element import UFCInterval from FIAT import quadrature use_tensorproduct, N, family, variant = tensor_product_space_query(V) assert use_tensorproduct cell = UFCInterval() if variant == "equispaced": return cell.make_points(1, 0, N + 1) elif family <= {"Q", "Lagrange"}: rule = quadrature.GaussLobattoLegendreQuadratureLineRule(cell, N + 1) return rule.get_points() elif family <= {"DQ", "Discontinuous Lagrange"}: rule = quadrature.GaussLegendreQuadratureLineRule(cell, N + 1) return rule.get_points() else: raise ValueError("Don't know how to get line nodes for %r" % family)
def test_fiat_p3intmoments(): # can create el = P3IntMoments(UFCInterval(), 3) # have expected number of nodes assert len(el.dual_basis()) == 4 # dual eval gives expected values from sum of point evaluations fns = (lambda x: x[0], lambda x: x[0]**2) expected = ([0, 1, 1 / 2, 1 / 3], [0, 1, 1 / 3, 1 / 4]) for fn, expect in zip(fns, expected): node_vals = [] for node in el.dual_basis(): pt_dict = node.pt_dict node_val = 0.0 for pt in pt_dict: for (w, _) in pt_dict[pt]: node_val += w * fn(pt) node_vals.append(node_val) assert np.allclose(node_vals, expect)
def test_TFE_1Dx1D_scalar(): T = UFCInterval() P1_DG = DiscontinuousLagrange(T, 1) P2 = Lagrange(T, 2) elt = TensorProductElement(P1_DG, P2) assert elt.value_shape() == () tab = elt.tabulate(1, [(0.1, 0.2)]) tabA = P1_DG.tabulate(1, [(0.1, )]) tabB = P2.tabulate(1, [(0.2, )]) for da, db in [[(0, ), (0, )], [(1, ), (0, )], [(0, ), (1, )]]: dc = da + db assert np.isclose(tab[dc][0][0], tabA[da][0][0] * tabB[db][0][0]) assert np.isclose(tab[dc][1][0], tabA[da][0][0] * tabB[db][1][0]) assert np.isclose(tab[dc][2][0], tabA[da][0][0] * tabB[db][2][0]) assert np.isclose(tab[dc][3][0], tabA[da][1][0] * tabB[db][0][0]) assert np.isclose(tab[dc][4][0], tabA[da][1][0] * tabB[db][1][0]) assert np.isclose(tab[dc][5][0], tabA[da][1][0] * tabB[db][2][0])
def test_TFE_2Dx1D_scalar_triangle_hdiv(): S = UFCTriangle() T = UFCInterval() P1_DG = DiscontinuousLagrange(S, 1) P2 = Lagrange(T, 2) elt = Hdiv(TensorProductElement(P1_DG, P2)) assert elt.value_shape() == (3, ) tab = elt.tabulate(1, [(0.1, 0.2, 0.3)]) tabA = P1_DG.tabulate(1, [(0.1, 0.2)]) tabB = P2.tabulate(1, [(0.3, )]) for da, db in [[(0, 0), (0, )], [(1, 0), (0, )], [(0, 1), (0, )], [(0, 0), (1, )]]: dc = da + db assert tab[dc][0][0][0] == 0.0 assert tab[dc][1][0][0] == 0.0 assert tab[dc][2][0][0] == 0.0 assert tab[dc][3][0][0] == 0.0 assert tab[dc][4][0][0] == 0.0 assert tab[dc][5][0][0] == 0.0 assert tab[dc][6][0][0] == 0.0 assert tab[dc][7][0][0] == 0.0 assert tab[dc][8][0][0] == 0.0 assert tab[dc][0][1][0] == 0.0 assert tab[dc][1][1][0] == 0.0 assert tab[dc][2][1][0] == 0.0 assert tab[dc][3][1][0] == 0.0 assert tab[dc][4][1][0] == 0.0 assert tab[dc][5][1][0] == 0.0 assert tab[dc][6][1][0] == 0.0 assert tab[dc][7][1][0] == 0.0 assert tab[dc][8][1][0] == 0.0 assert np.isclose(tab[dc][0][2][0], tabA[da][0][0] * tabB[db][0][0]) assert np.isclose(tab[dc][1][2][0], tabA[da][0][0] * tabB[db][1][0]) assert np.isclose(tab[dc][2][2][0], tabA[da][0][0] * tabB[db][2][0]) assert np.isclose(tab[dc][3][2][0], tabA[da][1][0] * tabB[db][0][0]) assert np.isclose(tab[dc][4][2][0], tabA[da][1][0] * tabB[db][1][0]) assert np.isclose(tab[dc][5][2][0], tabA[da][1][0] * tabB[db][2][0]) assert np.isclose(tab[dc][6][2][0], tabA[da][2][0] * tabB[db][0][0]) assert np.isclose(tab[dc][7][2][0], tabA[da][2][0] * tabB[db][1][0]) assert np.isclose(tab[dc][8][2][0], tabA[da][2][0] * tabB[db][2][0])
def get_line_element(V): # Return the corresponding Line element for CG / DG from FIAT.reference_element import UFCInterval from FIAT import gauss_legendre, gauss_lobatto_legendre, lagrange, discontinuous_lagrange use_tensorproduct, N, family, variant = tensor_product_space_query(V) assert use_tensorproduct cell = UFCInterval() if family <= {"Q", "Lagrange"}: if variant == "equispaced": element = lagrange.Lagrange(cell, N) else: element = gauss_lobatto_legendre.GaussLobattoLegendre(cell, N) elif family <= {"DQ", "Discontinuous Lagrange"}: if variant == "equispaced": element = discontinuous_lagrange.DiscontinuousLagrange(cell, N) else: element = gauss_legendre.GaussLegendre(cell, N) else: raise ValueError("Don't know how to get line element for %r" % family) return element
def test_flattened_against_tpe_hex(): T = UFCInterval() P1 = Lagrange(T, 1) tpe_quad = TensorProductElement(P1, P1) tpe_hex = TensorProductElement(tpe_quad, P1) flattened_quad = FlattenedDimensions(tpe_quad) flattened_hex = FlattenedDimensions( TensorProductElement(flattened_quad, P1)) assert tpe_quad.value_shape() == () tpe_tab = tpe_hex.tabulate(1, [(0.1, 0.2, 0.3)]) flattened_tab = flattened_hex.tabulate(1, [(0.1, 0.2, 0.3)]) for da, db, dc in [[(0, ), (0, ), (0, )], [(1, ), (0, ), (0, )], [(0, ), (1, ), (0, )], [(0, ), (0, ), (1, )]]: dd = da + db + dc assert np.isclose(tpe_tab[dd][0][0], flattened_tab[dd][0][0]) assert np.isclose(tpe_tab[dd][1][0], flattened_tab[dd][1][0]) assert np.isclose(tpe_tab[dd][2][0], flattened_tab[dd][2][0]) assert np.isclose(tpe_tab[dd][3][0], flattened_tab[dd][3][0]) assert np.isclose(tpe_tab[dd][4][0], flattened_tab[dd][4][0]) assert np.isclose(tpe_tab[dd][5][0], flattened_tab[dd][5][0]) assert np.isclose(tpe_tab[dd][6][0], flattened_tab[dd][6][0]) assert np.isclose(tpe_tab[dd][7][0], flattened_tab[dd][7][0])
def test_edge_degree(degree): """Verify that the outer edges of a degree KMV element are indeed of degree and the interior is of degree+1""" # create a degree+1 polynomial I = UFCInterval() # an exact quad. rule for a degree+1 polynomial on the UFCinterval qr = make_quadrature(I, degree + 1) W = np.diag(qr.wts) sd = I.get_spatial_dimension() pset = polynomial_set.ONPolynomialSet(I, degree + 1, (sd, )) pset = pset.take([degree + 1]) # tabulate at the quadrature points interval_vals = pset.tabulate(qr.get_points())[(0, )] interval_vals = np.squeeze(interval_vals) # create degree KMV element (should have degree outer edges and degree+1 edge in center) T = UFCTriangle() element = KMV(T, degree) # tabulate values on an edge of the KMV element for e in range(3): edge_values = element.tabulate(0, qr.get_points(), (1, e))[(0, 0)] # degree edge should be orthogonal to degree+1 ONpoly edge values result = edge_values @ W @ interval_vals.T assert np.allclose(np.sum(result), 0.0)
from __future__ import absolute_import, print_function, division import pytest import numpy as np from FIAT.reference_element import UFCInterval, UFCTriangle, UFCTetrahedron from FIAT.reference_element import FiredrakeQuadrilateral, TensorProductCell from tsfc.fem import make_cell_facet_jacobian interval = UFCInterval() triangle = UFCTriangle() quadrilateral = FiredrakeQuadrilateral() tetrahedron = UFCTetrahedron() interval_x_interval = TensorProductCell(interval, interval) triangle_x_interval = TensorProductCell(triangle, interval) quadrilateral_x_interval = TensorProductCell(quadrilateral, interval) @pytest.mark.parametrize( ('cell', 'cell_facet_jacobian'), [(interval, [[], []]), (triangle, [[-1, 1], [0, 1], [1, 0]]), (quadrilateral, [[0, 1], [0, 1], [1, 0], [1, 0]]), (tetrahedron, [[-1, -1, 1, 0, 0, 1], [0, 0, 1, 0, 0, 1], [1, 0, 0, 0, 0, 1], [1, 0, 0, 1, 0, 0]])]) def test_cell_facet_jacobian(cell, cell_facet_jacobian): facet_dim = cell.get_spatial_dimension() - 1 for facet_number in range(len(cell.get_topology()[facet_dim])): actual = make_cell_facet_jacobian(cell, facet_dim, facet_number) expected = np.reshape(cell_facet_jacobian[facet_number], actual.shape) assert np.allclose(expected, actual)
from FIAT.hellan_herrmann_johnson import HellanHerrmannJohnson # noqa: F401 from FIAT.brezzi_douglas_fortin_marini import BrezziDouglasFortinMarini # noqa: F401 from FIAT.gauss_legendre import GaussLegendre # noqa: F401 from FIAT.gauss_lobatto_legendre import GaussLobattoLegendre # noqa: F401 from FIAT.restricted import RestrictedElement # noqa: F401 from FIAT.tensor_product import TensorProductElement # noqa: F401 from FIAT.tensor_product import FlattenedDimensions # noqa: F401 from FIAT.hdivcurl import Hdiv, Hcurl # noqa: F401 from FIAT.argyris import Argyris, QuinticArgyris # noqa: F401 from FIAT.hermite import CubicHermite # noqa: F401 from FIAT.morley import Morley # noqa: F401 from FIAT.bubble import Bubble from FIAT.enriched import EnrichedElement # noqa: F401 from FIAT.nodal_enriched import NodalEnrichedElement I = UFCInterval() # noqa: E741 T = UFCTriangle() S = UFCTetrahedron() def test_basis_derivatives_scaling(): "Regression test for issue #9" class Interval(ReferenceElement): def __init__(self, a, b): verts = ((a, ), (b, )) edges = {0: (0, 1)} topology = {0: {0: (0, ), 1: (1, )}, 1: edges} super(Interval, self).__init__(LINE, verts, topology) random.seed(42)
def test_quad(base, extr, horiz_expected, vert_expected): elem_A = FIAT.supported_elements[base[0]](UFCInterval(), base[1]) elem_B = FIAT.supported_elements[extr[0]](UFCInterval(), extr[1]) elem = FIAT.TensorProductElement(elem_A, elem_B) assert horiz_expected == entity_support_dofs(elem, (1, 0)) assert vert_expected == entity_support_dofs(elem, (0, 1))
from FIAT.hdiv_trace import HDivTrace # noqa: F401 from FIAT.hellan_herrmann_johnson import HellanHerrmannJohnson # noqa: F401 from FIAT.brezzi_douglas_fortin_marini import BrezziDouglasFortinMarini # noqa: F401 from FIAT.gauss_legendre import GaussLegendre # noqa: F401 from FIAT.gauss_lobatto_legendre import GaussLobattoLegendre # noqa: F401 from FIAT.restricted import RestrictedElement # noqa: F401 from FIAT.tensor_product import TensorProductElement # noqa: F401 from FIAT.hdivcurl import Hdiv, Hcurl # noqa: F401 from FIAT.argyris import Argyris, QuinticArgyris # noqa: F401 from FIAT.hermite import CubicHermite # noqa: F401 from FIAT.morley import Morley # noqa: F401 from FIAT.bubble import Bubble from FIAT.enriched import EnrichedElement # noqa: F401 from FIAT.nodal_enriched import NodalEnrichedElement I = UFCInterval() T = UFCTriangle() S = UFCTetrahedron() def test_basis_derivatives_scaling(): "Regression test for issue #9" class Interval(ReferenceElement): def __init__(self, a, b): verts = ((a, ), (b, )) edges = {0: (0, 1)} topology = {0: {0: (0, ), 1: (1, )}, 1: edges} super(Interval, self).__init__(LINE, verts, topology) random.seed(42)
# # Modified by David A. Ham ([email protected]), 2018 from FIAT import finite_element, polynomial_set, dual_set, functional from FIAT.reference_element import (Point, DefaultLine, UFCInterval, UFCQuadrilateral, UFCHexahedron, UFCTriangle, UFCTetrahedron, make_affine_mapping, flatten_reference_cube) from FIAT.P0 import P0Dual import numpy as np hypercube_simplex_map = { Point(): Point(), DefaultLine(): DefaultLine(), UFCInterval(): UFCInterval(), UFCQuadrilateral(): UFCTriangle(), UFCHexahedron(): UFCTetrahedron() } class DPC0(finite_element.CiarletElement): def __init__(self, ref_el): flat_el = flatten_reference_cube(ref_el) poly_set = polynomial_set.ONPolynomialSet( hypercube_simplex_map[flat_el], 0) dual = P0Dual(ref_el) degree = 0 formdegree = ref_el.get_spatial_dimension() # n-form super(DPC0, self).__init__(poly_set=poly_set, dual=dual,
def test_invalid_quadrature_rule(): from FIAT.quadrature import QuadratureRule with pytest.raises(ValueError): QuadratureRule(UFCInterval(), [[0.5, 0.5]], [0.5, 0.5, 0.5])
def extr_quadrilateral(): """Extruded quadrilateral = quadrilateral x interval""" return TensorProductCell(UFCQuadrilateral(), UFCInterval())
def extr_triangle(): """Extruded triangle = triangle x interval""" return TensorProductCell(UFCTriangle(), UFCInterval())
def extr_interval(): """Extruded interval = interval x interval""" return TensorProductCell(UFCInterval(), UFCInterval())