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  /**
33   * This class implements the Luther sixth order Runge-Kutta
34   * integrator for Ordinary Differential Equations.
35  
36   * <p>
37   * This method is described in H. A. Luther 1968 paper <a
38   * href="http://www.ams.org/journals/mcom/1968-22-102/S0025-5718-68-99876-1/S0025-5718-68-99876-1.pdf">
39   * An explicit Sixth-Order Runge-Kutta Formula</a>.
40   * </p>
41  
42   * <p>This method is an explicit Runge-Kutta method, its Butcher-array
43   * is the following one :</p>
44   * <pre>
45   *        0   |               0                     0                     0                     0                     0                     0
46   *        1   |               1                     0                     0                     0                     0                     0
47   *       1/2  |              3/8                   1/8                    0                     0                     0                     0
48   *       2/3  |              8/27                  2/27                  8/27                   0                     0                     0
49   *   (7-q)/14 | (  -21 +   9q)/392    (  -56 +   8q)/392    (  336 -  48q)/392    (  -63 +   3q)/392                  0                     0
50   *   (7+q)/14 | (-1155 - 255q)/1960   ( -280 -  40q)/1960   (    0 - 320q)/1960   (   63 + 363q)/1960   ( 2352 + 392q)/1960                 0
51   *        1   | (  330 + 105q)/180    (  120 +   0q)/180    ( -200 + 280q)/180    (  126 - 189q)/180    ( -686 - 126q)/180     ( 490 -  70q)/180
52   *            |--------------------------------------------------------------------------------------------------------------------------------------------------
53   *            |              1/20                   0                   16/45                  0                   49/180                 49/180         1/20
54   * </pre>
55   * <p>where q = &radic;21</p>
56   *
57   * @see EulerFieldIntegrator
58   * @see ClassicalRungeKuttaFieldIntegrator
59   * @see GillFieldIntegrator
60   * @see MidpointFieldIntegrator
61   * @see ThreeEighthesFieldIntegrator
62   * @param <T> the type of the field elements
63   */
64  
65  public class LutherFieldIntegrator<T extends CalculusFieldElement<T>>
66      extends RungeKuttaFieldIntegrator<T> {
67  
68      /** Name of integration scheme. */
69      public static final String METHOD_NAME = LutherIntegrator.METHOD_NAME;
70  
71      /** Simple constructor.
72       * Build a fourth-order Luther integrator with the given step.
73       * @param field field to which the time and state vector elements belong
74       * @param step integration step
75       */
76      public LutherFieldIntegrator(final Field<T> field, final T step) {
77          super(field, METHOD_NAME, step);
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public T[] getC() {
83          final T q = getField().getZero().add(21).sqrt();
84          final T[] c = MathArrays.buildArray(getField(), 6);
85          c[0] = getField().getOne();
86          c[1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 2);
87          c[2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 2, 3);
88          c[3] = q.subtract(7).divide(-14);
89          c[4] = q.add(7).divide(14);
90          c[5] = getField().getOne();
91          return c;
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public T[][] getA() {
97          final T q = getField().getZero().add(21).sqrt();
98          final T[][] a = MathArrays.buildArray(getField(), 6, -1);
99          for (int i = 0; i < a.length; ++i) {
100             a[i] = MathArrays.buildArray(getField(), i + 1);
101         }
102         a[0][0] = getField().getOne();
103         a[1][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 3,  8);
104         a[1][1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1,  8);
105         a[2][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 8, 27);
106         a[2][1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 2, 27);
107         a[2][2] = a[2][0];
108         a[3][0] = q.multiply(   9).add(  -21).divide( 392);
109         a[3][1] = q.multiply(   8).add(  -56).divide( 392);
110         a[3][2] = q.multiply( -48).add(  336).divide( 392);
111         a[3][3] = q.multiply(   3).add(  -63).divide( 392);
112         a[4][0] = q.multiply(-255).add(-1155).divide(1960);
113         a[4][1] = q.multiply( -40).add( -280).divide(1960);
114         a[4][2] = q.multiply(-320)           .divide(1960);
115         a[4][3] = q.multiply( 363).add(   63).divide(1960);
116         a[4][4] = q.multiply( 392).add( 2352).divide(1960);
117         a[5][0] = q.multiply( 105).add(  330).divide( 180);
118         a[5][1] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 2, 3);
119         a[5][2] = q.multiply( 280).add( -200).divide( 180);
120         a[5][3] = q.multiply(-189).add(  126).divide( 180);
121         a[5][4] = q.multiply(-126).add( -686).divide( 180);
122         a[5][5] = q.multiply( -70).add(  490).divide( 180);
123         return a;
124     }
125 
126     /** {@inheritDoc} */
127     @Override
128     public T[] getB() {
129 
130         final T[] b = MathArrays.buildArray(getField(), 7);
131         b[0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(),  1,  20);
132         b[1] = getField().getZero();
133         b[2] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 16,  45);
134         b[3] = getField().getZero();
135         b[4] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 49, 180);
136         b[5] = b[4];
137         b[6] = b[0];
138 
139         return b;
140 
141     }
142 
143     /** {@inheritDoc} */
144     @Override
145     protected LutherFieldStateInterpolator<T>
146         createInterpolator(final boolean forward, T[][] yDotK,
147                            final FieldODEStateAndDerivative<T> globalPreviousState,
148                            final FieldODEStateAndDerivative<T> globalCurrentState,
149                            final FieldEquationsMapper<T> mapper) {
150         return new LutherFieldStateInterpolator<T>(getField(), forward, yDotK,
151                                                   globalPreviousState, globalCurrentState,
152                                                   globalPreviousState, globalCurrentState,
153                                                   mapper);
154     }
155 
156 }