conspire/physics/molecular/potential/harmonic/
mod.rs1use crate::{math::Scalar, physics::molecular::potential::Potential};
2
3#[derive(Clone, Debug)]
5pub struct Harmonic {
6 pub rest_length: Scalar,
8 pub stiffness: Scalar,
10}
11
12impl Potential for Harmonic {
13 fn energy(&self, length: Scalar) -> Scalar {
17 0.5 * self.stiffness * (length - self.rest_length).powi(2)
18 }
19 fn force(&self, length: Scalar) -> Scalar {
23 self.stiffness * (length - self.rest_length)
24 }
25 fn stiffness(&self, _length: Scalar) -> Scalar {
29 self.stiffness
30 }
31 fn anharmonicity(&self, _length: Scalar) -> Scalar {
35 0.0
36 }
37 fn extension(&self, force: Scalar) -> Scalar {
41 force / self.stiffness
42 }
43 fn compliance(&self, _force: Scalar) -> Scalar {
47 1.0 / self.stiffness
48 }
49 fn peak(&self) -> Scalar {
53 Scalar::INFINITY
54 }
55 fn peak_force(&self) -> Scalar {
59 Scalar::INFINITY
60 }
61 fn rest_length(&self) -> Scalar {
65 self.rest_length
66 }
67}