~ubuntu-branches/ubuntu/quantal/commons-math/quantal

« back to all changes in this revision

Viewing changes to src/main/java/org/apache/commons/math/ode/ContinuousOutputModel.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan, Torsten Werner, Damien Raude-Morvan
  • Date: 2011-03-07 21:14:46 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110307211446-4zea7og4eeyzhpai
Tags: 2.2-1
[ Torsten Werner ]
* Change maintainers into Maintainers.

[ Damien Raude-Morvan ]
* New upstream release (Closes: #617209).
* d/control: Bump Standards-Version to 3.9.1 (no changes needed).
* d/copyright: Refresh years, upgrade to DEP5 r166 and relicence my work
  under Apache-2.0.
* d/ant.properties: Set junit.jar to /usr/share/java/junit4.jar
  to ensure unit tests are launched.
* d/docs: Install upstream RELEASE-NOTES.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import java.io.Serializable;
23
23
 
24
24
import org.apache.commons.math.MathRuntimeException;
 
25
import org.apache.commons.math.ode.DerivativeException;
 
26
import org.apache.commons.math.exception.util.LocalizedFormats;
25
27
import org.apache.commons.math.ode.sampling.StepHandler;
26
28
import org.apache.commons.math.ode.sampling.StepInterpolator;
 
29
import org.apache.commons.math.util.FastMath;
27
30
 
28
31
/**
29
32
 * This class stores all information provided by an ODE integrator
79
82
 *
80
83
 * @see StepHandler
81
84
 * @see StepInterpolator
82
 
 * @version $Revision: 811827 $ $Date: 2009-09-06 11:32:50 -0400 (Sun, 06 Sep 2009) $
 
85
 * @version $Revision: 1073158 $ $Date: 2011-02-21 22:46:52 +0100 (lun. 21 févr. 2011) $
83
86
 * @since 1.2
84
87
 */
85
88
 
114
117
 
115
118
  /** Append another model at the end of the instance.
116
119
   * @param model model to add at the end of the instance
117
 
   * @exception DerivativeException if some step interpolators from
118
 
   * the appended model cannot be copied
 
120
   * @exception DerivativeException if user code called from step interpolator
 
121
   * finalization triggers one
119
122
   * @exception IllegalArgumentException if the model to append is not
120
123
   * compatible with the instance (dimension of the state vector,
121
124
   * propagation direction, hole between the dates)
134
137
 
135
138
      if (getInterpolatedState().length != model.getInterpolatedState().length) {
136
139
          throw MathRuntimeException.createIllegalArgumentException(
137
 
                "dimension mismatch {0} != {1}",
 
140
                LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE,
138
141
                getInterpolatedState().length, model.getInterpolatedState().length);
139
142
      }
140
143
 
141
144
      if (forward ^ model.forward) {
142
145
          throw MathRuntimeException.createIllegalArgumentException(
143
 
                "propagation direction mismatch");
 
146
                LocalizedFormats.PROPAGATION_DIRECTION_MISMATCH);
144
147
      }
145
148
 
146
149
      final StepInterpolator lastInterpolator = steps.get(index);
148
151
      final double previous = lastInterpolator.getPreviousTime();
149
152
      final double step = current - previous;
150
153
      final double gap = model.getInitialTime() - current;
151
 
      if (Math.abs(gap) > 1.0e-3 * Math.abs(step)) {
 
154
      if (FastMath.abs(gap) > 1.0e-3 * FastMath.abs(step)) {
152
155
        throw MathRuntimeException.createIllegalArgumentException(
153
 
              "{0} wide hole between models time ranges", Math.abs(gap));
 
156
              LocalizedFormats.HOLE_BETWEEN_MODELS_TIME_RANGES, FastMath.abs(gap));
154
157
      }
155
158
 
156
159
    }
191
194
   * the instance for later use.
192
195
   * @param interpolator interpolator for the last accepted step.
193
196
   * @param isLast true if the step is the last one
194
 
   * @throws DerivativeException this exception is propagated to the
195
 
   * caller if the underlying user function triggers one
 
197
   * @exception DerivativeException if user code called from step interpolator
 
198
   * finalization triggers one
196
199
   */
197
200
  public void handleStep(final StepInterpolator interpolator, final boolean isLast)
198
201
    throws DerivativeException {
296
299
        final StepInterpolator sMed = steps.get(iMed);
297
300
        final double tMed = 0.5 * (sMed.getPreviousTime() + sMed.getCurrentTime());
298
301
 
299
 
        if ((Math.abs(tMed - tMin) < 1e-6) || (Math.abs(tMax - tMed) < 1e-6)) {
 
302
        if ((FastMath.abs(tMed - tMin) < 1e-6) || (FastMath.abs(tMax - tMed) < 1e-6)) {
300
303
          // too close to the bounds, we estimate using a simple dichotomy
301
304
          index = iMed;
302
305
        } else {
313
316
                                    (dt1 * dt3 * d13) * iMed +
314
317
                                    (dt1 * dt2 * d12) * iMin) /
315
318
                                   (d12 * d23 * d13);
316
 
          index = (int) Math.rint(iLagrange);
 
319
          index = (int) FastMath.rint(iLagrange);
317
320
        }
318
321
 
319
322
        // force the next size reduction to be at least one tenth
320
 
        final int low  = Math.max(iMin + 1, (9 * iMin + iMax) / 10);
321
 
        final int high = Math.min(iMax - 1, (iMin + 9 * iMax) / 10);
 
323
        final int low  = FastMath.max(iMin + 1, (9 * iMin + iMax) / 10);
 
324
        final int high = FastMath.min(iMax - 1, (iMin + 9 * iMax) / 10);
322
325
        if (index < low) {
323
326
          index = low;
324
327
        } else if (index > high) {
340
343
  /**
341
344
   * Get the state vector of the interpolated point.
342
345
   * @return state vector at time {@link #getInterpolatedTime}
343
 
   * @throws DerivativeException if this call induces an automatic
344
 
   * step finalization that throws one
 
346
   * @exception DerivativeException if user code called from step interpolator
 
347
   * finalization triggers one
345
348
   */
346
349
  public double[] getInterpolatedState() throws DerivativeException {
347
350
    return steps.get(index).getInterpolatedState();