removed MathUserException from ODE package

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1165792 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2011-09-06 19:17:52 +00:00
parent e751cc22b6
commit 1de3d116a9
40 changed files with 91 additions and 216 deletions

View File

@ -95,7 +95,6 @@ public enum LocalizedFormats implements Localizable {
ENDPOINTS_NOT_AN_INTERVAL("endpoints do not specify an interval: [{0}, {1}]"), ENDPOINTS_NOT_AN_INTERVAL("endpoints do not specify an interval: [{0}, {1}]"),
EQUAL_VERTICES_IN_SIMPLEX("equal vertices {0} and {1} in simplex configuration"), EQUAL_VERTICES_IN_SIMPLEX("equal vertices {0} and {1} in simplex configuration"),
EULER_ANGLES_SINGULARITY("Euler angles singularity"), EULER_ANGLES_SINGULARITY("Euler angles singularity"),
EVALUATION_FAILED("evaluation failed for argument = {0}"),
EVALUATION("evaluation"), /* keep */ EVALUATION("evaluation"), /* keep */
EXPANSION_FACTOR_SMALLER_THAN_ONE("expansion factor smaller than one ({0})"), EXPANSION_FACTOR_SMALLER_THAN_ONE("expansion factor smaller than one ({0})"),
FACTORIAL_NEGATIVE_PARAMETER("must have n >= 0 for n!, got n = {0}"), FACTORIAL_NEGATIVE_PARAMETER("must have n >= 0 for n!, got n = {0}"),

View File

@ -17,12 +17,12 @@
package org.apache.commons.math.ode; package org.apache.commons.math.ode;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepHandler;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
@ -117,14 +117,12 @@ public class ContinuousOutputModel
/** Append another model at the end of the instance. /** Append another model at the end of the instance.
* @param model model to add at the end of the instance * @param model model to add at the end of the instance
* @exception MathUserException if user code called from step interpolator * @exception MathIllegalArgumentException if the model to append is not
* finalization triggers one
* @exception IllegalArgumentException if the model to append is not
* compatible with the instance (dimension of the state vector, * compatible with the instance (dimension of the state vector,
* propagation direction, hole between the dates) * propagation direction, hole between the dates)
*/ */
public void append(final ContinuousOutputModel model) public void append(final ContinuousOutputModel model)
throws MathUserException { throws MathIllegalArgumentException {
if (model.steps.size() == 0) { if (model.steps.size() == 0) {
return; return;
@ -136,14 +134,12 @@ public class ContinuousOutputModel
} else { } else {
if (getInterpolatedState().length != model.getInterpolatedState().length) { if (getInterpolatedState().length != model.getInterpolatedState().length) {
throw MathRuntimeException.createIllegalArgumentException( throw new DimensionMismatchException(model.getInterpolatedState().length,
LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, getInterpolatedState().length);
getInterpolatedState().length, model.getInterpolatedState().length);
} }
if (forward ^ model.forward) { if (forward ^ model.forward) {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(LocalizedFormats.PROPAGATION_DIRECTION_MISMATCH);
LocalizedFormats.PROPAGATION_DIRECTION_MISMATCH);
} }
final StepInterpolator lastInterpolator = steps.get(index); final StepInterpolator lastInterpolator = steps.get(index);
@ -152,8 +148,8 @@ public class ContinuousOutputModel
final double step = current - previous; final double step = current - previous;
final double gap = model.getInitialTime() - current; final double gap = model.getInitialTime() - current;
if (FastMath.abs(gap) > 1.0e-3 * FastMath.abs(step)) { if (FastMath.abs(gap) > 1.0e-3 * FastMath.abs(step)) {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(LocalizedFormats.HOLE_BETWEEN_MODELS_TIME_RANGES,
LocalizedFormats.HOLE_BETWEEN_MODELS_TIME_RANGES, FastMath.abs(gap)); FastMath.abs(gap));
} }
} }
@ -184,11 +180,8 @@ public class ContinuousOutputModel
* the instance for later use. * the instance for later use.
* @param interpolator interpolator for the last accepted step. * @param interpolator interpolator for the last accepted step.
* @param isLast true if the step is the last one * @param isLast true if the step is the last one
* @exception MathUserException if user code called from step interpolator
* finalization triggers one
*/ */
public void handleStep(final StepInterpolator interpolator, final boolean isLast) public void handleStep(final StepInterpolator interpolator, final boolean isLast) {
throws MathUserException {
if (steps.size() == 0) { if (steps.size() == 0) {
initialTime = interpolator.getPreviousTime(); initialTime = interpolator.getPreviousTime();
@ -333,10 +326,8 @@ public class ContinuousOutputModel
/** /**
* Get the state vector of the interpolated point. * Get the state vector of the interpolated point.
* @return state vector at time {@link #getInterpolatedTime} * @return state vector at time {@link #getInterpolatedTime}
* @exception MathUserException if user code called from step interpolator
* finalization triggers one
*/ */
public double[] getInterpolatedState() throws MathUserException { public double[] getInterpolatedState() {
return steps.get(index).getInterpolatedState(); return steps.get(index).getInterpolatedState();
} }

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode; package org.apache.commons.math.ode;
import org.apache.commons.math.exception.MathUserException;
/** This class converts second order differential equations to first /** This class converts second order differential equations to first
* order ones. * order ones.
@ -97,11 +96,8 @@ public class FirstOrderConverter implements FirstOrderDifferentialEquations {
* @param t current value of the independent <I>time</I> variable * @param t current value of the independent <I>time</I> variable
* @param y array containing the current value of the state vector * @param y array containing the current value of the state vector
* @param yDot placeholder array where to put the time derivative of the state vector * @param yDot placeholder array where to put the time derivative of the state vector
* @throws MathUserException this exception is propagated to the caller if the
* underlying user function triggers one
*/ */
public void computeDerivatives(final double t, final double[] y, final double[] yDot) public void computeDerivatives(final double t, final double[] y, final double[] yDot) {
throws MathUserException {
// split the state vector in two // split the state vector in two
System.arraycopy(y, 0, z, 0, dimension); System.arraycopy(y, 0, z, 0, dimension);

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode; package org.apache.commons.math.ode;
import org.apache.commons.math.exception.MathUserException;
/** This interface represents a first order differential equations set. /** This interface represents a first order differential equations set.
@ -58,10 +57,7 @@ public interface FirstOrderDifferentialEquations {
* @param t current value of the independent <I>time</I> variable * @param t current value of the independent <I>time</I> variable
* @param y array containing the current value of the state vector * @param y array containing the current value of the state vector
* @param yDot placeholder array where to put the time derivative of the state vector * @param yDot placeholder array where to put the time derivative of the state vector
* @throws MathUserException this user-defined exception should be used if an error is
* is triggered by user code
*/ */
void computeDerivatives(double t, double[] y, double[] yDot) void computeDerivatives(double t, double[] y, double[] yDot);
throws MathUserException;
} }

View File

@ -19,7 +19,6 @@ package org.apache.commons.math.ode;
import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.MathIllegalStateException; import org.apache.commons.math.exception.MathIllegalStateException;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.linear.Array2DRowRealMatrix; import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.ode.nonstiff.AdaptiveStepsizeIntegrator; import org.apache.commons.math.ode.nonstiff.AdaptiveStepsizeIntegrator;
@ -417,8 +416,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void computeDerivatives(double t, double[] y, double[] dot) public void computeDerivatives(double t, double[] y, double[] dot) {
throws MathUserException {
MultistepIntegrator.this.computeDerivatives(t, y, dot); MultistepIntegrator.this.computeDerivatives(t, y, dot);
} }

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode; package org.apache.commons.math.ode;
import org.apache.commons.math.exception.MathUserException;
/** This interface represents a second order differential equations set. /** This interface represents a second order differential equations set.
@ -60,10 +59,7 @@ public interface SecondOrderDifferentialEquations {
* of the state vector * of the state vector
* @param yDDot placeholder array where to put the second time derivative * @param yDDot placeholder array where to put the second time derivative
* of the state vector * of the state vector
* @throws MathUserException this user-defined exception should be used if an error is
* is triggered by user code
*/ */
void computeSecondDerivatives(double t, double[] y, double[] yDot, double[] yDDot) void computeSecondDerivatives(double t, double[] y, double[] yDot, double[] yDDot);
throws MathUserException;
} }

View File

@ -259,14 +259,11 @@ public abstract class AdaptiveStepsizeIntegrator
* @param y1 work array for a state vector * @param y1 work array for a state vector
* @param yDot1 work array for the first time derivative of y1 * @param yDot1 work array for the first time derivative of y1
* @return first integration step * @return first integration step
* @exception MathUserException this exception is propagated to
* the caller if the underlying user function triggers one
*/ */
public double initializeStep(final FirstOrderDifferentialEquations equations, public double initializeStep(final FirstOrderDifferentialEquations equations,
final boolean forward, final int order, final double[] scale, final boolean forward, final int order, final double[] scale,
final double t0, final double[] y0, final double[] yDot0, final double t0, final double[] y0, final double[] yDot0,
final double[] y1, final double[] yDot1) final double[] y1, final double[] yDot1) {
throws MathUserException {
if (initialStep > 0) { if (initialStep > 0) {
// use the user provided value // use the user provided value

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
/** /**
@ -82,8 +81,7 @@ class ClassicalRungeKuttaStepInterpolator
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void computeInterpolatedStateAndDerivatives(final double theta, protected void computeInterpolatedStateAndDerivatives(final double theta,
final double oneMinusThetaH) final double oneMinusThetaH) {
throws MathUserException {
final double fourTheta = 4 * theta; final double fourTheta = 4 * theta;
final double oneMinusTheta = 1 - theta; final double oneMinusTheta = 1 - theta;

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.AbstractIntegrator; import org.apache.commons.math.ode.AbstractIntegrator;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
@ -165,8 +164,7 @@ class DormandPrince54StepInterpolator
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void computeInterpolatedStateAndDerivatives(final double theta, protected void computeInterpolatedStateAndDerivatives(final double theta,
final double oneMinusThetaH) final double oneMinusThetaH) {
throws MathUserException {
if (! vectorsInitialized) { if (! vectorsInitialized) {

View File

@ -21,7 +21,6 @@ import java.io.IOException;
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.AbstractIntegrator; import org.apache.commons.math.ode.AbstractIntegrator;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
@ -311,8 +310,7 @@ class DormandPrince853StepInterpolator
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void computeInterpolatedStateAndDerivatives(final double theta, protected void computeInterpolatedStateAndDerivatives(final double theta,
final double oneMinusThetaH) final double oneMinusThetaH) {
throws MathUserException {
if (! vectorsInitialized) { if (! vectorsInitialized) {
@ -385,8 +383,7 @@ class DormandPrince853StepInterpolator
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void doFinalize() protected void doFinalize() {
throws MathUserException {
if (currentState == null) { if (currentState == null) {
// we are finalizing an uninitialized instance // we are finalizing an uninitialized instance
@ -436,7 +433,7 @@ class DormandPrince853StepInterpolator
try { try {
// save the local attributes // save the local attributes
finalizeStep(); finalizeStep();
} catch (MathUserException e) { } catch (Exception e) {
IOException ioe = new IOException(e.getLocalizedMessage()); IOException ioe = new IOException(e.getLocalizedMessage());
ioe.initCause(e); ioe.initCause(e);
throw ioe; throw ioe;

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
/** /**
@ -78,8 +77,7 @@ class EulerStepInterpolator
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void computeInterpolatedStateAndDerivatives(final double theta, protected void computeInterpolatedStateAndDerivatives(final double theta,
final double oneMinusThetaH) final double oneMinusThetaH) {
throws MathUserException {
for (int i = 0; i < interpolatedState.length; ++i) { for (int i = 0; i < interpolatedState.length; ++i) {
interpolatedState[i] = currentState[i] - oneMinusThetaH * yDotK[0][i]; interpolatedState[i] = currentState[i] - oneMinusThetaH * yDotK[0][i];

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
@ -90,8 +89,7 @@ class GillStepInterpolator
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void computeInterpolatedStateAndDerivatives(final double theta, protected void computeInterpolatedStateAndDerivatives(final double theta,
final double oneMinusThetaH) final double oneMinusThetaH) {
throws MathUserException {
final double twoTheta = 2 * theta; final double twoTheta = 2 * theta;
final double fourTheta = 4 * theta; final double fourTheta = 4 * theta;

View File

@ -20,7 +20,6 @@ package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.analysis.solvers.UnivariateRealSolver; import org.apache.commons.math.analysis.solvers.UnivariateRealSolver;
import org.apache.commons.math.exception.MathIllegalArgumentException; import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.MathIllegalStateException; import org.apache.commons.math.exception.MathIllegalStateException;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.events.EventHandler; import org.apache.commons.math.ode.events.EventHandler;
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator; import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
@ -451,14 +450,11 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator {
* @param yTmp placeholder for one state vector * @param yTmp placeholder for one state vector
* @return true if computation was done properly, * @return true if computation was done properly,
* false if stability check failed before end of computation * false if stability check failed before end of computation
* @throws MathUserException this exception is propagated to the caller if the
* underlying user function triggers one
*/ */
private boolean tryStep(final double t0, final double[] y0, final double step, final int k, private boolean tryStep(final double t0, final double[] y0, final double step, final int k,
final double[] scale, final double[][] f, final double[] scale, final double[][] f,
final double[] yMiddle, final double[] yEnd, final double[] yMiddle, final double[] yEnd,
final double[] yTmp) final double[] yTmp) {
throws MathUserException {
final int n = sequence[k]; final int n = sequence[k];
final double subStep = step / n; final double subStep = step / n;

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
/** /**
@ -70,8 +69,7 @@ class HighamHall54StepInterpolator
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void computeInterpolatedStateAndDerivatives(final double theta, protected void computeInterpolatedStateAndDerivatives(final double theta,
final double oneMinusThetaH) final double oneMinusThetaH) {
throws MathUserException {
final double theta2 = theta * theta; final double theta2 = theta * theta;

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
/** /**
@ -80,8 +79,7 @@ class MidpointStepInterpolator
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void computeInterpolatedStateAndDerivatives(final double theta, protected void computeInterpolatedStateAndDerivatives(final double theta,
final double oneMinusThetaH) final double oneMinusThetaH) {
throws MathUserException {
final double coeff1 = oneMinusThetaH * theta; final double coeff1 = oneMinusThetaH * theta;
final double coeff2 = oneMinusThetaH * (1.0 + theta); final double coeff2 = oneMinusThetaH * (1.0 + theta);

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
/** /**
@ -85,8 +84,7 @@ class ThreeEighthesStepInterpolator
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void computeInterpolatedStateAndDerivatives(final double theta, protected void computeInterpolatedStateAndDerivatives(final double theta,
final double oneMinusThetaH) final double oneMinusThetaH) {
throws MathUserException {
final double fourTheta2 = 4 * theta * theta; final double fourTheta2 = 4 * theta * theta;
final double s = oneMinusThetaH / 8.0; final double s = oneMinusThetaH / 8.0;

View File

@ -21,8 +21,6 @@ import java.io.IOException;
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import org.apache.commons.math.exception.MathUserException;
/** This abstract class represents an interpolator over the last step /** This abstract class represents an interpolator over the last step
* during an ODE integration. * during an ODE integration.
* *
@ -197,7 +195,7 @@ public abstract class AbstractStepInterpolator
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public StepInterpolator copy() throws MathUserException { public StepInterpolator copy() {
// finalize the step before performing copy // finalize the step before performing copy
finalizeStep(); finalizeStep();
@ -326,15 +324,12 @@ public abstract class AbstractStepInterpolator
* (theta is zero at the previous time step and one at the current time step) * (theta is zero at the previous time step and one at the current time step)
* @param oneMinusThetaH time gap between the interpolated time and * @param oneMinusThetaH time gap between the interpolated time and
* the current time * the current time
* @throws MathUserException this exception is propagated to the caller if the
* underlying user function triggers one
*/ */
protected abstract void computeInterpolatedStateAndDerivatives(double theta, protected abstract void computeInterpolatedStateAndDerivatives(double theta,
double oneMinusThetaH) double oneMinusThetaH);
throws MathUserException;
/** {@inheritDoc} */ /** {@inheritDoc} */
public double[] getInterpolatedState() throws MathUserException { public double[] getInterpolatedState() {
// lazy evaluation of the state // lazy evaluation of the state
if (dirtyState) { if (dirtyState) {
@ -349,7 +344,7 @@ public abstract class AbstractStepInterpolator
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public double[] getInterpolatedDerivatives() throws MathUserException { public double[] getInterpolatedDerivatives() {
// lazy evaluation of the state // lazy evaluation of the state
if (dirtyState) { if (dirtyState) {
@ -401,11 +396,8 @@ public abstract class AbstractStepInterpolator
* Therefore, subclasses are not allowed not reimplement it, they * Therefore, subclasses are not allowed not reimplement it, they
* should rather reimplement <code>doFinalize</code>.</p> * should rather reimplement <code>doFinalize</code>.</p>
* @throws MathUserException this exception is propagated to the
* caller if the underlying user function triggers one
*/ */
public final void finalizeStep() public final void finalizeStep() {
throws MathUserException {
if (! finalized) { if (! finalized) {
doFinalize(); doFinalize();
finalized = true; finalized = true;
@ -415,11 +407,8 @@ public abstract class AbstractStepInterpolator
/** /**
* Really finalize the step. * Really finalize the step.
* The default implementation of this method does nothing. * The default implementation of this method does nothing.
* @throws MathUserException this exception is propagated to the
* caller if the underlying user function triggers one
*/ */
protected void doFinalize() protected void doFinalize() {
throws MathUserException {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -465,7 +454,7 @@ public abstract class AbstractStepInterpolator
// finalize the step (and don't bother saving the now true flag) // finalize the step (and don't bother saving the now true flag)
try { try {
finalizeStep(); finalizeStep();
} catch (MathUserException e) { } catch (Exception e) {
IOException ioe = new IOException(e.getLocalizedMessage()); IOException ioe = new IOException(e.getLocalizedMessage());
ioe.initCause(e); ioe.initCause(e);
throw ioe; throw ioe;

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.sampling; package org.apache.commons.math.ode.sampling;
import org.apache.commons.math.exception.MathUserException;
/** /**
* This interface represents a handler that should be called after * This interface represents a handler that should be called after
@ -55,8 +54,7 @@ public interface FixedStepHandler {
* provide at the end of the integration a complete array of all * provide at the end of the integration a complete array of all
* steps), it should build a local copy store this copy. * steps), it should build a local copy store this copy.
* @param isLast true if the step is the last one * @param isLast true if the step is the last one
* @throws MathUserException if some error condition is encountered
*/ */
void handleStep(double t, double[] y, double[] yDot, boolean isLast) throws MathUserException; void handleStep(double t, double[] y, double[] yDot, boolean isLast);
} }

View File

@ -22,7 +22,6 @@ import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import java.util.Arrays; import java.util.Arrays;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.linear.Array2DRowRealMatrix; import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
@ -171,11 +170,8 @@ public class NordsieckStepInterpolator extends AbstractStepInterpolator {
* to be preserved across several calls.</p> * to be preserved across several calls.</p>
* @return state vector at time {@link #getInterpolatedTime} * @return state vector at time {@link #getInterpolatedTime}
* @see #getInterpolatedDerivatives() * @see #getInterpolatedDerivatives()
* @throws MathUserException if this call induces an automatic
* step finalization that throws one
*/ */
public double[] getInterpolatedStateVariation() public double[] getInterpolatedStateVariation() {
throws MathUserException {
// compute and ignore interpolated state // compute and ignore interpolated state
// to make sure state variation is computed as a side effect // to make sure state variation is computed as a side effect
getInterpolatedState(); getInterpolatedState();

View File

@ -19,8 +19,6 @@ package org.apache.commons.math.ode.sampling;
import java.io.Externalizable; import java.io.Externalizable;
import org.apache.commons.math.exception.MathUserException;
/** This interface represents an interpolator over the last step /** This interface represents an interpolator over the last step
* during an ODE integration. * during an ODE integration.
* *
@ -89,10 +87,8 @@ public interface StepInterpolator extends Externalizable {
* to be preserved across several calls.</p> * to be preserved across several calls.</p>
* @return state vector at time {@link #getInterpolatedTime} * @return state vector at time {@link #getInterpolatedTime}
* @see #getInterpolatedDerivatives() * @see #getInterpolatedDerivatives()
* @exception MathUserException if user code called from step interpolator
* finalization triggers one
*/ */
double[] getInterpolatedState() throws MathUserException; double[] getInterpolatedState();
/** /**
* Get the derivatives of the state vector of the interpolated point. * Get the derivatives of the state vector of the interpolated point.
@ -101,11 +97,9 @@ public interface StepInterpolator extends Externalizable {
* to be preserved across several calls.</p> * to be preserved across several calls.</p>
* @return derivatives of the state vector at time {@link #getInterpolatedTime} * @return derivatives of the state vector at time {@link #getInterpolatedTime}
* @see #getInterpolatedState() * @see #getInterpolatedState()
* @exception MathUserException if user code called from step interpolator
* finalization triggers one
* @since 2.0 * @since 2.0
*/ */
double[] getInterpolatedDerivatives() throws MathUserException; double[] getInterpolatedDerivatives();
/** Check if the natural integration direction is forward. /** Check if the natural integration direction is forward.
* <p>This method provides the integration direction as specified by * <p>This method provides the integration direction as specified by
@ -123,10 +117,8 @@ public interface StepInterpolator extends Externalizable {
* original one. Both can be used with different settings for * original one. Both can be used with different settings for
* interpolated time without any side effect.</p> * interpolated time without any side effect.</p>
* @return a deep copy of the instance, which can be used independently. * @return a deep copy of the instance, which can be used independently.
* @exception MathUserException if user code called from step interpolator
* finalization triggers one
* @see #setInterpolatedTime(double) * @see #setInterpolatedTime(double)
*/ */
StepInterpolator copy() throws MathUserException; StepInterpolator copy();
} }

View File

@ -17,10 +17,6 @@
package org.apache.commons.math.ode.sampling; package org.apache.commons.math.ode.sampling;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.sampling.FixedStepHandler;
import org.apache.commons.math.ode.sampling.StepHandler;
import org.apache.commons.math.ode.sampling.StepInterpolator;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.util.MathUtils;
@ -194,11 +190,8 @@ public class StepNormalizer implements StepHandler {
* should build a local copy using the clone method and store this * should build a local copy using the clone method and store this
* copy. * copy.
* @param isLast true if the step is the last one * @param isLast true if the step is the last one
* @throws MathUserException this exception is propagated to the
* caller if the underlying user function triggers one
*/ */
public void handleStep(final StepInterpolator interpolator, public void handleStep(final StepInterpolator interpolator, final boolean isLast) {
final boolean isLast) throws MathUserException {
// The first time, update the last state with the start information. // The first time, update the last state with the start information.
if (lastState == null) { if (lastState == null) {
firstTime = interpolator.getPreviousTime(); firstTime = interpolator.getPreviousTime();
@ -270,10 +263,8 @@ public class StepNormalizer implements StepHandler {
/** /**
* Invokes the underlying step handler for the current normalized step. * Invokes the underlying step handler for the current normalized step.
* @param isLast true if the step is the last one * @param isLast true if the step is the last one
* @throws MathUserException this exception is propagated to the
* caller if the underlying user function triggers one
*/ */
private void doNormalizedStep(boolean isLast) throws MathUserException { private void doNormalizedStep(boolean isLast) {
if (!bounds.firstIncluded() && firstTime == lastTime) { if (!bounds.firstIncluded() && firstTime == lastTime) {
return; return;
} }

View File

@ -66,7 +66,6 @@ EMPTY_STRING_FOR_IMAGINARY_CHARACTER = cha\u00eene vide pour le caract\u00e8 ima
ENDPOINTS_NOT_AN_INTERVAL = les bornes ne d\u00e9finissent pas un intervalle : [{0}, {1}] ENDPOINTS_NOT_AN_INTERVAL = les bornes ne d\u00e9finissent pas un intervalle : [{0}, {1}]
EQUAL_VERTICES_IN_SIMPLEX = sommets {0} et {1} \u00e9gaux dans la configuration du simplex EQUAL_VERTICES_IN_SIMPLEX = sommets {0} et {1} \u00e9gaux dans la configuration du simplex
EULER_ANGLES_SINGULARITY = singularit\u00e9 d''angles d''Euler EULER_ANGLES_SINGULARITY = singularit\u00e9 d''angles d''Euler
EVALUATION_FAILED = erreur d''\u00e9valuation pour l''argument {0}
EVALUATION = \u00e9valuation EVALUATION = \u00e9valuation
EXPANSION_FACTOR_SMALLER_THAN_ONE = facteur d''extension inf\u00e9rieur \u00e0 un ({0}) EXPANSION_FACTOR_SMALLER_THAN_ONE = facteur d''extension inf\u00e9rieur \u00e0 un ({0})
FACTORIAL_NEGATIVE_PARAMETER = n doit \u00eatre positif pour le calcul de n!, or n = {0} FACTORIAL_NEGATIVE_PARAMETER = n doit \u00eatre positif pour le calcul de n!, or n = {0}

View File

@ -19,7 +19,6 @@ package org.apache.commons.math.ode;
import java.util.Random; import java.util.Random;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.nonstiff.DormandPrince54Integrator; import org.apache.commons.math.ode.nonstiff.DormandPrince54Integrator;
import org.apache.commons.math.ode.nonstiff.DormandPrince853Integrator; import org.apache.commons.math.ode.nonstiff.DormandPrince853Integrator;
import org.apache.commons.math.ode.sampling.DummyStepInterpolator; import org.apache.commons.math.ode.sampling.DummyStepInterpolator;
@ -84,8 +83,7 @@ public class ContinuousOutputModelTest {
// theoretical solution: y[0] = cos(t), y[1] = sin(t) // theoretical solution: y[0] = cos(t), y[1] = sin(t)
FirstOrderDifferentialEquations problem = FirstOrderDifferentialEquations problem =
new FirstOrderDifferentialEquations() { new FirstOrderDifferentialEquations() {
public void computeDerivatives(double t, double[] y, double[] dot) public void computeDerivatives(double t, double[] y, double[] dot) {
throws MathUserException {
dot[0] = -y[1]; dot[0] = -y[1];
dot[1] = y[0]; dot[1] = y[0];
} }
@ -130,8 +128,7 @@ public class ContinuousOutputModelTest {
} }
@Test @Test
public void testErrorConditions() public void testErrorConditions() {
throws MathUserException {
ContinuousOutputModel cm = new ContinuousOutputModel(); ContinuousOutputModel cm = new ContinuousOutputModel();
cm.handleStep(buildInterpolator(0, new double[] { 0.0, 1.0, -2.0 }, 1), true); cm.handleStep(buildInterpolator(0, new double[] { 0.0, 1.0, -2.0 }, 1), true);
@ -151,8 +148,7 @@ public class ContinuousOutputModelTest {
} }
private boolean checkAppendError(ContinuousOutputModel cm, private boolean checkAppendError(ContinuousOutputModel cm,
double t0, double[] y0, double t1) double t0, double[] y0, double t1) {
throws MathUserException {
try { try {
ContinuousOutputModel otherCm = new ContinuousOutputModel(); ContinuousOutputModel otherCm = new ContinuousOutputModel();
otherCm.handleStep(buildInterpolator(t0, y0, t1), true); otherCm.handleStep(buildInterpolator(t0, y0, t1), true);

View File

@ -17,8 +17,6 @@
package org.apache.commons.math.ode; package org.apache.commons.math.ode;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.ODEIntegrator;
import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepHandler;
import org.apache.commons.math.ode.sampling.StepInterpolator; import org.apache.commons.math.ode.sampling.StepInterpolator;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
@ -67,9 +65,7 @@ public class TestProblemHandler
expectedStepStart = Double.NaN; expectedStepStart = Double.NaN;
} }
public void handleStep(StepInterpolator interpolator, public void handleStep(StepInterpolator interpolator, boolean isLast) {
boolean isLast)
throws MathUserException {
double start = integrator.getCurrentStepStart(); double start = integrator.getCurrentStepStart();
if (FastMath.abs((start - problem.getInitialTime()) / integrator.getCurrentSignedStepsize()) > 0.001) { if (FastMath.abs((start - problem.getInitialTime()) / integrator.getCurrentSignedStepsize()) > 0.001) {

View File

@ -21,7 +21,6 @@ import java.util.List;
import org.apache.commons.math.analysis.solvers.BaseSecantSolver; import org.apache.commons.math.analysis.solvers.BaseSecantSolver;
import org.apache.commons.math.analysis.solvers.PegasusSolver; import org.apache.commons.math.analysis.solvers.PegasusSolver;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.nonstiff.DormandPrince853Integrator; import org.apache.commons.math.ode.nonstiff.DormandPrince853Integrator;
@ -114,7 +113,7 @@ public class OverlappingEventsTest implements FirstOrderDifferentialEquations {
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void computeDerivatives(double t, double[] y, double[] yDot) throws MathUserException { public void computeDerivatives(double t, double[] y, double[] yDot) {
yDot[0] = 1.0; yDot[0] = 1.0;
yDot[1] = 2.0; yDot[1] = 2.0;
} }

View File

@ -19,7 +19,6 @@ package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.NumberIsTooSmallException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.FirstOrderIntegrator;
@ -248,8 +247,7 @@ public class ClassicalRungeKuttaIntegratorTest {
public void reset() { public void reset() {
maxError = 0; maxError = 0;
} }
public void handleStep(StepInterpolator interpolator, public void handleStep(StepInterpolator interpolator, boolean isLast) {
boolean isLast) throws MathUserException {
double[] interpolatedY = interpolator.getInterpolatedState (); double[] interpolatedY = interpolator.getInterpolatedState ();
double[] theoreticalY = pb.computeTheoreticalState(interpolator.getCurrentTime()); double[] theoreticalY = pb.computeTheoreticalState(interpolator.getCurrentTime());

View File

@ -18,7 +18,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.NumberIsTooSmallException;
import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.TestProblem1; import org.apache.commons.math.ode.TestProblem1;
@ -272,9 +271,7 @@ public class DormandPrince54IntegratorTest {
nbSteps = 0; nbSteps = 0;
maxError = 0; maxError = 0;
} }
public void handleStep(StepInterpolator interpolator, public void handleStep(StepInterpolator interpolator, boolean isLast) {
boolean isLast)
throws MathUserException {
++nbSteps; ++nbSteps;
for (int a = 1; a < 10; ++a) { for (int a = 1; a < 10; ++a) {

View File

@ -25,7 +25,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.Random; import java.util.Random;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.TestProblem3; import org.apache.commons.math.ode.TestProblem3;
import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepHandler;
@ -113,8 +112,7 @@ public class DormandPrince54StepInterpolatorTest {
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
integ.addStepHandler(new StepHandler() { integ.addStepHandler(new StepHandler() {
public void handleStep(StepInterpolator interpolator, boolean isLast) public void handleStep(StepInterpolator interpolator, boolean isLast) {
throws MathUserException {
StepInterpolator cloned = interpolator.copy(); StepInterpolator cloned = interpolator.copy();
double tA = cloned.getPreviousTime(); double tA = cloned.getPreviousTime();
double tB = cloned.getCurrentTime(); double tB = cloned.getCurrentTime();

View File

@ -18,7 +18,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.NumberIsTooSmallException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.FirstOrderIntegrator;
@ -296,9 +295,7 @@ public class DormandPrince853IntegratorTest {
nbSteps = 0; nbSteps = 0;
maxError = 0; maxError = 0;
} }
public void handleStep(StepInterpolator interpolator, public void handleStep(StepInterpolator interpolator, boolean isLast) {
boolean isLast)
throws MathUserException {
++nbSteps; ++nbSteps;
for (int a = 1; a < 10; ++a) { for (int a = 1; a < 10; ++a) {

View File

@ -25,7 +25,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.Random; import java.util.Random;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.TestProblem3; import org.apache.commons.math.ode.TestProblem3;
import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepHandler;
@ -113,8 +112,7 @@ public class DormandPrince853StepInterpolatorTest {
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
integ.addStepHandler(new StepHandler() { integ.addStepHandler(new StepHandler() {
public void handleStep(StepInterpolator interpolator, boolean isLast) public void handleStep(StepInterpolator interpolator, boolean isLast) {
throws MathUserException {
StepInterpolator cloned = interpolator.copy(); StepInterpolator cloned = interpolator.copy();
double tA = cloned.getPreviousTime(); double tA = cloned.getPreviousTime();
double tB = cloned.getCurrentTime(); double tB = cloned.getCurrentTime();

View File

@ -25,7 +25,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.Random; import java.util.Random;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.TestProblem1; import org.apache.commons.math.ode.TestProblem1;
import org.apache.commons.math.ode.TestProblem3; import org.apache.commons.math.ode.TestProblem3;
@ -56,8 +55,7 @@ public class EulerStepInterpolatorTest {
} }
@Test @Test
public void interpolationAtBounds() public void interpolationAtBounds() {
throws MathUserException {
double t0 = 0; double t0 = 0;
double[] y0 = {0.0, 1.0, -2.0}; double[] y0 = {0.0, 1.0, -2.0};
@ -93,8 +91,7 @@ public class EulerStepInterpolatorTest {
} }
@Test @Test
public void interpolationInside() public void interpolationInside() {
throws MathUserException {
double[] y = { 1.0, 3.0, -4.0 }; double[] y = { 1.0, 3.0, -4.0 };
double[][] yDot = { { 1.0, 2.0, -2.0 } }; double[][] yDot = { { 1.0, 2.0, -2.0 } };

View File

@ -19,7 +19,6 @@ package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.TestProblem1; import org.apache.commons.math.ode.TestProblem1;
@ -183,8 +182,7 @@ public class GillIntegratorTest {
public void reset() { public void reset() {
maxError = 0; maxError = 0;
} }
public void handleStep(StepInterpolator interpolator, public void handleStep(StepInterpolator interpolator, boolean isLast) {
boolean isLast) throws MathUserException {
double[] interpolatedY = interpolator.getInterpolatedState(); double[] interpolatedY = interpolator.getInterpolatedState();
double[] theoreticalY = pb.computeTheoreticalState(interpolator.getCurrentTime()); double[] theoreticalY = pb.computeTheoreticalState(interpolator.getCurrentTime());

View File

@ -18,7 +18,6 @@
package org.apache.commons.math.ode.nonstiff; package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.NumberIsTooSmallException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.FirstOrderIntegrator;
@ -275,7 +274,7 @@ public class GraggBulirschStoerIntegratorTest {
public void reset() {} public void reset() {}
public void handleStep(StepInterpolator interpolator, boolean isLast) throws MathUserException { public void handleStep(StepInterpolator interpolator, boolean isLast) {
double t = interpolator.getCurrentTime(); double t = interpolator.getCurrentTime();
interpolator.setInterpolatedTime(t); interpolator.setInterpolatedTime(t);
double[] y = interpolator.getInterpolatedState(); double[] y = interpolator.getInterpolatedState();
@ -308,9 +307,7 @@ public class GraggBulirschStoerIntegratorTest {
nbSteps = 0; nbSteps = 0;
maxError = 0; maxError = 0;
} }
public void handleStep(StepInterpolator interpolator, public void handleStep(StepInterpolator interpolator, boolean isLast) {
boolean isLast)
throws MathUserException {
++nbSteps; ++nbSteps;
for (int a = 1; a < 100; ++a) { for (int a = 1; a < 100; ++a) {

View File

@ -25,7 +25,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.Random; import java.util.Random;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.TestProblem3; import org.apache.commons.math.ode.TestProblem3;
import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepHandler;
@ -115,8 +114,7 @@ public class GraggBulirschStoerStepInterpolatorTest {
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
integ.addStepHandler(new StepHandler() { integ.addStepHandler(new StepHandler() {
public void handleStep(StepInterpolator interpolator, boolean isLast) public void handleStep(StepInterpolator interpolator, boolean isLast) {
throws MathUserException {
StepInterpolator cloned = interpolator.copy(); StepInterpolator cloned = interpolator.copy();
double tA = cloned.getPreviousTime(); double tA = cloned.getPreviousTime();
double tB = cloned.getCurrentTime(); double tB = cloned.getCurrentTime();

View File

@ -19,7 +19,7 @@ package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.exception.MathIllegalNumberException;
import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.NumberIsTooSmallException;
import org.apache.commons.math.exception.TooManyEvaluationsException; import org.apache.commons.math.exception.TooManyEvaluationsException;
import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.util.LocalizedFormats;
@ -43,12 +43,11 @@ public class HighamHall54IntegratorTest {
new HighamHall54Integrator(0.0, 1.0, 1.0e-10, 1.0e-10); new HighamHall54Integrator(0.0, 1.0, 1.0e-10, 1.0e-10);
FirstOrderDifferentialEquations equations = FirstOrderDifferentialEquations equations =
new FirstOrderDifferentialEquations() { new FirstOrderDifferentialEquations() {
public void computeDerivatives(double t, double[] y, double[] dot) public void computeDerivatives(double t, double[] y, double[] dot) {
throws MathUserException {
if (t < -0.5) { if (t < -0.5) {
throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, "oops"); throw new LocalException(t);
} else { } else {
throw new MathUserException(new RuntimeException("oops")); throw new RuntimeException("oops");
} }
} }
public int getDimension() { public int getDimension() {
@ -59,14 +58,14 @@ public class HighamHall54IntegratorTest {
try { try {
integrator.integrate(equations, -1.0, new double[1], 0.0, new double[1]); integrator.integrate(equations, -1.0, new double[1], 0.0, new double[1]);
Assert.fail("an exception should have been thrown"); Assert.fail("an exception should have been thrown");
} catch(MathUserException de) { } catch(LocalException de) {
// expected behavior // expected behavior
} }
try { try {
integrator.integrate(equations, 0.0, new double[1], 1.0, new double[1]); integrator.integrate(equations, 0.0, new double[1], 1.0, new double[1]);
Assert.fail("an exception should have been thrown"); Assert.fail("an exception should have been thrown");
} catch(MathUserException de) { } catch(RuntimeException de) {
// expected behavior // expected behavior
} }
@ -187,8 +186,8 @@ public class HighamHall54IntegratorTest {
} }
@Test @Test(expected=LocalException.class)
public void testEventsErrors() throws Exception { public void testEventsErrors() {
final TestProblem1 pb = new TestProblem1(); final TestProblem1 pb = new TestProblem1();
double minStep = 0; double minStep = 0;
@ -210,7 +209,7 @@ public class HighamHall54IntegratorTest {
double middle = (pb.getInitialTime() + pb.getFinalTime()) / 2; double middle = (pb.getInitialTime() + pb.getFinalTime()) / 2;
double offset = t - middle; double offset = t - middle;
if (offset > 0) { if (offset > 0) {
throw new MathUserException(LocalizedFormats.EVALUATION_FAILED, t); throw new LocalException(t);
} }
return offset; return offset;
} }
@ -218,17 +217,19 @@ public class HighamHall54IntegratorTest {
} }
}, Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000); }, Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000);
try { integ.integrate(pb,
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]);
pb.getFinalTime(), new double[pb.getDimension()]);
Assert.fail("an exception should have been thrown");
} catch (MathUserException ie) {
// expected behavior
}
} }
private static class LocalException extends MathIllegalNumberException {
private static final long serialVersionUID = 3041292643919807960L;
protected LocalException(Number wrong) {
super(LocalizedFormats.SIMPLE_MESSAGE, wrong);
}
}
@Test @Test
public void testEventsNoConvergence() throws Exception { public void testEventsNoConvergence() throws Exception {

View File

@ -25,7 +25,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.Random; import java.util.Random;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.TestProblem3; import org.apache.commons.math.ode.TestProblem3;
import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepHandler;
@ -113,8 +112,7 @@ public class HighamHall54StepInterpolatorTest {
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
integ.addStepHandler(new StepHandler() { integ.addStepHandler(new StepHandler() {
public void handleStep(StepInterpolator interpolator, boolean isLast) public void handleStep(StepInterpolator interpolator, boolean isLast) {
throws MathUserException {
StepInterpolator cloned = interpolator.copy(); StepInterpolator cloned = interpolator.copy();
double tA = cloned.getPreviousTime(); double tA = cloned.getPreviousTime();
double tB = cloned.getCurrentTime(); double tB = cloned.getCurrentTime();

View File

@ -19,7 +19,6 @@ package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.TestProblem1; import org.apache.commons.math.ode.TestProblem1;
@ -175,8 +174,7 @@ public class ThreeEighthesIntegratorTest {
maxError = 0; maxError = 0;
} }
public void handleStep(StepInterpolator interpolator, public void handleStep(StepInterpolator interpolator, boolean isLast) {
boolean isLast) throws MathUserException {
double[] interpolatedY = interpolator.getInterpolatedState(); double[] interpolatedY = interpolator.getInterpolatedState();
double[] theoreticalY = pb.computeTheoreticalState(interpolator.getCurrentTime()); double[] theoreticalY = pb.computeTheoreticalState(interpolator.getCurrentTime());

View File

@ -18,16 +18,14 @@
package org.apache.commons.math.ode.sampling; package org.apache.commons.math.ode.sampling;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ObjectOutputStream; import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.exception.MathIllegalStateException;
import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
import org.apache.commons.math.ode.sampling.DummyStepInterpolator;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -35,7 +33,7 @@ import org.junit.Test;
public class DummyStepInterpolatorTest { public class DummyStepInterpolatorTest {
@Test @Test
public void testNoReset() throws MathUserException { public void testNoReset() {
double[] y = { 0.0, 1.0, -2.0 }; double[] y = { 0.0, 1.0, -2.0 };
DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true); DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true);
@ -51,8 +49,7 @@ public class DummyStepInterpolatorTest {
} }
@Test @Test
public void testFixedState() public void testFixedState() {
throws MathUserException {
double[] y = { 1.0, 3.0, -4.0 }; double[] y = { 1.0, 3.0, -4.0 };
DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true); DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true);
@ -76,7 +73,7 @@ public class DummyStepInterpolatorTest {
@Test @Test
public void testSerialization() public void testSerialization()
throws MathUserException, IOException, ClassNotFoundException { throws IOException, ClassNotFoundException {
double[] y = { 0.0, 1.0, -2.0 }; double[] y = { 0.0, 1.0, -2.0 };
DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true); DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true);
@ -132,8 +129,8 @@ public class DummyStepInterpolatorTest {
super(y, new double[y.length], forward); super(y, new double[y.length], forward);
} }
@Override @Override
protected void doFinalize() throws MathUserException { protected void doFinalize() {
throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, ""); throw new MathIllegalStateException(LocalizedFormats.SIMPLE_MESSAGE, "");
} }
} }
} }

View File

@ -17,7 +17,6 @@
package org.apache.commons.math.ode.sampling; package org.apache.commons.math.ode.sampling;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.TestProblemAbstract; import org.apache.commons.math.ode.TestProblemAbstract;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
@ -30,8 +29,7 @@ public class StepInterpolatorTestUtils {
final double threshold) { final double threshold) {
integrator.addStepHandler(new StepHandler() { integrator.addStepHandler(new StepHandler() {
public void handleStep(StepInterpolator interpolator, boolean isLast) public void handleStep(StepInterpolator interpolator, boolean isLast) {
throws MathUserException {
final double h = 0.001 * (interpolator.getCurrentTime() - interpolator.getPreviousTime()); final double h = 0.001 * (interpolator.getCurrentTime() - interpolator.getPreviousTime());
final double t = interpolator.getCurrentTime() - 300 * h; final double t = interpolator.getCurrentTime() - 300 * h;

View File

@ -5,7 +5,6 @@ import static org.junit.Assert.assertArrayEquals;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.FirstOrderIntegrator; import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.nonstiff.GraggBulirschStoerIntegrator; import org.apache.commons.math.ode.nonstiff.GraggBulirschStoerIntegrator;
@ -208,14 +207,12 @@ public abstract class StepNormalizerOutputTestBase
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void computeDerivatives(double t, double[] y, double[] yDot) public void computeDerivatives(double t, double[] y, double[] yDot) {
throws MathUserException {
yDot[0] = y[0]; yDot[0] = y[0];
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void handleStep(double t, double[] y, double[] yDot, boolean isLast) public void handleStep(double t, double[] y, double[] yDot, boolean isLast) {
throws MathUserException {
output.add(t); output.add(t);
} }
} }