Different output from running Python script and cea binary directly #63
-
|
I compared the same problem running through the binary and the Python distribution in Just want to double check that I haven't made any mistake in my Python program. The input file is The input code to cea is import cea
import numpy as np
acrylonitrile_args = {
"name": "Acrylonitrile",
"formula": {"C": 3, "H": 3, "N": 1},
"enthalpy": 140,
"temperature": 298.15,
"molecular_weight": 53.0626,
}
"""https://webbook.nist.gov/cgi/cbook.cgi?ID=C107131&Mask=2"""
butadiene_args = {
"name": "Butadiene",
"formula": {"C": 4, "H": 6},
"enthalpy": 90.50,
"temperature": 298.15,
"molecular_weight": 54.0904,
}
"""https://webbook.nist.gov/cgi/cbook.cgi?ID=C106990&Mask=7"""
styrene_args = {
"name": "Styrene",
"formula": {"C": 8, "H": 8},
"enthalpy": 103.4,
"temperature": 298.15,
"molecular_weight": 104.1491,
}
"""https://webbook.nist.gov/cgi/cbook.cgi?ID=C100425&Mask=F"""
reac_names = [
cea.Reactant(**acrylonitrile_args),
cea.Reactant(**butadiene_args),
cea.Reactant(**styrene_args),
"N2O",
]
T_reactant = np.array([298.15] * 4) # Reactant temperatures (K)
fuel_weights = np.array([0.3992, 0.4737, 0.1271, 0.0])
oxidant_weights = np.array([0.0] * 3 + [1.0])
of_ratio = 5.098591
pi_p = 1.0 # Pressure ratio
supar = 4.0 # Supersonic area ratio
of = 5.098591 # O/F ratio
pc = 1.01325 # Chamber pressure (bar)
reac = cea.Mixture(reac_names)
prod = cea.Mixture(reac_names, products_from_reactants=True)
solver = cea.RocketSolver(prod, reactants=reac)
solution = cea.RocketSolution(solver)
weights = reac.of_ratio_to_weights(oxidant_weights, fuel_weights, of_ratio)
hc = reac.calc_property(cea.ENTHALPY, weights, T_reactant) / cea.R
solver.solve(solution, weights, pc, pi_p=pi_p, supar=supar, hc=hc, iac=True)
# see below for the printing stuffThe output of cea binary whereas the output of cea Python package # printing stuff
num_pts = solution.num_pts
T = solution.T
P = solution.P
rho = solution.density
enthalpy = solution.enthalpy
energy = solution.energy
gibbs = solution.gibbs_energy
entropy = solution.entropy
M_1n = solution.M
MW = solution.MW
cp_eq = solution.cp_eq
cp_fr = solution.cp_fr
cv_eq = solution.cv_eq
cv_fr = solution.cv_fr
Mach = solution.Mach
gamma_s = solution.gamma_s
v_sonic = solution.sonic_velocity
ae_at = solution.ae_at
c_star = solution.c_star
Cf = solution.coefficient_of_thrust
Isp = solution.Isp
Isp_vac = solution.Isp_vacuum
print("P, bar ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(P[i]), end=" ")
else:
print("{0:10.3f}".format(P[i]))
print("T, K ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(T[i]), end=" ")
else:
print("{0:10.3f}".format(T[i]))
print("Density, kg/m^3", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(rho[i]), end=" ")
else:
print("{0:10.3f}".format(rho[i]))
print("H, kJ/kg ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.2f}".format(enthalpy[i]), end=" ")
else:
print("{0:10.2f}".format(enthalpy[i]))
print("U, kJ/kg ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.2f}".format(energy[i]), end=" ")
else:
print("{0:10.2f}".format(energy[i]))
print("G, kJ/kg ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.1f}".format(gibbs[i]), end=" ")
else:
print("{0:10.1f}".format(gibbs[i]))
print("S, kJ/kg-K ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(entropy[i]), end=" ")
else:
print("{0:10.3f}".format(entropy[i]))
print("M, (1/n) ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(M_1n[i]), end=" ")
else:
print("{0:10.3f}".format(M_1n[i]))
print("MW ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(MW[i]), end=" ")
else:
print("{0:10.3f}".format(MW[i]))
print("Cp_eq, kJ/kg-K ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(cp_eq[i]), end=" ")
else:
print("{0:10.3f}".format(cp_eq[i]))
print("Cp_fr, kJ/kg-K ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(cp_fr[i]), end=" ")
else:
print("{0:10.3f}".format(cp_fr[i]))
print("Cv_eq, kJ/kg-K ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(cv_eq[i]), end=" ")
else:
print("{0:10.3f}".format(cv_eq[i]))
print("Cv_eq, kJ/kg-K ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(cv_fr[i]), end=" ")
else:
print("{0:10.3f}".format(cv_fr[i]))
print("Gamma_s ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(gamma_s[i]), end=" ")
else:
print("{0:10.3f}".format(gamma_s[i]))
print("Son. vel., m/s ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.2f}".format(v_sonic[i]), end=" ")
else:
print("{0:10.2f}".format(v_sonic[i]))
print("Mach ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(Mach[i]), end=" ")
else:
print("{0:10.3f}".format(Mach[i]))
print()
print("PERFORMANCE PARAMETERS")
print()
print("Ae/At ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(ae_at[i]), end=" ")
else:
print("{0:10.3f}".format(ae_at[i]))
print("C*, m/s ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.2f}".format(c_star[i]), end=" ")
else:
print("{0:10.2f}".format(c_star[i]))
print("Cf ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.4f}".format(Cf[i]), end=" ")
else:
print("{0:10.4f}".format(Cf[i]))
print("Isp, vac., m/s ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(Isp_vac[i]), end=" ")
else:
print("{0:10.3f}".format(Isp_vac[i]))
print("Isp, m/s ", end=" ")
for i in range(num_pts):
if i < num_pts - 1:
print("{0:10.3f}".format(Isp[i]), end=" ")
else:
print("{0:10.3f}".format(Isp[i]))
print()
print("MOLE FRACTIONS")
print("")
trace_species = []
for prod in solution.mole_fractions:
if np.any(solution.mole_fractions[prod] > 5e-6):
print("{0:15s}".format(prod), end=" ")
for j in range(len(solution.mole_fractions[prod])):
if j < len(solution.mole_fractions[prod]) - 1:
print("{0:10.5g}".format(solution.mole_fractions[prod][j]), end=" ")
else:
print("{0:10.5g}".format(solution.mole_fractions[prod][j]))
else:
trace_species.append(prod) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Thanks for reporting this and for comparing the binary and Python results so carefully. I took a closer look, and I do not think this is a solver divergence. The difference comes from the enthalpy units used in the Python API. Right now, the Python Reactant API interprets enthalpy using I am also working on improving this in the Python API so the units are more explicit. The plan is to add an Thanks again for flagging it. This was a helpful catch. |
Beta Was this translation helpful? Give feedback.
Thanks for reporting this and for comparing the binary and Python results so carefully.
I took a closer look, and I do not think this is a solver divergence. The difference comes from the enthalpy units used in the Python API. Right now, the Python Reactant API interprets enthalpy using
J/kg, while the.inpfile usedkJ/mol.Changing the values in your Python input to match these default units should make the Python and binary results consistent today.
I am also working on improving this in the Python API so the units are more explicit. The plan is to add an
enthalpy_unitsargument going forward. Initially this will be optional, but recommended, so existing code keeps working. After that …