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.sampling;
24  
25  import java.io.Serializable;
26  
27  import org.hipparchus.exception.MathIllegalStateException;
28  import org.hipparchus.ode.ODEStateAndDerivative;
29  import org.hipparchus.ode.sampling.ODEStateInterpolator;
30  
31  /** This interface represents an interpolator over the last step
32   * during an ODE integration.
33   *
34   * <p>The various ODE integrators provide objects implementing this
35   * interface to the step handlers. These objects are often custom
36   * objects tightly bound to the integrator internal algorithms. The
37   * handlers can use these objects to retrieve the state vector at
38   * intermediate times between the previous and the current grid points
39   * (this feature is often called dense output).</p>
40   *
41   * @see org.hipparchus.ode.ODEIntegrator
42   * @see StepHandler
43   * @deprecated as of 1.0, this class is a temporary wrapper between
44   * {@link ODEStateInterpolator} and {@link MigrationStepInterpolator}
45   */
46  @Deprecated
47  class MigrationStepInterpolator implements StepInterpolator {
48  
49      /** Serializable UID. */
50      private static final long serialVersionUID = 20160328L;
51  
52      /** Underlying interpolator. */
53      private final ODEStateInterpolator interpolator;
54  
55      /** Interpolated state. */
56      private ODEStateAndDerivative interpolated;
57  
58      /** Simple constructor.
59       * @param interpolator underlying interpolator
60       */
61      MigrationStepInterpolator(final ODEStateInterpolator interpolator) {
62          this.interpolator = interpolator;
63          this.interpolated = interpolator.getCurrentState();
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      @Deprecated
69      public double getPreviousTime() {
70          return getPreviousState().getTime();
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      @Deprecated
76      public double getCurrentTime() {
77          return getCurrentState().getTime();
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      @Deprecated
83      public double getInterpolatedTime() {
84          return interpolated.getTime();
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      @Deprecated
90      public void setInterpolatedTime(final double time) {
91          interpolated = getInterpolatedState(time);
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      @Deprecated
97      public double[] getInterpolatedState() throws MathIllegalStateException {
98          return interpolated.getPrimaryState();
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     @Deprecated
104     public double[] getInterpolatedDerivatives() throws MathIllegalStateException {
105         return interpolated.getPrimaryDerivative();
106     }
107 
108     /** {@inheritDoc} */
109     @Override
110     @Deprecated
111     public double[] getInterpolatedSecondaryState(final int index) throws MathIllegalStateException {
112         return interpolated.getSecondaryState(index);
113     }
114 
115     /** {@inheritDoc} */
116     @Override
117     @Deprecated
118     public double[] getInterpolatedSecondaryDerivatives(final int index) throws MathIllegalStateException {
119         return interpolated.getSecondaryDerivative(index);
120     }
121 
122     /** {@inheritDoc} */
123     @Override
124     public boolean isForward() {
125         return interpolator.isForward();
126     }
127 
128     /** {@inheritDoc} */
129     @Override
130     public MigrationStepInterpolator copy() throws MathIllegalStateException {
131         return new MigrationStepInterpolator(interpolator);
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     public ODEStateAndDerivative getPreviousState() {
137         return interpolator.getPreviousState();
138     }
139 
140     /** {@inheritDoc} */
141     @Override
142     public boolean isPreviousStateInterpolated() {
143         return interpolator.isPreviousStateInterpolated();
144     }
145 
146     /** {@inheritDoc} */
147     @Override
148     public ODEStateAndDerivative getCurrentState() {
149         return interpolator.getCurrentState();
150     }
151 
152     /** {@inheritDoc} */
153     @Override
154     public boolean isCurrentStateInterpolated() {
155         return interpolator.isCurrentStateInterpolated();
156     }
157 
158     /** {@inheritDoc} */
159     @Override
160     public ODEStateAndDerivative getInterpolatedState(final double time) {
161         return interpolator.getInterpolatedState(time);
162     }
163 
164     /**
165      * Replace the instance with a data transfer object for serialization.
166      * @return data transfer object that will be serialized
167      */
168     private Object writeReplace() {
169         return new DataTransferObject(interpolator, interpolated.getTime());
170     }
171 
172     /** Internal class used only for serialization. */
173     private static class DataTransferObject implements Serializable {
174 
175         /** Serializable UID. */
176         private static final long serialVersionUID = 20160328L;
177 
178         /** Underlying interpolator.
179          * @serial
180          */
181         private final ODEStateInterpolator interpolator;
182 
183         /** Interpolation time.
184          * @serial
185          */
186         private final double time;
187 
188         /** Simple constructor.
189          * @param interpolator underlying interpolator
190          * @param time interpolation time
191          */
192         DataTransferObject(final ODEStateInterpolator interpolator, final double time) {
193             this.interpolator = interpolator;
194             this.time         = time;
195         }
196 
197         /** Replace the deserialized data transfer object with a {@link MigrationStepInterpolator}.
198          * @return replacement {@link MigrationStepInterpolator}
199          */
200         private Object readResolve() {
201             final MigrationStepInterpolator msi = new MigrationStepInterpolator(interpolator);
202             msi.setInterpolatedTime(time);
203             return msi;
204         }
205 
206     }
207 
208 }