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.nonstiff; 19 20 import org.apache.commons.math.ode.DerivativeException; 21 import org.apache.commons.math.ode.sampling.AbstractStepInterpolator; 22 import org.apache.commons.math.ode.sampling.StepInterpolator; 23 24 /** 25 * This class implements a linear interpolator for step. 26 * 27 * <p>This interpolator computes dense output inside the last 28 * step computed. The interpolation equation is consistent with the 29 * integration scheme : 30 * 31 * <pre> 32 * y(t_n + theta h) = y (t_n + h) - (1-theta) h y' 33 * </pre> 34 * 35 * where theta belongs to [0 ; 1] and where y' is the evaluation of 36 * the derivatives already computed during the step.</p> 37 * 38 * @see EulerIntegrator 39 * @version $Revision: 782432 $ $Date: 2009-06-07 15:08:26 -0400 (Sun, 07 Jun 2009) $ 40 * @since 1.2 41 */ 42 43 class EulerStepInterpolator 44 extends RungeKuttaStepInterpolator { 45 46 /** Serializable version identifier */ 47 private static final long serialVersionUID = -7179861704951334960L; 48 49 /** Simple constructor. 50 * This constructor builds an instance that is not usable yet, the 51 * {@link AbstractStepInterpolator#reinitialize} method should be called 52 * before using the instance in order to initialize the internal arrays. This 53 * constructor is used only in order to delay the initialization in 54 * some cases. The {@link RungeKuttaIntegrator} class uses the 55 * prototyping design pattern to create the step interpolators by 56 * cloning an uninitialized model and latter initializing the copy. 57 */ 58 public EulerStepInterpolator() { 59 } 60 61 /** Copy constructor. 62 * @param interpolator interpolator to copy from. The copy is a deep 63 * copy: its arrays are separated from the original arrays of the 64 * instance 65 */ 66 public EulerStepInterpolator(final EulerStepInterpolator interpolator) { 67 super(interpolator); 68 } 69 70 /** {@inheritDoc} */ 71 @Override 72 protected StepInterpolator doCopy() { 73 return new EulerStepInterpolator(this); 74 } 75 76 77 /** {@inheritDoc} */ 78 @Override 79 protected void computeInterpolatedStateAndDerivatives(final double theta, 80 final double oneMinusThetaH) 81 throws DerivativeException { 82 83 for (int i = 0; i < interpolatedState.length; ++i) { 84 interpolatedState[i] = currentState[i] - oneMinusThetaH * yDotK[0][i]; 85 } 86 System.arraycopy(yDotK[0], 0, interpolatedDerivatives, 0, interpolatedDerivatives.length); 87 88 } 89 90 }