mirror of
https://github.com/aselimov/cea-rs.git
synced 2026-06-04 00:04:21 +00:00
Compare commits
No commits in common. "0910872a5513d1f4c943240f6c36c39874808b3c" and "52e9c0d3cca5046c9abe61e5a0c0ef8d46b4f202" have entirely different histories.
0910872a55
...
52e9c0d3cc
1 changed files with 47 additions and 63 deletions
|
|
@ -6,18 +6,11 @@ use crate::{
|
||||||
properties::thermo_fit::{Phase, SpeciesThermoData},
|
properties::thermo_fit::{Phase, SpeciesThermoData},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct MixtureComponent {
|
|
||||||
//kg-moles component/kg_mixture
|
|
||||||
n: f64,
|
|
||||||
// Coefficients
|
|
||||||
a: Vec<f64>,
|
|
||||||
s: SpeciesThermoData,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GasMixture {
|
pub struct GasMixture {
|
||||||
|
pub(crate) ns: Vec<f64>,
|
||||||
pub(crate) nsum: f64,
|
pub(crate) nsum: f64,
|
||||||
pub(crate) gasses: Vec<MixtureComponent>,
|
pub(crate) species: Vec<SpeciesThermoData>,
|
||||||
pub(crate) condensed: Vec<MixtureComponent>,
|
pub(crate) coeffs: Matrix<f64>,
|
||||||
pub(crate) elements: HashMap<String, usize>,
|
pub(crate) elements: HashMap<String, usize>,
|
||||||
pub(crate) binitial: Vec<f64>,
|
pub(crate) binitial: Vec<f64>,
|
||||||
}
|
}
|
||||||
|
|
@ -47,30 +40,23 @@ impl GasMixture {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now build the coefficients
|
||||||
|
let mut coeffs = Matrix::new(ei, species.len(), 0.0);
|
||||||
|
for (j, s) in species.iter().enumerate() {
|
||||||
|
s.elements.iter().for_each(|e| {
|
||||||
|
// Safe to unwrap because elements should always have e
|
||||||
|
let i = *elements.get(&e.element).unwrap();
|
||||||
|
coeffs.set(i, j, e.count);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let binitial = get_b_current(&elements, species, &ns);
|
let binitial = get_b_current(&elements, species, &ns);
|
||||||
|
|
||||||
// Now separate SpeciesThermoData in gas and condensed MixtureComponents
|
|
||||||
let (gasses, condensed) = ns
|
|
||||||
.iter()
|
|
||||||
.zip(species.iter())
|
|
||||||
.map(|(n, s)| {
|
|
||||||
let mut a = vec![0.0; elements.len()];
|
|
||||||
s.elements.iter().for_each(|e| {
|
|
||||||
let i = elements.get(&e.element).unwrap();
|
|
||||||
a[*i] += e.count;
|
|
||||||
});
|
|
||||||
MixtureComponent {
|
|
||||||
n: *n,
|
|
||||||
a,
|
|
||||||
s: s.clone(),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.partition(|c| matches!(c.s.phase, Phase::Gas));
|
|
||||||
|
|
||||||
GasMixture {
|
GasMixture {
|
||||||
|
ns,
|
||||||
nsum,
|
nsum,
|
||||||
gasses,
|
species: species.to_vec(),
|
||||||
condensed,
|
coeffs,
|
||||||
elements,
|
elements,
|
||||||
binitial,
|
binitial,
|
||||||
}
|
}
|
||||||
|
|
@ -78,18 +64,18 @@ impl GasMixture {
|
||||||
// Calculate the normalized chemical potential (μ/RT) for each component in the mixture.
|
// Calculate the normalized chemical potential (μ/RT) for each component in the mixture.
|
||||||
// Equations 2.11 from reference paper
|
// Equations 2.11 from reference paper
|
||||||
pub fn gas_chem_potentials_over_rt(&self, temp: f64, pressure: f64) -> Vec<f64> {
|
pub fn gas_chem_potentials_over_rt(&self, temp: f64, pressure: f64) -> Vec<f64> {
|
||||||
self.gasses
|
self.ns
|
||||||
.iter()
|
.iter()
|
||||||
.chain(self.condensed.iter())
|
.zip(self.species.iter())
|
||||||
.map(|c| -> f64 {
|
.map(|(n, s)| -> f64 {
|
||||||
match c.s.phase {
|
match s.phase {
|
||||||
Phase::Gas => {
|
Phase::Gas => {
|
||||||
let p =
|
let p = s
|
||||||
c.s.polynomial_at(temp)
|
.polynomial_at(temp)
|
||||||
.expect("Gas doesn't have a polynomial");
|
.expect("Gas doesn't have a polynomial");
|
||||||
p.h_over_rt(temp) - p.s_over_r(temp)
|
p.h_over_rt(temp) - p.s_over_r(temp)
|
||||||
+ (pressure / P_REF).ln()
|
+ (pressure / P_REF).ln()
|
||||||
+ (c.n / self.nsum).ln()
|
+ (n / self.nsum).ln()
|
||||||
}
|
}
|
||||||
Phase::Condensed => todo!(),
|
Phase::Condensed => todo!(),
|
||||||
}
|
}
|
||||||
|
|
@ -101,16 +87,16 @@ impl GasMixture {
|
||||||
//
|
//
|
||||||
// Equations 2.17 from reference paper
|
// Equations 2.17 from reference paper
|
||||||
pub fn gas_entropies_over_rt(&self, temp: f64, pressure: f64) -> Vec<f64> {
|
pub fn gas_entropies_over_rt(&self, temp: f64, pressure: f64) -> Vec<f64> {
|
||||||
self.gasses
|
self.ns
|
||||||
.iter()
|
.iter()
|
||||||
.chain(self.condensed.iter())
|
.zip(self.species.iter())
|
||||||
.map(|c| -> f64 {
|
.map(|(n, s)| -> f64 {
|
||||||
match c.s.phase {
|
match s.phase {
|
||||||
Phase::Gas => {
|
Phase::Gas => {
|
||||||
let p =
|
let p = s
|
||||||
c.s.polynomial_at(temp)
|
.polynomial_at(temp)
|
||||||
.expect("Gas doesn't have a polynomial");
|
.expect("Gas doesn't have a polynomial");
|
||||||
p.s_over_r(temp) - (c.n / self.nsum).ln() - (pressure / P_REF).ln()
|
p.s_over_r(temp) - (n / self.nsum).ln() - (pressure / P_REF).ln()
|
||||||
}
|
}
|
||||||
Phase::Condensed => todo!(),
|
Phase::Condensed => todo!(),
|
||||||
}
|
}
|
||||||
|
|
@ -122,16 +108,16 @@ impl GasMixture {
|
||||||
// Note that the enthalpy doesn't have a dependence on the pressure.
|
// Note that the enthalpy doesn't have a dependence on the pressure.
|
||||||
// Equation 2.14 from the paper
|
// Equation 2.14 from the paper
|
||||||
pub fn mixture_h_over_rt(&self, temp: f64) -> Vec<f64> {
|
pub fn mixture_h_over_rt(&self, temp: f64) -> Vec<f64> {
|
||||||
self.gasses
|
self.ns
|
||||||
.iter()
|
.iter()
|
||||||
.chain(self.condensed.iter())
|
.zip(self.species.iter())
|
||||||
.map(|c| -> f64 {
|
.map(|(n, s)| -> f64 {
|
||||||
match c.s.phase {
|
match s.phase {
|
||||||
Phase::Gas => {
|
Phase::Gas => {
|
||||||
let p =
|
let p = s
|
||||||
c.s.polynomial_at(temp)
|
.polynomial_at(temp)
|
||||||
.expect("Gas doesn't have a polynomial");
|
.expect("Gas doesn't have a polynomial");
|
||||||
c.n * p.h_over_rt(temp)
|
n * p.h_over_rt(temp)
|
||||||
}
|
}
|
||||||
Phase::Condensed => todo!(),
|
Phase::Condensed => todo!(),
|
||||||
}
|
}
|
||||||
|
|
@ -177,17 +163,15 @@ mod test {
|
||||||
0.01665842352342649,
|
0.01665842352342649,
|
||||||
0.02498763528513974,
|
0.02498763528513974,
|
||||||
];
|
];
|
||||||
let ns: Vec<f64> = gas.gasses.iter().map(|c| c.n).collect();
|
assert_vec_delta!(expected_ns, gas.ns, 1e-12);
|
||||||
|
|
||||||
assert_vec_delta!(expected_ns, ns, 1e-12);
|
|
||||||
assert_delta!(gas.nsum, 0.04997527057027948, 1e-12);
|
assert_delta!(gas.nsum, 0.04997527057027948, 1e-12);
|
||||||
|
|
||||||
assert_delta!(gas.gasses[0].a[0], 2.0, 1e-12);
|
assert_delta!(gas.coeffs.get(0, 0).unwrap(), 2.0, 1e-12);
|
||||||
assert_delta!(gas.gasses[1].a[0], 0.0, 1e-12);
|
assert_delta!(gas.coeffs.get(0, 1).unwrap(), 0.0, 1e-12);
|
||||||
assert_delta!(gas.gasses[2].a[0], 2.0, 1e-12);
|
assert_delta!(gas.coeffs.get(0, 2).unwrap(), 2.0, 1e-12);
|
||||||
assert_delta!(gas.gasses[0].a[1], 0.0, 1e-12);
|
assert_delta!(gas.coeffs.get(1, 0).unwrap(), 0.0, 1e-12);
|
||||||
assert_delta!(gas.gasses[1].a[1], 2.0, 1e-12);
|
assert_delta!(gas.coeffs.get(1, 1).unwrap(), 2.0, 1e-12);
|
||||||
assert_delta!(gas.gasses[2].a[1], 1.0, 1e-12);
|
assert_delta!(gas.coeffs.get(1, 2).unwrap(), 1.0, 1e-12);
|
||||||
|
|
||||||
let expected_b = [0.06663369409370597, 0.05830448233199272];
|
let expected_b = [0.06663369409370597, 0.05830448233199272];
|
||||||
assert_vec_delta!(gas.binitial, expected_b, 1e-12);
|
assert_vec_delta!(gas.binitial, expected_b, 1e-12);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue