Program: 57457
Project: 57457
Buggy source:
/** 
 * Start the integration. <p>This method computes the first few steps of the multistep method, using the underlying starter integrator, ensuring the returned steps all belong to the same smooth range.</p> <p>In order to ensure smoothness, the start phase is automatically restarted when a state or derivative reset is triggered by the registered events handlers before this start phase is completed. As an example, consider integrating a differential equation from t=0 to t=100 with a 4 steps method and step size equal to 0.2. If an event resets the state at t=0.5, the start phase will not end at t=0.6 with steps at [0.0, 0.2, 0.4, 0.6] but instead will end at t=1.1 with steps at [0.5, 0.7, 0.9, 1.1].</p> <p>A side effect of the need for smoothness is that an ODE triggering short period regular resets will remain in the start phase throughout the integration range if the step size or the number of steps to store are too large.</p> <p>If the start phase ends prematurely (because of some triggered event for example), then the time of latest previous steps will be set to <code>Double.NaN</code>.</p>
 * @param n number of steps to store
 * @param h signed step size to use for the first steps
 * @param manager discrete events manager to use
 * @param equations differential equations to integrate
 * @param t0 initial time
 * @param y state vector: contains the initial value of the state vector at t0,will be used to put the state vector at each successful step and hence contains the final value at the end of the start phase
 * @return time of the end of the start phase
 * @throws IntegratorException if the integrator cannot perform integration
 * @throws DerivativeException this exception is propagated to the caller ifthe underlying user function triggers one
 */
protected double start(final int n,final double h,final CombinedEventsManager manager,final double t0,final double[] y) throws DerivativeException, IntegratorException {
  Arrays.fill(previousT,Double.NaN);
  Arrays.fill(previousF,null);
  starter.clearEventHandlers();
  for (  EventState state : manager.getEventsStates()) {
    starter.addEventHandler(new ResetCheckingWrapper(state.getEventHandler()),state.getMaxCheckInterval(),state.getConvergence(),state.getMaxIterationCount());
  }
  starter.clearStepHandlers();
  for (  final StepHandler handler : stepHandlers) {
    starter.addStepHandler(new FilteringWrapper(handler));
  }
  final StoringStepHandler store=new StoringStepHandler(n);
  starter.addStepHandler(new StepNormalizer(h,store));
  double t=t0;
  double stopTime=Double.NaN;
  FirstOrderDifferentialEquations equations=new CountingDifferentialEquations(y.length);
  do {
    resetTime=Double.NaN;
    final double dt=(n - 0.9999) * h;
    for (    EventHandler handler : starter.getEventHandlers()) {
      ((ResetCheckingWrapper)handler).setRange(t,Math.abs(dt));
    }
    store.restart();
    stopTime=starter.integrate(equations,t,y,t + dt,y);
    if (!Double.isNaN(resetTime)) {
      t=resetTime;
    }
  }
 while (!Double.isNaN(resetTime));
  starter.clearEventHandlers();
  starter.clearStepHandlers();
  if (store.getFinalState() != null) {
    System.arraycopy(store.getFinalState(),0,y,0,y.length);
  }
  return stopTime;
}

Fixed version (ground truth):
/** 
 * Start the integration. <p>This method computes the first few steps of the multistep method, using the underlying starter integrator, ensuring the returned steps all belong to the same smooth range.</p> <p>In order to ensure smoothness, the start phase is automatically restarted when a state or derivative reset is triggered by the registered events handlers before this start phase is completed. As an example, consider integrating a differential equation from t=0 to t=100 with a 4 steps method and step size equal to 0.2. If an event resets the state at t=0.5, the start phase will not end at t=0.6 with steps at [0.0, 0.2, 0.4, 0.6] but instead will end at t=1.1 with steps at [0.5, 0.7, 0.9, 1.1].</p> <p>A side effect of the need for smoothness is that an ODE triggering short period regular resets will remain in the start phase throughout the integration range if the step size or the number of steps to store are too large.</p> <p>If the start phase ends prematurely (because of some triggered event for example), then the time of latest previous steps will be set to <code>Double.NaN</code>.</p>
 * @param n number of steps to store
 * @param h signed step size to use for the first steps
 * @param manager discrete events manager to use
 * @param t0 initial time
 * @param y state vector: contains the initial value of the state vector at t0,will be used to put the state vector at each successful step and hence contains the final value at the end of the start phase
 * @return time of the end of the start phase
 * @throws IntegratorException if the integrator cannot perform integration
 * @throws DerivativeException this exception is propagated to the caller ifthe underlying user function triggers one
 */
protected double start(final int n,final double h,final CombinedEventsManager manager,final double t0,final double[] y) throws DerivativeException, IntegratorException {
  Arrays.fill(previousT,Double.NaN);
  Arrays.fill(previousF,null);
  starter.clearEventHandlers();
  for (  EventState state : manager.getEventsStates()) {
    starter.addEventHandler(new ResetCheckingWrapper(state.getEventHandler()),state.getMaxCheckInterval(),state.getConvergence(),state.getMaxIterationCount());
  }
  starter.clearStepHandlers();
  for (  final StepHandler handler : stepHandlers) {
    starter.addStepHandler(new FilteringWrapper(handler));
  }
  final StoringStepHandler store=new StoringStepHandler(n);
  starter.addStepHandler(new StepNormalizer(h,store));
  double t=t0;
  double stopTime=Double.NaN;
  FirstOrderDifferentialEquations equations=new CountingDifferentialEquations(y.length);
  do {
    resetTime=Double.NaN;
    final double dt=(n - 0.9999) * h;
    for (    EventHandler handler : starter.getEventHandlers()) {
      ((ResetCheckingWrapper)handler).setRange(t,Math.abs(dt));
    }
    store.restart();
    stopTime=starter.integrate(equations,t,y,t + dt,y);
    if (!Double.isNaN(resetTime)) {
      t=resetTime;
    }
  }
 while (!Double.isNaN(resetTime));
  starter.clearEventHandlers();
  starter.clearStepHandlers();
  if (store.getFinalState() != null) {
    System.arraycopy(store.getFinalState(),0,y,0,y.length);
  }
  return stopTime;
}