def error_in_velocity(p3p4, state4=state4, state1=state1): "Compute the velocity mismatch for a given pressure ratio across the expansion." # Across the expansion, we get a test-gas velocity, V3g. p3 = p3p4*state4.p V3g, state3 = finite_wave_dp('cplus', 0.0, state4, p3) # Across the contact surface. p2 = p3 print "current guess for p3 and p2=", p2 V1s, V2, V2g, state2 = normal_shock_p2p1(state1, p2/state1.p) return (V3g - V2g)/V3g
def error_in_velocity(p5p2, state2=state2, V2g=V2g, state10=state10): "Compute the velocity mismatch for a given pressure ratio across the expansion." # Across the expansion, we get a test-gas velocity, V5g. V5g, state5 = finite_wave_dp('cplus', V2g, state2, p5p2 * state2.p) # Across the contact surface, p20 == p5 p20 = p5p2 * state2.p print "current guess for p5 and p20=", p20 V10, V20, V20g, state20 = normal_shock_p2p1(state10, p20 / state10.p) return ( V5g - V10 ) / V5g # V10 was V20g - lab speed of accelerator gas - we now make the assumption that this is the same as the shock speed
def main(): #build some gas objects print "pure He driver gas" state4 = Gas({'He': 1.0}, inputUnits='moles', outputUnits='moles') state4.set_pT(2.79e+07, 2700.0) print "state1:" state4.write_state(sys.stdout) print "Air test gas" state1 = Gas({ 'Air': 1.0, }) state1.set_pT(3000.0, 300.0) print "state1:" state1.write_state(sys.stdout) # print "Air accelerator gas" state5 = Gas({'Air': 1.0}) state5.set_pT(10.0, 300.0) print "state10:" state5.write_state(sys.stdout) print "Steady expansion of driver" #for 100%He condition mach number terminating steady expansion is 2.15 #need to work out the corresponding pressure for this to put into #the function M4dash = 2.15 #mach number terminating steady expansion (state4dash, V4dash) = expand_from_stagnation(1.0 / (p0_p(M4dash, state4.gam)), state4) print "state4dash:" state4dash.write_state(sys.stdout) print "V4dash = {0} m/s".format(V4dash) #I think we need to start guessing shock speeds to be able to keep going here print "Start working on the shock into the test gas" print "Guess US1 of 5080 m/s" state2 = state1.clone() V2, V2g = normal_shock(state1, 5080.0, state2) print "state2:" state2.write_state(sys.stdout) print "Checks:" print "p2/p1=", state2.p / state1.p print "rho2/rho1=", state2.rho / state1.rho print "T2/T1=", state2.T / state1.T print "V2g = {0} m/s".format(V2g) print "Unsteady expansion from state 4dash to state 3" print "Well, giving it a go for now anyway" (V3, state3) = finite_wave_dp('cplus', V4dash, state4dash, state2.p, steps=100) print "state3:" state3.write_state(sys.stdout) print "V3 = {0} m/s".format(V3) print "Start working on the shock into the accelerator gas" print "Guess US2 of 11100 m/s" state6 = state5.clone() V6, V6g = normal_shock(state5, 11100.0, state6) print "state6:" state6.write_state(sys.stdout) print "Checks:" print "p2/p1=", state6.p / state5.p print "rho2/rho1=", state6.rho / state5.rho print "T2/T1=", state6.T / state5.T print "V6g = {0} m/s".format(V6g) print "Unsteady expansion from state 2 to state 7" print "Well, giving it a go for now anyway" (V7, state7) = finite_wave_dp('cplus', V2g, state2, state6.p, steps=100) print "state7:" state7.write_state(sys.stdout) print "V7 = {0} m/s".format(V7) M7 = V7 / (state7.gam * state7.R * state7.T)**(0.5) print "M7 = {0}".format(M7) """
def main(): print "Helium driver gas" state4 = Gas({'He':1.0}) state4.set_pT(30.0e6, 3000.0) print "state4:" state4.write_state(sys.stdout) # print "Air driven gas" state1 = Gas({'Air':1.0}) state1.set_pT(30.0e3, 300.0) print "state1:" state1.write_state(sys.stdout) # print "\nNow do the classic shock tube solution..." # For the unsteady expansion of the driver gas, regulation of the amount # of expansion is determined by the shock-processed test gas. # Across the contact surface between these gases, the pressure and velocity # have to match so we set up some trials of various pressures and check # that velocities match. def error_in_velocity(p3p4, state4=state4, state1=state1): "Compute the velocity mismatch for a given pressure ratio across the expansion." # Across the expansion, we get a test-gas velocity, V3g. p3 = p3p4*state4.p V3g, state3 = finite_wave_dp('cplus', 0.0, state4, p3) # Across the contact surface. p2 = p3 print "current guess for p3 and p2=", p2 V1s, V2, V2g, state2 = normal_shock_p2p1(state1, p2/state1.p) return (V3g - V2g)/V3g p3p4 = secant(error_in_velocity, 0.1, 0.11, tol=1.0e-3) print "From secant solve: p3/p4=", p3p4 print "Expanded driver gas:" p3 = p3p4*state4.p V3g, state3 = finite_wave_dp('cplus', 0.0, state4, p3) print "V3g=", V3g print "state3:" state3.write_state(sys.stdout) print "Shock-processed test gas:" V1s, V2, V2g, state2 = normal_shock_p2p1(state1, p3/state1.p) print "V1s=", V1s, "V2g=", V2g print "state2:" state2.write_state(sys.stdout) assert abs(V2g - V3g)/V3g < 1.0e-3 # # Make a record for plotting against the Eilmer3 simulation data. # We reconstruct the expected data along a tube 0.0 <= x <= 1.0 # at t=100us, where the diaphragm is at x=0.5. x_centre = 0.5 # metres t = 100.0e-6 # seconds fp = open('exact.data', 'w') fp.write('# 1:x(m) 2:rho(kg/m**3) 3:p(Pa) 4:T(K) 5:V(m/s)\n') print 'Left end' x = 0.0 fp.write('%g %g %g %g %g\n' % (x, state4.rho, state4.p, state4.T, 0.0)) print 'Upstream head of the unsteady expansion.' x = x_centre - state4.a * t fp.write('%g %g %g %g %g\n' % (x, state4.rho, state4.p, state4.T, 0.0)) print 'The unsteady expansion in n steps.' n = 100 dp = (state3.p - state4.p) / n state = state4.clone() V = 0.0 p = state4.p for i in range(n): rhoa = state.rho * state.a dV = -dp / rhoa V += dV p += dp state.set_ps(p, state4.s) x = x_centre + t * (V - state.a) fp.write('%g %g %g %g %g\n' % (x, state.rho, state.p, state.T, V)) print 'Downstream tail of expansion.' x = x_centre + t * (V3g - state3.a) fp.write('%g %g %g %g %g\n' % (x, state3.rho, state3.p, state3.T, V3g)) print 'Contact surface.' x = x_centre + t * V3g fp.write('%g %g %g %g %g\n' % (x, state3.rho, state3.p, state3.T, V3g)) x = x_centre + t * V2g # should not have moved fp.write('%g %g %g %g %g\n' % (x, state2.rho, state2.p, state2.T, V2g)) print 'Shock front' x = x_centre + t * V1s # should not have moved fp.write('%g %g %g %g %g\n' % (x, state2.rho, state2.p, state2.T, V2g)) fp.write('%g %g %g %g %g\n' % (x, state1.rho, state1.p, state1.T, 0.0)) print 'Right end' x = 1.0 fp.write('%g %g %g %g %g\n' % (x, state1.rho, state1.p, state1.T, 0.0)) fp.close() return
def main(): print "Titan gas" state1 = Gas({ 'N2': 0.95, 'CH4': 0.05 }, inputUnits='moles', outputUnits='moles') state1.set_pT(2600.0, 300.0) print "state1:" state1.write_state(sys.stdout) # print "Air accelerator gas" state10 = Gas({'Air': 1.0}) state10.set_pT(10.0, 300.0) print "state10:" state10.write_state(sys.stdout) # print "Incident shock" state2 = state1.clone() V2, V2g = normal_shock(state1, 4100.0, state2) print "V2=", V2, "Vg=", V2g, "expected 3670.56" print "state2:" state2.write_state(sys.stdout) print "Checks:" print "p2/p1=", state2.p / state1.p, "expected 166.4" print "rho2/rho1=", state2.rho / state1.rho, "expected 9.5474" print "T2/T1=", state2.T / state1.T, "expected 14.9" # print "\nNow do unsteady expansion..." # For the unsteady expansion of the test gas, regulation of the amount # of expansion is determined by the shock-processed accelerator gas. # Across the contact surface between these gases, the pressure and velocity # have to match so we set up some trials of various pressures and check # that velocities match. def error_in_velocity(p5p2, state2=state2, V2g=V2g, state10=state10): "Compute the velocity mismatch for a given pressure ratio across the expansion." # Across the expansion, we get a test-gas velocity, V5g. V5g, state5 = finite_wave_dp('cplus', V2g, state2, p5p2 * state2.p) # Across the contact surface, p20 == p5 p20 = p5p2 * state2.p print "current guess for p5 and p20=", p20 V10, V20, V20g, state20 = normal_shock_p2p1(state10, p20 / state10.p) return ( V5g - V10 ) / V5g # V10 was V20g - lab speed of accelerator gas - we now make the assumption that this is the same as the shock speed p5p2 = secant(error_in_velocity, 0.01, 0.011, tol=1.0e-3) print "From secant solve: p5/p2=", p5p2 # It would have been faster and the code closer to Hadas' spreadsheet if we had # stepped down in pressure until we found the point where the velocities matched. # The expansion along the u+a wave would have appeared in the code here. V5g, state5 = finite_wave_dp('cplus', V2g, state2, p5p2 * state2.p) print "Expanded test gas, at end of acceleration tube:" print "V5g=", V5g print "state5:" state5.write_state(sys.stdout) V10, V20, V20g, state20 = normal_shock_p2p1(state10, state5.p / state10.p) print V10 print "Done." return