org.apache.commons.math3.ode.sampling.StepHandler Java Examples
The following examples show how to use
org.apache.commons.math3.ode.sampling.StepHandler.
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: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 6 votes |
/** Prepare the start of an integration. * @param t0 start value of the independent <i>time</i> variable * @param y0 array containing the start value of the state vector * @param t target time for the integration */ protected void initIntegration(final double t0, final double[] y0, final double t) { evaluations.resetCount(); for (final EventState state : eventsStates) { state.setExpandable(expandable); state.getEventHandler().init(t0, y0, t); } for (StepHandler handler : stepHandlers) { handler.init(t0, y0, t); } setStateInitialized(false); }
Example #2
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 6 votes |
/** Prepare the start of an integration. * @param t0 start value of the independent <i>time</i> variable * @param y0 array containing the start value of the state vector * @param t target time for the integration */ protected void initIntegration(final double t0, final double[] y0, final double t) { evaluations.resetCount(); for (final EventState state : eventsStates) { state.setExpandable(expandable); state.getEventHandler().init(t0, y0, t); } for (StepHandler handler : stepHandlers) { handler.init(t0, y0, t); } setStateInitialized(false); }
Example #3
Source File: Solver.java From gama with GNU General Public License v3.0 | 6 votes |
Solver(final double step, final FirstOrderIntegrator integrator, final IMap<String, IList<Double>> integrated_val) { this.step = step; this.integrator = integrator; if (integrated_val != null) { integrator.addStepHandler(new StepHandler() { @Override public void init(final double t0, final double[] y0, final double t) {} @Override public void handleStep(final StepInterpolator interpolator, final boolean isLast) { final double time = interpolator.getCurrentTime(); final double[] y = interpolator.getInterpolatedState(); count++; storeValues(time, y, integrated_val); } }); } }
Example #4
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 6 votes |
/** Prepare the start of an integration. * @param t0 start value of the independent <i>time</i> variable * @param y0 array containing the start value of the state vector * @param t target time for the integration */ protected void initIntegration(final double t0, final double[] y0, final double t) { evaluations.resetCount(); for (final EventState state : eventsStates) { state.setExpandable(expandable); state.getEventHandler().init(t0, y0, t); } for (StepHandler handler : stepHandlers) { handler.init(t0, y0, t); } setStateInitialized(false); }
Example #5
Source File: JGenProg2017_0030_t.java From coming with MIT License | 5 votes |
/** Build an instance. * @param name name of the method */ public AbstractIntegrator(final String name) { this.name = name; stepHandlers = new ArrayList<StepHandler>(); stepStart = Double.NaN; stepSize = Double.NaN; eventsStates = new ArrayList<EventState>(); statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); evaluations.resetCount(); }
Example #6
Source File: JGenProg2017_0030_s.java From coming with MIT License | 5 votes |
/** Build an instance. * @param name name of the method */ public AbstractIntegrator(final String name) { this.name = name; stepHandlers = new ArrayList<StepHandler>(); stepStart = Double.NaN; stepSize = Double.NaN; eventsStates = new ArrayList<EventState>(); statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); evaluations.resetCount(); }
Example #7
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 5 votes |
/** Build an instance. * @param name name of the method */ public AbstractIntegrator(final String name) { this.name = name; stepHandlers = new ArrayList<StepHandler>(); stepStart = Double.NaN; stepSize = Double.NaN; eventsStates = new ArrayList<EventState>(); statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); evaluations.resetCount(); }
Example #8
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 5 votes |
/** Build an instance. * @param name name of the method */ public AbstractIntegrator(final String name) { this.name = name; stepHandlers = new ArrayList<StepHandler>(); stepStart = Double.NaN; stepSize = Double.NaN; eventsStates = new ArrayList<EventState>(); statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); evaluations.resetCount(); }
Example #9
Source File: EulerStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void serialization() throws IOException, ClassNotFoundException { TestProblem1 pb = new TestProblem1(); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; EulerIntegrator integ = new EulerIntegrator(step); 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); } 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; } } Assert.assertTrue(maxError < 0.001); }
Example #10
Source File: Math_7_AbstractIntegrator_s.java From coming with MIT License | 5 votes |
/** Build an instance. * @param name name of the method */ public AbstractIntegrator(final String name) { this.name = name; stepHandlers = new ArrayList<StepHandler>(); stepStart = Double.NaN; stepSize = Double.NaN; eventsStates = new ArrayList<EventState>(); statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); evaluations.resetCount(); }
Example #11
Source File: EulerStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void serialization() throws IOException, ClassNotFoundException { TestProblem1 pb = new TestProblem1(); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; EulerIntegrator integ = new EulerIntegrator(step); 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); } 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; } } Assert.assertTrue(maxError < 0.001); }
Example #12
Source File: Math_7_AbstractIntegrator_t.java From coming with MIT License | 5 votes |
/** Build an instance. * @param name name of the method */ public AbstractIntegrator(final String name) { this.name = name; stepHandlers = new ArrayList<StepHandler>(); stepStart = Double.NaN; stepSize = Double.NaN; eventsStates = new ArrayList<EventState>(); statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); evaluations.resetCount(); }
Example #13
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 5 votes |
/** Build an instance. * @param name name of the method */ public AbstractIntegrator(final String name) { this.name = name; stepHandlers = new ArrayList<StepHandler>(); stepStart = Double.NaN; stepSize = Double.NaN; eventsStates = new ArrayList<EventState>(); statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); evaluations.resetCount(); }
Example #14
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 5 votes |
/** Build an instance. * @param name name of the method */ public AbstractIntegrator(final String name) { this.name = name; stepHandlers = new ArrayList<StepHandler>(); stepStart = Double.NaN; stepSize = Double.NaN; eventsStates = new ArrayList<EventState>(); statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); evaluations.resetCount(); }
Example #15
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 5 votes |
/** Build an instance. * @param name name of the method */ public AbstractIntegrator(final String name) { this.name = name; stepHandlers = new ArrayList<StepHandler>(); stepStart = Double.NaN; stepSize = Double.NaN; eventsStates = new ArrayList<EventState>(); statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); evaluations.resetCount(); }
Example #16
Source File: DormandPrince853StepInterpolatorTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void serialization() throws IOException, ClassNotFoundException { TestProblem3 pb = new TestProblem3(0.9); double minStep = 0; double maxStep = pb.getFinalTime() - pb.getInitialTime(); double scalAbsoluteTolerance = 1.0e-8; double scalRelativeTolerance = scalAbsoluteTolerance; DormandPrince853Integrator integ = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); 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); } Assert.assertTrue(bos.size () > 90000); Assert.assertTrue(bos.size () < 100000); 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; } } Assert.assertTrue(maxError < 2.4e-10); }
Example #17
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public Collection<StepHandler> getStepHandlers() { return Collections.unmodifiableCollection(stepHandlers); }
Example #18
Source File: DormandPrince853StepInterpolatorTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void serialization() throws IOException, ClassNotFoundException, DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem3 pb = new TestProblem3(0.9); double minStep = 0; double maxStep = pb.getFinalTime() - pb.getInitialTime(); double scalAbsoluteTolerance = 1.0e-8; double scalRelativeTolerance = scalAbsoluteTolerance; DormandPrince853Integrator integ = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); 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); } Assert.assertTrue(bos.size () > 90000); Assert.assertTrue(bos.size () < 100000); 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; } } Assert.assertTrue(maxError < 2.4e-10); }
Example #19
Source File: ClassicalRungeKuttaStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void serialization() throws IOException, ClassNotFoundException { TestProblem3 pb = new TestProblem3(0.9); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003; ClassicalRungeKuttaIntegrator integ = new ClassicalRungeKuttaIntegrator(step); 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); } Assert.assertTrue(bos.size () > 880000); Assert.assertTrue(bos.size () < 900000); 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; } } Assert.assertTrue(maxError > 0.005); }
Example #20
Source File: ThreeEighthesStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void serialization() throws IOException, ClassNotFoundException, DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem3 pb = new TestProblem3(0.9); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003; ThreeEighthesIntegrator integ = new ThreeEighthesIntegrator(step); 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); } Assert.assertTrue(bos.size () > 880000); Assert.assertTrue(bos.size () < 900000); 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; } } Assert.assertTrue(maxError > 0.005); }
Example #21
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 4 votes |
/** Prepare the start of an integration. * @param t0 start value of the independent <i>time</i> variable * @param y0 array containing the start value of the state vector * @param t target time for the integration */ protected void initIntegration(final double t0, final double[] y0, final double t) { evaluations.resetCount(); for (final EventState state : eventsStates) { state.getEventHandler().init(t0, y0, t); } for (StepHandler handler : stepHandlers) { handler.init(t0, y0, t); } setStateInitialized(false); }
Example #22
Source File: HighamHall54StepInterpolatorTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void serialization() throws IOException, ClassNotFoundException, DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem3 pb = new TestProblem3(0.9); double minStep = 0; double maxStep = pb.getFinalTime() - pb.getInitialTime(); double scalAbsoluteTolerance = 1.0e-8; double scalRelativeTolerance = scalAbsoluteTolerance; HighamHall54Integrator integ = new HighamHall54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); 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); } Assert.assertTrue(bos.size () > 185000); Assert.assertTrue(bos.size () < 195000); 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; } } Assert.assertTrue(maxError < 1.6e-10); }
Example #23
Source File: MidpointStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void serialization() throws IOException, ClassNotFoundException { TestProblem1 pb = new TestProblem1(); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; MidpointIntegrator integ = new MidpointIntegrator(step); 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); } Assert.assertTrue(bos.size () > 135000); Assert.assertTrue(bos.size () < 145000); 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; } } Assert.assertTrue(maxError < 1.0e-6); }
Example #24
Source File: GillStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void serialization() throws IOException, ClassNotFoundException, DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem3 pb = new TestProblem3(0.9); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003; GillIntegrator integ = new GillIntegrator(step); 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); } Assert.assertTrue(bos.size () > 880000); Assert.assertTrue(bos.size () < 900000); 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; } } Assert.assertTrue(maxError < 0.003); }
Example #25
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public Collection<StepHandler> getStepHandlers() { return Collections.unmodifiableCollection(stepHandlers); }
Example #26
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public void addStepHandler(final StepHandler handler) { stepHandlers.add(handler); }
Example #27
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public void addStepHandler(final StepHandler handler) { stepHandlers.add(handler); }
Example #28
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public void addStepHandler(final StepHandler handler) { stepHandlers.add(handler); }
Example #29
Source File: EulerStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void serialization() throws IOException, ClassNotFoundException, DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem1 pb = new TestProblem1(); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; EulerIntegrator integ = new EulerIntegrator(step); 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); } 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; } } Assert.assertTrue(maxError < 0.001); }
Example #30
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public Collection<StepHandler> getStepHandlers() { return Collections.unmodifiableCollection(stepHandlers); }