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      /** Simple constructor.
56       * Build a midpoint integrator with the given step.
57       * @param field field to which the time and state vector elements belong
58       * @param step integration step
59       */
60      public MidpointFieldIntegrator(final Field<T> field, final T step) {
61          super(field, "midpoint", step);
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public T[] getC() {
67          final T[] c = MathArrays.buildArray(getField(), 1);
68          c[0] = getField().getOne().multiply(0.5);
69          return c;
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public T[][] getA() {
75          final T[][] a = MathArrays.buildArray(getField(), 1, 1);
76          a[0][0] = fraction(1, 2);
77          return a;
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public T[] getB() {
83          final T[] b = MathArrays.buildArray(getField(), 2);
84          b[0] = getField().getZero();
85          b[1] = getField().getOne();
86          return b;
87      }
88  
89      /** {@inheritDoc} */
90      @Override
91      protected MidpointFieldStateInterpolator<T>
92          createInterpolator(final boolean forward, T[][] yDotK,
93                             final FieldODEStateAndDerivative<T> globalPreviousState,
94                             final FieldODEStateAndDerivative<T> globalCurrentState,
95                             final FieldEquationsMapper<T> mapper) {
96          return new MidpointFieldStateInterpolator<T>(getField(), forward, yDotK,
97                                                      globalPreviousState, globalCurrentState,
98                                                      globalPreviousState, globalCurrentState,
99                                                      mapper);
100     }
101 
102 }