Пример #1
0
def eos_derivatives(gas0, gmodel, tol=0.0001):
    # Finite difference evaluation, assuming that gas0 is valid state already.
    gas1 = GasState(gmodel)
    gas1.copy_values(gas0)
    p0 = gas0.p; rho0 = gas0.rho; u0 = gas0.u
    #
    drho = rho0 * tol; gas1.rho = rho0 + drho
    gas1.update_thermo_from_rhou()
    dpdrho = (gas1.p - p0)/drho
    #
    gas1.rho = rho0; du = u0 * tol; gas1.u = u0 + du
    gas1.update_thermo_from_rhou()
    dpdu = (gas1.p - p0)/du
    #
    return dpdrho, dpdu
Пример #2
0
    gas1.update_thermo_from_rhou()
    dpdrho = (gas1.p - p0) / drho
    #
    gas1.rho = rho0
    du = u0 * tol
    gas1.u = u0 + du
    gas1.update_thermo_from_rhou()
    dpdu = (gas1.p - p0) / du
    #
    return dpdrho, dpdu


#------------------------------------------------------------------
print("Step in time, allowing the gas to react and drift along in x.")
gas0 = GasState(gmodel)
gas0.copy_values(state2)  # start with post-shock conditions
x = 0  # position of shock, m
x_final = 1.0  # the marching will stop at this point, metres
v = v2  # velocity of gas post-shock, m/s
dt_suggest = 1.0e-8  # suggested starting time-step for chemistry updater
#
f = open(output_filename, 'w')
f.write(header)
f.write(string_data(x, v, gas0, dt_suggest))
#
t = 0  # time of drift is in seconds
t_final = 3.0e-3  # User-selected drift time, s
t_inc = 0.1e-6  # User-selected time steps, s
nsteps = int(t_final / t_inc)
# Notes:
#  Select t_final to be long enough to reach x_final.
Пример #3
0
print("# Start reactions...")
reactor = ThermochemicalReactor(gmodel, "h2-o2-n2-9sp-18r.lua")
t = 0  # time is in seconds
t_final = 22.0e-6
t_inc = 0.05e-6
nsteps = int(t_final / t_inc)
for j in range(1, nsteps + 1):
    # At the start of the step...
    rho = gas0.rho
    T = gas0.T
    p = gas0.p
    u = gas0.u
    #
    # Do the chemical increment.
    gas1 = GasState(gmodel)  # make the new one as a clone
    gas1.copy_values(gas0)
    dt_suggest = reactor.update_state(gas1, t_inc, dt_suggest)
    gas1.update_thermo_from_rhou()
    #
    du_chem = gas1.u - u
    dp_chem = gas1.p - p
    if debug: print("# du_chem=", du_chem, "dp_chem=", dp_chem)
    #
    # Do the gas-dynamic accommodation after the chemical change.
    etot = u + 0.5 * v * v
    dfdr, dfdu = eos_derivatives(gas1, gmodel)
    if debug: print("# dfdr=", dfdr, "dfdu=", dfdu)
    # Linear solve to get the accommodation increments.
    #   [v,      rho,        0.0, 0.0  ]   [drho  ]   [0.0           ]
    #   [0.0,    rho*v,      1.0, 0.0  ] * [dv    ] = [-dp_chem      ]
    #   [v*etot, rho*etot+p, 0.0, rho*v]   [dp_gda]   [-rho*v*du_chem]