-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to dynamically read pyro mech from input file
- Loading branch information
1 parent
d637d5b
commit ff40bc0
Showing
8 changed files
with
610 additions
and
593 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import cantera as ct | ||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
|
||
gas = ct.Solution("my_mechanism.yaml") | ||
gas.TP = 300, 101325 | ||
gas.X = "C2H4:1" | ||
|
||
numpts = 43 | ||
visc = np.zeros(numpts,) | ||
enthalpy = np.zeros(numpts,) | ||
cp = np.zeros(numpts,) | ||
cv = np.zeros(numpts,) | ||
temperature_list = np.linspace(300, 2400, numpts) | ||
ii = 0 | ||
for temp in temperature_list: | ||
gas.TP = temp, 101325 | ||
visc[ii] = gas.viscosity | ||
enthalpy[ii] = gas.enthalpy_mass | ||
cp[ii] = gas.cp_mass | ||
cv[ii] = gas.cv_mass | ||
ii += 1 | ||
|
||
gamma = cp/cv | ||
|
||
plt.close("all") | ||
fig = plt.figure(1, figsize=[6.4, 4.8]) | ||
ax1 = fig.add_subplot(111) | ||
ax1.set_position([0.16, 0.12, 0.75, 0.83]) | ||
ax1.plot(temperature_list, visc, "--", label="Current") | ||
ax1.set_ylabel(r"$\mathbf{Viscosity \, (Pa-s)}$") | ||
ax1.set_xlabel(r"$\mathbf{Temperature \, (K)}$") | ||
plt.savefig("viscosity.png", dpi=200) | ||
ax1.legend() | ||
plt.show() | ||
|
||
plt.close("all") | ||
fig = plt.figure(1, figsize=[6.4, 4.8]) | ||
ax1 = fig.add_subplot(111) | ||
ax1.set_position([0.16, 0.12, 0.75, 0.83]) | ||
ax1.plot(temperature_list, enthalpy, "--", label="Current") | ||
ax1.set_ylabel(r"$\mathbf{Enthalpy \, (J/kg)}$") | ||
ax1.set_xlabel(r"$\mathbf{Temperature \, (K)}$") | ||
plt.savefig("enthalpy.png", dpi=200) | ||
ax1.legend() | ||
plt.show() | ||
|
||
plt.close("all") | ||
fig = plt.figure(1, figsize=[6.4, 4.8]) | ||
ax1 = fig.add_subplot(111) | ||
ax1.set_position([0.16, 0.12, 0.75, 0.83]) | ||
ax1.plot(temperature_list, cp, "--", label="Current") | ||
ax1.set_ylabel(r"$\mathbf{Heat \; Capacity (Cp)\, (J/kg-K)}$") | ||
ax1.set_xlabel(r"$\mathbf{Temperature \, (K)}$") | ||
plt.savefig("heatCapacityCp.png", dpi=200) | ||
ax1.legend() | ||
plt.show() | ||
|
||
plt.close("all") | ||
fig = plt.figure(1, figsize=[6.4, 4.8]) | ||
ax1 = fig.add_subplot(111) | ||
ax1.set_position([0.16, 0.12, 0.75, 0.83]) | ||
ax1.plot(temperature_list, cv, "--", label="Current") | ||
ax1.set_ylabel(r"$\mathbf{Heat \; Capacity (Cv)\, (J/kg-K)}$") | ||
ax1.set_xlabel(r"$\mathbf{Temperature \, (K)}$") | ||
plt.savefig("heatCapacityCv.png", dpi=200) | ||
ax1.legend() | ||
plt.show() | ||
plt.close("all") | ||
|
||
fig = plt.figure(1, figsize=[6.4, 4.8]) | ||
ax1 = fig.add_subplot(111) | ||
ax1.set_position([0.16, 0.12, 0.75, 0.83]) | ||
ax1.plot(temperature_list, gamma, "--", label="Current") | ||
ax1.set_ylabel(r"$\mathbf{gamma}$") | ||
ax1.set_xlabel(r"$\mathbf{Temperature \, (K)}$") | ||
plt.savefig("gamma.png", dpi=200) | ||
ax1.legend() | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import cantera as ct | ||
import pyrometheus as pyro | ||
|
||
|
||
def generate_mechfile(mech_file): | ||
"""This produces the mechanism codes.""" | ||
|
||
sol = ct.Solution(f"{mech_file}", "gas") | ||
from pathlib import Path | ||
|
||
mech_output_file = Path(f"{mech_file}").stem | ||
with open(f"{mech_output_file}.py", "w") as file: | ||
code = pyro.codegen.python.gen_thermochem_code(sol) | ||
print(code, file=file) | ||
|
||
|
||
import logging | ||
import sys | ||
import argparse | ||
|
||
if __name__ == "__main__": | ||
|
||
logging.basicConfig( | ||
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", | ||
level=logging.INFO) | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Generate Pyrometheus mechanisms") | ||
parser.add_argument("-f", "--mech_file", type=ascii, dest="mech_file", | ||
nargs="?", action="store", help="mechanism file") | ||
|
||
args = parser.parse_args() | ||
|
||
# get mechanism name from the arguments | ||
from mirgecom.simutil import ApplicationOptionsError | ||
mech_file = "" | ||
if args.mech_file: | ||
print(f"Processing Cantera mechanism file {args.mech_file}") | ||
mech_file = args.mech_file.replace("'", "") | ||
else: | ||
raise ApplicationOptionsError("Missing Cantera mechanism file from input") | ||
|
||
print(f"Running {sys.argv[0]}\n") | ||
|
||
generate_mechfile(mech_file) |
Oops, something went wrong.