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 /**
21 * This class implements a linear interpolator for step.
22 *
23 * <p>This interpolator allow to compute dense output inside the last
24 * step computed. The interpolation equation is consistent with the
25 * integration scheme :
26 *
27 * <pre>
28 * y(t_n + theta h) = y (t_n + h) - (1-theta) h y'
29 * </pre>
30 *
31 * where theta belongs to [0 ; 1] and where y' is the evaluation of
32 * the derivatives already computed during the step.</p>
33 *
34 * @see EulerIntegrator
35 * @version $Revision: 620312 $ $Date: 2008-02-10 12:28:59 -0700 (Sun, 10 Feb 2008) $
36 * @since 1.2
37 */
38
39 class EulerStepInterpolator
40 extends RungeKuttaStepInterpolator {
41
42 /** Simple constructor.
43 * This constructor builds an instance that is not usable yet, the
44 * {@link AbstractStepInterpolator#reinitialize} method should be called
45 * before using the instance in order to initialize the internal arrays. This
46 * constructor is used only in order to delay the initialization in
47 * some cases. The {@link RungeKuttaIntegrator} class uses the
48 * prototyping design pattern to create the step interpolators by
49 * cloning an uninitialized model and latter initializing the copy.
50 */
51 public EulerStepInterpolator() {
52 }
53
54 /** Copy constructor.
55 * @param interpolator interpolator to copy from. The copy is a deep
56 * copy: its arrays are separated from the original arrays of the
57 * instance
58 */
59 public EulerStepInterpolator(EulerStepInterpolator interpolator) {
60 super(interpolator);
61 }
62
63 /** Really copy the finalized instance.
64 * @return a copy of the finalized instance
65 */
66 protected StepInterpolator doCopy() {
67 return new EulerStepInterpolator(this);
68 }
69
70
71 /** Compute the state at the interpolated time.
72 * This is the main processing method that should be implemented by
73 * the derived classes to perform the interpolation.
74 * @param theta normalized interpolation abscissa within the step
75 * (theta is zero at the previous time step and one at the current time step)
76 * @param oneMinusThetaH time gap between the interpolated time and
77 * the current time
78 * @throws DerivativeException this exception is propagated to the caller if the
79 * underlying user function triggers one
80 */
81 protected void computeInterpolatedState(double theta,
82 double oneMinusThetaH)
83 throws DerivativeException {
84
85 for (int i = 0; i < interpolatedState.length; ++i) {
86 interpolatedState[i] = currentState[i] - oneMinusThetaH * yDotK[0][i];
87 }
88
89 }
90
91 /** Serializable version identifier */
92 private static final long serialVersionUID = -7179861704951334960L;
93
94 }