org.apache.commons.math.ode.DerivativeException Java Examples

The following examples show how to use org.apache.commons.math.ode.DerivativeException. 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 cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testKepler()
  throws DerivativeException, IntegratorException {

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

  assertTrue(pb.getCalls() < 2900);

}
 
Example #2
Source File: DormandPrince54IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void handleStep(StepInterpolator interpolator,
                       boolean isLast)
throws DerivativeException {

  ++nbSteps;
  for (int a = 1; a < 10; ++a) {

    double prev   = interpolator.getPreviousTime();
    double curr   = interpolator.getCurrentTime();
    double interp = ((10 - a) * prev + a * curr) / 10;
    interpolator.setInterpolatedTime(interp);

    double[] interpolatedY = interpolator.getInterpolatedState ();
    double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
    double dx = interpolatedY[0] - theoreticalY[0];
    double dy = interpolatedY[1] - theoreticalY[1];
    double error = dx * dx + dy * dy;
    if (error > maxError) {
      maxError = error;
    }
  }
  if (isLast) {
    assertTrue(maxError < 7.0e-10);
    assertTrue(nbSteps < 400);
  }
}
 
Example #3
Source File: DormandPrince54IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testKepler()
  throws DerivativeException, IntegratorException {

  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 DormandPrince54Integrator(minStep, maxStep,
                                                             scalAbsoluteTolerance,
                                                             scalRelativeTolerance);
  integ.setStepHandler(new KeplerHandler(pb));
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);

  assertTrue(pb.getCalls() < 2800);

}
 
Example #4
Source File: DormandPrince54IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testVariableSteps()
  throws DerivativeException, IntegratorException {

  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 DormandPrince54Integrator(minStep, maxStep,
                                                             scalAbsoluteTolerance,
                                                             scalRelativeTolerance);
  integ.setStepHandler(new VariableHandler());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);
}
 
Example #5
Source File: DormandPrince54IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testSmallLastStep()
  throws DerivativeException, IntegratorException {

  TestProblemAbstract pb = new TestProblem5();
  double minStep = 1.25;
  double maxStep = Math.abs(pb.getFinalTime() - pb.getInitialTime());
  double scalAbsoluteTolerance = 6.0e-4;
  double scalRelativeTolerance = 6.0e-4;

  AdaptiveStepsizeIntegrator integ =
    new DormandPrince54Integrator(minStep, maxStep,
                                  scalAbsoluteTolerance,
                                  scalRelativeTolerance);

  DP54SmallLastHandler handler = new DP54SmallLastHandler(minStep);
  integ.setStepHandler(handler);
  integ.setInitialStepSize(1.7);
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);
  assertTrue(handler.wasLastSeen());
  assertEquals("Dormand-Prince 5(4)", integ.getName());

}
 
Example #6
Source File: DormandPrince54IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testMinStep()
  throws DerivativeException, IntegratorException {

  try {
    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.setStepHandler(handler);
    integ.integrate(pb,
                    pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);
    fail("an exception should have been thrown");
  } catch(DerivativeException de) {
    fail("wrong exception caught");
  } catch(IntegratorException ie) {
  }

}
 
Example #7
Source File: GillIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testSmallStep()
  throws DerivativeException, IntegratorException {

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

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

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

}
 
Example #8
Source File: GillIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testBigStep()
  throws DerivativeException, IntegratorException {

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

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

  assertTrue(handler.getLastError() > 0.0004);
  assertTrue(handler.getMaximalValueError() > 0.005);
  assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);

}
 
Example #9
Source File: FirstOrderConverterTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testDecreasingSteps()
  throws DerivativeException, IntegratorException {
    
  double previousError = Double.NaN;
  for (int i = 0; i < 10; ++i) {

    double step  = Math.pow(2.0, -(i + 1));
    double error = integrateWithSpecifiedStep(4.0, 0.0, 1.0, step)
                 - Math.sin(4.0);
    if (i > 0) {
      assertTrue(Math.abs(error) < Math.abs(previousError));
    }
    previousError = error;
    
  }
}
 
Example #10
Source File: GraggBulirschStoerIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void handleStep(StepInterpolator interpolator,
                       boolean isLast)
throws DerivativeException {

  ++nbSteps;
  for (int a = 1; a < 100; ++a) {

    double prev   = interpolator.getPreviousTime();
    double curr   = interpolator.getCurrentTime();
    double interp = ((100 - a) * prev + a * curr) / 100;
    interpolator.setInterpolatedTime(interp);

    double[] interpolatedY = interpolator.getInterpolatedState ();
    double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
    double dx = interpolatedY[0] - theoreticalY[0];
    double dy = interpolatedY[1] - theoreticalY[1];
    double error = dx * dx + dy * dy;
    if (error > maxError) {
      maxError = error;
    }
  }
  if (isLast) {
    assertTrue(maxError < 2.7e-6);
    assertTrue(nbSteps < 80);
  }
}
 
Example #11
Source File: GraggBulirschStoerIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testVariableSteps()
  throws DerivativeException, IntegratorException {

  final TestProblem3 pb = new TestProblem3(0.9);
  double minStep        = 0;
  double maxStep        = pb.getFinalTime() - pb.getInitialTime();
  double absTolerance   = 1.0e-8;
  double relTolerance   = 1.0e-8;
  FirstOrderIntegrator integ =
    new GraggBulirschStoerIntegrator(minStep, maxStep,
                                     absTolerance, relTolerance);
  integ.setStepHandler(new VariableStepHandler());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);
  assertEquals("Gragg-Bulirsch-Stoer", integ.getName());
}
 
Example #12
Source File: GraggBulirschStoerIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testKepler()
  throws DerivativeException, IntegratorException {

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

  assertTrue(pb.getCalls() < 2150);

}
 
Example #13
Source File: MidpointIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testSmallStep()
  throws DerivativeException, IntegratorException {

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

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

  assertTrue(handler.getLastError() < 2.0e-7);
  assertTrue(handler.getMaximalValueError() < 1.0e-6);
  assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
  assertEquals("midpoint", integ.getName());

}
 
Example #14
Source File: MidpointIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testBigStep()
  throws DerivativeException, IntegratorException {

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

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

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

}
 
Example #15
Source File: StepNormalizerTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testBeforeEnd()
  throws DerivativeException, IntegratorException {
  final double range = pb.getFinalTime() - pb.getInitialTime();
  setLastSeen(false);
  integ.setStepHandler(new StepNormalizer(range / 10.5,
                                     new FixedStepHandler() {
                                       public void handleStep(double t,
                                                              double[] y,
                                                              boolean isLast) {
                                         if (isLast) {
                                           setLastSeen(true);
                                           checkValue(t,
                                                      pb.getFinalTime() - range / 21.0);
                                         }
                                       }
                                     }));
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);
  assertTrue(lastSeen);
}
 
Example #16
Source File: ThreeEighthesIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testSmallStep()
  throws DerivativeException, IntegratorException {

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

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

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

}
 
Example #17
Source File: EulerIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testBigStep()
  throws DerivativeException, IntegratorException {

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

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

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

}
 
Example #18
Source File: HighamHall54IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testKepler()
  throws DerivativeException, IntegratorException {

  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);
  integ.setStepHandler(new KeplerHandler(pb));
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);
  assertEquals("Higham-Hall 5(4)", integ.getName());
}
 
Example #19
Source File: EulerIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testSmallStep()
  throws DerivativeException, IntegratorException {

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

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

 assertTrue(handler.getLastError() < 2.0e-4);
 assertTrue(handler.getMaximalValueError() < 1.0e-3);
 assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 assertEquals("Euler", integ.getName());

}
 
Example #20
Source File: EulerStepInterpolatorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testInterpolationInside()
  throws DerivativeException {

  double[]   y    =   { 1.0, 3.0, -4.0 };
  double[][] yDot = { { 1.0, 2.0, -2.0 } };
  EulerStepInterpolator interpolator = new EulerStepInterpolator();
  interpolator.reinitialize(new DummyEquations(), y, yDot, true);
  interpolator.storeTime(0);
  interpolator.shift();
  interpolator.storeTime(1);

  interpolator.setInterpolatedTime(0.1);
  double[] result = interpolator.getInterpolatedState();
  assertTrue(Math.abs(result[0] - 0.1) < 1.0e-10);
  assertTrue(Math.abs(result[1] - 1.2) < 1.0e-10);
  assertTrue(Math.abs(result[2] + 2.2) < 1.0e-10);

  interpolator.setInterpolatedTime(0.5);
  result = interpolator.getInterpolatedState();
  assertTrue(Math.abs(result[0] - 0.5) < 1.0e-10);
  assertTrue(Math.abs(result[1] - 2.0) < 1.0e-10);
  assertTrue(Math.abs(result[2] + 3.0) < 1.0e-10);

}
 
Example #21
Source File: HighamHall54IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testMinStep()
  throws DerivativeException, IntegratorException {

  try {
    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 HighamHall54Integrator(minStep, maxStep,
                                                            vecAbsoluteTolerance,
                                                            vecRelativeTolerance);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.setStepHandler(handler);
    integ.integrate(pb,
                    pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);
    fail("an exception should have been thrown");
  } catch(DerivativeException de) {
    fail("wrong exception caught");
  } catch(IntegratorException ie) {
  }

}
 
Example #22
Source File: ClassicalRungeKuttaIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testSmallStep()
  throws DerivativeException, IntegratorException {

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

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

  assertTrue(handler.getLastError() < 2.0e-13);
  assertTrue(handler.getMaximalValueError() < 4.0e-12);
  assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
  assertEquals("classical Runge-Kutta", integ.getName());
}
 
Example #23
Source File: ClassicalRungeKuttaIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testBigStep()
  throws DerivativeException, IntegratorException {

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

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

  assertTrue(handler.getLastError() > 0.0004);
  assertTrue(handler.getMaximalValueError() > 0.005);
  assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);

}
 
Example #24
Source File: DormandPrince853IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void handleStep(StepInterpolator interpolator,
                       boolean isLast)
throws DerivativeException {

  ++nbSteps;
  for (int a = 1; a < 10; ++a) {

    double prev   = interpolator.getPreviousTime();
    double curr   = interpolator.getCurrentTime();
    double interp = ((10 - a) * prev + a * curr) / 10;
    interpolator.setInterpolatedTime(interp);

    double[] interpolatedY = interpolator.getInterpolatedState ();
    double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
    double dx = interpolatedY[0] - theoreticalY[0];
    double dy = interpolatedY[1] - theoreticalY[1];
    double error = dx * dx + dy * dy;
    if (error > maxError) {
      maxError = error;
    }
  }
  if (isLast) {
    assertTrue(maxError < 2.4e-10);
    assertTrue(nbSteps < 150);
  }
}
 
Example #25
Source File: DormandPrince853IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testMinStep()
  throws DerivativeException, IntegratorException {

  try {
    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 DormandPrince853Integrator(minStep, maxStep,
                                                                vecAbsoluteTolerance,
                                                                vecRelativeTolerance);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.setStepHandler(handler);
    integ.integrate(pb,
                    pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);
    fail("an exception should have been thrown");
  } catch(DerivativeException de) {
    fail("wrong exception caught");
  } catch(IntegratorException ie) {
  }

}
 
Example #26
Source File: DormandPrince853IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testVariableSteps()
  throws DerivativeException, IntegratorException {

  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.setStepHandler(new VariableHandler());
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);
  assertEquals("Dormand-Prince 8 (5, 3)", integ.getName());
}
 
Example #27
Source File: StepNormalizerTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testBoundaries()
  throws DerivativeException, IntegratorException {
  double range = pb.getFinalTime() - pb.getInitialTime();
  setLastSeen(false);
  integ.setStepHandler(new StepNormalizer(range / 10.0,
                                     new FixedStepHandler() {
                                       private boolean firstCall = true;
                                       public void handleStep(double t,
                                                              double[] y,
                                                              boolean isLast) {
                                         if (firstCall) {
                                           checkValue(t, pb.getInitialTime());
                                           firstCall = false;
                                         }
                                         if (isLast) {
                                           setLastSeen(true);
                                           checkValue(t, pb.getFinalTime());
                                         }
                                       }
                                     }));
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);
  assertTrue(lastSeen);
}
 
Example #28
Source File: DormandPrince853IntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handleStep(StepInterpolator interpolator,
                       boolean isLast)
throws DerivativeException {
  double prev = interpolator.getPreviousTime();
  double curr = interpolator.getCurrentTime();
  interpolator.setInterpolatedTime(0.5*(prev + curr));
}
 
Example #29
Source File: GillIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testUnstableDerivative()
throws DerivativeException, IntegratorException {
  final StepProblem stepProblem = new StepProblem(0.0, 1.0, 2.0);
  FirstOrderIntegrator integ = new GillIntegrator(0.3);
  integ.addSwitchingFunction(stepProblem, 1.0, 1.0e-12, 1000);
  double[] y = { Double.NaN };
  integ.integrate(stepProblem, 0.0, new double[] { 0.0 }, 10.0, y);
  assertEquals(8.0, y[0], 1.0e-12);
}
 
Example #30
Source File: GraggBulirschStoerIntegratorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testUnstableDerivative()
  throws DerivativeException, IntegratorException {
  final StepProblem stepProblem = new StepProblem(0.0, 1.0, 2.0);
  FirstOrderIntegrator integ =
    new GraggBulirschStoerIntegrator(0.1, 10, 1.0e-12, 0.0);
  integ.addSwitchingFunction(stepProblem, 1.0, 1.0e-12, 1000);
  double[] y = { Double.NaN };
  integ.integrate(stepProblem, 0.0, new double[] { 0.0 }, 10.0, y);
  assertEquals(8.0, y[0], 1.0e-12);
}