def test_dy_dxi():
    '''
    This test checks the derivative :math:`\\frac{\\partial y}{\\partial \\xi}`
    calculated using the function :math:`dg_maxwell.wave_equation_2d.dy_dxi`
    for the :math:`0^{th}` element of a mesh for a circular ring. You may
    download the file from this
    :download:`link <../dg_maxwell/tests/wave_equation_2d/files/circle.msh>`.
    '''
    threshold = 1e-7

    dy_dxi_reference = af.np_to_af_array(
        utils.csv_to_numpy(
            'dg_maxwell/tests/wave_equation_2d/files/dy_dxi_data.csv'))

    nodes, elements = msh_parser.read_order_2_msh(
        'dg_maxwell/tests/wave_equation_2d/files/circle.msh')

    N_LGL = 16
    xi_LGL = lagrange.LGL_points(N_LGL)
    eta_LGL = lagrange.LGL_points(N_LGL)
    Xi = af.data.tile(af.array.transpose(xi_LGL), d0=N_LGL)
    Eta = af.data.tile(eta_LGL, d0=1, d1=N_LGL)

    dy_dxi = wave_equation_2d.dy_dxi(nodes[elements[0]][:, 1], Xi, Eta)

    check = af.abs(dy_dxi - dy_dxi_reference) < threshold

    assert af.all_true(check)
def test_Li_basis_value():
    '''
    This test compares the output of the lagrange basis value calculated by the
    function ``Li_basis_value`` to the analytical value of the lagrange
    polynomials created using the same LGL points.
    The analytical values were calculated in this sage worksheet_
    
    .. _worksheet: https://goo.gl/ADyA3U
    '''
    
    threshold = 1e-11
    
    Li_value_ref = af.np_to_af_array(utils.csv_to_numpy(
        'dg_maxwell/tests/lagrange/files/Li_value.csv'))
    
    N_LGL = 8
    xi_LGL = lagrange.LGL_points(N_LGL)
    L_basis_poly1d, L_basis_af = lagrange.lagrange_polynomials(xi_LGL)
    L_basis_af = af.np_to_af_array(L_basis_af)
    
    Li_indexes = af.np_to_af_array(np.arange(3, dtype = np.int32))
    xi = af.np_to_af_array(np.linspace(-1., 1, 10))
                           
    Li_value = lagrange.Li_basis_value(L_basis_af, Li_indexes, xi)
    
    assert af.all_true(af.abs(Li_value - Li_value_ref) < threshold)
def test_A_matrix():
    '''
    Compares the tensor product calculated using the ``A_matrix`` function
    with an analytic value of the tensor product for :math:`N_{LGL} = 4`.
    The analytic value of the tensor product is calculated in this
    `document`_
    
    .. _document: https://goo.gl/QNWxXp
    '''
    threshold = 1e-12

    A_matrix_ref = af.np_to_af_array(
        utils.csv_to_numpy(
            'dg_maxwell/tests/wave_equation_2d/files/A_matrix_ref.csv'))

    params.N_LGL = 4
    advec_var = gvar.advection_variables(params.N_LGL, params.N_quad,
                                         params.x_nodes, params.N_Elements,
                                         params.c, params.total_time,
                                         params.wave, params.c_x, params.c_y,
                                         params.courant, params.mesh_file,
                                         params.total_time_2d)

    A_matrix_test = wave_equation_2d.A_matrix(params.N_LGL, advec_var)

    assert af.max(af.abs(A_matrix_test - A_matrix_ref)) < threshold