summaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/commons/math3/ode/FirstOrderFieldIntegrator.java
blob: 8d264950030c8935a13742b250d0519c38c94068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.math3.ode;

import org.apache.commons.math3.RealFieldElement;
import org.apache.commons.math3.analysis.solvers.BracketedRealFieldUnivariateSolver;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NoBracketingException;
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.ode.events.FieldEventHandler;
import org.apache.commons.math3.ode.sampling.FieldStepHandler;

import java.util.Collection;

/**
 * This interface represents a first order integrator for differential equations.
 *
 * <p>The classes which are devoted to solve first order differential equations should implement
 * this interface. The problems which can be handled should implement the {@link
 * FirstOrderDifferentialEquations} interface.
 *
 * @see FirstOrderFieldDifferentialEquations
 * @param <T> the type of the field elements
 * @since 3.6
 */
public interface FirstOrderFieldIntegrator<T extends RealFieldElement<T>> {

    /**
     * Get the name of the method.
     *
     * @return name of the method
     */
    String getName();

    /**
     * Add a step handler to this integrator.
     *
     * <p>The handler will be called by the integrator for each accepted step.
     *
     * @param handler handler for the accepted steps
     * @see #getStepHandlers()
     * @see #clearStepHandlers()
     */
    void addStepHandler(FieldStepHandler<T> handler);

    /**
     * Get all the step handlers that have been added to the integrator.
     *
     * @return an unmodifiable collection of the added events handlers
     * @see #addStepHandler(FieldStepHandler)
     * @see #clearStepHandlers()
     */
    Collection<FieldStepHandler<T>> getStepHandlers();

    /**
     * Remove all the step handlers that have been added to the integrator.
     *
     * @see #addStepHandler(FieldStepHandler)
     * @see #getStepHandlers()
     */
    void clearStepHandlers();

    /**
     * Add an event handler to the integrator.
     *
     * <p>The default solver is a 5<sup>th</sup> order {@link
     * org.apache.commons.math3.analysis.solvers.FieldBracketingNthOrderBrentSolver}.
     *
     * @param handler event handler
     * @param maxCheckInterval maximal time interval between switching function checks (this
     *     interval prevents missing sign changes in case the integration steps becomes very large)
     * @param convergence convergence threshold in the event time search
     * @param maxIterationCount upper limit of the iteration count in the event time search events.
     * @see #addEventHandler(FieldEventHandler, double, double, int,
     *     org.apache.commons.math3.analysis.solvers.BracketedRealFieldUnivariateSolver)
     * @see #getEventHandlers()
     * @see #clearEventHandlers()
     */
    void addEventHandler(
            FieldEventHandler<T> handler,
            double maxCheckInterval,
            double convergence,
            int maxIterationCount);

    /**
     * Add an event handler to the integrator.
     *
     * @param handler event handler
     * @param maxCheckInterval maximal time interval between switching function checks (this
     *     interval prevents missing sign changes in case the integration steps becomes very large)
     * @param convergence convergence threshold in the event time search
     * @param maxIterationCount upper limit of the iteration count in the event time search events.
     * @param solver solver to use to locate the event
     * @see #addEventHandler(FieldEventHandler, double, double, int)
     * @see #getEventHandlers()
     * @see #clearEventHandlers()
     */
    void addEventHandler(
            FieldEventHandler<T> handler,
            double maxCheckInterval,
            double convergence,
            int maxIterationCount,
            BracketedRealFieldUnivariateSolver<T> solver);

    /**
     * Get all the event handlers that have been added to the integrator.
     *
     * @return an unmodifiable collection of the added events handlers
     * @see #addEventHandler(FieldEventHandler, double, double, int)
     * @see #clearEventHandlers()
     */
    Collection<FieldEventHandler<T>> getEventHandlers();

    /**
     * Remove all the event handlers that have been added to the integrator.
     *
     * @see #addEventHandler(FieldEventHandler, double, double, int)
     * @see #getEventHandlers()
     */
    void clearEventHandlers();

    /**
     * Get the current value of the step start time t<sub>i</sub>.
     *
     * <p>This method can be called during integration (typically by the object implementing the
     * {@link FirstOrderDifferentialEquations differential equations} problem) if the value of the
     * current step that is attempted is needed.
     *
     * <p>The result is undefined if the method is called outside of calls to <code>integrate</code>
     * .
     *
     * @return current value of the state at step start time t<sub>i</sub>
     */
    FieldODEStateAndDerivative<T> getCurrentStepStart();

    /**
     * Get the current signed value of the integration stepsize.
     *
     * <p>This method can be called during integration (typically by the object implementing the
     * {@link FirstOrderDifferentialEquations differential equations} problem) if the signed value
     * of the current stepsize that is tried is needed.
     *
     * <p>The result is undefined if the method is called outside of calls to <code>integrate</code>
     * .
     *
     * @return current signed value of the stepsize
     */
    T getCurrentSignedStepsize();

    /**
     * Set the maximal number of differential equations function evaluations.
     *
     * <p>The purpose of this method is to avoid infinite loops which can occur for example when
     * stringent error constraints are set or when lots of discrete events are triggered, thus
     * leading to many rejected steps.
     *
     * @param maxEvaluations maximal number of function evaluations (negative values are silently
     *     converted to maximal integer value, thus representing almost unlimited evaluations)
     */
    void setMaxEvaluations(int maxEvaluations);

    /**
     * Get the maximal number of functions evaluations.
     *
     * @return maximal number of functions evaluations
     */
    int getMaxEvaluations();

    /**
     * Get the number of evaluations of the differential equations function.
     *
     * <p>The number of evaluations corresponds to the last call to the <code>integrate</code>
     * method. It is 0 if the method has not been called yet.
     *
     * @return number of evaluations of the differential equations function
     */
    int getEvaluations();

    /**
     * Integrate the differential equations up to the given time.
     *
     * <p>This method solves an Initial Value Problem (IVP).
     *
     * <p>Since this method stores some internal state variables made available in its public
     * interface during integration ({@link #getCurrentSignedStepsize()}), it is <em>not</em>
     * thread-safe.
     *
     * @param equations differential equations to integrate
     * @param initialState initial state (time, primary and secondary state vectors)
     * @param finalTime target time for the integration (can be set to a value smaller than {@code
     *     t0} for backward integration)
     * @return final state, its time will be the same as {@code finalTime} if integration reached
     *     its target, but may be different if some {@link
     *     org.apache.commons.math3.ode.events.FieldEventHandler} stops it at some point.
     * @exception NumberIsTooSmallException if integration step is too small
     * @exception MaxCountExceededException if the number of functions evaluations is exceeded
     * @exception NoBracketingException if the location of an event cannot be bracketed
     */
    FieldODEStateAndDerivative<T> integrate(
            FieldExpandableODE<T> equations, FieldODEState<T> initialState, T finalTime)
            throws NumberIsTooSmallException, MaxCountExceededException, NoBracketingException;
}