pub trait UnivariateEnergy {
// Required method
fn energy(&self, r: f64) -> f64;
}Expand description
Computes energy as a function of one variable.
A univariate energy is function only of one variable. Often, this is
distance between two points: $U(r)$, but it could be a distance from a
point to a surface, or any other single variable.
Implement UnivariateEnergy on a custom type or use one of the provided
potentials in univariate in MD or MC simulations.
- Use
UnivariateEnergyin combination withIsotropicandPairwiseCutoffto model pairwise interactions between sites.
§Examples
Set a custom potential using a closure:
use hoomd_interaction::univariate::UnivariateEnergy;
let a = 2.0;
let custom = |r: f64| a / (r.powi(12));
let energy = custom.energy(1.0);
assert_eq!(energy, 2.0);Implement a custom potential via a type:
use hoomd_interaction::univariate::UnivariateEnergy;
struct Custom {
a: f64,
}
impl UnivariateEnergy for Custom {
fn energy(&self, r: f64) -> f64 {
self.a / r.powi(12)
}
}
let custom = Custom { a: 2.0 };
let energy = custom.energy(1.0);
assert_eq!(energy, 2.0);