View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  
23  package org.hipparchus.migration.ode;
24  
25  import org.hipparchus.exception.MathIllegalStateException;
26  import org.hipparchus.ode.DenseOutputModel;
27  
28  /**
29   * This class stores all information provided by an ODE integrator
30   * during the integration process and build a continuous model of the
31   * solution from this.
32   *
33   * <p>This class act as a step handler from the integrator point of
34   * view. It is called iteratively during the integration process and
35   * stores a copy of all steps information in a sorted collection for
36   * later use. Once the integration process is over, the user can use
37   * the {@link #setInterpolatedTime setInterpolatedTime} and {@link
38   * #getInterpolatedState getInterpolatedState} to retrieve this
39   * information at any time. It is important to wait for the
40   * integration to be over before attempting to call {@link
41   * #setInterpolatedTime setInterpolatedTime} because some internal
42   * variables are set only once the last step has been handled.</p>
43   *
44   * <p>This is useful for example if the main loop of the user
45   * application should remain independent from the integration process
46   * or if one needs to mimic the behaviour of an analytical model
47   * despite a numerical model is used (i.e. one needs the ability to
48   * get the model value at any time or to navigate through the
49   * data).</p>
50   *
51   * <p>If problem modeling is done with several separate
52   * integration phases for contiguous intervals, the same
53   * ContinuousOutputModel can be used as step handler for all
54   * integration phases as long as they are performed in order and in
55   * the same direction. As an example, one can extrapolate the
56   * trajectory of a satellite with one model (i.e. one set of
57   * differential equations) up to the beginning of a maneuver, use
58   * another more complex model including thrusters modeling and
59   * accurate attitude control during the maneuver, and revert to the
60   * first model after the end of the maneuver. If the same continuous
61   * output model handles the steps of all integration phases, the user
62   * do not need to bother when the maneuver begins or ends, he has all
63   * the data available in a transparent manner.</p>
64   *
65   * <p>An important feature of this class is that it implements the
66   * <code>Serializable</code> interface. This means that the result of
67   * an integration can be serialized and reused later (if stored into a
68   * persistent medium like a filesystem or a database) or elsewhere (if
69   * sent to another application). Only the result of the integration is
70   * stored, there is no reference to the integrated problem by
71   * itself.</p>
72   *
73   * <p>One should be aware that the amount of data stored in a
74   * ContinuousOutputModel instance can be important if the state vector
75   * is large, if the integration interval is long or if the steps are
76   * small (which can result from small tolerance settings in {@link
77   * org.hipparchus.ode.nonstiff.AdaptiveStepsizeIntegrator adaptive
78   * step size integrators}).</p>
79   *
80   * @see org.hipparchus.migration.ode.sampling.StepHandler
81   * @see org.hipparchus.ode.sampling.ODEStateInterpolator
82   * @deprecated as of 1.0, replaced with {@link DenseOutputModel}
83   */
84  @Deprecated
85  public class ContinuousOutputModel extends DenseOutputModel {
86  
87      /** Serializable version identifier */
88      private static final long serialVersionUID = 20160403L;
89  
90      /** Interpolation time. */
91      private double interpolatedTime;
92  
93      /** Empty constructor.
94       * <p>
95       * This constructor is not strictly necessary, but it prevents spurious
96       * javadoc warnings with JDK 18 and later.
97       * </p>
98       * @since 3.0
99       */
100     public ContinuousOutputModel() { // NOPMD - unnecessary constructor added intentionally to make javadoc happy
101         // nothing to do
102     }
103 
104     /** Set the time of the interpolated point.
105      * <p>This method should <strong>not</strong> be called before the
106      * integration is over because some internal variables are set only
107      * once the last step has been handled.</p>
108      * <p>Setting the time outside of the integration interval is now
109      * allowed, but should be used with care since the accuracy of the
110      * interpolator will probably be very poor far from this interval.
111      * This allowance has been added to simplify implementation of search
112      * algorithms near the interval endpoints.</p>
113      * <p>Note that each time this method is called, the internal arrays
114      * returned in {@link #getInterpolatedState()}, {@link
115      * #getInterpolatedDerivatives()} and {@link #getInterpolatedSecondaryState(int)}
116      * <em>will</em> be overwritten. So if their content must be preserved
117      * across several calls, user must copy them.</p>
118      * @param time time of the interpolated point
119      * @see #getInterpolatedState()
120      * @see #getInterpolatedDerivatives()
121      * @see #getInterpolatedSecondaryState(int)
122      */
123     public void setInterpolatedTime(final double time) {
124         this.interpolatedTime = time;
125     }
126 
127     /**
128      * Get the time of the interpolated point.
129      * If {@link #setInterpolatedTime} has not been called, it returns
130      * the final integration time.
131      * @return interpolation point time
132      */
133     public double getInterpolatedTime() {
134       return interpolatedTime;
135     }
136 
137     /**
138      * Get the state vector of the interpolated point.
139      * <p>The returned vector is a reference to a reused array, so
140      * it should not be modified and it should be copied if it needs
141      * to be preserved across several calls to the associated
142      * {@link #setInterpolatedTime(double)} method.</p>
143      * @return state vector at time {@link #getInterpolatedTime}
144      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
145      * @see #setInterpolatedTime(double)
146      * @see #getInterpolatedDerivatives()
147      * @see #getInterpolatedSecondaryState(int)
148      * @see #getInterpolatedSecondaryDerivatives(int)
149      */
150     public double[] getInterpolatedState() throws MathIllegalStateException {
151       return getInterpolatedState(getInterpolatedTime()).getPrimaryState();
152     }
153 
154     /**
155      * Get the derivatives of the state vector of the interpolated point.
156      * <p>The returned vector is a reference to a reused array, so
157      * it should not be modified and it should be copied if it needs
158      * to be preserved across several calls to the associated
159      * {@link #setInterpolatedTime(double)} method.</p>
160      * @return derivatives of the state vector at time {@link #getInterpolatedTime}
161      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
162      * @see #setInterpolatedTime(double)
163      * @see #getInterpolatedState()
164      * @see #getInterpolatedSecondaryState(int)
165      * @see #getInterpolatedSecondaryDerivatives(int)
166      */
167     public double[] getInterpolatedDerivatives() throws MathIllegalStateException {
168       return getInterpolatedState(getInterpolatedTime()).getPrimaryDerivative();
169     }
170 
171     /** Get the interpolated secondary state corresponding to the secondary equations.
172      * <p>The returned vector is a reference to a reused array, so
173      * it should not be modified and it should be copied if it needs
174      * to be preserved across several calls to the associated
175      * {@link #setInterpolatedTime(double)} method.</p>
176      * @param secondaryStateIndex index of the secondary set, as returned by {@link
177      * org.hipparchus.ode.ExpandableODE#addSecondaryEquations(org.hipparchus.ode.SecondaryODE)
178      * ExpandableODE.addSecondaryEquations(secondary)}
179      * @return interpolated secondary state at the current interpolation date
180      * @see #setInterpolatedTime(double)
181      * @see #getInterpolatedState()
182      * @see #getInterpolatedDerivatives()
183      * @see #getInterpolatedSecondaryDerivatives(int)
184      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
185      */
186     public double[] getInterpolatedSecondaryState(final int secondaryStateIndex)
187       throws MathIllegalStateException {
188       return getInterpolatedState(getInterpolatedTime()).getSecondaryState(secondaryStateIndex);
189     }
190 
191     /** Get the interpolated secondary derivatives corresponding to the secondary equations.
192      * <p>The returned vector is a reference to a reused array, so
193      * it should not be modified and it should be copied if it needs
194      * to be preserved across several calls to the associated
195      * {@link #setInterpolatedTime(double)} method.</p>
196      * @param secondaryStateIndex index of the secondary set, as returned by {@link
197      * org.hipparchus.ode.ExpandableODE#addSecondaryEquations(org.hipparchus.ode.SecondaryODE)
198      * ExpandableODE.addSecondaryEquations(secondary)}
199      * @return interpolated secondary derivatives at the current interpolation date
200      * @see #setInterpolatedTime(double)
201      * @see #getInterpolatedState()
202      * @see #getInterpolatedDerivatives()
203      * @see #getInterpolatedSecondaryState(int)
204      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
205      */
206     public double[] getInterpolatedSecondaryDerivatives(final int secondaryStateIndex)
207       throws MathIllegalStateException {
208       return getInterpolatedState(getInterpolatedTime()).getSecondaryDerivative(secondaryStateIndex);
209     }
210 
211 }