コード例 #1
0
ファイル: test_tensor_product.py プロジェクト: mscroggs/fiat
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
コード例 #2
0
ファイル: test_tensor_product.py プロジェクト: mscroggs/fiat
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])
コード例 #3
0
ファイル: test_tensor_product.py プロジェクト: mscroggs/fiat
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
コード例 #4
0
ファイル: test_tensor_product.py プロジェクト: mscroggs/fiat
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
コード例 #5
0
ファイル: test_tensor_product.py プロジェクト: mscroggs/fiat
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])
コード例 #6
0
ファイル: test_tensor_product.py プロジェクト: mscroggs/fiat
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])
コード例 #7
0
ファイル: test_fiat.py プロジェクト: mscroggs/fiat
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().__init__("LINE", verts, topology)

    random.seed(42)
    for i in range(26):
        a = 1000.0 * (random.random() - 0.5)
        b = 1000.0 * (random.random() - 0.5)
        a, b = min(a, b), max(a, b)

        interval = Interval(a, b)
        element = Lagrange(interval, 1)

        points = [(a, ), (0.5 * (a + b), ), (b, )]
        tab = element.get_nodal_basis().tabulate(points, 2)

        # first basis function
        assert np.isclose(tab[(0, )][0][0], 1.0)
        assert np.isclose(tab[(0, )][0][1], 0.5)
        assert np.isclose(tab[(0, )][0][2], 0.0)
        # second basis function
        assert np.isclose(tab[(0, )][1][0], 0.0)
        assert np.isclose(tab[(0, )][1][1], 0.5)
        assert np.isclose(tab[(0, )][1][2], 1.0)

        # first and second derivatives
        D = 1.0 / (b - a)
        for p in range(len(points)):
            assert np.isclose(tab[(1, )][0][p], -D)
            assert np.isclose(tab[(1, )][1][p], +D)
            assert np.isclose(tab[(2, )][0][p], 0.0)
            assert np.isclose(tab[(2, )][1][p], 0.0)
コード例 #8
0
ファイル: test_tensor_product.py プロジェクト: mscroggs/fiat
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])
コード例 #9
0
ファイル: test_tensor_product.py プロジェクト: mscroggs/fiat
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])
コード例 #10
0
        #'legend.markerscale' : 8,
        'xtick.labelsize': 16,
        'ytick.labelsize': 16,
        'text.usetex': True,
        'linewidth': 4,
        'figure.figsize': fig_size
    })
    #subplots_adjust(left=0.06,right=0.975,bottom=0.08,top=0.94)
    subplots_adjust(left=0.15, right=0.95, bottom=0.06, top=0.95)


set_sizes_talk()
rcParams.update({'backend': 'png'})
m = 5
n = 100
u = Lagrange.Lagrange(1, m, shapes.line_point_family_lgl)
ufs = u.function_space()
q = quadrature.make_quadrature(1, n)
x = q.get_points()
t = ufs.tabulate_jet(1, x)
B = t[0][(0, )]
D = t[1][(1, )]
subplot(211)
p = [plot(x, B[i], linewidth=2) for i in range(m + 1)]
ylabel('Basis functions')
#xlabel('$\hat{x}$')
subplot(212)
p = [plot(x, D[i], linewidth=2) for i in range(m + 1)]
ylim(-10, 10)
ylabel('Derivatives')
xlabel('$\hat{x}$')
コード例 #11
0
ファイル: test_fiat.py プロジェクト: mscroggs/fiat
    # Get coeffs of primal and dual bases w.r.t. expansion set
    coeffs_poly = poly_set.get_coeffs()
    coeffs_dual = dual_set.to_riesz(poly_set)
    assert coeffs_poly.shape == coeffs_dual.shape

    # Check nodality
    for i in range(coeffs_dual.shape[0]):
        for j in range(coeffs_poly.shape[0]):
            assert np.isclose(
                coeffs_dual[i].flatten().dot(coeffs_poly[j].flatten()),
                1.0 if i == j else 0.0)


@pytest.mark.parametrize('elements', [
    (Lagrange(I, 2), Bubble(I, 2)),
    (Lagrange(T, 3), Bubble(T, 3)),
    (Lagrange(S, 4), Bubble(S, 4)),
    (Lagrange(I, 1), Lagrange(I, 1)),
    (Lagrange(I, 1), Bubble(I, 2), Bubble(I, 2)),
])
def test_illposed_nodal_enriched(elements):
    """Check that nodal enriched element fails on ill-posed
    (non-unisolvent) case
    """
    with pytest.raises(np.linalg.LinAlgError):
        NodalEnrichedElement(*elements)


def test_empty_bubble():
    "Check that bubble of too low degree fails"