Steffen Müller > Physics-Springs-Friction-1.01 > Physics::Springs::Friction

Download:
Physics-Springs-Friction-1.01.tar.gz

Dependencies

Annotate this POD

Related Modules

Physics::Springs
Data::Dumper
more...
By perlmonks.org
View/Report Bugs
Module Version: 1.01   Source  

NAME ^

Physics::Springs::Friction - Simulate Dynamics with Springs and Friction

SYNOPSIS ^

  use Physics::Springs::Friction;
  
  my $sim = Physics::Springs::Friction->new();

ABSTRACT ^

  Simulate particle dynamics with springs and friction.

DESCRIPTION ^

This module is intended as an add-on to the Physics::Springs (from version 1.00) and Physics::Particles (from version 1.00) modules and may be used to simulate particle dynamics including spring-like forces between any two particles you specify and friction-like forces that are applied to the movement of all particles.

The module extends the API of Physics::Springs by one method which is documented below. Please see the documentation to Physics::Springs and Physics::Particles for more information about the API.

There are several particle properties required by Physics::Springs::Friction in order to work: These are the x/y/z coordinates, the vx/vy/vz velocity vector components, and a non-zero mass 'm'.

Method add_friction

This method adds a new frictional force to the simulation. This force can be thought of as an external force field that applies to any particles depending on any of its properties. That means you're welcome to abuse this functionality to implement any kind of external force fields.

The method is to be called with zero to two arguments. Without arguments, the default friction implementation will be used which is meant to model Stokes' friction. More on Stokes' friction in the section named 'On Stokes' Friction'. It is strongly suggested you skim it even if you have a strong background in Physics. Same applies to the section 'On Newtonian Friction'.

With one argument, you may choose what type of friction to apply. Valid first arguments are either 'stokes', 'newton', an anonymous subroutine, or an arbitrary string representing a piece of code that uses a particle $P and a friction-magnitude $M to compute the force excerted on the particle. The force components are expected to be stored in an existing variable $F that contains an array reference to an array of [0, 0, 0]. In case of the anonymous subroutine, the subroutine is expected to return the three force components. This behaviour has changed in version 1.00.

With two arguments, the second argument sets the friction-magnitude.

iterate_step

Iterates next simulation step. Please refer to the documentation of the super method to this in Physics::Particles.

On Friction

Friction is one of the concepts that physicists hardly understand because there are simply too many processes involved. We can, however, describe macroscopic effects of friction in many cases. There are several formulars that describe special cases of frictional forces. Two of these, Stokes' friction and Newtonian friction are implemented in this module. Using anonymous subroutines or code strings that compute friction, it is possible to extend the module's functionality.

On Stokes' Friction

The formula to calculate Stokes' friction of a sphere of radius r is

  Force = 6 * Pi * r * eta * velocity

Trivially, the force is antiparallel to the velocity. Stokes' friction is usually applied when a rather small object moves rather slowly through a fluid or gas of viscosity eta.

In the Physics::Springs::Friction implementation, the friction is simply computed as

  Force = magnitude * velocity
  
  Hence:
  magnitude = 6 * Pi * r * eta (for small spheres)

The magnitude is passed as the second argument to the add_friction() method. This behaviour was chosen to allow for flexibility concerning geometry and viscosity.

On Newtonian Friction

The formula to calculate Newtonian friction of a body in a fluid:

  Force = 1/2 * c * rho * area * velocity^2

rho is the density of the fluid, the area is the projected area of the body in direction of movement, and c is coefficient that is determined by the body's geometry. For hydro-dynamically good geometries: c < 1. For spheres: c = about 1. For hydro-dynamically inefficient geometries: c > 1.

Newtonian friction is usually applied in cases of high velocity and bodies of significant size. As with Stokes' friction, all constants are summed up into the magnitude property of the friction as follows:

  Force = magnitude * velocity^2
  magnitude = 0.5*c*rho*area

DIAGNOSTICS ^

Here is a list of some not-so-selfexplanatory errors:

  "Precondition 1 for Physics::Springs::Friction::new failed."
  new() does not expect any arguments.

  "Postcondition 1 for Physics::Springs::Friction::new failed."
  Please contact the author about this error.
  
  "Precondition 1 for Physics::Springs::Friction::add_friction failed."
  add_friction() takes between 0 and 2 arguments and is an object method.

  "Precondition 2 for Physics::Springs::Friction::add_friction failed."
  add_friction() expects a defined first argument if any.
  
  "Precondition 3 for Physics::Springs::Friction::add_friction failed."
  add_friction() expects a defined second argument if any.

  "Postcondition 1 for Physics::Springs::Friction::add_friction failed."
  add_friction() screwed up. Please contact the author about this error.

SEE ALSO ^

Physics::Particles, Physics::Springs

Math::Project3D, Math::Project3D::Plot for a reasonably simple way to visualize your data.

http://steffen-mueller.net or CPAN for the current version of this module.

AUTHOR ^

Steffen Mueller, <friction-module at steffen-mueller dot net>

COPYRIGHT AND LICENSE ^

Copyright 2003-2005 by Steffen Mueller

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: