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    *      http://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      /** Set the time of the interpolated point.
94       * <p>This method should <strong>not</strong> be called before the
95       * integration is over because some internal variables are set only
96       * once the last step has been handled.</p>
97       * <p>Setting the time outside of the integration interval is now
98       * allowed, but should be used with care since the accuracy of the
99       * interpolator will probably be very poor far from this interval.
100      * This allowance has been added to simplify implementation of search
101      * algorithms near the interval endpoints.</p>
102      * <p>Note that each time this method is called, the internal arrays
103      * returned in {@link #getInterpolatedState()}, {@link
104      * #getInterpolatedDerivatives()} and {@link #getInterpolatedSecondaryState(int)}
105      * <em>will</em> be overwritten. So if their content must be preserved
106      * across several calls, user must copy them.</p>
107      * @param time time of the interpolated point
108      * @see #getInterpolatedState()
109      * @see #getInterpolatedDerivatives()
110      * @see #getInterpolatedSecondaryState(int)
111      */
112     public void setInterpolatedTime(final double time) {
113         this.interpolatedTime = time;
114     }
115 
116     /**
117      * Get the time of the interpolated point.
118      * If {@link #setInterpolatedTime} has not been called, it returns
119      * the final integration time.
120      * @return interpolation point time
121      */
122     public double getInterpolatedTime() {
123       return interpolatedTime;
124     }
125 
126     /**
127      * Get the state vector of the interpolated point.
128      * <p>The returned vector is a reference to a reused array, so
129      * it should not be modified and it should be copied if it needs
130      * to be preserved across several calls to the associated
131      * {@link #setInterpolatedTime(double)} method.</p>
132      * @return state vector at time {@link #getInterpolatedTime}
133      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
134      * @see #setInterpolatedTime(double)
135      * @see #getInterpolatedDerivatives()
136      * @see #getInterpolatedSecondaryState(int)
137      * @see #getInterpolatedSecondaryDerivatives(int)
138      */
139     public double[] getInterpolatedState() throws MathIllegalStateException {
140       return getInterpolatedState(getInterpolatedTime()).getPrimaryState();
141     }
142 
143     /**
144      * Get the derivatives of the state vector of the interpolated point.
145      * <p>The returned vector is a reference to a reused array, so
146      * it should not be modified and it should be copied if it needs
147      * to be preserved across several calls to the associated
148      * {@link #setInterpolatedTime(double)} method.</p>
149      * @return derivatives of the state vector at time {@link #getInterpolatedTime}
150      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
151      * @see #setInterpolatedTime(double)
152      * @see #getInterpolatedState()
153      * @see #getInterpolatedSecondaryState(int)
154      * @see #getInterpolatedSecondaryDerivatives(int)
155      */
156     public double[] getInterpolatedDerivatives() throws MathIllegalStateException {
157       return getInterpolatedState(getInterpolatedTime()).getPrimaryDerivative();
158     }
159 
160     /** Get the interpolated secondary state corresponding to the secondary equations.
161      * <p>The returned vector is a reference to a reused array, so
162      * it should not be modified and it should be copied if it needs
163      * to be preserved across several calls to the associated
164      * {@link #setInterpolatedTime(double)} method.</p>
165      * @param secondaryStateIndex index of the secondary set, as returned by {@link
166      * org.hipparchus.ode.ExpandableODE#addSecondaryEquations(org.hipparchus.ode.SecondaryODE)
167      * ExpandableODE.addSecondaryEquations(secondary)}
168      * @return interpolated secondary state at the current interpolation date
169      * @see #setInterpolatedTime(double)
170      * @see #getInterpolatedState()
171      * @see #getInterpolatedDerivatives()
172      * @see #getInterpolatedSecondaryDerivatives(int)
173      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
174      */
175     public double[] getInterpolatedSecondaryState(final int secondaryStateIndex)
176       throws MathIllegalStateException {
177       return getInterpolatedState(getInterpolatedTime()).getSecondaryState(secondaryStateIndex);
178     }
179 
180     /** Get the interpolated secondary derivatives corresponding to the secondary equations.
181      * <p>The returned vector is a reference to a reused array, so
182      * it should not be modified and it should be copied if it needs
183      * to be preserved across several calls to the associated
184      * {@link #setInterpolatedTime(double)} method.</p>
185      * @param secondaryStateIndex index of the secondary set, as returned by {@link
186      * org.hipparchus.ode.ExpandableODE#addSecondaryEquations(org.hipparchus.ode.SecondaryODE)
187      * ExpandableODE.addSecondaryEquations(secondary)}
188      * @return interpolated secondary derivatives at the current interpolation date
189      * @see #setInterpolatedTime(double)
190      * @see #getInterpolatedState()
191      * @see #getInterpolatedDerivatives()
192      * @see #getInterpolatedSecondaryState(int)
193      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
194      */
195     public double[] getInterpolatedSecondaryDerivatives(final int secondaryStateIndex)
196       throws MathIllegalStateException {
197       return getInterpolatedState(getInterpolatedTime()).getSecondaryDerivative(secondaryStateIndex);
198     }
199 
200 }