22f64 shamphys::SodTube::soundspeed(
f64 P,
f64 rho) {
return std::sqrt(gamma * P / rho); };
24shamphys::SodTube::SodTube(
f64 _gamma,
f64 _rho_1,
f64 _P_1,
f64 _rho_5,
f64 _P_5)
25 : gamma(_gamma), rho_1(_rho_1), P_1(_P_1), rho_5(_rho_5), P_5(_P_5) {
34f64 shamphys::SodTube::solve_P_4() {
36 auto shock_tube_function = [=](
f64 P_4) {
37 f64 z = (P_4 / P_5 - 1.);
39 f64 gm1 = gamma - 1.0;
40 f64 gp1 = gamma + 1.0;
43 f64 fact1 = gm1 / g2 * (c_5 / c_1) * z / std::sqrt(1. + gp1 / g2 * z);
44 f64 fact = std::pow(1.0 - fact1, g2 / gm1);
46 return P_1 * fact - P_4;
49 auto df = [=](
f64 P_4) {
50 return shammath::derivative_upwind<f64>(P_4, 1e-6, shock_tube_function);
53 return shammath::newton_rhaphson<f64>(shock_tube_function, df, 1e-6, P_1);
56auto shamphys::SodTube::get_value(
f64 t,
f64 x) -> field_val {
58 f64 P_4 = solve_P_4();
60 f64 z = (P_4 / P_5 - 1.);
62 f64 gm1 = gamma - 1.0;
63 f64 gp1 = gamma + 1.0;
64 f64 gmfact1 = 0.5 * gm1 / gamma;
65 f64 gmfact2 = 0.5 * gp1 / gamma;
67 f64 fact = std::sqrt(1. + gmfact2 * z);
69 f64 vx_4 = c_5 * z / (gamma * fact);
70 f64 rho_4 = rho_5 * (1. + gmfact2 * z) / (1. + gmfact1 * z);
79 f64 rho_3 = rho_1 * std::pow(P_3 / P_1, 1. / gamma);
84 f64 xhd, xft, xcd, xsh;
89 xft = xi + (vx_3 - c3) * t;
106 }
else if (x < xft) {
107 vx = 2. / gp1 * (c_1 + (x - xi) / t);
108 f64 locfact = 1. - 0.5 * gm1 * vx / c_1;
109 rho = rho_1 * std::pow(locfact, 2. / gm1);
110 p = P_1 * std::pow(locfact, 2. * gamma / gm1);
111 }
else if (x < xcd) {
116 }
else if (x < xsh) {
constexpr const char * soundspeed
Sound speed c_s (derived from EOS)
double f64
Alias for double.