org.apache.commons.math3.ode.events.EventHandler Java Examples

The following examples show how to use org.apache.commons.math3.ode.events.EventHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Let the event handler reset the state if it wants.
 * @param t value of the independent <i>time</i> variable at the
 * beginning of the next step
 * @param y array were to put the desired state vector at the beginning
 * of the next step
 * @return true if the integrator should reset the derivatives too
 */
public boolean reset(final double t, final double[] y) {

    if (!(pendingEvent && (FastMath.abs(pendingEventTime - t) <= convergence))) {
        return false;
    }

    if (nextAction == EventHandler.Action.RESET_STATE) {
        handler.resetState(t, y);
    }
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;

    return (nextAction == EventHandler.Action.RESET_STATE) ||
           (nextAction == EventHandler.Action.RESET_DERIVATIVES);

}
 
Example #2
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Simple constructor.
 * @param handler event handler
 * @param maxCheckInterval maximal time interval between switching
 * function checks (this interval prevents missing sign changes in
 * case the integration steps becomes very large)
 * @param convergence convergence threshold in the event time search
 * @param maxIterationCount upper limit of the iteration count in
 * the event time search
 * @param solver Root-finding algorithm to use to detect state events
 */
public EventState(final EventHandler handler, final double maxCheckInterval,
                  final double convergence, final int maxIterationCount,
                  final UnivariateSolver solver) {
    this.handler           = handler;
    this.maxCheckInterval  = maxCheckInterval;
    this.convergence       = FastMath.abs(convergence);
    this.maxIterationCount = maxIterationCount;
    this.solver            = solver;

    // some dummy values ...
    t0                = Double.NaN;
    g0                = Double.NaN;
    g0Positive        = true;
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;
    previousEventTime = Double.NaN;
    increasing        = true;
    nextAction        = EventHandler.Action.CONTINUE;

}
 
Example #3
Source File: HierarchicalODERKSimulator.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
@Override
public Action eventOccurred(double t, double[] y, boolean increasing) {
  value = -value;
  currentTime.setValue(0, t);
  vectorWrapper.setValues(y);
  computeRates();
  for (HierarchicalModel modelstate : modules) {
    int index = modelstate.getIndex();
    for (EventNode event : modelstate.getListOfEvents()) {
      for (HierarchicalNode subNode : event) {
        if (event.getMaxDisabledTime(index) > t) {
          event.setMaxDisabledTime(index, t);
        }
      }
    }
  }
  computeEvents();
  return EventHandler.Action.STOP;
}
 
Example #4
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount) {
    addEventHandler(handler, maxCheckInterval, convergence,
                    maxIterationCount,
                    new BracketingNthOrderBrentSolver(convergence, 5));
}
 
Example #5
Source File: GraggBulirschStoerIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addEventHandler(final EventHandler function,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
  super.addEventHandler(function, maxCheckInterval, convergence,
                        maxIterationCount, solver);

  // reinitialize the arrays
  initializeArrays();

}
 
Example #6
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount) {
    addEventHandler(handler, maxCheckInterval, convergence,
                    maxIterationCount,
                    new BracketingNthOrderBrentSolver(convergence, 5));
}
 
Example #7
Source File: Nopol2017_0077_s.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
    eventsStates.add(new EventState(handler, maxCheckInterval, convergence,
                                    maxIterationCount, solver));
}
 
Example #8
Source File: Nopol2017_0077_s.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount) {
    addEventHandler(handler, maxCheckInterval, convergence,
                    maxIterationCount,
                    new BracketingNthOrderBrentSolver(convergence, 5));
}
 
Example #9
Source File: DormandPrince853IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-9;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                              scalAbsoluteTolerance,
                                                              scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertEquals(0, handler.getMaximalValueError(), 2.1e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #10
Source File: Math_7_AbstractIntegrator_s.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
    eventsStates.add(new EventState(handler, maxCheckInterval, convergence,
                                    maxIterationCount, solver));
}
 
Example #11
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public Collection<EventHandler> getEventHandlers() {
    final List<EventHandler> list = new ArrayList<EventHandler>(eventsStates.size());
    for (EventState state : eventsStates) {
        list.add(state.getEventHandler());
    }
    return Collections.unmodifiableCollection(list);
}
 
Example #12
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount) {
    addEventHandler(handler, maxCheckInterval, convergence,
                    maxIterationCount,
                    new BracketingNthOrderBrentSolver(convergence, 5));
}
 
Example #13
Source File: DormandPrince853IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-9;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                              scalAbsoluteTolerance,
                                                              scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertEquals(0, handler.getMaximalValueError(), 2.1e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #14
Source File: HighamHall54IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-8;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                          scalAbsoluteTolerance,
                                                          scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l],
                               Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getMaximalValueError() < 1.0e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #15
Source File: GraggBulirschStoerIntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-10;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep,
                                                                scalAbsoluteTolerance,
                                                                scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getMaximalValueError() < 4.0e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #16
Source File: HighamHall54IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-8;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                          scalAbsoluteTolerance,
                                                          scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l],
                               Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getMaximalValueError() < 1.0e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #17
Source File: HighamHall54IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-8;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                          scalAbsoluteTolerance,
                                                          scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l],
                               Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getMaximalValueError() < 1.0e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #18
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount) {
    addEventHandler(handler, maxCheckInterval, convergence,
                    maxIterationCount,
                    new BracketingNthOrderBrentSolver(convergence, 5));
}
 
Example #19
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public Collection<EventHandler> getEventHandlers() {
    final List<EventHandler> list = new ArrayList<EventHandler>();
    for (EventState state : eventsStates) {
        list.add(state.getEventHandler());
    }
    return Collections.unmodifiableCollection(list);
}
 
Example #20
Source File: DormandPrince54IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-8;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
                                                             scalAbsoluteTolerance,
                                                             scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l],
                               Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getMaximalValueError() < 5.0e-6);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #21
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public Collection<EventHandler> getEventHandlers() {
    final List<EventHandler> list = new ArrayList<EventHandler>();
    for (EventState state : eventsStates) {
        list.add(state.getEventHandler());
    }
    return Collections.unmodifiableCollection(list);
}
 
Example #22
Source File: DormandPrince853IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-9;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                              scalAbsoluteTolerance,
                                                              scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertEquals(0, handler.getMaximalValueError(), 2.1e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #23
Source File: DormandPrince54IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-8;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
                                                             scalAbsoluteTolerance,
                                                             scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l],
                               Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getMaximalValueError() < 5.0e-6);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #24
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public Collection<EventHandler> getEventHandlers() {
    final List<EventHandler> list = new ArrayList<EventHandler>(eventsStates.size());
    for (EventState state : eventsStates) {
        list.add(state.getEventHandler());
    }
    return Collections.unmodifiableCollection(list);
}
 
Example #25
Source File: HighamHall54IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
  {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-8;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                          scalAbsoluteTolerance,
                                                          scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l],
                               Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getMaximalValueError() < 1.0e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #26
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount) {
    addEventHandler(handler, maxCheckInterval, convergence,
                    maxIterationCount,
                    new BracketingNthOrderBrentSolver(convergence, 5));
}
 
Example #27
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public Collection<EventHandler> getEventHandlers() {
    final List<EventHandler> list = new ArrayList<EventHandler>();
    for (EventState state : eventsStates) {
        list.add(state.getEventHandler());
    }
    return Collections.unmodifiableCollection(list);
}
 
Example #28
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
    eventsStates.add(new EventState(handler, maxCheckInterval, convergence,
                                    maxIterationCount, solver));
}
 
Example #29
Source File: GraggBulirschStoerIntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
  {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-10;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep,
                                                                scalAbsoluteTolerance,
                                                                scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getMaximalValueError() < 4.0e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}
 
Example #30
Source File: HighamHall54IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEvents()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem4 pb = new TestProblem4();
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-8;
  double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                          scalAbsoluteTolerance,
                                                          scalRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  EventHandler[] functions = pb.getEventsHandlers();
  double convergence = 1.0e-8 * maxStep;
  for (int l = 0; l < functions.length; ++l) {
    integ.addEventHandler(functions[l],
                               Double.POSITIVE_INFINITY, convergence, 1000);
  }
  Assert.assertEquals(functions.length, integ.getEventHandlers().size());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getMaximalValueError() < 1.0e-7);
  Assert.assertEquals(0, handler.getMaximalTimeError(), convergence);
  Assert.assertEquals(12.0, handler.getLastTime(), convergence);
  integ.clearEventHandlers();
  Assert.assertEquals(0, integ.getEventHandlers().size());

}