Skip to content

Commit

Permalink
Merge pull request #377 from Serrof/issue-376
Browse files Browse the repository at this point in the history
fixed visibility issue in interpolators for non-stiff integrators
  • Loading branch information
Serrof authored Feb 8, 2025
2 parents 6142c30 + a9018b5 commit b45c756
Show file tree
Hide file tree
Showing 84 changed files with 491 additions and 421 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.hipparchus.ode.events.FieldODEStepEndHandler;
import org.hipparchus.ode.events.FieldStepEndEventState;
import org.hipparchus.ode.sampling.AbstractFieldODEStateInterpolator;
import org.hipparchus.ode.sampling.FieldODEStateInterpolator;
import org.hipparchus.ode.sampling.FieldODEStepHandler;
import org.hipparchus.util.FastMath;
import org.hipparchus.util.Incrementor;
Expand Down Expand Up @@ -221,13 +222,13 @@ protected FieldODEStateAndDerivative<T> initIntegration(final FieldExpandableODE
eqn.getMapper().mapStateAndDerivative(t0, y0, y0Dot);

// initialize detector based event states (both and step end based)
detectorBasedEventsStates.stream().forEach(s -> {
detectorBasedEventsStates.forEach(s -> {
s.init(s0WithDerivatives, t);
s.getEventDetector().getHandler().init(s0WithDerivatives, t, s.getEventDetector());
});

// initialize step end based event states
stepEndEventsStates.stream().forEach(s -> {
stepEndEventsStates.forEach(s -> {
s.init(s0WithDerivatives, t);
s.getHandler().init(s0WithDerivatives, t);
});
Expand Down Expand Up @@ -310,12 +311,12 @@ protected FieldODEStateAndDerivative<T> acceptStep(final AbstractFieldODEStateIn

FieldODEStateAndDerivative<T> previousState = interpolator.getGlobalPreviousState();
final FieldODEStateAndDerivative<T> currentState = interpolator.getGlobalCurrentState();
AbstractFieldODEStateInterpolator<T> restricted = interpolator;
FieldODEStateInterpolator<T> restricted = interpolator;

// initialize the events states if needed
if (!statesInitialized) {
// initialize event states
detectorBasedEventsStates.stream().forEach(s -> s.reinitializeBegin(interpolator));
detectorBasedEventsStates.forEach(s -> s.reinitializeBegin(interpolator));
statesInitialized = true;
}

Expand All @@ -339,7 +340,7 @@ public int compare(FieldEventState<T> es0, FieldEventState<T> es1) {

// Evaluate all event detectors and end steps for events
occurringEvents.clear();
final AbstractFieldODEStateInterpolator<T> finalRestricted = restricted;
final FieldODEStateInterpolator<T> finalRestricted = restricted;
Stream.concat(detectorBasedEventsStates.stream(), stepEndEventsStates.stream()).
forEach(s -> { if (s.evaluateStep(finalRestricted)) {
// the event occurs during the current step
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.hipparchus.ode.events.ODEStepEndHandler;
import org.hipparchus.ode.events.StepEndEventState;
import org.hipparchus.ode.sampling.AbstractODEStateInterpolator;
import org.hipparchus.ode.sampling.ODEStateInterpolator;
import org.hipparchus.ode.sampling.ODEStepHandler;
import org.hipparchus.util.FastMath;
import org.hipparchus.util.Incrementor;
Expand Down Expand Up @@ -81,7 +82,7 @@ public abstract class AbstractIntegrator implements ODEIntegrator {
private Incrementor evaluations;

/** Differential equations to integrate. */
private transient ExpandableODE equations;
private ExpandableODE equations;

/** Build an instance.
* @param name name of the method
Expand Down Expand Up @@ -208,13 +209,13 @@ protected ODEStateAndDerivative initIntegration(final ExpandableODE eqn,
eqn.getMapper().mapStateAndDerivative(t0, y0, y0Dot);

// initialize detector based event states (both and step end based)
detectorBasedEventsStates.stream().forEach(s -> {
detectorBasedEventsStates.forEach(s -> {
s.init(s0WithDerivatives, t);
s.getEventDetector().getHandler().init(s0WithDerivatives, t, s.getEventDetector());
});

// initialize step end based event states
stepEndEventsStates.stream().forEach(s -> {
stepEndEventsStates.forEach(s -> {
s.init(s0WithDerivatives, t);
s.getHandler().init(s0WithDerivatives, t);
});
Expand Down Expand Up @@ -292,18 +293,18 @@ protected ODEStateAndDerivative acceptStep(final AbstractODEStateInterpolator in

ODEStateAndDerivative previousState = interpolator.getGlobalPreviousState();
final ODEStateAndDerivative currentState = interpolator.getGlobalCurrentState();
AbstractODEStateInterpolator restricted = interpolator;
ODEStateInterpolator restricted = interpolator;


// initialize the events states if needed
if (!statesInitialized) {
// initialize event states
detectorBasedEventsStates.stream().forEach(s -> s.reinitializeBegin(interpolator));
detectorBasedEventsStates.forEach(s -> s.reinitializeBegin(interpolator));
statesInitialized = true;
}

// set end of step
stepEndEventsStates.stream().forEach(s -> s.setStepEnd(currentState.getTime()));
stepEndEventsStates.forEach(s -> s.setStepEnd(currentState.getTime()));

// search for next events that may occur during the step
final int orderingSign = interpolator.isForward() ? +1 : -1;
Expand All @@ -322,7 +323,7 @@ public int compare(final EventState es0, final EventState es1) {

// Evaluate all event detectors and end steps for events
occurringEvents.clear();
final AbstractODEStateInterpolator finalRestricted = restricted;
final ODEStateInterpolator finalRestricted = restricted;
Stream.concat(detectorBasedEventsStates.stream(), stepEndEventsStates.stream()).
forEach(s -> { if (s.evaluateStep(finalRestricted)) {
// the event occurs during the current step
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hipparchus.linear.FieldMatrix;
import org.hipparchus.ode.FieldEquationsMapper;
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.AdamsFieldStateInterpolator;
import org.hipparchus.util.FastMath;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hipparchus.linear.RealMatrix;
import org.hipparchus.ode.EquationsMapper;
import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.AdamsStateInterpolator;
import org.hipparchus.util.FastMath;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.ode.LocalizedODEFormats;
import org.hipparchus.ode.MultistepFieldIntegrator;
import org.hipparchus.ode.nonstiff.interpolators.AdamsFieldStateInterpolator;
import org.hipparchus.util.MathArrays;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hipparchus.ode.MultistepIntegrator;
import org.hipparchus.ode.ODEState;
import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.AdamsStateInterpolator;


/** Base class for {@link AdamsBashforthIntegrator Adams-Bashforth} and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.hipparchus.ode.FieldEquationsMapper;
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.ode.LocalizedODEFormats;
import org.hipparchus.ode.nonstiff.interpolators.AdamsFieldStateInterpolator;
import org.hipparchus.util.MathArrays;
import org.hipparchus.util.MathUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hipparchus.ode.EquationsMapper;
import org.hipparchus.ode.LocalizedODEFormats;
import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.AdamsStateInterpolator;
import org.hipparchus.util.FastMath;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hipparchus.Field;
import org.hipparchus.ode.FieldEquationsMapper;
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.ClassicalRungeKuttaFieldStateInterpolator;
import org.hipparchus.util.MathArrays;

/**
Expand Down Expand Up @@ -111,7 +112,7 @@ public T[] getB() {
final FieldODEStateAndDerivative<T> globalPreviousState,
final FieldODEStateAndDerivative<T> globalCurrentState,
final FieldEquationsMapper<T> mapper) {
return new ClassicalRungeKuttaFieldStateInterpolator<T>(getField(), forward, yDotK,
return new ClassicalRungeKuttaFieldStateInterpolator<>(getField(), forward, yDotK,
globalPreviousState, globalCurrentState,
globalPreviousState, globalCurrentState,
mapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.hipparchus.ode.EquationsMapper;
import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.ClassicalRungeKuttaStateInterpolator;

/**
* This class implements the classical fourth order Runge-Kutta
Expand Down Expand Up @@ -85,15 +86,12 @@ public double[] getB() {

/** {@inheritDoc} */
@Override
protected ClassicalRungeKuttaStateInterpolator
createInterpolator(final boolean forward, double[][] yDotK,
final ODEStateAndDerivative globalPreviousState,
final ODEStateAndDerivative globalCurrentState,
final EquationsMapper mapper) {
return new ClassicalRungeKuttaStateInterpolator(forward, yDotK,
globalPreviousState, globalCurrentState,
globalPreviousState, globalCurrentState,
mapper);
protected ClassicalRungeKuttaStateInterpolator createInterpolator(final boolean forward, final double[][] yDotK,
final ODEStateAndDerivative globalPreviousState,
final ODEStateAndDerivative globalCurrentState,
final EquationsMapper mapper) {
return new ClassicalRungeKuttaStateInterpolator(forward, yDotK, globalPreviousState, globalCurrentState,
globalPreviousState, globalCurrentState, mapper);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hipparchus.Field;
import org.hipparchus.ode.FieldEquationsMapper;
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.DormandPrince54FieldStateInterpolator;
import org.hipparchus.util.FastMath;
import org.hipparchus.util.MathArrays;

Expand Down Expand Up @@ -165,7 +166,7 @@ public T[] getB() {
createInterpolator(final boolean forward, T[][] yDotK,
final FieldODEStateAndDerivative<T> globalPreviousState,
final FieldODEStateAndDerivative<T> globalCurrentState, final FieldEquationsMapper<T> mapper) {
return new DormandPrince54FieldStateInterpolator<T>(getField(), forward, yDotK,
return new DormandPrince54FieldStateInterpolator<>(getField(), forward, yDotK,
globalPreviousState, globalCurrentState,
globalPreviousState, globalCurrentState,
mapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.hipparchus.ode.EquationsMapper;
import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.DormandPrince54StateInterpolator;
import org.hipparchus.util.FastMath;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hipparchus.Field;
import org.hipparchus.ode.FieldEquationsMapper;
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.DormandPrince853FieldStateInterpolator;
import org.hipparchus.util.FastMath;
import org.hipparchus.util.MathArrays;

Expand Down Expand Up @@ -318,7 +319,7 @@ public T[] getB() {
createInterpolator(final boolean forward, T[][] yDotK,
final FieldODEStateAndDerivative<T> globalPreviousState,
final FieldODEStateAndDerivative<T> globalCurrentState, final FieldEquationsMapper<T> mapper) {
return new DormandPrince853FieldStateInterpolator<T>(getField(), forward, yDotK,
return new DormandPrince853FieldStateInterpolator<>(getField(), forward, yDotK,
globalPreviousState, globalCurrentState,
globalPreviousState, globalCurrentState,
mapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.hipparchus.ode.EquationsMapper;
import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.DormandPrince853StateInterpolator;
import org.hipparchus.util.FastMath;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.hipparchus.ode.FieldExpandableODE;
import org.hipparchus.ode.FieldODEState;
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.RungeKuttaFieldStateInterpolator;
import org.hipparchus.util.FastMath;
import org.hipparchus.util.MathArrays;
import org.hipparchus.util.MathUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hipparchus.ode.LocalizedODEFormats;
import org.hipparchus.ode.ODEState;
import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.RungeKuttaStateInterpolator;
import org.hipparchus.util.FastMath;

/**
Expand Down Expand Up @@ -163,9 +164,9 @@ protected EmbeddedRungeKuttaIntegrator(final String name, final int fsal,
* @return external weights for the high order method from Butcher array
*/
protected abstract RungeKuttaStateInterpolator createInterpolator(boolean forward, double[][] yDotK,
ODEStateAndDerivative globalPreviousState,
ODEStateAndDerivative globalCurrentState,
EquationsMapper mapper);
ODEStateAndDerivative globalPreviousState,
ODEStateAndDerivative globalCurrentState,
EquationsMapper mapper);
/** Get the order of the method.
* @return order of the method
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hipparchus.Field;
import org.hipparchus.ode.FieldEquationsMapper;
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.EulerFieldStateInterpolator;
import org.hipparchus.util.MathArrays;

/**
Expand Down Expand Up @@ -97,7 +98,7 @@ public T[] getB() {
final FieldODEStateAndDerivative<T> globalPreviousState,
final FieldODEStateAndDerivative<T> globalCurrentState,
final FieldEquationsMapper<T> mapper) {
return new EulerFieldStateInterpolator<T>(getField(), forward, yDotK,
return new EulerFieldStateInterpolator<>(getField(), forward, yDotK,
globalPreviousState, globalCurrentState,
globalPreviousState, globalCurrentState,
mapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.hipparchus.ode.EquationsMapper;
import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.EulerStateInterpolator;

/**
* This class implements a simple Euler integrator for Ordinary
Expand Down Expand Up @@ -80,15 +81,12 @@ public double[] getB() {

/** {@inheritDoc} */
@Override
protected EulerStateInterpolator
createInterpolator(final boolean forward, double[][] yDotK,
final ODEStateAndDerivative globalPreviousState,
final ODEStateAndDerivative globalCurrentState,
final EquationsMapper mapper) {
return new EulerStateInterpolator(forward, yDotK,
globalPreviousState, globalCurrentState,
globalPreviousState, globalCurrentState,
mapper);
protected EulerStateInterpolator createInterpolator(final boolean forward, final double[][] yDotK,
final ODEStateAndDerivative globalPreviousState,
final ODEStateAndDerivative globalCurrentState,
final EquationsMapper mapper) {
return new EulerStateInterpolator(forward, yDotK, globalPreviousState, globalCurrentState,
globalPreviousState, globalCurrentState, mapper);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.hipparchus.ode.FieldExpandableODE;
import org.hipparchus.ode.FieldODEState;
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.RungeKuttaFieldStateInterpolator;
import org.hipparchus.util.MathArrays;

/**
Expand Down Expand Up @@ -137,9 +138,9 @@ public int getNumberOfStages() {
* @return external weights for the high order method from Butcher array
*/
protected abstract RungeKuttaFieldStateInterpolator<T> createInterpolator(boolean forward, T[][] yDotK,
FieldODEStateAndDerivative<T> globalPreviousState,
FieldODEStateAndDerivative<T> globalCurrentState,
FieldEquationsMapper<T> mapper);
FieldODEStateAndDerivative<T> globalPreviousState,
FieldODEStateAndDerivative<T> globalCurrentState,
FieldEquationsMapper<T> mapper);

/** {@inheritDoc} */
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hipparchus.ode.LocalizedODEFormats;
import org.hipparchus.ode.ODEState;
import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.nonstiff.interpolators.RungeKuttaStateInterpolator;
import org.hipparchus.util.FastMath;

/**
Expand Down Expand Up @@ -95,9 +96,9 @@ public double getDefaultStep() {
* @return external weights for the high order method from Butcher array
*/
protected abstract RungeKuttaStateInterpolator createInterpolator(boolean forward, double[][] yDotK,
ODEStateAndDerivative globalPreviousState,
ODEStateAndDerivative globalCurrentState,
EquationsMapper mapper);
ODEStateAndDerivative globalPreviousState,
ODEStateAndDerivative globalCurrentState,
EquationsMapper mapper);

/** {@inheritDoc} */
@Override
Expand Down
Loading

0 comments on commit b45c756

Please sign in to comment.