View Javadoc
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    *      https://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  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  
23  package org.hipparchus.ode.nonstiff;
24  
25  import org.hipparchus.CalculusFieldElement;
26  import org.hipparchus.Field;
27  import org.hipparchus.ode.FieldEquationsMapper;
28  import org.hipparchus.ode.FieldODEStateAndDerivative;
29  import org.hipparchus.util.MathArrays;
30  
31  /**
32   * This class implements the 3/8 fourth order Runge-Kutta
33   * integrator for Ordinary Differential Equations.
34   *
35   * <p>This method is an explicit Runge-Kutta method, its Butcher-array
36   * is the following one :</p>
37   * <pre>
38   *    0  |  0    0    0    0
39   *   1/3 | 1/3   0    0    0
40   *   2/3 |-1/3   1    0    0
41   *    1  |  1   -1    1    0
42   *       |--------------------
43   *       | 1/8  3/8  3/8  1/8
44   * </pre>
45   *
46   * @see EulerFieldIntegrator
47   * @see ClassicalRungeKuttaFieldIntegrator
48   * @see GillFieldIntegrator
49   * @see MidpointFieldIntegrator
50   * @see LutherFieldIntegrator
51   * @param <T> the type of the field elements
52   */
53  
54  public class ThreeEighthesFieldIntegrator<T extends CalculusFieldElement<T>>
55      extends RungeKuttaFieldIntegrator<T> {
56  
57      /** Name of integration scheme. */
58      public static final String METHOD_NAME = ThreeEighthesIntegrator.METHOD_NAME;
59  
60      /** Simple constructor.
61       * Build a 3/8 integrator with the given step.
62       * @param field field to which the time and state vector elements belong
63       * @param step integration step
64       */
65      public ThreeEighthesFieldIntegrator(final Field<T> field, final T step) {
66          super(field, METHOD_NAME, step);
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public T[] getC() {
72          final T[] c = MathArrays.buildArray(getField(), 3);
73          c[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 3);
74          c[1] = c[0].add(c[0]);
75          c[2] = getField().getOne();
76          return c;
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public T[][] getA() {
82          final T[][] a = MathArrays.buildArray(getField(), 3, -1);
83          for (int i = 0; i < a.length; ++i) {
84              a[i] = MathArrays.buildArray(getField(), i + 1);
85          }
86          a[0][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 3);
87          a[1][0] = a[0][0].negate();
88          a[1][1] = getField().getOne();
89          a[2][0] = getField().getOne();
90          a[2][1] = getField().getOne().negate();
91          a[2][2] = getField().getOne();
92          return a;
93      }
94  
95      /** {@inheritDoc} */
96      @Override
97      public T[] getB() {
98          final T[] b = MathArrays.buildArray(getField(), 4);
99          b[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 8);
100         b[1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 3, 8);
101         b[2] = b[1];
102         b[3] = b[0];
103         return b;
104     }
105 
106     /** {@inheritDoc} */
107     @Override
108     protected ThreeEighthesFieldStateInterpolator<T>
109         createInterpolator(final boolean forward, T[][] yDotK,
110                            final FieldODEStateAndDerivative<T> globalPreviousState,
111                            final FieldODEStateAndDerivative<T> globalCurrentState,
112                            final FieldEquationsMapper<T> mapper) {
113         return new ThreeEighthesFieldStateInterpolator<T>(getField(), forward, yDotK,
114                                                          globalPreviousState, globalCurrentState,
115                                                          globalPreviousState, globalCurrentState,
116                                                          mapper);
117     }
118 
119 }