Exemple #1
0
def test_gradient():
    msh = circular_mesh(200, 1.0)
    bf = basis_from_nodes([0.0, 1.0])
    gradient = bf.get_gradient_basis()
    e = msh.elements[57]
    chain_rule = gradient.chain_rule(e.mapping.get_jacobian(0.0))
    value = np.array(gradient.evaluate(0, 0.5))
    np.testing.assert_almost_equal(chain_rule * value,
                                   -31.83229765 * np.ones(2))
Exemple #2
0
def test_basis_nodes():
    bf = basis_from_nodes([-1.0, 0.0, 1.0])
    # Check to make sure the nodes are right
    x = [1.0, 1.0]
    my_assert(bf.evaluate(0, -1.0), 1.0)
    my_assert(bf.evaluate(0, 0.0), 0.0)
    my_assert(bf.evaluate(0, 1.0), 0.0)
    my_assert(bf.evaluate(1, 0.0), 1.0)
    my_assert(bf.evaluate(2, 1.0), 1.0)
Exemple #3
0
def test_basis_derivative():
    bf = basis_from_nodes([-1.0, 0.0, 1.0])
    x_hat = 0.3
    yd_exact1 = x_hat - 0.5
    yd_exact2 = -2 * x_hat
    yd_exact3 = x_hat + 0.5
    yd_est1 = bf.get_gradient_basis().evaluate(0, x_hat)
    yd_est2 = bf.get_gradient_basis().evaluate(1, x_hat)
    yd_est3 = bf.get_gradient_basis().evaluate(2, x_hat)
    my_assert(yd_exact1, yd_est1)
    my_assert(yd_exact2, yd_est2)
    my_assert(yd_exact3, yd_est3)
Exemple #4
0
def test_basis_2nd_order():
    bf = basis_from_nodes([-1.0, 0.0, 1.0])
    # Test for 2nd degree polynomials
    x_hat = 0.3
    y_exact1 = 0.5 * x_hat * (x_hat - 1)
    y_exact2 = (1 - x_hat) * (1 + x_hat)
    y_exact3 = 0.5 * x_hat * (1 + x_hat)
    y_est1 = bf.evaluate(0, x_hat)
    y_est2 = bf.evaluate(1, x_hat)
    y_est3 = bf.evaluate(2, x_hat)
    my_assert(y_exact1, y_est1)
    my_assert(y_exact2, y_est2)
    my_assert(y_exact3, y_est3)
Exemple #5
0
def test_mass_matrix_functional():
    bf = basis_funcs.basis_from_nodes([0.001, 0.999])
    msh = simple_line_mesh(2)
    q = quadrature.gauss(2)
    apply_to_elements(msh, "basis", bf, non_gen = True)
    apply_to_elements(msh, "continuous", False, non_gen = True)
    init_dofs(msh)

    fnc_coeffs = interpolate(lambda x,d: [[1,2][x[0] >= 0]] * 2, msh)
    apply_coeffs(msh, fnc_coeffs, "function_yay")
    basis_grabber = lambda e: e.function_yay

    m = mass_matrix_for_rhs(assemble_mass_matrix(msh, q, basis_grabber))
    M_exact = [0.5, 0.5, 1.0, 1.0]
    np.testing.assert_almost_equal(M_exact, m[0:4])