org.apache.commons.math3.exception.NoBracketingException Java Examples

The following examples show how to use org.apache.commons.math3.exception.NoBracketingException. 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: DormandPrince853IntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testBackward()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

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

    FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                                scalAbsoluteTolerance,
                                                                scalRelativeTolerance);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 1.1e-7);
    Assert.assertTrue(handler.getMaximalValueError() < 1.1e-7);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    Assert.assertEquals("Dormand-Prince 8 (5, 3)", integ.getName());
}
 
Example #2
Source File: AdamsMoultonIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test(expected=NumberIsTooSmallException.class)
public void testMinStep()
        throws DimensionMismatchException, NumberIsTooSmallException,
        MaxCountExceededException, NoBracketingException {

      TestProblem1 pb = new TestProblem1();
      double minStep = 0.1 * (pb.getFinalTime() - pb.getInitialTime());
      double maxStep = pb.getFinalTime() - pb.getInitialTime();
      double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
      double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };

      FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, minStep, maxStep,
                                                              vecAbsoluteTolerance,
                                                              vecRelativeTolerance);
      TestProblemHandler handler = new TestProblemHandler(pb, integ);
      integ.addStepHandler(handler);
      integ.integrate(pb,
                      pb.getInitialTime(), pb.getInitialState(),
                      pb.getFinalTime(), new double[pb.getDimension()]);

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

    TestProblem5 pb = new TestProblem5();
    double range = FastMath.abs(pb.getFinalTime() - pb.getInitialTime());

    FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, 0, range, 1.0e-12, 1.0e-12);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 1.5e-8);
    Assert.assertTrue(handler.getMaximalValueError() < 1.5e-8);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-16);
    Assert.assertEquals("Adams-Bashforth", integ.getName());
}
 
Example #4
Source File: RobustBrentSolver.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected double doSolve() throws TooManyEvaluationsException, NoBracketingException {
    final double min = getMin();
    final double max = getMax();
    final double[] xSearchGrid = createHybridSearchGrid(min, max, numBisections, depth);
    final double[] fSearchGrid = Arrays.stream(xSearchGrid).map(this::computeObjectiveValue).toArray();

    /* find bracketing intervals on the search grid */
    final List<Bracket> bracketsList = detectBrackets(xSearchGrid, fSearchGrid);
    if (bracketsList.isEmpty()) {
        throw new NoBracketingException(min, max, fSearchGrid[0], fSearchGrid[fSearchGrid.length-1]);
    }
    final BrentSolver solver = new BrentSolver(getRelativeAccuracy(), getAbsoluteAccuracy(), getFunctionValueAccuracy());
    final List<Double> roots = bracketsList.stream()
            .map(b -> solver.solve(getMaxEvaluations(), this::computeObjectiveValue, b.min, b.max, 0.5 * (b.min + b.max)))
            .collect(Collectors.toList());
    if (roots.size() == 1 || meritFunc == null) {
        return roots.get(0);
    }
    final double[] merits = roots.stream().mapToDouble(meritFunc::value).toArray();
    final int bestRootIndex = IntStream.range(0, roots.size())
            .boxed()
            .max((i, j) -> (int) (merits[i] - merits[j]))
            .get();
    return roots.get(bestRootIndex);
}
 
Example #5
Source File: DormandPrince54IntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test(expected=NumberIsTooSmallException.class)
public void testMinStep()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

    TestProblem1 pb = new TestProblem1();
    double minStep = 0.1 * (pb.getFinalTime() - pb.getInitialTime());
    double maxStep = pb.getFinalTime() - pb.getInitialTime();
    double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
    double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };

    FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
                                                               vecAbsoluteTolerance,
                                                               vecRelativeTolerance);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb,
                    pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);
    Assert.fail("an exception should have been thrown");

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

  final TestProblem3 pb  = new TestProblem3(0.9);
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double[] vecAbsoluteTolerance = { 1.0e-8, 1.0e-8, 1.0e-10, 1.0e-10 };
  double[] vecRelativeTolerance = { 1.0e-10, 1.0e-10, 1.0e-8, 1.0e-8 };

  FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                          vecAbsoluteTolerance,
                                                          vecRelativeTolerance);
  TestProblemHandler handler = new TestProblemHandler(pb, integ); 
  integ.addStepHandler(handler);
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);
  Assert.assertEquals(0.0, handler.getMaximalValueError(), 1.5e-4);
  Assert.assertEquals("Higham-Hall 5(4)", integ.getName());
}
 
Example #7
Source File: ClassicalRungeKuttaIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testBackward()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem5 pb = new TestProblem5();
  double step = FastMath.abs(pb.getFinalTime() - pb.getInitialTime()) * 0.001;

  FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getLastError() < 5.0e-10);
  Assert.assertTrue(handler.getMaximalValueError() < 7.0e-10);
  Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
  Assert.assertEquals("classical Runge-Kutta", integ.getName());
}
 
Example #8
Source File: GraggBulirschStoerIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testKepler()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  final TestProblem3 pb = new TestProblem3(0.9);
  double minStep        = 0;
  double maxStep        = pb.getFinalTime() - pb.getInitialTime();
  double absTolerance   = 1.0e-6;
  double relTolerance   = 1.0e-6;

  FirstOrderIntegrator integ =
    new GraggBulirschStoerIntegrator(minStep, maxStep,
                                     absTolerance, relTolerance);
  integ.addStepHandler(new KeplerStepHandler(pb));
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertEquals(integ.getEvaluations(), pb.getCalls());
  Assert.assertTrue(pb.getCalls() < 2150);

}
 
Example #9
Source File: AdamsMoultonIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void polynomial()
        throws DimensionMismatchException, NumberIsTooSmallException,
        MaxCountExceededException, NoBracketingException {
    TestProblem6 pb = new TestProblem6();
    double range = FastMath.abs(pb.getFinalTime() - pb.getInitialTime());

    for (int nSteps = 2; nSteps < 8; ++nSteps) {
        AdamsMoultonIntegrator integ =
            new AdamsMoultonIntegrator(nSteps, 1.0e-6 * range, 0.1 * range, 1.0e-5, 1.0e-5);
        TestProblemHandler handler = new TestProblemHandler(pb, integ);
        integ.addStepHandler(handler);
        integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                        pb.getFinalTime(), new double[pb.getDimension()]);
        if (nSteps < 4) {
            Assert.assertTrue(handler.getMaximalValueError() > 7.0e-04);
        } else {
            Assert.assertTrue(handler.getMaximalValueError() < 3.0e-13);
        }
    }

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

  double previousError = Double.NaN;
  for (int i = 0; i < 10; ++i) {

    double step  = FastMath.pow(2.0, -(i + 1));
    double error = integrateWithSpecifiedStep(4.0, 0.0, 1.0, step)
                 - FastMath.sin(4.0);
    if (i > 0) {
      Assert.assertTrue(FastMath.abs(error) < FastMath.abs(previousError));
    }
    previousError = error;

  }
}
 
Example #11
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public double integrate(final FirstOrderDifferentialEquations equations,
                        final double t0, final double[] y0, final double t, final double[] y)
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

    if (y0.length != equations.getDimension()) {
        throw new DimensionMismatchException(y0.length, equations.getDimension());
    }
    if (y.length != equations.getDimension()) {
        throw new DimensionMismatchException(y.length, equations.getDimension());
    }

    // prepare expandable stateful equations
    final ExpandableStatefulODE expandableODE = new ExpandableStatefulODE(equations);
    expandableODE.setTime(t0);
    expandableODE.setPrimaryState(y0);

    // perform integration
    integrate(expandableODE, t);

    // extract results back from the stateful equations
    System.arraycopy(expandableODE.getPrimaryState(), 0, y, 0, y.length);
    return expandableODE.getTime();

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

  double previousError = Double.NaN;
  for (int i = 0; i < 10; ++i) {

    double step  = FastMath.pow(2.0, -(i + 1));
    double error = integrateWithSpecifiedStep(4.0, 0.0, 1.0, step)
                 - FastMath.sin(4.0);
    if (i > 0) {
      Assert.assertTrue(FastMath.abs(error) < FastMath.abs(previousError));
    }
    previousError = error;

  }
}
 
Example #13
Source File: UnivariateSolverUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the endpoints specify an interval and the end points
 * bracket a root.
 *
 * @param function Function.
 * @param lower Lower endpoint.
 * @param upper Upper endpoint.
 * @throws NoBracketingException if the function has the same sign at the
 * endpoints.
 * @throws NullArgumentException if {@code function} is {@code null}.
 */
public static void verifyBracketing(UnivariateFunction function,
                                    final double lower,
                                    final double upper)
    throws NullArgumentException,
           NoBracketingException {
    if (function == null) {
        throw new NullArgumentException(LocalizedFormats.FUNCTION);
    }
    verifyInterval(lower, upper);
    if (!isBracketing(function, lower, upper)) {
        throw new NoBracketingException(lower, upper,
                                        function.value(lower),
                                        function.value(upper));
    }
}
 
Example #14
Source File: GillIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testSmallStep()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem1 pb = new TestProblem1();
  double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;

  FirstOrderIntegrator integ = new GillIntegrator(step);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getLastError() < 2.0e-13);
  Assert.assertTrue(handler.getMaximalValueError() < 4.0e-12);
  Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
  Assert.assertEquals("Gill", integ.getName());

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

    TestProblem5 pb = new TestProblem5();
    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);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 5.0e-7);
    Assert.assertTrue(handler.getMaximalValueError() < 5.0e-7);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    Assert.assertEquals("Higham-Hall 5(4)", integ.getName());
}
 
Example #16
Source File: GraggBulirschStoerIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testBackward()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

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

    FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep,
                                                                  scalAbsoluteTolerance,
                                                                  scalRelativeTolerance);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 7.5e-9);
    Assert.assertTrue(handler.getMaximalValueError() < 8.1e-9);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    Assert.assertEquals("Gragg-Bulirsch-Stoer", integ.getName());
}
 
Example #17
Source File: AdamsMoultonIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test(expected = MaxCountExceededException.class)
public void exceedMaxEvaluations()
        throws DimensionMismatchException, NumberIsTooSmallException,
        MaxCountExceededException, NoBracketingException {

    TestProblem1 pb  = new TestProblem1();
    double range = pb.getFinalTime() - pb.getInitialTime();

    AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(2, 0, range, 1.0e-12, 1.0e-12);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.setMaxEvaluations(650);
    integ.integrate(pb,
                    pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

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

    TestProblem5 pb = new TestProblem5();
    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);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 5.0e-7);
    Assert.assertTrue(handler.getMaximalValueError() < 5.0e-7);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    Assert.assertEquals("Higham-Hall 5(4)", integ.getName());
}
 
Example #19
Source File: ThreeEighthesIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testSmallStep()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

   TestProblem1 pb = new TestProblem1();
   double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;

   FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step);
   TestProblemHandler handler = new TestProblemHandler(pb, integ);
   integ.addStepHandler(handler);
   integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                   pb.getFinalTime(), new double[pb.getDimension()]);

   Assert.assertTrue(handler.getLastError() < 2.0e-13);
   Assert.assertTrue(handler.getMaximalValueError() < 4.0e-12);
   Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
   Assert.assertEquals("3/8", integ.getName());

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

    TestProblem1 pb = new TestProblem1();
    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;

    FirstOrderIntegrator integ = new LutherIntegrator(step);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 9.0e-17);
    Assert.assertTrue(handler.getMaximalValueError() < 4.0e-15);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    Assert.assertEquals("Luther", integ.getName());
}
 
Example #21
Source File: HighamHall54IntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testBackward()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

    TestProblem5 pb = new TestProblem5();
    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);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 5.0e-7);
    Assert.assertTrue(handler.getMaximalValueError() < 5.0e-7);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    Assert.assertEquals("Higham-Hall 5(4)", integ.getName());
}
 
Example #22
Source File: EulerIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testBackward()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

    TestProblem5 pb = new TestProblem5();
    double step = FastMath.abs(pb.getFinalTime() - pb.getInitialTime()) * 0.001;

    FirstOrderIntegrator integ = new EulerIntegrator(step);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 0.45);
    Assert.assertTrue(handler.getMaximalValueError() < 0.45);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    Assert.assertEquals("Euler", integ.getName());
}
 
Example #23
Source File: GraggBulirschStoerIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testBackward()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

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

    FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep,
                                                                  scalAbsoluteTolerance,
                                                                  scalRelativeTolerance);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 7.5e-9);
    Assert.assertTrue(handler.getMaximalValueError() < 8.1e-9);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    Assert.assertEquals("Gragg-Bulirsch-Stoer", integ.getName());
}
 
Example #24
Source File: EulerIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testBigStep()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem1 pb  = new TestProblem1();
  double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;

  FirstOrderIntegrator integ = new EulerIntegrator(step);
  TestProblemHandler handler = new TestProblemHandler(pb, integ);
  integ.addStepHandler(handler);
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertTrue(handler.getLastError() > 0.01);
  Assert.assertTrue(handler.getMaximalValueError() > 0.2);
  Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);

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

  final TestProblem3 pb  = new TestProblem3(0.9);
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-8;
  double scalRelativeTolerance = scalAbsoluteTolerance;

  FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                              scalAbsoluteTolerance,
                                                              scalRelativeTolerance);
  integ.addStepHandler(new KeplerHandler(pb));
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  Assert.assertEquals(integ.getEvaluations(), pb.getCalls());
  Assert.assertTrue(pb.getCalls() < 3300);

}
 
Example #26
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public double integrate(final FirstOrderDifferentialEquations equations,
                        final double t0, final double[] y0, final double t, final double[] y)
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

    if (y0.length != equations.getDimension()) {
        throw new DimensionMismatchException(y0.length, equations.getDimension());
    }
    if (y.length != equations.getDimension()) {
        throw new DimensionMismatchException(y.length, equations.getDimension());
    }

    // prepare expandable stateful equations
    final ExpandableStatefulODE expandableODE = new ExpandableStatefulODE(equations);
    expandableODE.setTime(t0);
    expandableODE.setPrimaryState(y0);

    // perform integration
    integrate(expandableODE, t);

    // extract results back from the stateful equations
    System.arraycopy(expandableODE.getPrimaryState(), 0, y, 0, y.length);
    return expandableODE.getTime();

}
 
Example #27
Source File: GraggBulirschStoerIntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=NumberIsTooSmallException.class)
public void testNullIntervalCheck()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {
    TestProblem1 pb = new TestProblem1();
    GraggBulirschStoerIntegrator integrator =
      new GraggBulirschStoerIntegrator(0.0, 1.0, 1.0e-10, 1.0e-10);
    integrator.integrate(pb,
                         0.0, new double[pb.getDimension()],
                         0.0, new double[pb.getDimension()]);
}
 
Example #28
Source File: AdamsBashforthIntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=DimensionMismatchException.class)
public void dimensionCheck() throws NumberIsTooSmallException, DimensionMismatchException, MaxCountExceededException, NoBracketingException {
    TestProblem1 pb = new TestProblem1();
    FirstOrderIntegrator integ =
        new AdamsBashforthIntegrator(2, 0.0, 1.0, 1.0e-10, 1.0e-10);
    integ.integrate(pb,
                    0.0, new double[pb.getDimension()+10],
                    1.0, new double[pb.getDimension()+10]);
}
 
Example #29
Source File: StepNormalizerOutputTestBase.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testIncLastRev()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {
    double[] exp = getArray(getExpIncRev(), getO()[5][0], getO()[5][1]);
    doTest(StepNormalizerMode.INCREMENT, StepNormalizerBounds.LAST, exp, true);
}
 
Example #30
Source File: FirstOrderConverterTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSmallStep()
    throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException {
  double error = integrateWithSpecifiedStep(4.0, 0.0, 1.0, 1.0e-4)
                 - FastMath.sin(4.0);
  Assert.assertTrue(FastMath.abs(error) < 1.0e-10);
}