You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2011/02/10 22:07:53 UTC
svn commit: r1069568 - in
/commons/proper/math/trunk/src/main/java/org/apache/commons/math: ode/
ode/events/ ode/nonstiff/ ode/sampling/ util/
Author: luc
Date: Thu Feb 10 21:07:53 2011
New Revision: 1069568
URL: http://svn.apache.org/viewvc?rev=1069568&view=rev
Log:
fixed checkstyle and findbugs warnings
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java?rev=1069568&r1=1069567&r2=1069568&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java Thu Feb 10 21:07:53 2011
@@ -20,6 +20,7 @@ package org.apache.commons.math.ode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -62,7 +63,7 @@ public abstract class AbstractIntegrator
private Collection<EventState> eventsStates;
/** Initialization indicator of events states. */
- protected boolean statesInitialized;
+ private boolean statesInitialized;
/** Name of the method. */
private final String name;
@@ -208,6 +209,16 @@ public abstract class AbstractIntegrator
equations.computeDerivatives(t, y, yDot);
}
+ /** Set the stateInitialized flag.
+ * <p>This method must be called by integrators with the value
+ * {@code false} before they start integration, so a proper lazy
+ * initialization is done automatically on the first step.</p>
+ * @param stateInitialized new value for the flag
+ */
+ protected void setStateInitialized(final boolean stateInitialized) {
+ this.statesInitialized = stateInitialized;
+ }
+
/** Accept a step, triggering events and step handlers.
* @param interpolator step interpolator
* @param y state vector at step end time, must be reset if an event
@@ -234,8 +245,16 @@ public abstract class AbstractIntegrator
statesInitialized = true;
}
+ SortedSet<EventState> occuringEvents = new TreeSet<EventState>(new Comparator<EventState>() {
+
+ /** {@inheritDoc} */
+ public int compare(EventState es0, EventState es1) {
+ return Double.compare(es0.getEventTime(), es1.getEventTime());
+ }
+
+ });
+
// find all events that occur during the step
- SortedSet<EventState> occuringEvents = new TreeSet<EventState>();
for (final EventState state : eventsStates) {
if (state.evaluateStep(interpolator)) {
// the event occurs during the current step
@@ -248,7 +267,8 @@ public abstract class AbstractIntegrator
// restrict the interpolator to the first part of the step, up to the event
final double eventT = state.getEventTime();
- interpolator.setSoftBounds(previousT, eventT);
+ interpolator.setSoftPreviousTime(previousT);
+ interpolator.setSoftCurrentTime(eventT);
// trigger the event
interpolator.setInterpolatedTime(eventT);
@@ -278,7 +298,8 @@ public abstract class AbstractIntegrator
// prepare handling of the remaining part of the step
previousT = eventT;
- interpolator.setSoftBounds(eventT, currentT);
+ interpolator.setSoftPreviousTime(eventT);
+ interpolator.setSoftCurrentTime(currentT);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java?rev=1069568&r1=1069567&r2=1069568&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java Thu Feb 10 21:07:53 2011
@@ -38,7 +38,7 @@ import org.apache.commons.math.util.Fast
* @version $Revision$ $Date$
* @since 1.2
*/
-public class EventState implements Comparable<EventState> {
+public class EventState {
/** Event handler. */
private final EventHandler handler;
@@ -300,13 +300,12 @@ public class EventState implements Compa
}
- /** Get the occurrence time of the event triggered in the current
- * step.
+ /** Get the occurrence time of the event triggered in the current step.
* @return occurrence time of the event triggered in the current
- * step.
+ * step or positive infinity if no events are triggered
*/
public double getEventTime() {
- return pendingEventTime;
+ return pendingEvent ? pendingEventTime : Double.POSITIVE_INFINITY;
}
/** Acknowledge the fact the step has been accepted by the integrator.
@@ -369,21 +368,4 @@ public class EventState implements Compa
}
- /** Compare the instance with another event state.
- * <p>
- * Event state ordering is based on occurrence time within the last
- * evaluated step. If no event occurs during the step, a time arbitrarily
- * set to positive infinity is used.
- * </p>
- * @param state other event state to compare the instance to
- * @return a negative integer, zero, or a positive integer as the event
- * occurs before, simultaneous, or after the specified event of the
- * specified state.
- */
- public int compareTo(final EventState state) {
- final double instanceTime = pendingEvent ? pendingEventTime : Double.POSITIVE_INFINITY;
- final double otherTime = state.pendingEvent ? state.pendingEventTime : Double.POSITIVE_INFINITY;
- return Double.compare(instanceTime, otherTime);
- }
-
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java?rev=1069568&r1=1069567&r2=1069568&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java Thu Feb 10 21:07:53 2011
@@ -210,7 +210,7 @@ public class AdamsBashforthIntegrator ex
for (StepHandler handler : stepHandlers) {
handler.reset();
}
- statesInitialized = false;
+ setStateInitialized(false);
// compute the initial Nordsieck vector using the configured starter integrator
start(t0, y, t);
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java?rev=1069568&r1=1069567&r2=1069568&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java Thu Feb 10 21:07:53 2011
@@ -230,7 +230,7 @@ public class AdamsMoultonIntegrator exte
for (StepHandler handler : stepHandlers) {
handler.reset();
}
- statesInitialized = false;
+ setStateInitialized(false);
// compute the initial Nordsieck vector using the configured starter integrator
start(t0, y, t);
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java?rev=1069568&r1=1069567&r2=1069568&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java Thu Feb 10 21:07:53 2011
@@ -226,7 +226,7 @@ public abstract class EmbeddedRungeKutta
for (StepHandler handler : stepHandlers) {
handler.reset();
}
- statesInitialized = false;
+ setStateInitialized(false);
// main integration loop
isLastStep = false;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java?rev=1069568&r1=1069567&r2=1069568&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java Thu Feb 10 21:07:53 2011
@@ -633,7 +633,7 @@ public class GraggBulirschStoerIntegrato
for (StepHandler handler : stepHandlers) {
handler.reset();
}
- statesInitialized = false;
+ setStateInitialized(false);
costPerTimeUnit[0] = 0;
isLastStep = false;
do {
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java?rev=1069568&r1=1069567&r2=1069568&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java Thu Feb 10 21:07:53 2011
@@ -131,7 +131,7 @@ public abstract class RungeKuttaIntegrat
for (StepHandler handler : stepHandlers) {
handler.reset();
}
- statesInitialized = false;
+ setStateInitialized(false);
// main integration loop
isLastStep = false;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java?rev=1069568&r1=1069567&r2=1069568&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java Thu Feb 10 21:07:53 2011
@@ -43,18 +43,6 @@ import org.apache.commons.math.exception
public abstract class AbstractStepInterpolator
implements StepInterpolator {
- /** global previous time */
- private double globalPreviousTime;
-
- /** global current time */
- private double globalCurrentTime;
-
- /** soft previous time */
- private double softPreviousTime;
-
- /** soft current time */
- private double softCurrentTime;
-
/** current time step */
protected double h;
@@ -70,6 +58,18 @@ public abstract class AbstractStepInterp
/** interpolated derivatives */
protected double[] interpolatedDerivatives;
+ /** global previous time */
+ private double globalPreviousTime;
+
+ /** global current time */
+ private double globalCurrentTime;
+
+ /** soft previous time */
+ private double softPreviousTime;
+
+ /** soft current time */
+ private double softCurrentTime;
+
/** indicate if the step has been finalized or not. */
private boolean finalized;
@@ -245,14 +245,27 @@ public abstract class AbstractStepInterp
* <p>
* This method can be used to restrict a step and make it appear
* as if the original step was smaller. Calling this method
- * <em>only</em> changes the value returned by {@link #getPreviousTime()}
- * and {@link #getCurrentTime()}, it does not change any
+ * <em>only</em> changes the value returned by {@link #getPreviousTime()},
+ * it does not change any other property
* </p>
* @param softPreviousTime start of the restricted step
- * @param softCurrentTime end of the restricted step
+ * @since 2.2
*/
- public void setSoftBounds(final double softPreviousTime, final double softCurrentTime) {
+ public void setSoftPreviousTime(final double softPreviousTime) {
this.softPreviousTime = softPreviousTime;
+ }
+
+ /** Restrict step range to a limited part of the global step.
+ * <p>
+ * This method can be used to restrict a step and make it appear
+ * as if the original step was smaller. Calling this method
+ * <em>only</em> changes the value returned by {@link #getCurrentTime()},
+ * it does not change any other property
+ * </p>
+ * @param softCurrentTime end of the restricted step
+ * @since 2.2
+ */
+ public void setSoftCurrentTime(final double softCurrentTime) {
this.softCurrentTime = softCurrentTime;
}
@@ -275,7 +288,7 @@ public abstract class AbstractStepInterp
/**
* Get the previous soft grid point time.
* @return previous soft grid point time
- * @see #setSoftBounds(double, double)
+ * @see #setSoftPreviousTime(double)
*/
public double getPreviousTime() {
return softPreviousTime;
@@ -284,7 +297,7 @@ public abstract class AbstractStepInterp
/**
* Get the current soft grid point time.
* @return current soft grid point time
- * @see #setSoftBounds(double, double)
+ * @see #setSoftCurrentTime(double)
*/
public double getCurrentTime() {
return softCurrentTime;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java?rev=1069568&r1=1069567&r2=1069568&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java Thu Feb 10 21:07:53 2011
@@ -1359,7 +1359,7 @@ public class FastMath {
double xb = ab;
/* Need a more accurate epsilon, so adjust the division. */
- double numer = (bits & 0x3ffffffffffL);
+ double numer = bits & 0x3ffffffffffL;
double denom = TWO_POWER_52 + (bits & 0x000ffc0000000000L);
aa = numer - xa*denom - xb * denom;
xb += aa / denom;