pub trait Force {
// Required methods
fn system_name(&self) -> &str;
fn potential(&self, particle: &Particle, other: &Particle) -> f64;
// Provided methods
fn force(&self, particle: &Particle, other: &Particle) -> Vec3 { ... }
fn apply_force(&self, particle: &mut Particle, other: &mut Particle) { ... }
}Expand description
The trait for force systems. A force system is a mathematical model which describes the potential energy between two particles.
This trait provides two methods Force::potential and Force::force for interacting with the force system. The potential is the scalar value used as the factor to the normalized force vector.
The method Force::system_name is used for serialization of the force system.
Required Methods§
Sourcefn system_name(&self) -> &str
fn system_name(&self) -> &str
§Returns
Name of the force system, which is used for serialization and
deserialization. The characters are expected to be in dash-case.
Provided Methods§
Sourcefn force(&self, particle: &Particle, other: &Particle) -> Vec3
fn force(&self, particle: &Particle, other: &Particle) -> Vec3
Calculates the force between two particles. For directly applying the force, see Force::apply_force.
§Formula
F = -U / r (simplified to scalar, actually a vector)The resulting force is a three dimensional vector pointing towards the other particle. The magnitude is the fraction of potential energy and distance.
§Returns
The force vector that should be applied to the first particle. According to the Third Law the second particle should receive the negated force.
§Example
use moldyn_core::{Particle, Vec3, LennardJonesForce, Force};
let mut particle1 = Particle::from_data(Vec3::new(0.0, 0.0, 0.0), Vec3::zero(), 1.0);
let mut particle2 = Particle::from_data(Vec3::new(1.0, 0.0, 0.0), Vec3::zero(), 1.0);
let force = LennardJonesForce::default().force(&particle1, &particle2);
particle1.apply_force(force);
particle2.apply_force(-force);Sourcefn apply_force(&self, particle: &mut Particle, other: &mut Particle)
fn apply_force(&self, particle: &mut Particle, other: &mut Particle)
Applies the calculated force to a particle pair.
§Example
use moldyn_core::{Particle, Vec3, LennardJonesForce, Force};
let mut particle1 = Particle::from_data(Vec3::new(0.0, 0.0, 0.0), Vec3::zero(), 1.0);
let mut particle2 = Particle::from_data(Vec3::new(1.0, 0.0, 0.0), Vec3::zero(), 1.0);
let lennard_jones = LennardJonesForce::default();
let force = lennard_jones.apply_force(&mut particle1, &mut particle2);