Skip to content

Commit

Permalink
Common association implementation for different SAFT models (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
prehner authored Apr 19, 2024
1 parent 0428c78 commit 83088e2
Show file tree
Hide file tree
Showing 29 changed files with 624 additions and 597 deletions.
3 changes: 3 additions & 0 deletions docs/api/dft.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ Implementations of Helmholtz energy functionals for DFT.
:toctree: generated/
State
StateVec
PhaseEquilibrium
PhaseDiagram
Contributions
Verbosity
FMTVersion
DFTSolver
```

## Interfaces
Expand All @@ -54,6 +56,7 @@ Implementations of Helmholtz energy functionals for DFT.
ExternalPotential
Geometry
Pore1D
Pore2D
Pore3D
Adsorption1D
Adsorption3D
Expand Down
6 changes: 3 additions & 3 deletions docs/api/gc_pcsaft.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `feos.gc_pcsaft`

Utilities to build `GcPcSaftParameters`. To learn more about ways to build parameters from files or within Python, see [this example](/examples/eos/pcsaft/pcsaft_working_with_parameters).
Utilities to build `GcPcSaftParameters`. To learn more about ways to build parameters from files or within Python, see [this example](/tutorials/eos/pcsaft/pcsaft_working_with_parameters).

## Example

Expand All @@ -20,10 +20,10 @@ from feos.gc_pcsaft import GcPcSaftParameters
Identifier
IdentifierOption
ChemicalRecord
AssociationRecord
SmartsRecord
GcPcSaftRecord
SegmentRecord
BinarySegmentRecord
GcPcSaftRecord
GcPcSaftEosParameters
GcPcSaftFunctionalParameters
```
9 changes: 6 additions & 3 deletions docs/api/pcsaft.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `feos.pcsaft`

Utilities to build `PcSaftParameters`. To learn more about ways to build parameters from files or within Python, see [this example](/examples/eos/pcsaft/pcsaft_working_with_parameters).
Utilities to build `PcSaftParameters`. To learn more about ways to build parameters from files or within Python, see [this example](/tutorials/eos/pcsaft/pcsaft_working_with_parameters).

## Example

Expand All @@ -19,12 +19,15 @@ parameters = PcSaftParameters.from_json(['methane', 'ethane'], 'parameters.json'
:toctree: generated/
Identifier
IdentifierOption
ChemicalRecord
SmartsRecord
DQVariants
PcSaftRecord
PcSaftBinaryRecord
PureRecord
SegmentRecord
BinaryRecord
BinarySegmentRecord
DQVariants
PcSaftRecord
PcSaftParameters
```
1 change: 1 addition & 0 deletions docs/api/pets.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:toctree: generated/
Identifier
IdentifierOption
ChemicalRecord
PureRecord
BinaryRecord
Expand Down
3 changes: 2 additions & 1 deletion docs/api/saftvrmie.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ parameters = SaftVRMieParameters.from_json(['ethane', 'methane'], path)
:toctree: generated/
Identifier
ChemicalRecord
IdentifierOption
PureRecord
BinaryRecord
SaftVRMieRecord
SaftVRMieBinaryRecord
SaftVRMieParameters
```
1 change: 1 addition & 0 deletions docs/api/saftvrqmie.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ parameters = SaftVRQMieParameters.from_json(['hydrogen', 'neon'], 'parameters.js
FeynmanHibbsOrder
Identifier
IdentifierOption
PureRecord
BinaryRecord
SaftVRQMieRecord
Expand Down
4 changes: 2 additions & 2 deletions docs/api/si.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `feos.si`

This module contains data types for dimensioned quantities, i.e. floating point values multiplied with units.
If you want to learn more about this module, take a look at [this notebook](/examples/utility/working_with_units).
If you want to learn more about this module, take a look at [this notebook](/tutorials/utility/core_working_with_units).

## Example usage

Expand All @@ -11,7 +11,7 @@ from feos.si import KELVIN, RGAS, METER, MOL, BAR
p_ig = 25.0 * MOL / METER**3 * RGAS * 315.5 * KELVIN
print('Ideal gas pressure: {:.2f} bar'.format(p_ig / BAR))
```
```terminal
```
Ideal gas pressure: 0.66 bar
```

Expand Down
1 change: 1 addition & 0 deletions docs/api/uvtheory.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ parameters = UVTheoryParameters.from_json(['methane', 'ethane'], 'parameters.jso
:toctree: generated/
Identifier
IdentifierOption
ChemicalRecord
PureRecord
BinaryRecord
Expand Down
2 changes: 1 addition & 1 deletion docs/recipes/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Recipes

This section contains short code snippets for specific, commonly used tasks.
If you are looking for examples with explanations, see the [examples](/examples/index).
If you are looking for tutorials with explanations, see the [tutorials](/tutorials/index).

## Plots

Expand Down
16 changes: 11 additions & 5 deletions src/association/dft.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::*;
use crate::hard_sphere::HardSphereProperties;
use feos_core::EosResult;
use feos_dft::{FunctionalContribution, WeightFunction, WeightFunctionInfo, WeightFunctionShape};
use num_dual::DualNum;
Expand All @@ -8,7 +7,10 @@ use std::ops::MulAssign;

pub const N0_CUTOFF: f64 = 1e-9;

impl<P: HardSphereProperties + Sync + Send> FunctionalContribution for Association<P> {
impl<P: AssociationStrength + Sync + Send> FunctionalContribution for Association<P>
where
P::Record: Sync + Send,
{
fn weight_functions<N: DualNum<f64> + Copy>(&self, temperature: N) -> WeightFunctionInfo<N> {
let p = &self.parameters;
let r = p.hs_diameter(temperature) * 0.5;
Expand Down Expand Up @@ -103,7 +105,7 @@ impl<P: HardSphereProperties + Sync + Send> FunctionalContribution for Associati
}
}

impl<P: HardSphereProperties> Association<P> {
impl<P: AssociationStrength> Association<P> {
pub fn _helmholtz_energy_density<N: DualNum<f64> + Copy + ScalarOperand, S: Data<Elem = N>>(
&self,
temperature: N,
Expand Down Expand Up @@ -199,7 +201,9 @@ impl<P: HardSphereProperties> Association<P> {
let dj = diameter[j];
let k = n2 * n3i * (di * dj / (di + dj));
let delta = (((&k / 18.0 + 0.5) * &k * xi + 1.0) * n3i)
* ((temperature.recip() * a.epsilon_k_ab[(0, 0)]).exp_m1() * a.sigma3_kappa_ab[(0, 0)]);
* self
.parameters
.association_strength(temperature, 0, 0, a.parameters_ab[(0, 0)]);

// no cross association, two association sites
let aux = &delta * (&rhob - &rhoa) + 1.0;
Expand Down Expand Up @@ -233,7 +237,9 @@ impl<P: HardSphereProperties> Association<P> {
let di = diameter[i];
let k = n2 * n3i * (di * 0.5);
let delta = (((&k / 18.0 + 0.5) * &k * xi + 1.0) * n3i)
* ((temperature.recip() * a.epsilon_k_cc[(0, 0)]).exp_m1() * a.sigma3_kappa_cc[(0, 0)]);
* self
.parameters
.association_strength(temperature, 0, 0, a.parameters_cc[(0, 0)]);

// no cross association, two association sites
let xc = ((delta * 4.0 * &rhoc + 1.0).map(N::sqrt) + 1.0).map(N::recip) * 2.0;
Expand Down
Loading

0 comments on commit 83088e2

Please sign in to comment.