Exemple #1
0
def test_convergence_name():

    in_path = os.path.join(DATA_DIR_PATH, "prD.do")
    main_list = simple_read(in_path)
    convergence = Convergence("test")
    convergence.add_grids(main_list)

    assert str(convergence)
Exemple #2
0
def test_convergence_two_grids():

    convergence = Convergence()

    with pytest.warns(UserWarning):
        convergence.add_grids([(1, 0.5), (0.5, 0.4)])

    lines = str(convergence).split("\n")

    assert len(lines) == 10
    assert lines[1] == "Number of grids to be examined = 2 "
    assert lines[-2] == " *** Insufficient grids for analysis *** "
Exemple #3
0
def test_convergence_gci_error(mocker):

    mocker.patch('convergence.interface.gci',
                 side_effect=ArithmeticError("mock"))

    in_path = os.path.join(DATA_DIR_PATH, "prD.do")
    main_list = simple_read(in_path)
    convergence = Convergence(f_anal=0.9713)

    with pytest.warns(UserWarning):
        convergence.add_grids(main_list)

    expected_lines = (
        '', 'Number of grids to be examined = 3 ', '',
        '     Grid Size     Quantity ', '', '     1.000000      0.970500 ',
        '     2.000000      0.968540 ', '     4.000000      0.961780 ', '', '',
        'Discretisation errors for fine grids: ', '',
        '       Grids |   e_analytic |     e_approx |     e_extrap |   f_analytic | ',
        ' ========================================================================= ',
        '       1 2 3 |     0.000824 |     0.002020 |     0.000824 |     0.971300 | ',
        ' ------------------------------------------------------------------------- ',
        '',
        '       Grids |      f_delta |      f_exact |   gci_coarse |     gci_fine | ',
        ' ========================================================================= ',
        '       1 2 3 |    -0.000000 |     0.971300 |              |              | ',
        ' ------------------------------------------------------------------------- ',
        '', '       Grids |            p |          r21 |          r32 | ',
        ' ========================================================== ',
        '       1 2 3 |     1.786170 |     2.000000 |     2.000000 | ',
        ' ---------------------------------------------------------- ', '', '',
        'Discretisation errors for coarse grids: ', '',
        '       Grids |   e_analytic |     e_approx |     e_extrap |   f_analytic | ',
        ' ========================================================================= ',
        '       1 2 3 |     0.002842 |     0.006980 |     0.002842 |     0.971300 | ',
        ' ------------------------------------------------------------------------- ',
        '',
        '       Grids |      f_delta |      f_exact |   gci_coarse |     gci_fine | ',
        ' ========================================================================= ',
        '       1 2 3 |    -0.000000 |     0.971300 |              |              | ',
        ' ------------------------------------------------------------------------- ',
        '', '       Grids |            p |          r21 |          r32 | ',
        ' ========================================================== ',
        '       1 2 3 |     1.786170 |     2.000000 |     2.000000 | ',
        ' ---------------------------------------------------------- ', '', '',
        'Asymptotic ratio test: ', '',
        '           Grids | Asymptotic ratio | ',
        ' ==================================== ',
        '           1 2 3 |                  | ',
        ' ------------------------------------ ', '')

    for actual, expected in zip(str(convergence).split("\n"), expected_lines):
        assert actual == expected
Exemple #4
0
def test_order_of_convergence_runtimeerror(mocker):

    mocker.patch('convergence.interface.order_of_convergence',
                 side_effect=RuntimeError("mock"))

    in_path = os.path.join(DATA_DIR_PATH, "prD.do")
    main_list = simple_read(in_path)
    convergence = Convergence(f_anal=0.9713)

    with pytest.warns(UserWarning):
        convergence.add_grids(main_list)

    assert str(convergence)
Exemple #5
0
def test_get_coarse_values_gci_error(mocker):

    mocker.patch('convergence.interface.gci',
                 side_effect=ArithmeticError("mock"))

    in_path = os.path.join(DATA_DIR_PATH, "prD.do")
    main_list = simple_read(in_path)
    convergence = Convergence(f_anal=0.9713)
    convergence._set_grids(main_list)
    convergence._set_grid_triplets()
    convergence._get_shared()

    with pytest.warns(UserWarning):
        convergence._get_coarse_values()

    assert convergence._grid_coarse[0]["gci_f"] is None
Exemple #6
0
def test_get_fine_values_richardson_extrapolate_error(mocker):

    mocker.patch('convergence.interface.richardson_extrapolate',
                 side_effect=ArithmeticError("mock"))

    in_path = os.path.join(DATA_DIR_PATH, "prD.do")
    main_list = simple_read(in_path)
    convergence = Convergence(f_anal=0.9713)
    convergence._set_grids(main_list)
    convergence._set_grid_triplets()
    convergence._get_shared()

    with pytest.warns(UserWarning):
        convergence._get_fine_values()

    assert convergence._grid_fine[0]["f_exact"] is None
    assert convergence._grid_fine[0]["f_delta"] is None
Exemple #7
0
def test_get_resolution_insufficient_grids():

    convergence = Convergence()

    with pytest.warns(UserWarning):
        convergence.add_grids([(1, 0.5)])

    with pytest.raises(RuntimeError) as excinfo:
        convergence.get_resolution(0.001)

    assert "Insufficient grids" in str(excinfo)
Exemple #8
0
def test_get_ratios_error(mocker, test_input):

    mocker.patch(test_input, side_effect=ArithmeticError("mock"))

    in_path = os.path.join(DATA_DIR_PATH, "prD.do")
    main_list = simple_read(in_path)
    convergence = Convergence(f_anal=0.9713)
    convergence._set_grids(main_list)
    convergence._set_grid_triplets()
    convergence._get_shared()

    with pytest.warns(UserWarning):
        convergence._get_fine_values()
        convergence._get_coarse_values()
        convergence._get_ratios()

    assert convergence._grid_ratios[0]['assym_ratio'] is None
Exemple #9
0
def convergence_anal():
    in_path = os.path.join(DATA_DIR_PATH, "prD.do")
    main_list = simple_read(in_path)
    convergence = Convergence(f_anal=0.9713)
    convergence.add_grids(main_list)
    return convergence
Exemple #10
0
def test_convergence_no_iter():
    convergence = Convergence()
    with pytest.raises(IndexError):
        convergence[0]
Exemple #11
0
def test_convergence_no_len():
    convergence = Convergence()
    assert len(convergence) == 0