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 package org.apache.commons.math.ode.sampling;
19
20 import java.io.IOException;
21 import java.io.ObjectInput;
22 import java.io.ObjectOutput;
23
24 import org.apache.commons.math.ode.DerivativeException;
25 import org.apache.commons.math.ode.nonstiff.EmbeddedRungeKuttaIntegrator;
26
27 /** This class is a step interpolator that does nothing.
28 *
29 * <p>This class is used when the {@link StepHandler "step handler"}
30 * set up by the user does not need step interpolation. It does not
31 * recompute the state when {@link AbstractStepInterpolator#setInterpolatedTime
32 * setInterpolatedTime} is called. This implies the interpolated state
33 * is always the state at the end of the current step.</p>
34 *
35 * @see StepHandler
36 *
37 * @version $Revision: 782431 $ $Date: 2009-06-07 15:04:37 -0400 (Sun, 07 Jun 2009) $
38 * @since 1.2
39 */
40
41 public class DummyStepInterpolator
42 extends AbstractStepInterpolator {
43
44 /** Simple constructor.
45 * This constructor builds an instance that is not usable yet, the
46 * <code>AbstractStepInterpolator.reinitialize</code> protected method
47 * should be called before using the instance in order to initialize
48 * the internal arrays. This constructor is used only in order to delay
49 * the initialization in some cases. As an example, the {@link
50 * EmbeddedRungeKuttaIntegrator} uses the prototyping design pattern
51 * to create the step interpolators by cloning an uninitialized
52 * model and latter initializing the copy.
53 */
54 public DummyStepInterpolator() {
55 super();
56 }
57
58 /** Simple constructor.
59 * @param y reference to the integrator array holding the state at
60 * the end of the step
61 * @param forward integration direction indicator
62 */
63 public DummyStepInterpolator(final double[] y, final boolean forward) {
64 super(y, forward);
65 }
66
67 /** Copy constructor.
68 * @param interpolator interpolator to copy from. The copy is a deep
69 * copy: its arrays are separated from the original arrays of the
70 * instance
71 */
72 public DummyStepInterpolator(final DummyStepInterpolator interpolator) {
73 super(interpolator);
74 }
75
76 /** Really copy the finalized instance.
77 * @return a copy of the finalized instance
78 */
79 @Override
80 protected StepInterpolator doCopy() {
81 return new DummyStepInterpolator(this);
82 }
83
84 /** Compute the state at the interpolated time.
85 * In this class, this method does nothing: the interpolated state
86 * is always the state at the end of the current step.
87 * @param theta normalized interpolation abscissa within the step
88 * (theta is zero at the previous time step and one at the current time step)
89 * @param oneMinusThetaH time gap between the interpolated time and
90 * the current time
91 * @throws DerivativeException this exception is propagated to the caller if the
92 * underlying user function triggers one
93 */
94 @Override
95 protected void computeInterpolatedStateAndDerivatives(final double theta, final double oneMinusThetaH)
96 throws DerivativeException {
97 System.arraycopy(currentState, 0, interpolatedState, 0, currentState.length);
98 }
99
100 /** Write the instance to an output channel.
101 * @param out output channel
102 * @exception IOException if the instance cannot be written
103 */
104 @Override
105 public void writeExternal(final ObjectOutput out)
106 throws IOException {
107 // save the state of the base class
108 writeBaseExternal(out);
109 }
110
111 /** Read the instance from an input channel.
112 * @param in input channel
113 * @exception IOException if the instance cannot be read
114 */
115 @Override
116 public void readExternal(final ObjectInput in)
117 throws IOException {
118
119 // read the base class
120 final double t = readBaseExternal(in);
121
122 // we can now set the interpolated time and state
123 setInterpolatedTime(t);
124
125 }
126
127 /** Serializable version identifier */
128 private static final long serialVersionUID = 1708010296707839488L;
129
130 }