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
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
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)
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)
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)
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)
def test_eos_gamma_law_react(): eos_inert = eos_defns.eos_gamma_law(5.0/3.0) eos = eos_defns.eos_gamma_law_react(5.0/3.0, 0.5, 1.0, 10.0, eos_inert) rho = 1.0 eps = 1.0 p_true = 1.0 / 3.0 h_true = 7.0 / 3.0 cs_true = numpy.sqrt(5.0 / 21.0) t_true = 0.5 p = eos['p_from_rho_eps'](rho, eps) h = eos['h_from_rho_eps'](rho, eps) cs = eos['cs_from_rho_eps'](rho, eps) t = eos['t_from_rho_eps'](rho, eps) assert_allclose([p, h, cs, t], [p_true, h_true, cs_true, t_true], rtol=1.e-8)
def test_eos_gamma_law_react(): eos_inert = eos_defns.eos_gamma_law(5.0 / 3.0) eos = eos_defns.eos_gamma_law_react(5.0 / 3.0, 0.5, 1.0, 10.0, eos_inert) rho = 1.0 eps = 1.0 p_true = 1.0 / 3.0 h_true = 7.0 / 3.0 cs_true = numpy.sqrt(5.0 / 21.0) t_true = 0.5 p = eos['p_from_rho_eps'](rho, eps) h = eos['h_from_rho_eps'](rho, eps) cs = eos['cs_from_rho_eps'](rho, eps) t = eos['t_from_rho_eps'](rho, eps) assert_allclose([p, h, cs, t], [p_true, h_true, cs_true, t_true], rtol=1.e-8)
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)
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)
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)
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)
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
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
critical_patterns.append(pattern) if len(critical_vts) == 1: print('There is one critical tangential velocity ') else: print('There are {} critical tangential velocities '.format( len(critical_vts))) for i, v in enumerate(critical_vts): print('vt: {}, patterns: {} -> {}'.format( 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
for i in range(len(vts) - 1): if not flat_patterns[i] == flat_patterns[i+1]: vt, pattern = bisect(vts[i], vts[i+1]) critical_vts.append(vt) critical_patterns.append(pattern) if len(critical_vts) == 1: print('There is one critical tangential velocity ') else: print('There are {} critical tangential velocities '.format(len(critical_vts))) for i, v in enumerate(critical_vts): print('vt: {}, patterns: {} -> {}'.format(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