[The EJS ODE editor allows users to express arrays of ODEs in vector notation.]

Week 6 Notes: Event Driven Models

We study ODE event driven models and show how they can be used to detect hard disk collisions in models such as the ideal gas and Newton's cradle.  We also introduce discrete maps and Poincare sections. 

Bouncing Balls

There is little new physics in the Bouncing Balls Model.  The purpose of this model is to introduce EJS features that enable us to model systems with many particles and many discrete events.  These features include:
 

ODE Arrays

The ODE editor assumes that a differential equation for an array element, such as x[i], is a pattern that should be applied to all elements in the array.  This assumption makes it easy to solve arrays of differential equations.  The Bouncing Ball Model, for example, solves 128 differential equations because the each of the 4 dynamical variable array has dimension 32 in the variables table.

Shape Sets

The Bouncing Ball Model uses a Shape Set to display an array of 2D shapes.  The inspector for the Shape Set has X- and Y-input properties that are connected to the x and y dynamical variable arrays.  If the # Elements property is empty, EJS automatically determines the length of the position array and creates the necessary shapes.  If the # Elements property is set to an integer that is lower than the length of the position array, EJS will display fewer shapes and the length of the x-array.

Multiple ODE Events

The most difficult aspect of the Bouncing Balls Model is the ODE-event algorithm.  Because we have no a priori way of knowing which ball has moved past a wall, we must check every ball at every boundary.  In fact, it is likely that more than one ball will be outside the box after a time step dt.  EJS gracefully handles this situation by backing up the ODE solver until all four zero conditions return positive numbers.

 

The left wall zero condition shows how to write a typical multi-particle ODE event.

double err=Double.POSITIVE_INFINITY;
double r=ballSize/2;
// find particle furthest left
for(int i=0; i<np; i++){ // loop over all particles
if(vx[i]<0 && x[i]-r<err){ // only check particles moving to left
bounceIndex=i; // remember the particle
err = x[i]-r; // set the error
}
}
return err;

The zero condition code starts by defining an error variable that is as large as possible and then checks every particle to see if it is moving to the left and if its x-position is less than the error value.  After the loop, the error variable contains the coordinate of the left-moving particle that is furthest to the left.  If this value is zero or positive the event is not triggered.  If this value is negative the ODE solver backs up to find the time when the trigger occurs.  This process is repeated for all four walls until all collisions have been processed.

Exercise:

  1. Add an Arrow Set to the Bouncing Ball Model to display the ball velocities.
  2. Add a trace that shows the trajectory of a single particle.
  3. Create an action that changes the particle trace in (2) to another particle by clicking on that particle.

 

Hint for (3): Create a mouse action method the uses the _view.particleSet.getInteractedIndex() method to find the particle that should be traced.

Related Models

The following models use ODE events to detect collisions between hard objects (disks or spheres).

 

Additional models may be be posted for self-study.

Credits:

The Bouncing Balls Model was created by Wolfgang Christian using the Easy Java Simulations (EJS) version 4.1 authoring and modeling tool.  You can examine and modify a compiled EJS model if you run the model (double click on the model's jar file), right-click within a plot, and select "Open Ejs Model" from the pop-up menu.  You must, of course, have EJS installed on your computer.

 

Information about Ejs is available at: <http://www.um.es/fem/Ejs/> and in the OSP comPADRE collection <http://www.compadre.org/OSP/>.