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