Skip to content

Commit c3e5d3a

Browse files
authored
Merge pull request #344 from Serrof/issue-335
add propagation direction in (Field)AdaptableInterval
2 parents 9bad1c2 + 0a18c06 commit c3e5d3a

27 files changed

+240
-59
lines changed

hipparchus-ode/src/changes/changes.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ If the output is not quite correct, check for invisible trailing spaces!
5454
</action>
5555
</release>
5656
<body>
57+
<release version="4.0" date="TBD" description="TBD">
58+
<action dev="serrof" type="add" issue="issues/335">
59+
Add boolean for propagation direction in (Field)AdaptableInterval.
60+
</action>
61+
</release>
5762
<release version="3.1" date="2024-04-05" description="This is a maintenance release. It includes one
5863
bugfixes and adds two features on existing integrators.">
5964
<action dev="serrof" type="add" issue="issues/269">

hipparchus-ode/src/main/java/org/hipparchus/ode/events/AbstractFieldODEDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public BracketedRealFieldUnivariateSolver<E> getSolver() {
114114
* @return a new detector with updated configuration (the instance is not changed)
115115
*/
116116
public T withMaxCheck(final E newMaxCheck) {
117-
return withMaxCheck(s -> newMaxCheck.getReal());
117+
return withMaxCheck((s, isForward) -> newMaxCheck.getReal());
118118
}
119119

120120
/**

hipparchus-ode/src/main/java/org/hipparchus/ode/events/AbstractODEDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public BracketedUnivariateSolver<UnivariateFunction> getSolver() {
112112
* @return a new detector with updated configuration (the instance is not changed)
113113
*/
114114
public T withMaxCheck(final double newMaxCheck) {
115-
return withMaxCheck(s -> newMaxCheck);
115+
return withMaxCheck((s, isForward) -> newMaxCheck);
116116
}
117117

118118
/**

hipparchus-ode/src/main/java/org/hipparchus/ode/events/AdaptableInterval.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
@FunctionalInterface
2929
public interface AdaptableInterval {
3030

31-
/** Get the current value of maximal time interval between events handler checks.
32-
* @param state current state
31+
/**
32+
* Get the current value of maximal time interval between events handler checks.
33+
*
34+
* @param state current state
35+
* @param isForward true if propagation is forward in independent variable, false otherwise
3336
* @return current value of maximal time interval between events handler checks
3437
*/
35-
double currentInterval(ODEStateAndDerivative state);
38+
double currentInterval(ODEStateAndDerivative state, boolean isForward);
3639

3740
}

hipparchus-ode/src/main/java/org/hipparchus/ode/events/DetectorBasedEventState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private ODEStateAndDerivative nextCheck(final ODEStateAndDerivative done, final
263263
// we have to select some intermediate state
264264
// attempting to split the remaining time in an integer number of checks
265265
final double dt = target.getTime() - done.getTime();
266-
final double maxCheck = detector.getMaxCheckInterval().currentInterval(done);
266+
final double maxCheck = detector.getMaxCheckInterval().currentInterval(done, dt >= 0.);
267267
final int n = FastMath.max(1, (int) FastMath.ceil(FastMath.abs(dt) / maxCheck));
268268
return n == 1 ? target : interpolator.getInterpolatedState(done.getTime() + dt / n);
269269
}

hipparchus-ode/src/main/java/org/hipparchus/ode/events/FieldAdaptableInterval.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929
@FunctionalInterface
3030
public interface FieldAdaptableInterval<T extends CalculusFieldElement<T>> {
3131

32-
/** Get the current value of maximal time interval between events handler checks.
33-
* @param state current state
32+
/**
33+
* Get the current value of maximal time interval between events handler checks.
34+
*
35+
* @param state current state
36+
* @param isForward true if propagation is forward in independent variable, false otherwise
3437
* @return current value of maximal time interval between events handler checks (only as a double)
3538
*/
36-
double currentInterval(FieldODEStateAndDerivative<T> state);
39+
double currentInterval(FieldODEStateAndDerivative<T> state, boolean isForward);
3740

3841
}

hipparchus-ode/src/main/java/org/hipparchus/ode/events/FieldDetectorBasedEventState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private FieldODEStateAndDerivative<T> nextCheck(final FieldODEStateAndDerivative
279279
// we have to select some intermediate state
280280
// attempting to split the remaining time in an integer number of checks
281281
final T dt = target.getTime().subtract(done.getTime());
282-
final double maxCheck = detector.getMaxCheckInterval().currentInterval(done);
282+
final double maxCheck = detector.getMaxCheckInterval().currentInterval(done, dt.getReal() >= 0.);
283283
final int n = FastMath.max(1, (int) FastMath.ceil(dt.abs().divide(maxCheck).getReal()));
284284
return n == 1 ? target : interpolator.getInterpolatedState(done.getTime().add(dt.divide(n)));
285285
}

hipparchus-ode/src/test/java/org/hipparchus/ode/TestFieldProblem4.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected BaseDetector(final double maxCheck, final T threshold, final int maxIt
138138
}
139139

140140
public FieldAdaptableInterval<T> getMaxCheckInterval() {
141-
return s -> maxCheck;
141+
return (s, isForward) -> maxCheck;
142142
}
143143

144144
public int getMaxIterationCount() {

hipparchus-ode/src/test/java/org/hipparchus/ode/TestProblem4.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected BaseDetector(final double maxCheck, final double threshold, final int
113113
}
114114

115115
public AdaptableInterval getMaxCheckInterval() {
116-
return s -> maxCheck;
116+
return (s, isForward) -> maxCheck;
117117
}
118118

119119
public int getMaxIterationCount() {

hipparchus-ode/src/test/java/org/hipparchus/ode/events/CloseEventsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,7 @@ private static abstract class BaseDetector implements ODEEventDetector {
20982098

20992099
public BaseDetector(final double maxCheck, final double threshold, final int maxIter,
21002100
Action action, List<Event> events) {
2101-
this.maxCheck = s -> maxCheck;
2101+
this.maxCheck = (s, isForward) -> maxCheck;
21022102
this.maxIter = maxIter;
21032103
this.solver = new BracketingNthOrderBrentSolver(0, threshold, 0, 5);
21042104
this.action = action;
@@ -2382,7 +2382,7 @@ private class ResetChangesSignGenerator implements ODEEventDetector {
23822382

23832383
public ResetChangesSignGenerator(final double y1, final double y2, final double change,
23842384
final double maxCheck, final double threshold, final int maxIter) {
2385-
this.maxCheck = s -> maxCheck;
2385+
this.maxCheck = (s, isForward) -> maxCheck;
23862386
this.maxIter = maxIter;
23872387
this.solver = new BracketingNthOrderBrentSolver(0, threshold, 0, 5);
23882388
this.y1 = y1;

0 commit comments

Comments
 (0)