From 23bca88404b688c4b7091c51f9a93723ca49f2ca Mon Sep 17 00:00:00 2001 From: moataz-sabry Date: Sun, 12 Feb 2023 17:47:47 +0100 Subject: [PATCH] Adjusted utils.jl --- Project.toml | 2 +- src/utils.jl | 35 +++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Project.toml b/Project.toml index 0e228e0..ae5a74a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Apophis" uuid = "cf72b054-1e85-4718-a3f4-02cfdc10a054" authors = ["moataz-sabry ", "Ahmed Hassan "] -version = "1.2.3" +version = "1.2.4" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" diff --git a/src/utils.jl b/src/utils.jl index 233a36d..3713b61 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,5 +1,5 @@ export - Gas, Species, species, Reaction, reactions, reaction, TPC!, TρC!, TPY!, TPX!, TρY!, TρX!, update, temperature, pressure, density, mass_fractions, molar_fractions, mass_fractions, + Gas, Species, species, Reaction, reactions, reaction, TPC!, TρC!, TPY!, TPX!, TρY!, TρX!, update, temperature, pressure, density, mass_fractions, molar_fractions, molar_concentrations, molecular_weights, production_rates, heat_capacities_pressure, average_heat_capacity_pressure, heat_capacities_volume, average_heat_capacity_volume, enthalpies, internal_energies, entropies, forward_rates, reverse_rates, progress_rates, stoichiometry_matrix @@ -62,34 +62,34 @@ species(gas::Gas, s::Union{String, Symbol}) = assign(species(gas), s) molecular_weights(gas::Gas{<:Number}, f::Function=identity) = mapview(s -> f(s.weight), species(gas)) stoichiometry_matrix((; mechanism)::Gas) = mechanism.stoichiometry_matrix -heat_capacity_pressure(species::Species{<:Number}, ::Val{:val} = Val(:val); in=nothing) = species.thermo.cₚ.val[] * (isnothing(in) || ustrip(in, 1u"erg/(mol*K)")) +heat_capacity_pressure(species::Species{<:Number}, ::Val{:val}=Val(:val); in=nothing) = species.thermo.cₚ.val[] * (isnothing(in) || ustrip(in, 1u"erg/(mol*K)")) heat_capacity_pressure(species::Species{<:Number}, ::Val{:dT}; in=nothing) = species.thermo.cₚ.dT[] * (isnothing(in) || ustrip(in, 1u"erg/(mol*K^2)")) -heat_capacities_pressure(gas::Gas{<:Number}, v::Val = Val(:val); in=nothing) = mapview(s -> heat_capacity_pressure(s, v; in), species(gas)) -average_heat_capacity_pressure(gas::Gas{<:Number}, v::Val = Val(:val); in=nothing) = sum(cₚ * y / w for (cₚ, y, w) in zip(heat_capacities_pressure(gas, v; in = isnothing(in) ? nothing : in * u"g/mol"), mass_fractions(gas), molecular_weights(gas))) +heat_capacities_pressure(gas::Gas{<:Number}, v::Val=Val(:val); in=nothing) = mapview(s -> heat_capacity_pressure(s, v; in), species(gas)) +average_heat_capacity_pressure(gas::Gas{<:Number}, v::Val=Val(:val); in=nothing) = sum(cₚ * y / w for (cₚ, y, w) in zip(heat_capacities_pressure(gas, v; in = isnothing(in) ? nothing : in * u"g/mol"), mass_fractions(gas), molecular_weights(gas))) -heat_capacities_volume(gas::Gas{<:Number}, ::Val{:val} = Val(:val); in=nothing) = mapview(cₚ -> cₚ - R, heat_capacities_pressure(gas; in)) +heat_capacities_volume(gas::Gas{<:Number}, ::Val{:val}=Val(:val); in=nothing) = mapview(cₚ -> cₚ - R, heat_capacities_pressure(gas; in)) heat_capacities_volume(gas::Gas{<:Number}, v::Val{:dT}; in=nothing) = heat_capacities_pressure(gas, v; in) -average_heat_capacity_volume(gas::Gas{<:Number}, v::Val = Val(:val); in=nothing) = sum(cᵥ * y / w for (cᵥ, y, w) in zip(heat_capacities_volume(gas, v; in = isnothing(in) ? nothing : in * u"g/mol"), mass_fractions(gas), molecular_weights(gas))) +average_heat_capacity_volume(gas::Gas{<:Number}, v::Val=Val(:val); in=nothing) = sum(cᵥ * y / w for (cᵥ, y, w) in zip(heat_capacities_volume(gas, v; in = isnothing(in) ? nothing : in * u"g/mol"), mass_fractions(gas), molecular_weights(gas))) enthalpy(species::Species{<:Number}; in=nothing) = enthalpy(species, Val(:val); in) enthalpy(species::Species{<:Number}, ::Val{:val}; in=nothing) = species.thermo.h.val[] * (isnothing(in) || ustrip(in, 1u"erg/mol")) enthalpy(species::Species{<:Number}, ::Val{:dT}; in=nothing) = species.thermo.h.dT[] * (isnothing(in) || ustrip(in, 1u"erg/(mol*K)")) -enthalpies(gas::Gas{<:Number}, v::Val = Val(:val); in=nothing) = mapview(s -> enthalpy(s, v; in), species(gas)) +enthalpies(gas::Gas{<:Number}, v::Val=Val(:val); in=nothing) = mapview(s -> enthalpy(s, v; in), species(gas)) -internal_energies(gas::Gas{<:Number}, ::Val{:val} = Val(:val); in=nothing) = mapview(h -> h - R * temperature(gas), enthalpies(gas; in)) +internal_energies(gas::Gas{<:Number}, ::Val{:val}=Val(:val); in=nothing) = mapview(h -> h - R * temperature(gas), enthalpies(gas; in)) internal_energies(gas::Gas{<:Number}, v::Val{:dT}; in=nothing) = mapview(h -> h - R, enthalpies(gas, v; in)) entropy(species::Species{<:Number}; in=nothing) = entropy(species, Val(:val); in) entropy(species::Species{<:Number}, ::Val{:val}; in=nothing) = species.thermo.s.val[] * (isnothing(in) || ustrip(in, 1u"erg/(mol*K)")) entropy(species::Species{<:Number}, ::Val{:dT}; in=nothing) = species.thermo.s.dT[] * (isnothing(in) || ustrip(in, 1u"erg/(mol*K^2)")) -entropies(gas::Gas{<:Number}, v::Val = Val(:val); in=nothing) = mapview(s -> entropy(s, v; in), species(gas)) +entropies(gas::Gas{<:Number}, v::Val=Val(:val); in=nothing) = mapview(s -> entropy(s, v; in), species(gas)) -production_rate(gas::Gas, s::Union{String, Symbol}, v::Val = Val(:val); in=nothing) = species(gas, s) |> s -> production_rate(s, v, in) -production_rate(species::Species{<:Number}, ::Val{:val} = Val(:val); in=nothing) = species.rates.ω̇.val[] * (isnothing(in) || ustrip(in, 1u"mol/(cm^3*s)")) +production_rate(gas::Gas, s::Union{String, Symbol}, v::Val=Val(:val); in=nothing) = species(gas, s) |> s -> production_rate(s, v, in) +production_rate(species::Species{<:Number}, ::Val{:val}=Val(:val); in=nothing) = species.rates.ω̇.val[] * (isnothing(in) || ustrip(in, 1u"mol/(cm^3*s)")) production_rate(species::Species{<:Number}, ::Val{:dT}; in=nothing) = species.rates.ω̇.dT[] * (isnothing(in) || ustrip(in, 1u"mol/(cm^3*K*s)")) production_rate(species::Species{<:Number}, ::Val{:dC}; in=nothing) = species.rates.ω̇.dC -production_rates(gas::Gas{<:Number}, v::Val = Val(:val); in=nothing) = mapview(s -> production_rate(s, v; in), species(gas)) |> x -> v isa Val{:dC} ? combinedimsview(x, 1) : x -#production_rates(gas::Gas{<:Number}, v::Val{:dC}; in=nothing) = +production_rates(gas::Gas{<:Number}, v::Val=Val(:val); in=nothing) = mapview(s -> production_rate(s, v; in), species(gas)) +production_rates(gas::Gas{<:Number}, v::Val{:dC}; in=nothing) = mapview(s -> production_rate(s, v; in), species(gas)) |> Fix2(combinedimsview, 1) reactions((; mechanism)::Gas) = mechanism.reactions reaction(gas::Gas, i::Int) = reactions(gas)[i] @@ -100,14 +100,17 @@ order_unit(reaction::AbstractReaction{N}, part::Vector{Pair{Species{N}, N}}) whe forward_rate(reaction::AbstractReaction{<:Number}, ::Val{:val}=Val(:val)) = reaction.rates.kf.val[] forward_rate(reaction::AbstractReaction{<:Number}, ::Val{:dT}) = reaction.rates.kf.dT[] forward_rate(reaction::AbstractReaction{<:Number}, ::Val{:dC}) = reaction.rates.kf.dC -forward_rates(gas::Gas{<:Number}, v::Val = Val(:val)) = mapview(r -> forward_rate(r, v), reactions(gas)) +forward_rates(gas::Gas{<:Number}, v::Val=Val(:val)) = mapview(r -> forward_rate(r, v), reactions(gas)) +forward_rates(gas::Gas{<:Number}, v::Val{:dC}) = mapview(r -> forward_rate(r, v), reactions(gas)) |> Fix2(combinedimsview, 1) reverse_rate(reaction::AbstractReaction{<:Number}, ::Val{:val}=Val(:val)) = reaction.rates.kr.val[] reverse_rate(reaction::AbstractReaction{<:Number}, ::Val{:dT}) = reaction.rates.kr.dT[] reverse_rate(reaction::AbstractReaction{<:Number}, ::Val{:dC}) = reaction.rates.kr.dC -reverse_rates(gas::Gas{<:Number}, v::Val = Val(:val)) = mapview(r -> reverse_rate(r, v), reactions(gas)) +reverse_rates(gas::Gas{<:Number}, v::Val=Val(:val)) = mapview(r -> reverse_rate(r, v), reactions(gas)) +reverse_rates(gas::Gas{<:Number}, v::Val{:dC}) = mapview(r -> reverse_rate(r, v), reactions(gas)) |> Fix2(combinedimsview, 1) progress_rate(reaction::AbstractReaction{<:Number}, ::Val{:val}=Val(:val); in=nothing) = reaction.rates.q.val[] * (isnothing(in) || ustrip(in, 1u"mol/(cm^3*s)")) progress_rate(reaction::AbstractReaction{<:Number}, ::Val{:dT}; in=nothing) = reaction.rates.q.dT[] * (isnothing(in) || ustrip(in, 1u"mol/(cm^3*K*s)")) progress_rate(reaction::AbstractReaction{<:Number}, ::Val{:dC}; in=nothing) = reaction.rates.q.dC -progress_rates(gas::Gas{<:Number}, v::Val = Val(:val)) = mapview(r -> progress_rate(r, v), reactions(gas)) \ No newline at end of file +progress_rates(gas::Gas{<:Number}, v::Val=Val(:val)) = mapview(r -> progress_rate(r, v), reactions(gas)) +progress_rates(gas::Gas{<:Number}, v::Val{:dC}) = mapview(r -> progress_rate(r, v), reactions(gas)) |> Fix2(combinedimsview, 1) \ No newline at end of file