Molecular Dynamics Simulation  1.0
Public Member Functions | List of all members
GravitationalForce Class Reference

Class to calculate gravitational forces between particles. Implements the interface PairwiseForceSource. More...

#include <GravitationalForce.h>

Inheritance diagram for GravitationalForce:
Inheritance graph
Collaboration diagram for GravitationalForce:
Collaboration graph

Public Member Functions

std::array< double, 3UL > calculateForce (const Particle &p, const Particle &q) const override
 Calculates the gravitational forces between two particles. More...
 
 operator std::string () const override
 Returns "Gravity" as name of the force. More...
 
- Public Member Functions inherited from PairwiseForceSource
virtual ~PairwiseForceSource ()=default
 Virtual destructor for correct cleanup of derived classes. More...
 

Detailed Description

Class to calculate gravitational forces between particles. Implements the interface PairwiseForceSource.

Implementation of the force calculation to simulate gravity forces between particles. This class implements the interface PairwiseForceSource.

Definition at line 11 of file GravitationalForce.h.

Member Function Documentation

◆ calculateForce()

std::array< double, 3UL > GravitationalForce::calculateForce ( const Particle p,
const Particle q 
) const
overridevirtual

Calculates the gravitational forces between two particles.

Parameters
pParticle
qParticle
Returns
Gravitational force exerted by q on p

Calculates the gravitational force which q exerts on p

Implements PairwiseForceSource.

Definition at line 5 of file GravitationalForce.cpp.

5  {
6  const auto displacement = q.getX() - p.getX();
7  const double dist = ArrayUtils::L2Norm(displacement);
8 
9  const auto f_gravity = (p.getM() * q.getM() / (std::pow(dist, 3))) * displacement;
10 
11  return f_gravity;
12 }
const std::array< double, 3 > & getX() const
Gets the position of the particle.
Definition: Particle.h:157
double getM() const
Gets the mass of the particle.
Definition: Particle.h:177
auto L2Norm(const Container &c)
Definition: ArrayUtils.h:174

◆ operator std::string()

GravitationalForce::operator std::string ( ) const
explicitoverridevirtual

Returns "Gravity" as name of the force.

Implements PairwiseForceSource.

Definition at line 14 of file GravitationalForce.cpp.

14 { return "Gravitational"; }

The documentation for this class was generated from the following files: