# [math] ode event handler

3 messages
Open this post in threaded view
|

## [math] ode event handler

 Hi there, I'm new to Java and working on a project to integrate some ODEs. I'm having issues knowing how to work with the event handler. My ODE class looks like: public class DipoleODEimplements FirstOrderDifferentialEquations {      public int getDimension() {          return 6; }      public void computeDerivatives(double t, double[] y, double[] yDot) {          double r = y[0]; double r2 = r * r; double r3 = r2 * r; double r4 = r3 * r; double theta = y[1]; double phi = y[2]; double sin_phi = Math.sin(phi); double cos_phi = Math.cos(phi); double pr = y[3]; double ptheta = y[4]; double ptheta2 = ptheta * ptheta; double pphi = y[5]; double cos2 = Math.cos(phi -2 * theta); double sin2 = Math.sin(phi -2 * theta); yDot[0] = pr; yDot[1] = ptheta / r2; yDot[2] =10 * pphi; yDot[3] = ptheta2 / r3 - (cos_phi +3 * cos2) / (4 * r4); yDot[4] = sin2 / (2 * r3); yDot[5] = -(sin_phi +3 * sin2) / (12 * r3); } } When the y[0] value gets below 1.0, I'd like to change the y[3] value and the continue the integration. Basically I'm looking for a ball to bounce off another one. The integration gets stuck though and I can't seem to get things bouncing. Here's my event handler, too: EventHandler handler =new EventHandler() {      @Override public void init(double t0, double[] y0, double t) {      }      @Override public double g(double t, double[] y) {          return y[0] -1.0; }      @Override public ActioneventOccurred(double t, double[] y, boolean increasing) {          return Action.RESET_STATE; }      @Override public void resetState(double t, double[] y) {          y[3] *= -1.0; } }; And adding it to the integrator: dp853.addEventHandler(handler, 50.0, 1e-6, 100); Thanks for the help, -- Bo Johnson (801) 503-2043