示例#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
    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
    gas0.copy_values(gas1)  # gas0 will be used in the next iteration
print("Done stepping.")
示例#3
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))