APS Excellence in Physics Education Award
November 2019

Science SPORE Prize
November 2011

The Open Source Physics Project is supported by NSF DUE-0442581.

## Best methods to compensate for runaway mechanical energy. post and replies

What are the best methods for keeping mechanical energy from running away in a many-body simulation?
Stephen Salser
8 Posts

Here are two approaches I have tried to keep mechanical energy from running away in a many body simulation of coulomb interactions.

1.  The approach that worked fairly well was to introduce small velocity dependent drag forces with coefficients that depend on how much too high or too low the total mechanical energy is.  When the mechanical energy is too high, the drag coefficients are positive and the particles slow down, but when the mechanical energy is too low, the drag coefficients are negative and the particles speed up.  To make this work well I also had to limit the intensity of the interactions by setting the coulomb force to zero below a particular cutoff radius -- in effect treating each particle pair as if it were a hollow sphere interacting with a point-like particle, but not specifying which is which.  I treated the potential energy in a consistent way, and things became fairly stable.  The disadvantage of this method is that ALL particles are slowed down when the bulk of the mechanical energy runaway typically involves just the particles that are interacting very strongly.

2.  The approach that totally failed was to try to adjust the velocities of the particles manually either in the "Fixed relations" page or in the "Prelim code".  If the adjustments were made in "Fixed relations", then events like wall collisions were no longer handled properly.  If the adjustments were made in "Prelim code", the ODE solver appeared to compensate for my manual changes.  For example, if I clamped the velocities to zero in the "Prelim code" the ODE solver appeared to vary the velocity anyway, while keeping the particles position fixed, as if the particles were simultaneously accelerating and standing still.

My conclusion was that it is better to compensate for errors in a way that uses physically meaningful changes like modifications in the interaction force law or the addition of compensatory drag forces.

Are there other more elegant methods I should be aware of for many-body simulations?

P.S.  I was very interested in looking at the "Particles and Walls" simulation that is pictured at the front of "Easy Java Simulations -- The Manual" by Francisco Esquembre, but I couldn't find a download that worked for me and/or could be opened in the EjsS environment.

Post edited August 11, 2016 at 2:53 PM EST.

### Replies to What are the best methods for keeping mechanical energy from running away in a many-body simulation?

Re: What are the best methods for keeping mechanical energy from running away in a many-body simulation? -

lookang
239 Posts

the file you seek is here ejs_model_ParticlesAndWalls.jar http://iwant2study.org/lookangejss/05electricitynmagnetism/ejs/ejs_model_ParticlesAndWalls.jar

by Fu-Kwun Hwang and Paco i believe.

enjoy!

OSP@SG blog
OSP@SG Digital Library

Re: What are the best methods for keeping mechanical energy from running away in a many-body simulation? -
Wolfgang
182 Posts

Unless the simulation is running for very long times, a good adaptive stepsize ODE solver will produce a very little energy drift if the ODE tolerance is set to a small value, such as 1.0E-9. I recommend that is built into  Runge-Kutta 4/5 in EJS.

For Hamiltonian systems, the best energy conservation is achieved using a symplectic ODE solver, such as the velocity Verlet method.   The position accuracy is not as good as with  Runge-Kutta, but it has zero energy drift because it is a symplectic solver.   The velocity Verlet solver is often used in molecular dynamics simulations.