narupatools.physics.force

Common force calculations such as springs and linear drag.

Functions

centripetal_force

Calculate the centripetal force on a collection of particles about an origin.

critically_damped_spring_force

Calculate the force caused by a critically damped spring using Hooke’s law.

damped_rotational_spring_forces

Calculate the forces on a set of particles from a damped rotational spring.

damped_spring_force

Calculate the force \(F\) caused by a damped spring using Hooke’s law.

gaussian_force_and_energy

Calculate the force and potential energy caused by a gaussian well.

linear_drag_force

Calculate the linear drag force which opposes and scales linearly with velocity.

mass_weighted_forces

Calculate the forces on a collection of particles by distributing a force \(F\).

spring_force

Calculate the force \(F\) caused by a spring using Hooke’s law.

spring_force_and_energy

Calculate the force and potential energy caused by a spring using Hooke’s law.

narupatools.physics.force.centripetal_force(*, masses: Union[numpy.ndarray[Any, numpy.dtype[numpy.float64]], Sequence[float]], positions: Union[numpy.ndarray[Any, numpy.dtype[numpy.float64]], Sequence[numpy.ndarray[Any, numpy.dtype[numpy.float64]]], Sequence[Sequence[float]]], angular_velocity: Union[numpy.ndarray[Any, numpy.dtype[numpy.float64]], Sequence[float]], origin: Optional[numpy.ndarray[Any, numpy.dtype[numpy.float64]]] = None)numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Calculate the centripetal force on a collection of particles about an origin.

This has the form:

\[F_i = m_i \omega \times (\omega \times (r_i - c))\]

This force pulls each particle towards the origin, depending on the magnitude of the angular velocity and their distance from the axis of rotation.

If an origin is not provided, the center of mass of the particles is used.

Parameters
  • masses – List of masses \(m_i\) of each particle.

  • positions – List of positions \(R_i\) of each particle.

  • angular_velocity – Angular velocity of the system as a whole.

  • origin – Optional origin that the rotation axis is defined around. Defaults to the center of mass.

narupatools.physics.force.critically_damped_spring_force(*, mass: float, offset: numpy.ndarray[Any, numpy.dtype[numpy.float64]], velocity: numpy.ndarray[Any, numpy.dtype[numpy.float64]], spring_constant: float)numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Calculate the force caused by a critically damped spring using Hooke’s law.

This has the form:

\[F = - k x - \gamma v\]

This is a sum of a standard spring force and a linear damping, with the damping coefficient chosen to minimize the time taken to achieve equilibrium whilst avoiding oscillations.

Parameters
  • mass – Mass \(m\) of the particle.

  • offset – Offset \(x\) of the spring from its resting position.

  • velocity – Velocity \(v\) of the particle.

  • spring_constant – Spring constant \(k\) that scales the force.

Returns

Force \(F\) applied by the spring.

narupatools.physics.force.damped_rotational_spring_forces(*, masses: numpy.ndarray[Any, numpy.dtype[numpy.float64]], positions: numpy.ndarray[Any, numpy.dtype[numpy.float64]], velocities: numpy.ndarray[Any, numpy.dtype[numpy.float64]], angle: numpy.ndarray[Any, numpy.dtype[numpy.float64]], spring_constant: float, damping_coefficient: float)numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Calculate the forces on a set of particles from a damped rotational spring.

This consists of three forces:

A rotational torque to rotate the system in the direction of angle

\[F_i = m_i k \theta \times r_i\]

A rotational torque opposing the current angular velocity of the system

\[F_i = - m_i \gamma \omega \times r_i\]

A centripetal force holding the system together

\[F_i = m_i \omega \times (\omega \times r_i)\]
Parameters
  • masses – List of masses \(m_i\) of each particle.

  • positions – List of positions \(R_i\) of each particle.

  • velocities – List of velocities \(v_i\) of each particle.

  • angle – 3D vector indicating the angle \(\theta\) to rotate around and which axis to do so.

  • spring_constant – Spring constant \(k\) which scales the force used to rotate the system in the desired direction.

  • damping_coefficient – Damping coefficient \(\gamma\) to scale the force which decelerates the rotational motion of the system.

Returns

List of forces \(F_i\) for each particle.

narupatools.physics.force.damped_spring_force(*, offset: numpy.ndarray[Any, numpy.dtype[numpy.float64]], velocity: numpy.ndarray[Any, numpy.dtype[numpy.float64]], spring_constant: float, damping_coefficient: float)numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Calculate the force \(F\) caused by a damped spring using Hooke’s law.

This has the form:

\[F = - k x - \gamma v\]

This is a sum of a standard spring force and a linear damping.

Parameters
  • offset – Offset \(x\) of the spring from its resting position.

  • velocity – Velocity \(v\) of the particle.

  • spring_constant – Spring constant \(k\) that scales the force.

  • damping_coefficient – Damping coefficient \(\gamma\) that scales the force.

Returns

Force \(F\) applied by the spring.

narupatools.physics.force.gaussian_force_and_energy(*, offset: numpy.ndarray[Any, numpy.dtype[numpy.float64]], depth: float = 1, sigma: float = 1)Tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], float]

Calculate the force and potential energy caused by a gaussian well.

This has the form:

\[V = - k \exp(-\frac{x^2}{2 \sigma^2}))\]
\[F = - k \frac{x}{\sigma^2} \exp(-\frac{x^2}{2 \sigma^2}))\]
Parameters
  • offset – Offset \(x\) of the spring from its resting position.

  • depth – Depth \(k\) of the gaussian well.

  • sigma – The standard deviation of the gaussian, describing its width.

Returns

Tuple of the force \(F\) applied by the spring and potential energy \(V\).

narupatools.physics.force.linear_drag_force(*, velocity: numpy.ndarray[Any, numpy.dtype[numpy.float64]], damping_coefficient: float)numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Calculate the linear drag force which opposes and scales linearly with velocity.

This has the form:

\[F = - \gamma v\]
Parameters
  • velocity – Velocity \(v\) of the particle.

  • damping_coefficient – Damping coefficient \(\gamma\) that scales the force.

Returns

Force \(F\) applied by the drag.

narupatools.physics.force.mass_weighted_forces(*, masses: numpy.ndarray[Any, numpy.dtype[numpy.float64]], force: numpy.ndarray[Any, numpy.dtype[numpy.float64]])numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Calculate the forces on a collection of particles by distributing a force \(F\).

The force \(F\) is distributed such that the acceleration that this force causes on the system’s center of mass is equal to the acceleration that \(F_i\) will cause on each particle. This distributes the force such that all particles experiance an equal acceleration.

The force \(F_i\) is given by:

\[F_i = m_i F / M\]

where \(M\) is the total mass.

Parameters
  • masses – List of masses \(m_i\) of each particle.

  • force – Force \(F\) to apply to the collection of particles.

Returns

List of forces \(F_i\) on each particle, in the same units as \(F\).

narupatools.physics.force.spring_force(*, offset: numpy.ndarray[Any, numpy.dtype[numpy.float64]], spring_constant: float = 1)numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Calculate the force \(F\) caused by a spring using Hooke’s law.

This has the form:

\[F = - k x\]
Parameters
  • offset – Offset \(x\) of the spring from its resting position.

  • spring_constant – Spring constant \(k\) that scales the force.

Returns

Force \(F\) applied by the spring.

narupatools.physics.force.spring_force_and_energy(*, offset: numpy.ndarray[Any, numpy.dtype[numpy.float64]], spring_constant: float = 1)Tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], float]

Calculate the force and potential energy caused by a spring using Hooke’s law.

This has the form:

\[V = \frac{1}{2} k x^2\]
\[F = - k x\]
Parameters
  • offset – Offset \(x\) of the spring from its resting position.

  • spring_constant – Spring constant \(k\) that scales the force.

Returns

Tuple of the force \(F\) applied by the spring and potential energy \(V\).