Beispiel #1
0
# ideal-shock-test.py
#
# $ prep-gas ideal-air.inp ideal-air-gas-model.lua
# $ python3 ideal-shock-test.py
#
# PJ, 2019-11-28
# 
import math
from eilmer.gas import GasModel, GasState, GasFlow

gmodel = GasModel('ideal-air-gas-model.lua')
state1 = GasState(gmodel)
state1.p = 125.0e3 # Pa
state1.T = 300.0 # K
state1.update_thermo_from_pT()
state1.update_sound_speed()
print("state1: %s" % state1)
print("normal shock (in ideal gas), given shock speed")
vs = 2414.0
state2 = GasState(gmodel)
flow = GasFlow(gmodel)
v2, vg = flow.ideal_shock(state1, vs, state2)
print("v2=%g vg=%g" % (v2, vg))
print("state2: %s" % state2)
Beispiel #2
0
# PJ, 2019-12-01
# 
import math
def approxEqual(a, b):
    result = math.isclose(a, b, rel_tol=1.0e-2, abs_tol=1.0e-5)
    # print("a=",a, "b=",b, "rel=",(a-b)/b, "abs=",a-b, "result=",result) 
    return result
from eilmer.gas import GasModel, GasState, GasFlow

m1 = 1.5
print("Conical-shock demo for m1=%g" % m1)

gmodel = GasModel('cea-air13species-gas-model.lua')
state1 = GasState(gmodel)
state1.p = 100.0e3 # Pa
state1.T = 300.0 # K ideal air, not high T
state1.update_thermo_from_pT()
state1.update_sound_speed()
print("state1: %s" % state1)
v1 = m1*state1.a
print("v1=%g" % v1)

beta = 45.0 * math.pi/180.0
print("  given beta(degrees)=%g" % (beta*180/math.pi))
state_c = GasState(gmodel)
flow = GasFlow(gmodel)
theta_c, v_c = flow.theta_cone(state1, v1, beta, state_c)
print("  theta_c=%g degrees" % (theta_c*180/math.pi))
print("  v_c=%g" % (v_c))
print("  state_c: %s" % state_c)
#
# To run this script:
# $ prep-gas thermally-perfect-N2-O2.inp thermally-perfect-N2-O2.lua
# $ python3 transport-properties-for-air.py
#
from eilmer.gas import GasModel, GasState

gasModelFile = 'thermally-perfect-N2-O2.lua'
gmodel = GasModel(gasModelFile)

gs = GasState(gmodel)
gs.p = 1.0e5 # Pa
gs.massf = {"N2":0.78, "O2":0.22} # approximation for the composition of air

outputFile = 'trans-props-air.dat'
print("Opening file for writing: %s" % outputFile)
f = open(outputFile, "w")
f.write("#  1:T[K]      2:mu[Pa.s]      3:k[W/(m.K)]\n")

lowT = 200.0
dT = 100.0

for i in range(199):
    gs.T = dT*i + lowT
    gs.update_thermo_from_pT()
    gs.update_trans_coeffs()
    f.write(" %12.6e %12.6e %12.6e\n" % (gs.T, gs.mu, gs.k))

f.close()
print("File closed. Done.")
from eilmer.gas import GasModel, GasState, GasFlow, ThermochemicalReactor
debug = False

print("Initialise a gas model.")
print("Park et al mars atmosphere reaction scheme.")
gmodel = GasModel("mars-atm-with-ions.lua")
nsp = gmodel.n_species
nmodes = gmodel.n_modes
if debug: print("nsp=", nsp, " nmodes=", nmodes, " gmodel=", gmodel)
reactor = ThermochemicalReactor(gmodel, "mars-atm-with-ions-chemistry.lua")
# The example here matches the case on p.17 of Park's publication
v1 = 8000
state1 = GasState(gmodel)
state1.rho = 0.15 * 101300 / v1**2  # freestream density according to Park to keep p after the shock at 0.15atm
print("Free stream desnity:", state1.rho)
state1.T = 210.0  # K, Mars surface temp
state1.massf = {
    "CO2": 0.9664,
    "N2": 0.0174,
    "Ar": 0.0147,
    "O2": 0.001,
    "CO": 0.0005
}
print("Free stream conditions, before the shock.")
state1.update_thermo_from_rhoT()
state1.update_sound_speed()
print("    state1: %s" % state1)
mach1 = v1 / state1.a
print("mach1:", mach1, "v1:", v1)

print("Stationary normal shock with chemically-frozen gas.")
Beispiel #5
0
#
#------------------------------------------------------------------
from eilmer.gas import GasModel, GasState, GasFlow, ThermochemicalReactor
debug = False

print("Initialise a gas model.")
print("air 7 species Gupta-et-al reactions")
gmodel = GasModel("air-7sp-gas-model.lua")
nsp = gmodel.n_species
nmodes = gmodel.n_modes
if debug: print("nsp=", nsp, " nmodes=", nmodes, " gmodel=", gmodel)
reactor = ThermochemicalReactor(gmodel, "air-7sp-chemistry.lua")
# The example here matches the case discussed on page 63 of the thesis.
state1 = GasState(gmodel)
state1.p = 133.3  # Pa
state1.T = 300.0  # degree K
state1.massf = {"N2": 0.78, "O2": 0.22}
print("Free stream conditions, before the shock.")
state1.update_thermo_from_pT()
state1.update_sound_speed()
print("    state1: %s" % state1)
mach1 = 12.28
v1 = mach1 * state1.a
print("mach1:", mach1, "v1:", v1)

print("Stationary normal shock with chemically-frozen gas.")
flow = GasFlow(gmodel)
state2 = GasState(gmodel)
v2, vg = flow.normal_shock(state1, v1, state2)
print("    v2=", v2, "vg=", vg)
print("    state2: %s" % state2)
Beispiel #6
0
# Step through a steady isentropic expansion,
# from stagnation condition to sonic condition.
#
# $ prep-gas ideal-air.inp ideal-air-gas-model.lua
# $ python3 isentropic-air-expansion.py
#
# Python port, PJ, 2019-11-21
# 
import math
from eilmer.gas import GasModel, GasState

gmodel = GasModel('ideal-air-gas-model.lua')
gs = GasState(gmodel)
gs.p = 500e3 # Pa
gs.T = 300.0 # K
gs.update_thermo_from_pT()
# Compute enthalpy and entropy at stagnation conditions
h0 = gs.enthalpy
s0 = gs.entropy
# Set up for stepping process
dp = 1.0 # Pa, use 1 Pa as pressure step size
gs.p = gs.p - dp
mach_tgt = 1.0
# Begin stepping until Mach = mach_tgt
while True:
    gs.update_thermo_from_ps(s0)
    h1 = gs.enthalpy
    v1 = math.sqrt(2*(h0 - h1))
    m1 = v1/gs.a
    if m1 >= mach_tgt:
        print("Stopping at Mach=%g" % m1)
Beispiel #7
0
debug = False
print("# Reacting pipe flow -- Bittker-Scullin test case 3.")
print(sample_header)

# Gas model setup
gmodel = GasModel("h2-o2-n2-9sp.lua")
nsp = gmodel.n_species
nmodes = gmodel.n_modes
if debug: print("nsp=", nsp, " nmodes=", nmodes, " gmodel=", gmodel)

print("# Gas properties at the start of the pipe.")
gas0 = GasState(gmodel)
gas0.p = 96.87e3  # Pa
x = 0.0  # m  (inlet of pipe)
v = 4551.73  # m/s
gas0.T = 1559.0  # degree K
gas0.molef = {"O2": 0.1480, "N2": 0.5562, "H2": 0.2958}
gas0.update_thermo_from_pT()
dt_suggest = 1.0e-8  # suggested starting time-step for chemistry updater
print(sample_data(x, v, gas0, dt_suggest))

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
Beispiel #8
0
# the gas-model Lua file is visible, as given by the path below.
#
# PJ 2019-07-24 direct use of FFI
#    2019-07-25 using Pythonic wrapper
#
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))
Beispiel #9
0
print("# Reacting nozzle flow.")
print(sample_header)

# Gas model setup
gmodel = GasModel("h2-o2-n2-5sp.lua")
nsp = gmodel.n_species
nmodes = gmodel.n_modes
if debug: print("nsp=", nsp, " nmodes=", nmodes, " gmodel=", gmodel)

print("# Gas properties at the start of the pipe.")
gas0 = GasState(gmodel)
gas0.p = 81.0e3 # Pa
x = 0.0 # m  (inlet of duct)
area = duct_area(x)
v = 1230.0 # m/s
gas0.T = 1900.0 # degree K
gas0.molef = {"O2":0.1865, "N2":0.7016, "H2":0.1119}
gas0.update_thermo_from_pT()

dt_suggest = 1.0e-12  # suggested starting time-step for chemistry
print(sample_data(x, area, v, gas0, dt_suggest))
if debug:
    print("# species=", gmodel.species_names)
    print("# massf=", gas0.massf)

print("# Start reactions...")
reactor = ThermochemicalReactor(gmodel, "h2-o2-n2-5sp-2r.lua") 
t = 0 # time is in seconds
t_final = 1.15e-3 # long enough to convect past exit
t_inc = 0.005e-6 # start small
t_inc_max = 0.05e-6
Beispiel #10
0
#
# To prepare:
#   $ prep-gas nitrogen-2sp.inp nitrogen-2sp.lua
#   $ prep-chem nitrogen-2sp.lua nitrogen-2sp-2r.lua chem.lua
#
# To run:
#   $ python3 fvreactor.py

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)