コード例 #1
0
ファイル: drummond-diffuser.py プロジェクト: lkampoli/Eilmer4
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
 denom = rho * rho * v * v - dfdr * rho * rho - dfdu * p
 drho = (dp_chem - du_chem * dfdu) * rho * rho / denom
 dv = -(dp_chem - du_chem * dfdu) * rho * v / denom
 dp_gda = -(du_chem * dfdu * rho * rho * v * v -
            dfdr * dp_chem * rho * rho - dfdu * dp_chem * p) / denom
 du_gda = -(du_chem * rho * rho * v * v - du_chem * dfdr * rho * rho -
            dp_chem * p) / denom
 if debug:
     print("# drho=", drho, "dv=", dv, "dp_gda=", dp_gda, "du_gda=", du_gda)
     print(
         "# residuals=", v * drho + rho * dv,
         rho * v * dv + dp_gda + dp_chem, v * etot * drho +
         (rho * etot + p) * dv + rho * v * du_gda + rho * v * du_chem,
         dfdr * drho - dp_gda + dfdu * du_gda)
 # Add the accommodation increments.
 gas1.rho = gas0.rho + drho
 v1 = v + dv
 p1_check = gas1.p + dp_gda
 gas1.u = gas1.u + du_gda
 gas1.update_thermo_from_rhou()
 if debug:
     print("# At new point for step ", j, ": gas1.p=", gas1.p, "p1_check=",
           p1_check, "rel_error=",
           abs(gas1.p - p1_check) / p1_check)
 # Have now finished the chemical and gas-dynamic update.
 t = t + t_inc
 x = x + 0.5 * (v + v1) * t_inc
 f.write(string_data(x, v1, gas1, dt_suggest))
 if x > x_final: break
 # House-keeping for the next step.
 v = v1
コード例 #3
0
#
#------------------------------------------------------------------
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)
コード例 #4
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))