Esempio n. 1
0
def test_quad_rule_xyoz():
    '''Test that the KernelInterface class quad_rule method adds the expected
    classes to the symbol table and the _arglist list for xyoz quadrature

    '''
    _, invoke_info = parse(os.path.join(BASE_PATH,
                                        "1.1.0_single_invoke_xyoz_qr.f90"),
                           api="dynamo0.3")
    psy = PSyFactory("dynamo0.3", distributed_memory=False).create(invoke_info)
    schedule = psy.invokes.invoke_list[0].schedule
    kernel = schedule[0].loop_body[0]
    kernel_interface = KernelInterface(kernel)
    kernel_interface.quad_rule()

    # nqp_xy declared and added to argument list
    nqph_symbol = kernel_interface._symbol_table.lookup("nqp_xy")
    assert isinstance(nqph_symbol, lfric_psyir.NumberOfQrPointsInXyDataSymbol)
    assert isinstance(nqph_symbol.interface, ArgumentInterface)
    assert (
        nqph_symbol.interface.access == kernel_interface._read_access.access)
    assert kernel_interface._arglist[-4] is nqph_symbol
    # nqp_z declared and added to argument list
    nqpv_symbol = kernel_interface._symbol_table.lookup("nqp_z")
    assert isinstance(nqpv_symbol, lfric_psyir.NumberOfQrPointsInZDataSymbol)
    assert isinstance(nqpv_symbol.interface, ArgumentInterface)
    assert (
        nqpv_symbol.interface.access == kernel_interface._read_access.access)
    assert kernel_interface._arglist[-3] is nqpv_symbol
    # weights_xy declared and added to argument list
    weightsh_symbol = kernel_interface._symbol_table.lookup("weights_xy")
    assert isinstance(weightsh_symbol, lfric_psyir.QrWeightsInXyDataSymbol)
    assert isinstance(weightsh_symbol.interface, ArgumentInterface)
    assert (weightsh_symbol.interface.access ==
            kernel_interface._read_access.access)
    assert kernel_interface._arglist[-2] is weightsh_symbol
    assert len(weightsh_symbol.shape) == 1
    assert isinstance(weightsh_symbol.shape[0], Reference)
    assert weightsh_symbol.shape[0].symbol is nqph_symbol
    # weights_z declared and added to argument list
    weightsz_symbol = kernel_interface._symbol_table.lookup("weights_z")
    assert isinstance(weightsz_symbol, lfric_psyir.QrWeightsInZDataSymbol)
    assert isinstance(weightsz_symbol.interface, ArgumentInterface)
    assert (weightsz_symbol.interface.access ==
            kernel_interface._read_access.access)
    assert kernel_interface._arglist[-1] is weightsz_symbol
    assert len(weightsz_symbol.shape) == 1
    assert isinstance(weightsz_symbol.shape[0], Reference)
    assert weightsz_symbol.shape[0].symbol is nqpv_symbol
Esempio n. 2
0
def test_quad_rule_error(monkeypatch):
    '''Test that the KernelInterface class quad_rule method raises the
    expected exception when an unsupported quadrature shape is
    provided.

    '''
    _, invoke_info = parse(os.path.join(BASE_PATH, "6.1_eval_invoke.f90"),
                           api="dynamo0.3")
    psy = PSyFactory("dynamo0.3", distributed_memory=False).create(invoke_info)
    schedule = psy.invokes.invoke_list[0].schedule
    kernel = schedule[0].loop_body[0]
    kernel_interface = KernelInterface(kernel)
    # Force an unsupported shape
    monkeypatch.setattr(kernel, "_qr_rules", ["invalid_shape"])
    with pytest.raises(InternalError) as info:
        kernel_interface.quad_rule()
    assert ("Unsupported quadrature shape 'invalid_shape' found in "
            "kernel_interface." in str(info.value))