001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.math.ode.sampling;
019    
020    import java.io.IOException;
021    import java.io.ObjectInput;
022    import java.io.ObjectOutput;
023    
024    import org.apache.commons.math.ode.DerivativeException;
025    import org.apache.commons.math.ode.nonstiff.EmbeddedRungeKuttaIntegrator;
026    
027    /** This class is a step interpolator that does nothing.
028     *
029     * <p>This class is used when the {@link StepHandler "step handler"}
030     * set up by the user does not need step interpolation. It does not
031     * recompute the state when {@link AbstractStepInterpolator#setInterpolatedTime
032     * setInterpolatedTime} is called. This implies the interpolated state
033     * is always the state at the end of the current step.</p>
034     *
035     * @see StepHandler
036     *
037     * @version $Revision: 782431 $ $Date: 2009-06-07 15:04:37 -0400 (Sun, 07 Jun 2009) $
038     * @since 1.2
039     */
040    
041    public class DummyStepInterpolator
042      extends AbstractStepInterpolator {
043    
044      /** Simple constructor.
045       * This constructor builds an instance that is not usable yet, the
046       * <code>AbstractStepInterpolator.reinitialize</code> protected method
047       * should be called before using the instance in order to initialize
048       * the internal arrays. This constructor is used only in order to delay
049       * the initialization in some cases. As an example, the {@link
050       * EmbeddedRungeKuttaIntegrator} uses the prototyping design pattern
051       * to create the step interpolators by cloning an uninitialized
052       * model and latter initializing the copy.
053       */
054      public DummyStepInterpolator() {
055        super();
056      }
057    
058      /** Simple constructor.
059       * @param y reference to the integrator array holding the state at
060       * the end of the step
061       * @param forward integration direction indicator
062       */
063      public DummyStepInterpolator(final double[] y, final boolean forward) {
064        super(y, forward);
065      }
066    
067      /** Copy constructor.
068       * @param interpolator interpolator to copy from. The copy is a deep
069       * copy: its arrays are separated from the original arrays of the
070       * instance
071       */
072      public DummyStepInterpolator(final DummyStepInterpolator interpolator) {
073        super(interpolator);
074      }
075    
076      /** Really copy the finalized instance.
077       * @return a copy of the finalized instance
078       */
079      @Override
080      protected StepInterpolator doCopy() {
081        return new DummyStepInterpolator(this);
082      }
083    
084      /** Compute the state at the interpolated time.
085       * In this class, this method does nothing: the interpolated state
086       * is always the state at the end of the current step.
087       * @param theta normalized interpolation abscissa within the step
088       * (theta is zero at the previous time step and one at the current time step)
089       * @param oneMinusThetaH time gap between the interpolated time and
090       * the current time
091       * @throws DerivativeException this exception is propagated to the caller if the
092       * underlying user function triggers one
093       */
094      @Override
095      protected void computeInterpolatedStateAndDerivatives(final double theta, final double oneMinusThetaH)
096        throws DerivativeException {
097          System.arraycopy(currentState, 0, interpolatedState, 0, currentState.length);
098      }
099        
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    }