Skip to content

Commit f7e3eef

Browse files
committed
Add functions for constructing mechdict from cantera yml
1 parent bde680b commit f7e3eef

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

src/yml.jl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,74 @@ function getmechdictfromchemkin(spcs,rxns)
3232
return D
3333
end
3434

35+
function convertcanterayml2rmsyml(path;output="chem.rms")
36+
canterayml = YAML.load_file(path)
37+
D = getmechdictfromcantera(canterayml)
38+
writeyml(D;path=output)
39+
end
40+
41+
function getmechdictfromcantera(canterayml)
42+
unsupportedphases = [
43+
"binary-solution-tabulated",
44+
"compound-lattice",
45+
"constant-density",
46+
"Debye-Huckel",
47+
"edge",
48+
"electron-cloud",
49+
"fixed-stoichiometry",
50+
"HMW-electrolyte",
51+
# "ideal-gas",
52+
"ideal-molal-solution",
53+
"ideal-condensed",
54+
"ideal-solution-VPSS",
55+
# "ideal-surface",
56+
"ions-from-neutral-molecule",
57+
"lattice",
58+
"liquid-water-IAPWS95",
59+
"Margules",
60+
"Maskell-solid-solution",
61+
"Peng-Robinson",
62+
"plasma",
63+
"pure-fluid",
64+
"Redlich-Kister",
65+
"Redlich-Kwong",
66+
]
67+
68+
spcs = canterayml["species"]
69+
rxns = canterayml["reactions"]
70+
phases = canterayml["phases"]
71+
units = canterayml["units"] #user specified units
72+
units = Dict(key=>uparse(value) for (key,value) in units) #convert to Unitful units
73+
74+
#prevent duplicate names
75+
spc_names = [spc["name"] for spc in spcs]
76+
for (i,name) in enumerate(spc_names)
77+
if count(spc_names.==name) > 1
78+
k = 2
79+
new_name = name
80+
while new_name in spc_names
81+
new_name = string(name,"-",k)
82+
end
83+
spc_names[i] = new_name
84+
end
85+
end
86+
87+
D = Dict([])
88+
D["Units"] = Dict([]) #will be converting all values to SI
89+
D["Phases"] = []
90+
for phase in phases
91+
if phase["thermo"] in unsupportedphases
92+
@error "Currently not supporting $(phase["thermo"])"
93+
end
94+
phasedict = Dict()
95+
phasedict["name"] = phase["name"]
96+
phasedict["Species"] = [canteradict2rmsdict(spc,spcs,spc_names,units,:species) for spc in spcs if spc["name"] in phase["species"]]
97+
push!(D["Phases"],phasedict)
98+
end
99+
D["Reactions"] = [canteradict2rmsdict(rxn,spcs,spc_names,units,:reaction) for rxn in rxns]
100+
return D
101+
end
102+
35103
function getradicals(obj::T) where {T}
36104
sm = obj.molecule[1].to_smiles()
37105
if sm == "[O][O]"

0 commit comments

Comments
 (0)