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 a second order Runge-Kutta integrator for
33   * 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
39   *   1/2 | 1/2   0
40   *       |----------
41   *       |  0    1
42   * </pre>
43   *
44   * @see EulerFieldIntegrator
45   * @see ClassicalRungeKuttaFieldIntegrator
46   * @see GillFieldIntegrator
47   * @see ThreeEighthesFieldIntegrator
48   * @see LutherFieldIntegrator
49   *
50   * @param <T> the type of the field elements
51   */
52  
53  public class MidpointFieldIntegrator<T extends CalculusFieldElement<T>> extends RungeKuttaFieldIntegrator<T> {
54  
55      /** Name of integration scheme. */
56      public static final String METHOD_NAME = MidpointIntegrator.METHOD_NAME;
57  
58      /** Simple constructor.
59       * Build a midpoint integrator with the given step.
60       * @param field field to which the time and state vector elements belong
61       * @param step integration step
62       */
63      public MidpointFieldIntegrator(final Field<T> field, final T step) {
64          super(field, METHOD_NAME, step);
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public T[] getC() {
70          final T[] c = MathArrays.buildArray(getField(), 1);
71          c[0] = getField().getOne().newInstance(0.5);
72          return c;
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public T[][] getA() {
78          final T[][] a = MathArrays.buildArray(getField(), 1, 1);
79          a[0][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 2);
80          return a;
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      public T[] getB() {
86          final T[] b = MathArrays.buildArray(getField(), 2);
87          b[0] = getField().getZero();
88          b[1] = getField().getOne();
89          return b;
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      protected MidpointFieldStateInterpolator<T>
95          createInterpolator(final boolean forward, T[][] yDotK,
96                             final FieldODEStateAndDerivative<T> globalPreviousState,
97                             final FieldODEStateAndDerivative<T> globalCurrentState,
98                             final FieldEquationsMapper<T> mapper) {
99          return new MidpointFieldStateInterpolator<T>(getField(), forward, yDotK,
100                                                     globalPreviousState, globalCurrentState,
101                                                     globalPreviousState, globalCurrentState,
102                                                     mapper);
103     }
104 
105 }