Esempio n. 1
0
def test_multi_gamma():
    """
    Test using different equations of state either side of the interface.

    This is essentially the strong test (Figure 3) of Millmore and Hawke
    """
    eos1 = eos_defns.eos_gamma_law(1.4)
    eos2 = eos_defns.eos_gamma_law(1.67)
    w_left = State(10.2384,
                   0.9411,
                   0.0,
                   50.0 / 0.4 / 10.23841,
                   eos1,
                   label="L")
    w_right = State(0.1379, 0.0, 0.0, 1.0 / 0.1379 / 0.67, eos2, label="R")
    rp = RiemannProblem(w_left, w_right)
    v_shock_ref = 0.989670551306888
    v_contact_ref = 0.949361020941429
    v_raref_ref = [0.774348025484414, 0.804130593636139]
    p_star_ref = 41.887171487985299
    prim_star_l = [
        9.022178190552809, 0.949361020941429, 0.0, 11.606723621310707
    ]
    prim_star_r = [
        1.063740721273106, 0.949361020941430, 0.0, 58.771996925298758
    ]
    assert_allclose(rp.waves[0].wavespeed, v_raref_ref, rtol=1e-6)
    assert_allclose(rp.waves[1].wavespeed, v_contact_ref, rtol=1e-6)
    assert_allclose(rp.waves[2].wavespeed, v_shock_ref, rtol=1e-6)
    assert_allclose(rp.p_star, p_star_ref, rtol=1e-6)
    assert_allclose(rp.state_star_l.prim(), prim_star_l, rtol=1e-6)
    assert_allclose(rp.state_star_r.prim(), prim_star_r, rtol=1e-6)
Esempio n. 2
0
def test_bench_1():
    """
    Test Bench problem 1.

    Take from Marti & Muller's Living Review (section 6.3). See
    http://computastrophys.livingreviews.org/Articles/lrca-2015-3

    Uses Matlab code to test, so extreme accuracy given.
    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    w_left = State(10.0, 0.0, 0.0, 2.0, eos, label="L")
    w_right = State(1.0, 0.0, 0.0, 1.5e-6, eos, label="R")
    rp = RiemannProblem(w_left, w_right)
    v_shock_ref = 0.828398034190528
    v_contact_ref = 0.714020700932637
    v_raref_ref = [-0.716114874039433, 0.167236293932105]
    p_star_ref = 1.447945155994138
    prim_star_l = [
        2.639295549545608, 0.714020700932637, 0.0, 0.822915695957254
    ]
    prim_star_r = [
        5.070775964247521, 0.714020700932636, 0.0, 0.428320586297783
    ]
    assert_allclose(rp.waves[0].wavespeed, v_raref_ref, rtol=1e-8)
    assert_allclose(rp.waves[1].wavespeed, v_contact_ref, rtol=1e-8)
    assert_allclose(rp.waves[2].wavespeed, v_shock_ref, rtol=1e-8)
    assert_allclose(rp.p_star, p_star_ref, rtol=1e-8)
    assert_allclose(rp.state_star_l.prim(), prim_star_l, rtol=1e-8)
    assert_allclose(rp.state_star_r.prim(), prim_star_r, rtol=1e-8)
Esempio n. 3
0
def test_bench_2():
    """
    Test Bench problem 2.

    Take from Marti & Muller's Living Review (section 6.3). See
    http://computastrophys.livingreviews.org/Articles/lrca-2015-3

    Uses Matlab code to test, so extreme accuracy given.
    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    w_left = State(1.0, 0.0, 0.0, 1500.0, eos, label="L")
    w_right = State(1.0, 0.0, 0.0, 1.5e-2, eos, label="R")
    rp = RiemannProblem(w_left, w_right)
    v_shock_ref = 0.986804253648698
    v_contact_ref = 0.960409611243646
    v_raref_ref = [-0.816333330585011, 0.668125119704241]
    p_star_ref = 18.597078678567343
    prim_star_l = [
        0.091551789392213, 0.960409611243646, 0.0, 304.6976820774594
    ]
    prim_star_r = [
        10.415581582734182, 0.960409611243650, 0.0, 2.678258318680287
    ]
    assert_allclose(rp.waves[0].wavespeed, v_raref_ref, rtol=1e-8)
    assert_allclose(rp.waves[1].wavespeed, v_contact_ref, rtol=1e-8)
    assert_allclose(rp.waves[2].wavespeed, v_shock_ref, rtol=1e-8)
    assert_allclose(rp.p_star, p_star_ref, rtol=1e-8)
    assert_allclose(rp.state_star_l.prim(), prim_star_l, rtol=1e-8)
    assert_allclose(rp.state_star_r.prim(), prim_star_r, rtol=1e-8)
Esempio n. 4
0
def test_reactive_state():
    """
    Reactive EOS.
    """
    
    eos = eos_defns.eos_gamma_law(5.0/3.0)
    eos_reactive = eos_defns.eos_gamma_law_react(5.0/3.0, 1.0, 1.0, 1.0, eos)
    U = State(1.0, 0.0, 0.0, 1.5, eos_reactive, label="Test")
    string = r"\begin{pmatrix} \rho \\ v_x \\ v_t \\ \epsilon \\ q \end{pmatrix}_{Test}"
    string += r" = \begin{pmatrix} 1.0000 \\ 0.0000 \\ 0.0000 \\ 1.5000 \\ 1.0000 \end{pmatrix}"
    assert U.latex_string() == string
Esempio n. 5
0
def test_reactive_state():
    """
    Reactive EOS.
    """

    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    eos_reactive = eos_defns.eos_gamma_law_react(5.0 / 3.0, 1.0, 1.0, 1.0, eos)
    U = State(1.0, 0.0, 0.0, 1.5, eos_reactive, label="Test")
    string = r"\begin{pmatrix} \rho \\ v_x \\ v_t \\ \epsilon \\ q \end{pmatrix}_{Test}"
    string += r" = \begin{pmatrix} 1.0000 \\ 0.0000 \\ 0.0000 \\ 1.5000 \\ 1.0000 \end{pmatrix}"
    assert U.latex_string() == string
Esempio n. 6
0
def test_detonation_wave():
    """
    A single detonation wave
    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    eos_reactive = eos_defns.eos_gamma_law_react(5.0 / 3.0, 0.1, 1.0, 1.0, eos)
    U_reactive = State(5.0, 0.0, 0.0, 2.0, eos_reactive)
    U_burnt = State(8.113665227084942, -0.34940431910454606, 0.0,
                    2.7730993786742353, eos)
    rp = RiemannProblem(U_reactive, U_burnt)
    assert (rp.waves[2].wave_sections[0].trivial)
    assert_allclose(rp.waves[0].wavespeed, -0.82680400067536064)
Esempio n. 7
0
def test_deflagration_wave():
    """
    A single deflagration wave
    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    eos_reactive = eos_defns.eos_gamma_law_react(5.0 / 3.0, 0.1, 1.0, 1.0, eos)
    U_reactive = State(5.0, 0.0, 0.0, 2.0, eos_reactive)
    U_burnt = State(0.10089486779791534, 0.97346270073482888, 0.0,
                    0.14866950243842186, eos)
    rp = RiemannProblem(U_reactive, U_burnt)
    assert (rp.waves[2].wave_sections[0].trivial)
    wavespeed_deflagration = [-0.60970641412658788, 0.94395720523915128]
    assert_allclose(rp.waves[0].wavespeed, wavespeed_deflagration)
Esempio n. 8
0
def test_cj_detonation_wave():
    """
    A single CJ detonation wave
    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    eos_reactive = eos_defns.eos_gamma_law_react(5.0 / 3.0, 0.1, 1.0, 1.0, eos)
    U_reactive = State(5.0, 0.0, 0.0, 2.0, eos_reactive)
    U_burnt = State(5.1558523350586452, -0.031145176327346744, 0.0,
                    2.0365206985013153, eos)
    rp = RiemannProblem(U_reactive, U_burnt)
    assert (rp.waves[0].wave_sections[0].name == r"{\cal CJDT}_{\leftarrow}")
    assert (rp.waves[0].wave_sections[1].name == r"{\cal R}_{\leftarrow}")
    assert (rp.waves[2].wave_sections[0].trivial)
    wavespeed_cj_detonation = [-0.79738216287617047, -0.73237792243759536]
    assert_allclose(rp.waves[0].wavespeed, wavespeed_cj_detonation)
Esempio n. 9
0
def test_bench_3():
    """
    Test Bench problem 3.

    Take from Marti & Muller's Living Review (section 6.3). See
    http://computastrophys.livingreviews.org/Articles/lrca-2015-3

    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    w_left = State(1.0, 0.0, 0.0, 1500, eos, label="L")
    w_right = State(1.0, 0.0, 0.99, 0.015, eos, label="R")
    rp = RiemannProblem(w_left, w_right)
    v_shock_ref = 0.927006
    v_contact_ref = 0.766706
    assert_allclose(rp.waves[2].wavespeed, v_shock_ref, rtol=1e-5)
    assert_allclose(rp.waves[1].wavespeed, v_contact_ref, rtol=1e-5)
Esempio n. 10
0
def test_precursor_deflagration_wave():
    """
    A single deflagration wave with precursor shock
    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    eos_reactive = eos_defns.eos_gamma_law_react(5.0 / 3.0, 0.1, 1.0, 1.0, eos)
    U_reactive = State(0.5, 0.0, 0.0, 1.0, eos_reactive)
    U_burnt = State(0.24316548798524526, 0.39922932397353039, 0.0,
                    0.61686385086179807, eos)
    rp = RiemannProblem(U_reactive, U_burnt)
    assert (rp.waves[0].wave_sections[0].name == r"{\cal S}_{\leftarrow}")
    assert (rp.waves[0].wave_sections[1].name == r"{\cal CJDF}_{\leftarrow}")
    assert (rp.waves[0].wave_sections[2].name == r"{\cal R}_{\leftarrow}")
    assert (rp.waves[2].wave_sections[0].trivial)
    wavespeed_deflagration = [-0.65807776007359042, -0.23714630045322399]
    assert_allclose(rp.waves[0].wavespeed, wavespeed_deflagration)
Esempio n. 11
0
def test_standard_sod():
    """
    Relativistic Sod test.

    Numbers are taken from the General Matlab code, so accuracy isn't perfect.
    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    w_left = State(1.0, 0.0, 0.0, 1.5, eos, label="L")
    w_right = State(0.125, 0.0, 0.0, 1.2, eos, label="R")
    rp = RiemannProblem(w_left, w_right)
    p_star_matlab = 0.308909954203586
    assert_allclose(rp.p_star, p_star_matlab, rtol=1e-6)
    rarefaction_speeds_matlab = [-0.690065559342354, -0.277995552140227]
    assert_allclose(rp.waves[0].wavespeed,
                    rarefaction_speeds_matlab,
                    rtol=1e-6)
    shock_speed_matlab = 0.818591417744604
    assert_allclose(rp.waves[2].wavespeed, shock_speed_matlab, rtol=1e-6)
Esempio n. 12
0
def test_trivial():
    """
    A trivial Riemann Problem
    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    U = State(1.0, 0.0, 0.0, 1.0, eos)
    rp = RiemannProblem(U, U)
    for wave in rp.waves:
        assert (wave.wave_sections[0].trivial)
        assert (wave.name == "")
Esempio n. 13
0
def test_bench_4():
    """
    Test Bench problem 4.

    Take from Marti & Muller's Living Review (section 6.3). See
    http://computastrophys.livingreviews.org/Articles/lrca-2015-3

    Left and right states have been flipped so it complements the above
    Sod test.
    """
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    w_left = State(1.0, 0.0, 0.9, 0.015, eos, label="L")
    w_right = State(1.0, 0.0, 0.9, 1500, eos, label="R")
    rp = RiemannProblem(w_left, w_right)
    v_shock_ref = -0.445008
    v_contact_ref = -0.319371
    p_star_ref = 0.90379102665871947
    assert_allclose(rp.waves[0].wavespeed, v_shock_ref, rtol=1e-5)
    assert_allclose(rp.waves[1].wavespeed, v_contact_ref, rtol=1e-5)
    assert_allclose(rp.p_star, p_star_ref, rtol=1e-4)
Esempio n. 14
0
def make_flat_patterns(U_l, U_r, vts, vt_side):
    """
    Save some code repetition. Given reactive and burnt states, produces a list of lists of wave patterns for a given list of tangential velocities.
    """
    eos_l = eos_defns.eos_gamma_law(5.0 / 3.0)
    eos_r = eos_defns.eos_gamma_law_react(5.0 / 3.0, 0.1, 1.0, 1.0, eos_l)

    wave_patterns = []
    if vt_side == 'l':
        rho_l = U_l.rho
        v_l = U_l.v
        eps_l = U_l.eps
        eos_l = U_l.eos
    else:
        rho_r = U_r.rho
        v_r = U_r.v
        eps_r = U_r.eps
        eos_r = U_r.eos

    for vt in vts:
        # first change the vt
        if vt_side == 'l':
            U_l = State(rho_l, v_l, vt, eps_l, eos_l)
            U_r = State(rho_r, v_r, 0.0, eps_r, eos_r)
        else:
            U_r = State(rho_r, v_r, vt, eps_r, eos_r)
        rp = RiemannProblem(U_l, U_r)
        wave_patterns.append(rp.waves)

    # now check if all the wave patterns are the same

    # flatten patterns
    flat_patterns = []
    for i, p in enumerate(wave_patterns):
        flat_patterns.append([])
        for w in p:
            for s in w.wave_sections:
                if not s.trivial:
                    flat_patterns[i].append(s.type)

    return flat_patterns
Esempio n. 15
0
def test_basic_state():
    """
    Simple gamma law, inert state
    """

    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    U = State(1.0, 0.0, 0.0, 1.5, eos, label="Test")
    state = U.state()
    state_correct = [1.0, 0.0, 0.0, 1.5, 1.0, 1.0, 3.5, sqrt(10.0 / 21.0)]
    assert_allclose(state, state_correct)
    string = r"\begin{pmatrix} \rho \\ v_x \\ v_t \\ \epsilon \end{pmatrix}_{Test}"
    string += r" = \begin{pmatrix} 1.0000 \\ 0.0000 \\ 0.0000 \\ 1.5000 \end{pmatrix}"
    assert U.latex_string() == string
    assert U._repr_latex_() == r"$" + string + r"$"
    assert_allclose(U.wavespeed(0), -sqrt(10.0 / 21.0))
    assert_allclose(U.wavespeed(1), 0.0)
    assert_allclose(U.wavespeed(2), +sqrt(10.0 / 21.0))
    assert_raises(NotImplementedError, U.wavespeed, 3)
Esempio n. 16
0
def test_find_left_state_subsonic():
    """
    For setting up single shock initial data; subsonic case.
    """

    gamma = 5./3.
    K = 1.
    eos = eos_defns.eos_gamma_law(gamma)

    # right state
    rho_r, v_r, vt_r = (0.001, 0.0, 0.0)
    eps_r = K * rho_r**(gamma - 1.) / (gamma - 1.)

    # initialise right state
    q_r = State(rho_r, v_r, vt_r, eps_r, eos, label="R")

    q_l, v_s = utils.find_left(q_r, M=0.5)

    q_l_expected = [0.00066884219753554435, -0.048031759566342737,  0.0,  0.011472032502081871]
    v_s_expected = 0.064150029919561105

    assert_allclose(q_l.prim(), q_l_expected)
    assert_allclose(v_s, v_s_expected)
Esempio n. 17
0
def test_find_left_state():
    """
    For setting up single shock initial data.
    """

    gamma = 5./3.
    K = 1.
    eos = eos_defns.eos_gamma_law(gamma)

    # right state
    rho_r, v_r, vt_r = (0.001, 0.0, 0.0)
    eps_r = K * rho_r**(gamma - 1.) / (gamma - 1.)

    # initialise right state
    q_r = State(rho_r, v_r, vt_r, eps_r, eos, label="R")

    q_l, v_s = utils.find_left(q_r, M=20.)

    q_l_expected = [0.0062076725292866553,  0.85384931817355381,  0.0,  0.96757276531735015]
    v_s_expected = 0.93199842492399299

    assert_allclose(q_l.prim(), q_l_expected)
    assert_allclose(v_s, v_s_expected)
Esempio n. 18
0
def test_basic_state():
    """
    Simple gamma law, inert state
    """
    
    eos = eos_defns.eos_gamma_law(5.0/3.0)
    U = State(1.0, 0.0, 0.0, 1.5, eos, label="Test")
    state = U.state()
    state_correct = [1.0, 0.0, 0.0, 1.5, 1.0, 1.0, 3.5, sqrt(10.0/21.0)]
    assert_allclose(state, state_correct)
    string = r"\begin{pmatrix} \rho \\ v_x \\ v_t \\ \epsilon \end{pmatrix}_{Test}"
    string += r" = \begin{pmatrix} 1.0000 \\ 0.0000 \\ 0.0000 \\ 1.5000 \end{pmatrix}"
    assert U.latex_string() == string
    assert U._repr_latex_() == r"$" + string + r"$"
    assert_allclose(U.wavespeed(0), -sqrt(10.0/21.0))
    assert_allclose(U.wavespeed(1), 0.0)
    assert_allclose(U.wavespeed(2), +sqrt(10.0/21.0))
    assert_raises(NotImplementedError, U.wavespeed, 3)
Esempio n. 19
0
            v, ', '.join(critical_patterns[i][0]),
            ', '.join(critical_patterns[i][1])))


if __name__ == "__main__":
    eos = eos_defns.eos_gamma_law(5.0 / 3.0)
    eos_reactive = eos_defns.eos_gamma_law_react(5.0 / 3.0, 0.1, 1.0, 1.0, eos)
    #U_reactive = State(5.0, 0.0, 0.0, 2.0, eos_reactive)
    # detonation wave
    #U_burnt = State(8.113665227084942, -0.34940431910454606, 0.0,
    #                2.7730993786742353, eos)
    # cj detonation wave
    #U_burnt = State(5.1558523350586452, -0.031145176327346744, 0.0,
    #                2.0365206985013153, eos)
    # deflagration
    #U_burnt = State(0.10089486779791534, 0.97346270073482888, 0.0,
    #                0.14866950243842186, eos)
    # deflagration with precursor shock
    #U_burnt = State(0.24316548798524526, 0.39922932397353039, 0.0,
    #                0.61686385086179807, eos)

    # FIXME: there is a really weird bug where this breaks if U_r has a
    # non-zero normal velocity and try to give U_l tangential velocity.
    U_l = State(1.0, 0.0, 0.0, 1.6, eos)
    U_r = State(0.125, 0.5, 0.0, 1.2, eos_reactive)

    #check_wave_pattern(U_l, U_r, 'l', vts=[-0.5,-0.1, 0.0, 0.1, 0.5, 0.87])
    #check_wave_pattern(U_l, U_r, 'l', vts=[0.5, 0.55])
    #check_wave_pattern(U_r, U_l, 'l')
    find_critical_vt(U_l, U_r, 'l')