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_vector_triangle_hdiv_rotate(): S = UFCTriangle() T = UFCInterval() Ned1 = Nedelec(S, 1) P1_DG = DiscontinuousLagrange(T, 1) elt = Hdiv(TensorProductElement(Ned1, P1_DG)) 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_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][1][0]*tabB[db][0][0]) assert np.isclose(tab[dc][1][0][0], tabA[da][0][1][0]*tabB[db][1][0]) assert np.isclose(tab[dc][2][0][0], tabA[da][1][1][0]*tabB[db][0][0]) assert np.isclose(tab[dc][3][0][0], tabA[da][1][1][0]*tabB[db][1][0]) assert np.isclose(tab[dc][4][0][0], tabA[da][2][1][0]*tabB[db][0][0]) assert np.isclose(tab[dc][5][0][0], tabA[da][2][1][0]*tabB[db][1][0]) assert np.isclose(tab[dc][0][1][0], -tabA[da][0][0][0]*tabB[db][0][0]) assert np.isclose(tab[dc][1][1][0], -tabA[da][0][0][0]*tabB[db][1][0]) assert np.isclose(tab[dc][2][1][0], -tabA[da][1][0][0]*tabB[db][0][0]) assert np.isclose(tab[dc][3][1][0], -tabA[da][1][0][0]*tabB[db][1][0]) assert np.isclose(tab[dc][4][1][0], -tabA[da][2][0][0]*tabB[db][0][0]) assert np.isclose(tab[dc][5][1][0], -tabA[da][2][0][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 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 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_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_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_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 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 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 __init__(self, ref_el, degree): sd = ref_el.get_spatial_dimension() if sd in (0, 1): raise ValueError( "Cannot use this trace class on a %d-dimensional cell." % sd) # Constructing facet element as a discontinuous Lagrange element dglagrange = DiscontinuousLagrange(ufc_simplex(sd - 1), degree) # Construct entity ids (assigning top. dim. and initializing as empty) entity_dofs = {} # Looping over dictionary of cell topology to construct the empty # dictionary for entity ids of the trace element topology = ref_el.get_topology() for top_dim, entities in topology.items(): entity_dofs[top_dim] = {} for entity in entities: entity_dofs[top_dim][entity] = [] # Filling in entity ids and generating points for dual basis nf = dglagrange.space_dimension() points = [] num_facets = sd + 1 for f in range(num_facets): entity_dofs[sd - 1][f] = range(f * nf, (f + 1) * nf) for dof in dglagrange.dual_basis(): facet_point = list(dof.get_point_dict().keys())[0] transform = ref_el.get_entity_transform(sd - 1, f) points.append(tuple(transform(facet_point))) # Setting up dual basis - only point evaluations nodes = [PointEvaluation(ref_el, pt) for pt in points] dual = dual_set.DualSet(nodes, ref_el, entity_dofs) super(HDivTrace, self).__init__(ref_el, dual, dglagrange.get_order(), dglagrange.get_formdegree(), dglagrange.mapping()[0]) # Set up facet element self.facet_element = dglagrange # degree for quadrature rule self.polydegree = degree
sys.path.insert(0, bsDir) sys.path.insert(0, configDir) if os.path.isdir(os.path.join(fiatDir,'FIAT')): sys.path.insert(0, fiatDir) import PETSc.FEM from FIAT.reference_element import default_simplex from FIAT.lagrange import Lagrange from FIAT.discontinuous_lagrange import DiscontinuousLagrange generator = PETSc.FEM.QuadratureGenerator() generator.setup() elements = [] if not (len(sys.argv)-2) % 5 == 0: sys.exit('Incomplete set of arguments') for n in range((len(sys.argv)-2) / 5): dim = int(sys.argv[n*5+1]) order = int(sys.argv[n*5+2]) components = int(sys.argv[n*5+3]) numBlocks = int(sys.argv[n*5+4]) operator = sys.argv[n*5+5] if order == 0: element = DiscontinuousLagrange(default_simplex(dim), order) else: element = Lagrange(default_simplex(dim), order) element.numComponents = components elements.append(element) filename = sys.argv[-1] generator.quadDegree = max([e.order for e in elements]) generator.run(elements, numBlocks, operator, filename)