Force

Trait Force 

Source
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§

Source

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.

Source

fn potential(&self, particle: &Particle, other: &Particle) -> f64

Calculates the potential energy between two particles.

Provided Methods§

Source

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);
Source

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);

Trait Implementations§

Source§

impl Default for Box<dyn Force>

Source§

fn default() -> Self

The default force calculation system for this project is the lennard jones potential. If not specified, the system will be initialized with default parameters.

Source§

impl<'de> Deserialize<'de> for Box<dyn Force>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a> Serialize for dyn Force + 'a

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Implementors§