@Test
public void serialization()
throws DerivativeException, IntegratorException,
IOException, ClassNotFoundException {
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;
GraggBulirschStoerIntegrator integ =
new GraggBulirschStoerIntegrator(minStep, maxStep,
absTolerance, relTolerance);
integ.addStepHandler(new ContinuousOutputModel());
integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
for (StepHandler handler : integ.getStepHandlers()) {
oos.writeObject(handler);
}
assertTrue(bos.size () > 33000);
assertTrue(bos.size () < 34000);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
ContinuousOutputModel cm = (ContinuousOutputModel) ois.readObject();
Random random = new Random(347588535632l);
double maxError = 0.0;
for (int i = 0; i < 1000; ++i) {
double r = random.nextDouble();
double time = r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
cm.setInterpolatedTime(time);
double[] interpolatedY = cm.getInterpolatedState ();
double[] theoreticalY = pb.computeTheoreticalState(time);
double dx = interpolatedY[0] - theoreticalY[0];
double dy = interpolatedY[1] - theoreticalY[1];
double error = dx * dx + dy * dy;
if (error > maxError) {
maxError = error;