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.CalculusFieldElement;
21 import org.hipparchus.ode.FieldODEState;
22 import org.hipparchus.ode.FieldODEStateAndDerivative;
23 import org.hipparchus.ode.sampling.FieldODEStateInterpolator;
24
25
26
27
28
29
30 public class FieldStepEndEventState<T extends CalculusFieldElement<T>> implements FieldEventState<T> {
31
32
33 private final FieldODEStepEndHandler<T> handler;
34
35
36 private T stepEnd;
37
38
39 private boolean forward;
40
41
42
43
44 public FieldStepEndEventState(final FieldODEStepEndHandler<T> handler) {
45 this.handler = handler;
46 this.stepEnd = null;
47 }
48
49
50
51
52 public FieldODEStepEndHandler<T> getHandler() {
53 return handler;
54 }
55
56
57 @Override
58 public void init(final FieldODEStateAndDerivative<T> s0, final T t) {
59 forward = t.subtract(s0.getTime()).getReal() >= 0;
60 }
61
62
63
64
65 public void setStepEnd(final T stepEnd) {
66 this.stepEnd = stepEnd;
67 }
68
69
70 @Override
71 public boolean evaluateStep(final FieldODEStateInterpolator<T> interpolator) {
72 return stepEnd != null && stepEnd.subtract(interpolator.getCurrentState().getTime()).isZero();
73 }
74
75
76 @Override
77 public T getEventTime() {
78 return stepEnd;
79 }
80
81
82 @Override
83 public FieldEventOccurrence<T> doEvent(final FieldODEStateAndDerivative<T> state) {
84
85 final Action action = handler.stepEndOccurred(state, forward);
86 final FieldODEState<T> newState;
87 if (action == Action.RESET_STATE) {
88 newState = handler.resetState(state);
89 } else {
90 newState = state;
91 }
92
93 final FieldEventOccurrence<T> occurrence = new FieldEventOccurrence<>(action, newState, stepEnd);
94 setStepEnd(null);
95 return occurrence;
96
97 }
98
99 }