Skip to content

Commit

Permalink
TDDriver handles vv and uv problems separately
Browse files Browse the repository at this point in the history
Display trait gives different outputs depending on input data
  • Loading branch information
2AUK committed Nov 6, 2023
1 parent 7295be3 commit c06596e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 39 deletions.
8 changes: 4 additions & 4 deletions cSPCE_XRISM.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ lam = 1
potential = "LJ"
closure = "KH"
IE = "XRISM"
solver = "ADIIS"
solver = "MDIIS"
depth = 20
picard_damping = 0.5
mdiis_damping = 0.3
mdiis_damping = 0.5
itermax = 10000
tol = 1E-12
tol = 1E-6
diel = 78.497
adbcor = 0.5
adbcor = 1.0

[solvent]
nsv = 3
Expand Down
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ fn main() -> Result<(), lexopt::Error> {
&solutions,
);
writer.write().unwrap();
let wv = &driver.solvent.borrow().wk;
let wu = &driver.solute.as_ref().unwrap().borrow().wk;
let td = TDDriver::new(solutions, wv.clone(), wu.clone());
let wv = driver.solvent.borrow().wk.clone();
let wu = {
match driver.solute {
Some(v) => Some(v.borrow().wk.clone()),
None => None,
}
};
let td = TDDriver::new(solutions, wv, wu);
let thermo = td.execute();
println!("{}", thermo);
Ok(())
Expand Down
101 changes: 69 additions & 32 deletions src/thermodynamics/thermo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,54 @@ impl Densities {
}

pub struct Thermodynamics {
pub sfe: SFEs,
pub sfed: Densities,
pub isothermal_compressibility: f64,
pub molecular_kb_pmv: f64,
pub rism_kb_pmv: f64,
pub total_density: f64,
pub pressure: f64,
pub temperature: f64,
pub isothermal_compressibility: f64,
pub sfe: Option<SFEs>,
pub sfed: Option<Densities>,
pub molecular_kb_pmv: Option<f64>,
pub rism_kb_pmv: Option<f64>,
pub pressure: Option<f64>,
}

impl std::fmt::Display for Thermodynamics {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
match self.sfe {
Some(ref sfe) => {
write!(
f,
"Thermodynamics:\nIsothermal Compressibility: {}\nMolecular KB PMV: {} A^3\n {} cm^3/mol\nRISM KB PMV: {} A^3\n {} cm^3/mol\nTotal Density (1/A^3): {}\nPressure: {}\n{}",
"Thermodynamics:\nTemperature: {} K\nTotal Density: {} (1/A^3)\nIsothermal Compressibility: {}\nPressure: {}\nMolecular KB PMV: {} A^3\n {} cm^3/mol\nRISM KB PMV: {} A^3\n {} cm^3/mol\n{}",
self.temperature,
self.total_density,
self.isothermal_compressibility,
self.molecular_kb_pmv,
self.molecular_kb_pmv / 1e24 * 6.022e23,
self.rism_kb_pmv,
self.rism_kb_pmv / 1e24 * 6.022e23,
self.pressure.unwrap(),
self.molecular_kb_pmv.unwrap(),
self.molecular_kb_pmv.unwrap() / 1e24 * 6.022e23,
self.rism_kb_pmv.unwrap(),
self.rism_kb_pmv.unwrap() / 1e24 * 6.022e23,
sfe,
)
}
None => {
write!(
f,
"Thermodynamics:\nTemperature: {} K\nTotal Density: {} (1/A^3)\nIsothermal Compressibility: {}",
self.temperature,
self.total_density,
self.pressure,
self.sfe,
self.isothermal_compressibility,
)
}
}
}
}
pub struct TDDriver {
pub solutions: Solutions,
pub(crate) wv: Array3<f64>,
pub(crate) wu: Array3<f64>,
pub(crate) wu: Option<Array3<f64>>,
}

impl TDDriver {
pub fn new(solutions: Solutions, wv: Array3<f64>, wu: Array3<f64>) -> Self {
pub fn new(solutions: Solutions, wv: Array3<f64>, wu: Option<Array3<f64>>) -> Self {
TDDriver { solutions, wv, wu }
}

Expand All @@ -143,22 +158,44 @@ impl TDDriver {
self.solutions.config.data_config.npts,
self.solutions.config.data_config.radius,
);
let isothermal_compressibility = self.isothermal_compressibility();
let molecular_kb_pmv = self.kb_partial_molar_volume();
let rism_kb_pmv = self.rism_kb_partial_molar_volume();
let total_density = self.total_density();
let sfed = Densities::new(&self.solutions, &self.wv, &self.wu);
let pressure = self.pressure();
let sfe = SFEs::new(&sfed, pressure, rism_kb_pmv, grid.dr);

Thermodynamics {
sfe,
sfed,
isothermal_compressibility,
molecular_kb_pmv,
rism_kb_pmv,
total_density,
pressure,
match self.solutions.uv {
Some(_) => {
let isothermal_compressibility = self.isothermal_compressibility();
let molecular_kb_pmv = self.kb_partial_molar_volume();
let rism_kb_pmv = self.rism_kb_partial_molar_volume();
let total_density = self.total_density();
let sfed = Densities::new(&self.solutions, &self.wv, self.wu.as_ref().unwrap());
let pressure = self.pressure();
let sfe = SFEs::new(&sfed, pressure, rism_kb_pmv, grid.dr);
let temperature = self.solutions.config.data_config.temp;

Thermodynamics {
temperature,
total_density,
isothermal_compressibility,
sfe: Some(sfe),
sfed: Some(sfed),
molecular_kb_pmv: Some(molecular_kb_pmv),
rism_kb_pmv: Some(rism_kb_pmv),
pressure: Some(pressure),
}
}
None => {
let isothermal_compressibility = self.isothermal_compressibility();
let total_density = self.total_density();
let temperature = self.solutions.config.data_config.temp;

Thermodynamics {
temperature,
total_density,
isothermal_compressibility,
sfe: None,
sfed: None,
molecular_kb_pmv: None,
rism_kb_pmv: None,
pressure: None,
}
}
}
}

Expand Down

0 comments on commit c06596e

Please sign in to comment.