Exemplo n.º 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
Exemplo n.º 2
0
# Notes:
#  Select t_final to be long enough to reach x_final.
#  Select t_inc small enough to capture fast changes near x=0.
#
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]
    #   [dfdr,   0.0,       -1.0, dfdu ]   [du_gda]   [0.0           ]
    #
Exemplo n.º 3
0
from eilmer.gas import GasModel, GasState

gmodel = GasModel("ideal-air-gas-model.lua")
print("gmodel=", gmodel)
print("n_species=", gmodel.n_species, ", n_modes=", gmodel.n_modes)
print("species_names=", gmodel.species_names)
print("mol_masses=", gmodel.mol_masses)

gs = GasState(gmodel)
print("freshly minted gs=", gs)
gs.rho=1.1; gs.p=1.0e5; gs.T=300.0; gs.u=1.44e6; gs.massf=[1.0]
print("after setting some values")
print("  gs.rho=%g p=%g T=%g u=%g massf=%s a=%g k=%g mu=%g" %
      (gs.rho, gs.p, gs.T, gs.u, gs.massf, gs.a, gs.k, gs.mu))
gmodel.update_thermo_from_pT(gs) # the way that we do the update in D
gmodel.update_sound_speed(gs) # not necessary from Python but is available
gmodel.update_trans_coeffs(gs)
print("after update thermo from pT")
print("  gs.rho=%g p=%g T=%g u=%g massf=%s a=%g k=%g mu=%g" %
      (gs.rho, gs.p, gs.T, gs.u, gs.massf, gs.a, gs.k, gs.mu))
gs.p=3000.0; gs.T=99.0; gs.massf={'air':1.0}
gs.update_thermo_from_rhou() # update another way
gs.update_trans_coeffs()
print("after update thermo from rhou")
print("  gs.rho=%g p=%g T=%g u=%g massf=%s a=%g k=%g mu=%g" %
      (gs.rho, gs.p, gs.T, gs.u, gs.massf, gs.a, gs.k, gs.mu))

print("Some derived properties")
print("gs.Cv=%g Cp=%g R=%g enthalpy=%g entropy=%g molecular_mass=%g" %
      (gs.Cv, gs.Cp, gs.R, gs.enthalpy, gs.entropy, gs.molecular_mass))
Exemplo n.º 4
0
from eilmer.gas import GasModel, GasState, ThermochemicalReactor

gm = GasModel("nitrogen-2sp.lua")
reactor = ThermochemicalReactor(gm, "chem.lua")

gs = GasState(gm)
gs.p = 1.0e5  # Pa
gs.T = 4000.0  # degree K
gs.molef = {'N2': 2 / 3, 'N': 1 / 3}
gs.update_thermo_from_pT()

tFinal = 200.0e-6  # s
t = 0.0
dt = 1.0e-6
dtSuggest = 1.0e-11
print("# Start integration")
f = open("fvreactor.data", 'w')
f.write(
    '# 1:t(s)  2:T(K)  3:p(Pa)  4:massf_N2  5:massf_N  6:conc_N2  7:conc_N\n')
f.write("%10.3e %10.3f %10.3e %20.12e %20.12e %20.12e %20.12e\n" %
        (t, gs.T, gs.p, gs.massf[0], gs.massf[1], gs.conc[0], gs.conc[1]))
while t <= tFinal:
    dtSuggest = reactor.update_state(gs, dt, dtSuggest)
    t = t + dt
    # dt = dtSuggest # uncomment this to get quicker stepping
    gs.update_thermo_from_rhou()
    f.write("%10.3e %10.3f %10.3e %20.12e %20.12e %20.12e %20.12e\n" %
            (t, gs.T, gs.p, gs.massf[0], gs.massf[1], gs.conc[0], gs.conc[1]))
f.close()
print("# Done.")