Beispiel #1
0
// PairwiseLennardJonesForce calculates the force vector on particle Ri due to Rj using the Lennard Jones potential.
func PairwiseLennardJonesForce(Ri, Rj [3]float64, L float64) [3]float64 {
	if space.PointsAreEqual(Ri, Rj, L) {
		panic(fmt.Sprintf("%v and %v are equal, the pairwise force is infinite", Ri, Rj))
	}
	r := space.Displacement(Ri, Rj, L)
	magR := vector.Length(r)
	f := 4 * (-12*math.Pow(magR, -13) + 6*math.Pow(magR, -7))
	return vector.Scale(r, f/magR)
}
Beispiel #2
0
// KineticEnergy calculates the kinetic energy of a particle.
func KineticEnergy(v [3]float64, m float64) float64 {
	s := vector.Length(v)
	return 0.5 * m * s * s
}
Beispiel #3
0
// Distance calculates the scalar distance between two points in a cell with periodic boundary conditions.
func Distance(a, b [3]float64, L float64) float64 {
	d := Displacement(a, b, L)
	return vector.Length(d)
}