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