Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/adsorption/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::solver::DFTSolver;
use feos_core::{
Contributions, EosError, EosResult, EosUnit, EquationOfState, SolverOptions, StateBuilder,
};
use ndarray::{arr1, Array1, Dimension, Ix1, Ix3};
use ndarray::{arr1, Array1, Dimension, Ix1, Ix3, RemoveAxis};
use quantity::{QuantityArray1, QuantityArray2, QuantityScalar};
use std::rc::Rc;

Expand Down Expand Up @@ -55,12 +55,17 @@ where
})
}

fn equilibrium<D: Dimension, F: HelmholtzEnergyFunctional + FluidParameters>(
fn equilibrium<
D: Dimension + RemoveAxis + 'static,
F: HelmholtzEnergyFunctional + FluidParameters,
>(
&self,
equilibrium: &Adsorption<U, D, F>,
) -> EosResult<(QuantityArray1<U>, QuantityArray1<U>)>
where
D::Larger: Dimension<Smaller = D>,
D::Smaller: Dimension<Larger = D>,
<D::Larger as Dimension>::Larger: Dimension<Smaller = D::Larger>,
{
let p_eq = equilibrium.pressure().get(0);
match self {
Expand Down Expand Up @@ -111,10 +116,16 @@ pub type Adsorption1D<U, F> = Adsorption<U, Ix1, F>;
/// Container structure for adsorption isotherms in 3D pores.
pub type Adsorption3D<U, F> = Adsorption<U, Ix3, F>;

impl<U: EosUnit, D: Dimension, F: HelmholtzEnergyFunctional + FluidParameters> Adsorption<U, D, F>
impl<
U: EosUnit,
D: Dimension + RemoveAxis + 'static,
F: HelmholtzEnergyFunctional + FluidParameters,
> Adsorption<U, D, F>
where
QuantityScalar<U>: std::fmt::Display,
D::Larger: Dimension<Smaller = D>,
D::Smaller: Dimension<Larger = D>,
<D::Larger as Dimension>::Larger: Dimension<Smaller = D::Larger>,
{
fn new<S: PoreSpecification<U, D>>(
functional: &Rc<DFT<F>>,
Expand Down
15 changes: 6 additions & 9 deletions src/adsorption/pore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::solver::DFTSolver;
use feos_core::{Contributions, EosResult, EosUnit, State, StateBuilder};
use ndarray::prelude::*;
use ndarray::Axis as Axis_nd;
use ndarray::Zip;
use ndarray::{RemoveAxis, Zip};
use ndarray_stats::QuantileExt;
use quantity::{QuantityArray, QuantityArray2, QuantityArray4, QuantityScalar};
use std::rc::Rc;
Expand Down Expand Up @@ -133,22 +133,19 @@ impl<U: Copy, D: Dimension, F> Clone for PoreProfile<U, D, F> {
}
}

impl<U: EosUnit, D: Dimension, F: HelmholtzEnergyFunctional> PoreProfile<U, D, F>
impl<U: EosUnit, D: Dimension + RemoveAxis + 'static, F: HelmholtzEnergyFunctional>
PoreProfile<U, D, F>
where
D::Larger: Dimension<Smaller = D>,
D::Smaller: Dimension<Larger = D>,
<D::Larger as Dimension>::Larger: Dimension<Smaller = D::Larger>,
{
pub fn solve_inplace(&mut self, solver: Option<&DFTSolver>, debug: bool) -> EosResult<()> {
// Solve the profile
self.profile.solve(solver, debug)?;

// calculate grand potential density
let omega = self
.profile
.integrate(&self.profile.dft.grand_potential_density(
self.profile.temperature,
&self.profile.density,
&self.profile.convolver,
)?);
let omega = self.profile.grand_potential()?;
self.grand_potential = Some(omega);

// calculate interfacial tension
Expand Down
2 changes: 1 addition & 1 deletion src/functional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<T: HelmholtzEnergyFunctional> DFT<T> {
let rho = density.to_reduced(U::reference_density())?;
let (mut f, dfdrho) = self.functional_derivative(t, &rho, convolver)?;

// calculate the grand potential density
// Calculate the grand potential density
for ((rho, dfdrho), &m) in rho
.outer_iter()
.zip(dfdrho.outer_iter())
Expand Down
7 changes: 2 additions & 5 deletions src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ impl<U: EosUnit, F: HelmholtzEnergyFunctional> PlanarInterface<U, F> {

// postprocess
self.surface_tension = Some(self.profile.integrate(
&(self.profile.dft.grand_potential_density(
self.profile.temperature,
&self.profile.density,
&self.profile.convolver,
)? + self.vle.vapor().pressure(Contributions::Total)),
&(self.profile.grand_potential_density()?
+ self.vle.vapor().pressure(Contributions::Total)),
));
let delta_rho = self.vle.liquid().density - self.vle.vapor().density;
self.equimolar_radius = Some(
Expand Down
9 changes: 9 additions & 0 deletions src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,15 @@ where
Ok(self.integrate(&self.entropy_density(contributions)?))
}

pub fn grand_potential_density(&self) -> EosResult<QuantityArray<U, D>> {
self.dft
.grand_potential_density(self.temperature, &self.density, &self.convolver)
}

pub fn grand_potential(&self) -> EosResult<QuantityScalar<U>> {
Ok(self.integrate(&self.grand_potential_density()?))
}

pub fn internal_energy(&self, contributions: Contributions) -> EosResult<QuantityScalar<U>> {
// initialize convolver
let t = self.temperature.to_reduced(U::reference_temperature())?;
Expand Down
7 changes: 7 additions & 0 deletions src/python/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ macro_rules! impl_profile {
self.0.profile.internal_energy(contributions)?,
))
}

#[getter]
fn get_grand_potential_density(&self) -> PyResult<$si_arr> {
Ok($si_arr::from(
self.0.profile.grand_potential_density()?,
))
}
}
};
}
Expand Down
8 changes: 1 addition & 7 deletions src/solvation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ impl<U: EosUnit, F: HelmholtzEnergyFunctional> SolvationProfile<U, F> {
self.profile.solve(solver, debug)?;

// calculate grand potential density
let omega = self
.profile
.integrate(&self.profile.dft.grand_potential_density(
self.profile.temperature,
&self.profile.density,
&self.profile.convolver,
)?);
let omega = self.profile.grand_potential()?;
self.grand_potential = Some(omega);

// calculate solvation free energy
Expand Down
7 changes: 2 additions & 5 deletions src/solvation/pair_correlation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ impl<U: EosUnit, F: HelmholtzEnergyFunctional + PairPotential> PairCorrelation<U

// calculate self solvation free energy
self.self_solvation_free_energy = Some(self.profile.integrate(
&(self.profile.dft.grand_potential_density(
self.profile.temperature,
&self.profile.density,
&self.profile.convolver,
)? + self.profile.bulk.pressure(Contributions::Total)),
&(self.profile.grand_potential_density()?
+ self.profile.bulk.pressure(Contributions::Total)),
));

// calculate structure factor
Expand Down