Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.
Merged
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
add ideal_gas getter to HelmholtzEnergyFunctional
  • Loading branch information
prehner committed Feb 14, 2022
commit 5f83f5feee7526aea3382e3f18f67292b2024a30
32 changes: 31 additions & 1 deletion src/functional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use crate::ideal_chain_contribution::IdealChainContribution;
use crate::weight_functions::{WeightFunction, WeightFunctionInfo, WeightFunctionShape};
use feos_core::{
Contributions, EosResult, EosUnit, EquationOfState, HelmholtzEnergy, HelmholtzEnergyDual,
MolarWeight, StateHD,
IdealGasContribution, IdealGasContributionDual, MolarWeight, StateHD,
};
use ndarray::*;
use num_dual::*;
use petgraph::graph::{Graph, UnGraph};
use petgraph::visit::EdgeRef;
use petgraph::Directed;
use quantity::{QuantityArray, QuantityArray1, QuantityScalar};
use std::fmt;
use std::ops::{AddAssign, MulAssign};
use std::rc::Rc;

Expand Down Expand Up @@ -54,6 +55,19 @@ impl<T: MolarWeight<U>, U: EosUnit> MolarWeight<U> for DFT<T> {
}
}

struct DefaultIdealGasContribution();
impl<D: DualNum<f64>> IdealGasContributionDual<D> for DefaultIdealGasContribution {
fn de_broglie_wavelength(&self, _: D, components: usize) -> Array1<D> {
Array1::zeros(components)
}
}

impl fmt::Display for DefaultIdealGasContribution {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Ideal gas (default)")
}
}

impl<T: HelmholtzEnergyFunctional> EquationOfState for DFT<T> {
fn components(&self) -> usize {
self.component_index[self.component_index.len() - 1] + 1
Expand Down Expand Up @@ -107,6 +121,10 @@ impl<T: HelmholtzEnergyFunctional> EquationOfState for DFT<T> {
));
res
}

fn ideal_gas(&self) -> &dyn IdealGasContribution {
self.functional.ideal_gas()
}
}

/// A general Helmholtz energy functional.
Expand All @@ -125,6 +143,18 @@ pub trait HelmholtzEnergyFunctional: Sized {
/// equation of state anyways).
fn compute_max_density(&self, moles: &Array1<f64>) -> f64;

/// Return the ideal gas contribution.
///
/// Per default this function returns an ideal gas contribution
/// in which the de Broglie wavelength is 1 for every component.
/// Therefore, the correct ideal gas pressure is obtained even
/// with no explicit ideal gas term. If a more detailed model is
/// required (e.g. for the calculation of internal energies) this
/// function has to be overwritten.
fn ideal_gas(&self) -> &dyn IdealGasContribution {
&DefaultIdealGasContribution()
}

/// Overwrite this, if the functional consists of heterosegmented chains.
fn bond_lengths(&self, _temperature: f64) -> UnGraph<(), f64> {
Graph::with_capacity(0, 0)
Expand Down