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 1 commit
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
Next Next commit
Make FMT functional more flexible
  • Loading branch information
prehner committed Jun 6, 2022
commit 0fe5201ebcf3dc6c2dab6bee12be4c0e05d297dc
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "feos-dft"
version = "0.2.0"
authors = ["Philipp Rehner <prehner@ethz.ch>"]
edition = "2018"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Generic classical DFT implementations for the `feos` project."
homepage = "https://github.com/feos-org"
Expand Down
41 changes: 24 additions & 17 deletions src/fundamental_measure_theory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pub trait FMTProperties {
fn component_index(&self) -> Array1<usize>;
fn chain_length(&self) -> Array1<f64>;
fn hs_diameter<N: DualNum<f64>>(&self, temperature: N) -> Array1<N>;

fn geometry_coefficients<N: DualNum<f64>>(&self, _temperature: N) -> [Array1<N>; 4] {
let m = self.chain_length().mapv(|m| N::from(m));
[m.clone(), m.clone(), m.clone(), m]
}
}

/// Different versions of fundamental measure theory
Expand Down Expand Up @@ -60,8 +65,8 @@ impl<P> FMTContribution<P> {
impl<P: FMTProperties, N: DualNum<f64>> FunctionalContributionDual<N> for FMTContribution<P> {
fn weight_functions(&self, temperature: N) -> WeightFunctionInfo<N> {
let r = self.properties.hs_diameter(temperature) * 0.5;
let m = self.properties.chain_length();
match (self.version, m.len()) {
let [c0, c1, c2, c3] = self.properties.geometry_coefficients(temperature);
match (self.version, r.len()) {
(FMTVersion::WhiteBear | FMTVersion::AntiSymWhiteBear, 1) => {
WeightFunctionInfo::new(self.properties.component_index(), false).extend(
vec![
Expand All @@ -70,8 +75,9 @@ impl<P: FMTProperties, N: DualNum<f64>> FunctionalContributionDual<N> for FMTCon
WeightFunctionShape::DeltaVec,
]
.into_iter()
.map(|s| WeightFunction {
prefactor: self.properties.chain_length().mapv(|m| m.into()),
.zip([c2, c3.clone(), c3])
.map(|(s, c)| WeightFunction {
prefactor: c,
kernel_radius: r.clone(),
shape: s,
})
Expand All @@ -83,54 +89,54 @@ impl<P: FMTProperties, N: DualNum<f64>> FunctionalContributionDual<N> for FMTCon
WeightFunctionInfo::new(self.properties.component_index(), false)
.add(
WeightFunction {
prefactor: Zip::from(&m)
prefactor: Zip::from(&c0)
.and(&r)
.map_collect(|&m, &r| r.powi(-2) * m / (4.0 * PI)),
.map_collect(|&c, &r| r.powi(-2) * c / (4.0 * PI)),
kernel_radius: r.clone(),
shape: WeightFunctionShape::Delta,
},
true,
)
.add(
WeightFunction {
prefactor: Zip::from(&m)
prefactor: Zip::from(&c1)
.and(&r)
.map_collect(|&m, &r| r.recip() * m / (4.0 * PI)),
.map_collect(|&c, &r| r.recip() * c / (4.0 * PI)),
kernel_radius: r.clone(),
shape: WeightFunctionShape::Delta,
},
true,
)
.add(
WeightFunction {
prefactor: m.mapv(|m| m.into()),
prefactor: c2,
kernel_radius: r.clone(),
shape: WeightFunctionShape::Delta,
},
true,
)
.add(
WeightFunction {
prefactor: m.mapv(|m| m.into()),
prefactor: c3.clone(),
kernel_radius: r.clone(),
shape: WeightFunctionShape::Theta,
},
true,
)
.add(
WeightFunction {
prefactor: Zip::from(&m)
prefactor: Zip::from(&c3)
.and(&r)
.map_collect(|&m, &r| r.recip() * m / (4.0 * PI)),
.map_collect(|&c, &r| r.recip() * c / (4.0 * PI)),
kernel_radius: r.clone(),
shape: WeightFunctionShape::DeltaVec,
},
true,
)
.add(
WeightFunction {
prefactor: m.mapv(|m| m.into()),
kernel_radius: r.clone(),
prefactor: c3,
kernel_radius: r,
shape: WeightFunctionShape::DeltaVec,
},
true,
Expand All @@ -145,8 +151,9 @@ impl<P: FMTProperties, N: DualNum<f64>> FunctionalContributionDual<N> for FMTCon
WeightFunctionShape::Theta,
]
.into_iter()
.map(|s| WeightFunction {
prefactor: self.properties.chain_length().mapv(|m| m.into()),
.zip(self.properties.geometry_coefficients(temperature))
.map(|(s, c)| WeightFunction {
prefactor: c,
kernel_radius: r.clone(),
shape: s,
})
Expand All @@ -165,7 +172,7 @@ impl<P: FMTProperties, N: DualNum<f64>> FunctionalContributionDual<N> for FMTCon
let pure_component_weighted_densities = matches!(
self.version,
FMTVersion::WhiteBear | FMTVersion::AntiSymWhiteBear
) && self.properties.chain_length().len() == 1;
) && self.properties.component_index().len() == 1;

// scalar weighted densities
let (n2, n3) = if pure_component_weighted_densities {
Expand Down