Skip to content

Commit

Permalink
added tests for Helmholtz energy of Born and Ionic term, added parame…
Browse files Browse the repository at this point in the history
…ters of water NaCl to utils, some binary record troubleshooting
  • Loading branch information
LisaNeumaier committed Mar 26, 2024
1 parent 2b2c7d1 commit 8234e3e
Show file tree
Hide file tree
Showing 4 changed files with 430 additions and 119 deletions.
39 changes: 39 additions & 0 deletions src/epcsaft/eos/born.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::epcsaft::eos::permittivity::Permittivity;
use crate::epcsaft::parameters::ElectrolytePcSaftParameters;
use crate::hard_sphere::HardSphereProperties;
use feos_core::StateHD;
use ndarray::Array1;
use num_dual::DualNum;
Expand Down Expand Up @@ -49,3 +50,41 @@ impl fmt::Display for Born {
write!(f, "Born")
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::epcsaft::parameters::utils::{water_nacl_parameters, water_nacl_parameters_perturb};
use approx::assert_relative_eq;
use ndarray::arr1;

#[test]
fn helmholtz_energy_perturb() {
let born = Born {
parameters: water_nacl_parameters_perturb(),
};

let t = 298.0;
let v = 31.875;
let s = StateHD::new(t, v, arr1(&[0.9, 0.05, 0.05]));
let d = born.parameters.hs_diameter(t);
let a_rust = born.helmholtz_energy(&s, &d);

assert_relative_eq!(a_rust, -22.51064553710294, epsilon = 1e-10);
}

#[test]
fn helmholtz_energy() {
let born = Born {
parameters: water_nacl_parameters(),
};

let t = 298.0;
let v = 31.875;
let s = StateHD::new(t, v, arr1(&[0.9, 0.05, 0.05]));
let d = born.parameters.hs_diameter(t);
let a_rust = born.helmholtz_energy(&s, &d);

assert_relative_eq!(a_rust, -22.525624511559244, epsilon = 1e-10);
}
}
41 changes: 41 additions & 0 deletions src/epcsaft/eos/ionic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::epcsaft::eos::permittivity::Permittivity;
use crate::epcsaft::parameters::ElectrolytePcSaftParameters;
use crate::hard_sphere::HardSphereProperties;
use feos_core::StateHD;
use ndarray::*;
use num_dual::DualNum;
Expand Down Expand Up @@ -94,3 +95,43 @@ impl fmt::Display for Ionic {
write!(f, "Ionic")
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::epcsaft::parameters::utils::{water_nacl_parameters, water_nacl_parameters_perturb};
use approx::assert_relative_eq;
use ndarray::arr1;

#[test]
fn helmholtz_energy_perturb() {
let ionic = Ionic {
parameters: water_nacl_parameters_perturb(),
variant: ElectrolytePcSaftVariants::Advanced,
};
let t = 298.0;
let v = 31.875;

let s = StateHD::new(t, v, arr1(&[0.9, 0.05, 0.05]));

let d = ionic.parameters.hs_diameter(t);
let a_rust = ionic.helmholtz_energy(&s, &d);

assert_relative_eq!(a_rust, -0.07775796084032328, epsilon = 1e-10);
}

#[test]
fn helmholtz_energy() {
let ionic = Ionic {
parameters: water_nacl_parameters(),
variant: ElectrolytePcSaftVariants::Advanced,
};
let t = 298.0;
let v = 31.875;
let s = StateHD::new(t, v, arr1(&[0.9, 0.05, 0.05]));
let d = ionic.parameters.hs_diameter(t);
let a_rust = ionic.helmholtz_energy(&s, &d);

assert_relative_eq!(a_rust, -0.07341337106244776, epsilon = 1e-10);
}
}
4 changes: 2 additions & 2 deletions src/epcsaft/eos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ mod tests {

#[test]
fn association() {
let parameters = Arc::new(water_parameters());
let parameters = water_parameters();
let assoc = Association::new(&parameters, &parameters.association, 50, 1e-10);
let t = 350.0;
let v = 41.248289328513216;
Expand All @@ -462,7 +462,7 @@ mod tests {

#[test]
fn cross_association() {
let parameters = Arc::new(water_parameters());
let parameters = water_parameters();
let assoc =
Association::new_cross_association(&parameters, &parameters.association, 50, 1e-10);
let t = 350.0;
Expand Down
Loading

0 comments on commit 8234e3e

Please sign in to comment.