1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.hipparchus.ode.events;
19
20 import org.hipparchus.ode.ODEState;
21 import org.hipparchus.ode.ODEStateAndDerivative;
22 import org.hipparchus.ode.sampling.ODEStateInterpolator;
23
24
25
26
27
28 public class StepEndEventState implements EventState {
29
30
31 private final ODEStepEndHandler handler;
32
33
34 private double stepEnd;
35
36
37 private boolean forward;
38
39
40
41
42 public StepEndEventState(final ODEStepEndHandler handler) {
43 this.handler = handler;
44 this.stepEnd = Double.NaN;
45 }
46
47
48
49
50 public ODEStepEndHandler getHandler() {
51 return handler;
52 }
53
54
55 @Override
56 public void init(final ODEStateAndDerivative s0, final double t) {
57 forward = t >= s0.getTime();
58 }
59
60
61
62
63 public void setStepEnd(final double stepEnd) {
64 this.stepEnd = stepEnd;
65 }
66
67
68 @Override
69 public boolean evaluateStep(final ODEStateInterpolator interpolator) {
70 return stepEnd == interpolator.getCurrentState().getTime();
71 }
72
73
74 @Override
75 public double getEventTime() {
76 return stepEnd;
77 }
78
79
80 @Override
81 public EventOccurrence doEvent(final ODEStateAndDerivative state) {
82
83 final Action action = handler.stepEndOccurred(state, forward);
84 final ODEState newState;
85 if (action == Action.RESET_STATE) {
86 newState = handler.resetState(state);
87 } else {
88 newState = state;
89 }
90
91 final EventOccurrence occurrence = new EventOccurrence(action, newState, stepEnd);
92 setStepEnd(Double.NaN);
93 return occurrence;
94
95 }
96
97 }