mirror of
https://github.com/aselimov/cea-rs.git
synced 2026-04-19 00:24:20 +00:00
Fix some bugs
This commit is contained in:
parent
6d1d9bd290
commit
cc5ae45c31
6 changed files with 63 additions and 8 deletions
47
Cargo.lock
generated
47
Cargo.lock
generated
|
|
@ -2,6 +2,53 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cea-rs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
regex = "1"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
mod data;
|
||||
mod error;
|
||||
mod thermo_db;
|
||||
pub mod thermo_db;
|
||||
mod thermo_fit;
|
||||
mod transport_db;
|
||||
pub mod transport_db;
|
||||
mod transport_fit;
|
||||
mod utils;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ use crate::properties::{
|
|||
utils::parse_fields,
|
||||
};
|
||||
|
||||
|
||||
pub struct ThermoDB {
|
||||
pub products: Vec<SpeciesThermoData>,
|
||||
pub reactants: Vec<SpeciesThermoData>,
|
||||
|
|
@ -136,7 +135,7 @@ fn parse_polynomial_block<'a>(
|
|||
|
||||
let temp_hi: f64 = splits[1]
|
||||
.parse()
|
||||
.map_err(|_| make_parse_error("temp_hi", "f64", &splits[0]))?;
|
||||
.map_err(|_| make_parse_error("temp_hi", "f64", &splits[1]))?;
|
||||
|
||||
// Now parse the first 5 coefficients
|
||||
let line = lines.next().ok_or(PropertiesError::InvalidFile)?;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ impl TransportDB {
|
|||
data.push(parse_species_transport_block(&mut lines)?);
|
||||
|
||||
if let Some(line) = lines.peek() {
|
||||
if line.contains("end") {
|
||||
if line.to_lowercase().contains("end") {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -69,7 +69,7 @@ fn parse_species_header_line(line: &str) -> Result<(String, usize, usize), Prope
|
|||
|
||||
let conductivity_count: usize = splits[4]
|
||||
.parse()
|
||||
.map_err(|_| make_parse_error("C", "usize", &splits[2]))?;
|
||||
.map_err(|_| make_parse_error("C", "usize", &splits[4]))?;
|
||||
Ok((name, viscosity_count, conductivity_count))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,19 @@
|
|||
use std::sync::LazyLock;
|
||||
use regex::Regex;
|
||||
|
||||
// Matches Fortran D exponent (1.23D+04, 1.23D-04, 1.23D 04) and E exponent with a space
|
||||
// (1.23E 04). Captures: digit before, optional sign, digit after — drops any space.
|
||||
static FORTRAN_EXP: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new(r"([0-9])[DE]([+\-]?) ?([0-9])").unwrap()
|
||||
});
|
||||
|
||||
pub fn parse_fields(line: &str, widths: &[usize]) -> Vec<String> {
|
||||
let mut fields = Vec::new();
|
||||
let mut pos = 0;
|
||||
|
||||
for &width in widths {
|
||||
if let Some(field) = line.get(pos..pos + width) {
|
||||
// The replace changes the fortran formatted D exponential for the normal E exponential
|
||||
fields.push(field.trim().replace("D", "E").replace("E ", "E"));
|
||||
fields.push(FORTRAN_EXP.replace_all(field.trim(), "${1}E${2}${3}").into_owned());
|
||||
}
|
||||
pos += width;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue