Example #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
Example #2
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)
# A script to compute the viscosity and thermal conductivity
# of air (as a mixture of N2 and O2) from 200 -- 20000 K.
#
# Author: Peter J. and Rowan J. Gollan
# Date: 2019-11-21
#
# 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()
Example #4
0
# $ python3 conical-shock-test.py
#
# 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))
Example #5
0
# Typical use:
# $ python3 poshax.py
#
#------------------------------------------------------------------
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)
#
# PJ, 2019-11-30
#
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

gmodel = GasModel('cea-air13species-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("Initial test gas:")
print("  state1: %s" % state1)

print("normal shock, given shock speed")
vs = 2414.0
print("  vs=%g" % vs)
state2 = GasState(gmodel)
flow = GasFlow(gmodel)
v2, vg = flow.normal_shock(state1, vs, state2)
print("  v2=%g vg=%g" % (v2, vg))
print("  state2: %s" % state2)
Example #7
0
# gasModelFile = "ideal-air-gas-model.lua" # Alternative
gmodel = GasModel(gasModelFile)
if gmodel.n_species == 1:
    print("Ideal air gas model.")
    air_massf = {"air": 1.0}
else:
    print("Thermally-perfect air model.")
    air_massf = {"N2": 0.78, "O2": 0.22}

print("Compute cycle states:")
gs = []  # We will build up a list of gas states
h = []  # and enthalpies.
# Note that we want to use indices consistent with the Lua script,
# so we set up 5 elements but ignore the one with 0 index.
for i in range(5):
    gs.append(GasState(gmodel))
    h.append(0.0)
for i in range(1, 5):
    gs[i].massf = air_massf

print("   Start with ambient air")
gs[1].p = 100.0e3
gs[1].T = 300.0
gs[1].update_thermo_from_pT()
s12 = gs[1].entropy
h[1] = gs[1].enthalpy

print("   Isentropic compression with a pressure ratio of 8")
gs[2].p = 8 * gs[1].p
gs[2].update_thermo_from_ps(s12)
h[2] = gs[2].enthalpy
Example #8
0
# A simple fixed-volume reactor.
# PJ & RJG 2019-11-25
#
# 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]))