[]Trait lumol::Computation

pub trait Computation: Send + Sync {
    fn compute_energy(&self, r: f64) -> f64;
fn compute_force(&self, r: f64) -> f64; }

Alternative energy and forces computation.

The Computation trait represent an alternative way to compute a given potential. For example using interpolation on a table or on a grid, from a Fourier decomposition, etc.

Examples

use lumol_core::energy::Computation;
use lumol_core::energy::Harmonic;

/// This is just a thin wrapper logging every time the `energy/force`
/// methods are called.
#[derive(Clone)]
struct LoggingComputation<T: Potential>(T);

impl<T: Potential> Computation for LoggingComputation<T> {
    fn compute_energy(&self, r: f64) -> f64 {
        println!("Called energy");
        self.0.energy(r)
    }

    fn compute_force(&self, r: f64) -> f64 {
        println!("Called force");
        self.0.force(r)
    }
}

let potential = Harmonic{x0: 0.5, k: 4.2};
let computation = LoggingComputation(potential.clone());

assert_eq!(computation.energy(1.0), potential.energy(1.0));
assert_eq!(computation.force(2.0), potential.force(2.0));

Required methods

fn compute_energy(&self, r: f64) -> f64

Compute the energy value at r

fn compute_force(&self, r: f64) -> f64

Compute the force value at r

Loading content...

Implementors

impl Computation for TableComputation

Loading content...