Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalized Thermo generation to enable Solution with arbitrary thermo #76

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ Docstrings for Arrhenius.jl interface members can be [accessed through Julia's b
:wdot_func
```
## Thermo Interface API

The thermo functions can be called with the following functions.
The ‘cal_‘ functions internally dispatch to

```cal_phi(Solution,T,p,X) = cal_phi(Solution,Solution.thermo,T,p,X)```
to enable the usage of different thermo modules.

A new thermoModul should implement the dimless functions for cv, cp, h, a, g, s.
with the inputs ‘cal_phi(Solution,Solution.thermo,T,p,X)‘.
Then it should work with the rest of Arrenius. In the creation of a Solution object
the thermo model is generated by the function ‘MyThermo(yaml::Dict)‘, which must be available as well. If you specify the name of your Thermomodel in the yaml files phase
(e.g. ‘My‘ here or 'IdealGas') the code will automatically dispatch to the new thermomodel

```@autodocs
Modules = [Arrhenius]
Pages = ["Thermo.jl"]
Expand Down
52 changes: 18 additions & 34 deletions src/Solution.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function read_species_basics(yaml)
n_species = length(yaml["phases"][1]["species"])
n_reactions = length(yaml["reactions"])
species_names = yaml["phases"][1]["species"]
elements = yaml["phases"][1]["elements"]
n_elements = length(elements)

ele_matrix = zeros(n_elements, n_species)
return n_species, n_reactions, species_names, elements, n_elements, ele_matrix
end
"""
CreateSolution(mech)

Expand All @@ -9,44 +19,18 @@ test for math enviroment
function CreateSolution(mech)
yaml = YAML.load_file(mech)


#### Basics
n_species, n_reactions, species_names,
elements, n_elements, ele_matrix = read_species_basics(yaml)

n_species = length(yaml["phases"][1]["species"])
n_reactions = length(yaml["reactions"])
species_names = yaml["phases"][1]["species"]
elements = yaml["phases"][1]["elements"]
n_elements = length(elements)

ele_matrix = zeros(n_elements, n_species)


#### Thermodynamic data

nasa_low = zeros(n_species, 7)
nasa_high = zeros(n_species, 7)
Trange = zeros(n_species, 3)

_species_names =
[yaml["species"][i]["name"] for i = 1:length(yaml["species"])]

for (i, species) in enumerate(species_names)
spec = yaml["species"][findfirst(x -> x == species, _species_names)]
nasa_low[i, :] = spec["thermo"]["data"][1]
nasa_high[i, :] = spec["thermo"]["data"][2]
Trange[i, :] .= spec["thermo"]["temperature-ranges"]

for j = 1:n_elements
if haskey(spec["composition"], elements[j])
ele_matrix[j, i] = spec["composition"][elements[j]]
end
end
#### Thermo
if yaml["phases"][1]["thermo"]=="ideal-gas" # switch to work with Cantera standard
thermo = IdealGasThermo(yaml)
else
constructorThermo = Symbol(yaml["phases"][1]["thermo"],:Thermo)
thermo = @eval($constructorThermo)(yaml)
end

isTcommon = (maximum(Trange[:, 2]) - minimum(Trange[:, 2])) < 0.01

thermo = IdealGasThermo(nasa_low, nasa_high, Trange, isTcommon)


#### Kinetic data

Expand Down
30 changes: 30 additions & 0 deletions src/Thermo/IdealGasThermo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,37 @@ struct IdealGasThermo <: Thermo
isTcommon::Bool

end
"""
Constructor for the idealGasThermo:

yaml:: Dict of the input yaml file
"""
function IdealGasThermo(yaml::AbstractDict)
n_species, n_reactions, species_names,
elements, n_elements, ele_matrix = read_species_basics(yaml)

nasa_low = zeros(n_species, 7)
nasa_high = zeros(n_species, 7)
Trange = zeros(n_species, 3)

_species_names =
[yaml["species"][i]["name"] for i = 1:length(yaml["species"])]

for (i, species) in enumerate(species_names)
spec = yaml["species"][findfirst(x -> x == species, _species_names)]
nasa_low[i, :] = spec["thermo"]["data"][1]
nasa_high[i, :] = spec["thermo"]["data"][2]
Trange[i, :] .= spec["thermo"]["temperature-ranges"]

for j = 1:n_elements
if haskey(spec["composition"], elements[j])
ele_matrix[j, i] = spec["composition"][elements[j]]
end
end
end
isTcommon = (maximum(Trange[:, 2]) - minimum(Trange[:, 2])) < 0.01
return IdealGasThermo(nasa_low, nasa_high, Trange, isTcommon)
end
"""
cal_h_RT(gas, T, p, X)

Expand Down