blob: 19d5693c3812609cb4af9f372b217151d09519e0 [file] [log] [blame]
Raymonddee08492015-04-02 10:43:13 -07001/*
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 step interpolator for the 3/8 fourth
25 * order Runge-Kutta integrator.
26 *
27 * <p>This interpolator allows to compute 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)
33 * - (1 - theta) (h/8) [ (1 - 7 theta + 8 theta^2) y'_1
34 * + 3 (1 + theta - 4 theta^2) y'_2
35 * + 3 (1 + theta) y'_3
36 * + (1 + theta + 4 theta^2) y'_4
37 * ]
38 * </pre>
39 *
40 * where theta belongs to [0 ; 1] and where y'_1 to y'_4 are the four
41 * evaluations of the derivatives already computed during the
42 * step.</p>
43 *
44 * @see ThreeEighthesIntegrator
45 * @version $Revision: 1073158 $ $Date: 2011-02-21 22:46:52 +0100 (lun. 21 févr. 2011) $
46 * @since 1.2
47 */
48
49class ThreeEighthesStepInterpolator
50 extends RungeKuttaStepInterpolator {
51
52 /** Serializable version identifier */
53 private static final long serialVersionUID = -3345024435978721931L;
54
55 /** Simple constructor.
56 * This constructor builds an instance that is not usable yet, the
57 * {@link
58 * org.apache.commons.math.ode.sampling.AbstractStepInterpolator#reinitialize}
59 * method should be called before using the instance in order to
60 * initialize the internal arrays. This constructor is used only
61 * in order to delay the initialization in some cases. The {@link
62 * RungeKuttaIntegrator} class uses the prototyping design pattern
63 * to create the step interpolators by cloning an uninitialized model
64 * and later initializing the copy.
65 */
66 public ThreeEighthesStepInterpolator() {
67 }
68
69 /** Copy constructor.
70 * @param interpolator interpolator to copy from. The copy is a deep
71 * copy: its arrays are separated from the original arrays of the
72 * instance
73 */
74 public ThreeEighthesStepInterpolator(final ThreeEighthesStepInterpolator interpolator) {
75 super(interpolator);
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 protected StepInterpolator doCopy() {
81 return new ThreeEighthesStepInterpolator(this);
82 }
83
84
85 /** {@inheritDoc} */
86 @Override
87 protected void computeInterpolatedStateAndDerivatives(final double theta,
88 final double oneMinusThetaH)
89 throws DerivativeException {
90
91 final double fourTheta2 = 4 * theta * theta;
92 final double s = oneMinusThetaH / 8.0;
93 final double coeff1 = s * (1 - 7 * theta + 2 * fourTheta2);
94 final double coeff2 = 3 * s * (1 + theta - fourTheta2);
95 final double coeff3 = 3 * s * (1 + theta);
96 final double coeff4 = s * (1 + theta + fourTheta2);
97 final double coeffDot3 = 0.75 * theta;
98 final double coeffDot1 = coeffDot3 * (4 * theta - 5) + 1;
99 final double coeffDot2 = coeffDot3 * (5 - 6 * theta);
100 final double coeffDot4 = coeffDot3 * (2 * theta - 1);
101
102 for (int i = 0; i < interpolatedState.length; ++i) {
103 final double yDot1 = yDotK[0][i];
104 final double yDot2 = yDotK[1][i];
105 final double yDot3 = yDotK[2][i];
106 final double yDot4 = yDotK[3][i];
107 interpolatedState[i] =
108 currentState[i] - coeff1 * yDot1 - coeff2 * yDot2 - coeff3 * yDot3 - coeff4 * yDot4;
109 interpolatedDerivatives[i] =
110 coeffDot1 * yDot1 + coeffDot2 * yDot2 + coeffDot3 * yDot3 + coeffDot4 * yDot4;
111
112 }
113
114 }
115
116}